Index: ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js +++ ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js @@ -925,10 +925,13 @@ let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); cmpFormation.SetRearrange(false); this.StartTimer(0, 2000); + this.isIdle = true; + this.CallMemberFunction("ResetIdle"); return false; }, "leave": function() { + this.isIdle = false; this.StopTimer(); }, @@ -1611,6 +1614,13 @@ this.WalkToHeldPosition()) return; + if (this.IsFormationMember()) + { + let cmpFormationAI = Engine.QueryInterface(this.formationController, IID_UnitAI); + if (!cmpFormationAI || !cmpFormationAI.IsIdle()) + return; + } + this.isIdle = true; Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); } @@ -3531,6 +3541,18 @@ return this.isIdle; }; +/** + * Used by formation controllers to toggle the idleness of their members. + */ +UnitAI.prototype.ResetIdle = function() +{ + let shouldBeIdle = this.GetCurrentState().endsWith(".IDLE"); + if (this.isIdle == shouldBeIdle) + return; + this.isIdle = shouldBeIdle; + Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); +}; + UnitAI.prototype.IsGarrisoned = function() { return this.isGarrisoned;