From d5c758eef3aa47ea1c1ade058ac574c35ffd467e Mon Sep 17 00:00:00 2001 From: mimo Date: Sun, 27 Sep 2015 17:32:55 +0000 Subject: [PATCH] change immediately to IDLE state when no more orders, fixes #3430 This was SVN commit r17086. --- .../data/mods/public/simulation/components/UnitAI.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 9ce518049c..243509691a 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -3548,7 +3548,14 @@ UnitAI.prototype.FinishOrder = function() } else { - this.SetNextState("IDLE"); + // We must switch to the idle state immediately (and not do a simple SetNextState) + // otherwise we may be in a weird state if a ProcessMessage is triggered (by a MoveStarted + // or MoveCompleted) when starting a new order and before we have set our new state. + let index = this.GetCurrentState().indexOf("."); + if (index != -1) + this.UnitFsm.SwitchToNextState(this, this.GetCurrentState().slice(0,index+1) + "IDLE"); + else + this.SetNextState("IDLE"); // should never happen Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });