From a4c698ac48abe1b59f7fbb7cc318911afa6cd249 Mon Sep 17 00:00:00 2001 From: wraitii Date: Mon, 8 Feb 2021 10:20:34 +0000 Subject: [PATCH] Fix units restarting orders when tasked to attack/gather/repair/heal same unit. FSM states would be left/re-entered, resetting the timer, which did not happen pre a16e7c0a56 and is undesirable in general. This explicitly checks for a few cases where timers are relevant. Essentially a Patch by: Freagarach Differential Revision: https://code.wildfiregames.com/D3531 This was SVN commit r24855. --- .../public/simulation/components/UnitAI.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 5eeca513b0..a20b1f7bab 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -5586,6 +5586,16 @@ UnitAI.prototype.Attack = function(target, allowCapture = true, queued = false) this.RememberTargetPosition(order); + if (this.order && this.order.type == "Attack" && + this.order.data && + this.order.data.target === order.target && + this.order.data.allowCapture === order.allowCapture) + { + this.order.data.lastPos = order.lastPos; + this.order.data.force = order.force; + return; + } + this.AddOrder("Attack", order, queued); }; @@ -5672,6 +5682,16 @@ UnitAI.prototype.PerformGather = function(target, queued, force) this.RememberTargetPosition(order); order.initPos = order.lastPos; + if (this.order && + (this.order.type == "Gather" || this.order.type == "Attack") && + this.order.data && + this.order.data.target === order.target) + { + this.order.data.lastPos = order.lastPos; + this.order.data.force = order.force; + return; + } + this.AddOrder("Gather", order, queued); }; @@ -5701,6 +5721,14 @@ UnitAI.prototype.Heal = function(target, queued) return; } + if (this.order && this.order.type == "Heal" && + this.order.data && + this.order.data.target === target) + { + this.order.data.force = true; + return; + } + this.AddOrder("Heal", { "target": target, "force": true }, queued); }; @@ -5890,6 +5918,15 @@ UnitAI.prototype.Repair = function(target, autocontinue, queued) return; } + if (this.order && this.order.type == "Repair" && + this.order.data && + this.order.data.target === target && + this.order.data.autocontinue === autocontinue) + { + this.order.data.force = true; + return; + } + this.AddOrder("Repair", { "target": target, "autocontinue": autocontinue, "force": true }, queued); };