From 54ffd9df94fc00f2b026e33a25396c484afeee98 Mon Sep 17 00:00:00 2001 From: wraitii Date: Mon, 8 Jul 2019 18:06:37 +0000 Subject: [PATCH] Various Unit AI fixes following UM / UAI changes - Garrisoning cleanup (return true in some cases in ENTER when we do change the state) - Fix animal walking speed until D1901 lands - Fix trading behaviour which occasionally bugged out. Differential Revision: https://code.wildfiregames.com/D2045 This was SVN commit r22440. --- .../public/simulation/components/UnitAI.js | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 4b06b38af5..53844d902e 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -2795,9 +2795,8 @@ UnitAI.prototype.UnitFsmSpec = { "GARRISONED": { "enter": function() { - if (this.order.data.target) - var target = this.order.data.target; - else + let target = this.order.data.target; + if (!target) { this.FinishOrder(); return true; @@ -2808,7 +2807,6 @@ UnitAI.prototype.UnitFsmSpec = { // Check that we can garrison here if (this.CanGarrison(target)) - { // Check that we're in range of the garrison target if (this.CheckGarrisonRange(target)) { @@ -2859,7 +2857,10 @@ UnitAI.prototype.UnitFsmSpec = { } if (this.IsTurret()) + { this.SetNextState("IDLE"); + return true; + } return false; } @@ -2878,13 +2879,9 @@ UnitAI.prototype.UnitFsmSpec = { } } - if (!this.CheckTargetRangeExplicit(target, 0, 0) && this.MoveToTarget(target)) - { - this.SetNextState("APPROACHING"); - return false; - } + this.SetNextState("APPROACHING"); + return true; } - } // Garrisoning failed for some reason, so finish the order this.FinishOrder(); return true; @@ -3045,7 +3042,7 @@ UnitAI.prototype.UnitFsmSpec = { "ROAMING": { "enter": function() { // Walk in a random direction - this.SelectAnimation("walk", false, 1); + this.SelectAnimation("move", false, 1); this.SetFacePointAfterMove(false); this.MoveRandomly(+this.template.RoamDistance); // Set a random timer to switch to feeding state @@ -5199,7 +5196,7 @@ UnitAI.prototype.MoveToMarket = function(targetMarket) } this.waypoints = undefined; - return this.MoveToTarget(targetMarket); + return this.MoveToTargetRange(targetMarket, IID_Trader); }; UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket)