Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -1357,6 +1357,7 @@ "IDLE": { "enter": function() { + this.SetAnimationVariant("formation"); if (this.IsAnimal()) this.SetNextState("ANIMAL.IDLE"); else @@ -1374,6 +1375,7 @@ cmpVisual.ReplaceMoveAnimation("walk", cmpFormation.GetFormationAnimation(this.entity, "walk")); cmpVisual.ReplaceMoveAnimation("run", cmpFormation.GetFormationAnimation(this.entity, "run")); } + this.SetAnimationVariant("formation"); this.SelectAnimation("move"); }, @@ -1383,16 +1385,19 @@ // We can only finish this order if the move was really completed. if (!msg.data.error && this.FinishOrder()) return; + + var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); + if (cmpFormation) + cmpFormation.SetInPosition(this.entity); + }, + + "leave": function() { var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); if (cmpVisual) { cmpVisual.ResetMoveAnimation("walk"); cmpVisual.ResetMoveAnimation("run"); } - - var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); - if (cmpFormation) - cmpFormation.SetInPosition(this.entity); }, }, @@ -1559,14 +1564,6 @@ this.RespondToHealableEntities(msg.data.added); }, - "MoveStarted": function() { - this.SelectAnimation("move"); - }, - - "MoveCompleted": function() { - this.SelectAnimation("idle"); - }, - "Timer": function(msg) { if (!this.isIdle) { @@ -1601,7 +1598,6 @@ "leave": function(msg) { this.StopTimer(); - this.SetDefaultAnimationVariant(); }, "MoveCompleted": function() { @@ -1633,7 +1629,6 @@ "leave": function() { this.StopTimer(); delete this.patrolStartPosOrder; - this.SetDefaultAnimationVariant(); }, "Timer": function(msg) { @@ -1680,7 +1675,6 @@ "leave": function(msg) { this.SetMoveSpeed(this.GetWalkSpeed()); this.StopTimer(); - this.SetDefaultAnimationVariant(); }, "MoveStarted": function(msg) { @@ -1746,7 +1740,6 @@ "leave": function(msg) { this.StopTimer(); - this.SetDefaultAnimationVariant(); }, }, }, @@ -1802,9 +1795,6 @@ }, "leave": function() { - // Show carried resources when walking. - this.SetDefaultAnimationVariant(); - this.StopTimer(); }, @@ -1916,7 +1906,6 @@ if (cmpBuildingAI) cmpBuildingAI.SetUnitAITarget(0); this.StopTimer(); - this.SetDefaultAnimationVariant(); }, "Timer": function(msg) { @@ -2057,8 +2046,6 @@ "leave": function() { // Reset normal speed in case it was changed this.SetMoveSpeed(this.GetWalkSpeed()); - // Show carried resources when walking. - this.SetDefaultAnimationVariant(); this.StopTimer(); }, @@ -2202,7 +2189,6 @@ if (cmpSupply) cmpSupply.RemoveGatherer(this.entity); delete this.gatheringTarget; - this.SetDefaultAnimationVariant(); }, }, @@ -2472,6 +2458,7 @@ "APPROACHING": { "enter": function () { + this.SetAnimationVariant("heal"); this.SelectAnimation("move"); this.StartTimer(1000, 1000); }, @@ -2499,6 +2486,7 @@ "HEALING": { "enter": function() { + this.SetAnimationVariant("heal"); var cmpHeal = Engine.QueryInterface(this.entity, IID_Heal); this.healTimers = cmpHeal.GetTimers(); @@ -2573,6 +2561,7 @@ }, "CHASING": { "enter": function () { + this.SetDefaultAnimationVariant("heal"); this.SelectAnimation("move"); this.StartTimer(1000, 1000); }, @@ -2601,14 +2590,11 @@ "RETURNRESOURCE": { "APPROACHING": { "enter": function () { + this.SetDefaultAnimationVariant(); this.SelectAnimation("move"); }, "MoveCompleted": function() { - // Switch back to idle animation to guarantee we won't - // get stuck with the carry animation after stopping moving - this.SelectAnimation("idle"); - // Check the dropsite is in range and we can return our resource there // (we didn't get stopped before reaching it) if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) Index: binaries/data/mods/public/simulation/components/tests/test_UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_UnitAI.js +++ binaries/data/mods/public/simulation/components/tests/test_UnitAI.js @@ -10,6 +10,7 @@ Engine.LoadComponentScript("interfaces/Heal.js"); Engine.LoadComponentScript("interfaces/Health.js"); Engine.LoadComponentScript("interfaces/Pack.js"); +Engine.LoadComponentScript("interfaces/ResourceGatherer.js"); Engine.LoadComponentScript("interfaces/ResourceSupply.js"); Engine.LoadComponentScript("interfaces/Timer.js"); Engine.LoadComponentScript("interfaces/UnitAI.js");