From d5ff29d181dc1f76cb6542360e74fec7505ee8f2 Mon Sep 17 00:00:00 2001 From: mimo Date: Wed, 26 Mar 2014 09:11:06 +0000 Subject: [PATCH] fix a flaw in UnitAI trade management This was SVN commit r14868. --- .../public/simulation/components/UnitAI.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 39781c106e..0850dc3152 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -2513,7 +2513,10 @@ var UnitFsmSpec = { "MoveCompleted": function() { if (this.waypoints && this.waypoints.length) - this.MoveToMarket(this.order.data.firstMarket); + { + if (!this.MoveToMarket(this.order.data.firstMarket)) + this.stopTrading(); + } else this.PerformTradeAndMoveToNextMarket(this.order.data.firstMarket, this.order.data.secondMarket, "APPROACHINGSECONDMARKET"); }, @@ -2526,7 +2529,10 @@ var UnitFsmSpec = { "MoveCompleted": function() { if (this.waypoints && this.waypoints.length) - this.MoveToMarket(this.order.data.secondMarket); + { + if (!this.MoveToMarket(this.order.data.secondMarket)) + this.stopTrading(); + } else this.PerformTradeAndMoveToNextMarket(this.order.data.secondMarket, this.order.data.firstMarket, "APPROACHINGFIRSTMARKET"); }, @@ -5064,13 +5070,6 @@ UnitAI.prototype.MoveToMarket = function(targetMarket) var ok = this.MoveToTarget(targetMarket); } - if (!ok) - { - // We can't reach the market. Give up. - this.StopMoving(); - this.StopTrading(); - } - return ok; }; @@ -5114,6 +5113,7 @@ UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket, nextM UnitAI.prototype.StopTrading = function() { + this.StopMoving(); this.FinishOrder(); var cmpTrader = Engine.QueryInterface(this.entity, IID_Trader); cmpTrader.StopTrading();