From b807c39e6a48930c2ab02c357f6bf41e014b0ffe Mon Sep 17 00:00:00 2001 From: wraitii Date: Thu, 18 Jul 2019 19:59:37 +0000 Subject: [PATCH] Restore previous formation behaviour of targeting nearby enemies when idle / aborting orders This restores A23 formation behaviour, changed by 4ca448a686. Units will now start attacking nearby enemies when the formation goes idle (such as when the abort order button is clicked). This introduces a change that formation units that actually go idle will try to move back in formation shape, so it looks more like they're still in formation. Fixes #5519. Differential Revision: https://code.wildfiregames.com/D2097 This was SVN commit r22506. --- .../public/simulation/components/UnitAI.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index dd850eb0db..1ba2bf336a 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -1266,13 +1266,11 @@ UnitAI.prototype.UnitFsmSpec = { this.SetDefaultAnimationVariant(); }, - "IDLE": { - // Formation members do nothing while Idle, but we need the state - // so that they keep the formation variant. - }, + "IDLE": "INDIVIDUAL.IDLE", "WALKING": { "enter": function() { + this.formationOffset = { "x": this.order.data.x, "z": this.order.data.z }; let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); cmpUnitMotion.MoveToFormationOffset(this.order.data.target, this.order.data.x, this.order.data.z); }, @@ -1402,12 +1400,6 @@ UnitAI.prototype.UnitFsmSpec = { // get stuck with an incorrect animation this.SelectAnimation("idle"); - if (this.formationController) - { - this.SetNextState("FORMATIONMEMBER.IDLE"); - return true; - } - // Idle is the default state. If units try, from the IDLE.enter sub-state, to // begin another order, and that order fails (calling FinishOrder), they might // end up in an infinite loop. To avoid this, all methods that could put the unit in @@ -1468,6 +1460,16 @@ UnitAI.prototype.UnitFsmSpec = { if (this.FindNewTargets()) return; // (abort the FSM transition since we may have already switched state) + if (this.formationOffset && this.formationController) + { + this.PushOrder("FormationWalk", { + "target": this.formationController, + "x": this.formationOffset.x, + "z": this.formationOffset.z, + }); + return; + } + if (!this.isIdle) { this.isIdle = true;