From 6d187f21455ea994a42376bb366760502794c2d1 Mon Sep 17 00:00:00 2001 From: Stan Date: Thu, 12 Nov 2020 11:01:42 +0000 Subject: [PATCH] Do not attempt to gather when full on that resource. After this change, units will move directly to the nearest resource dropsite when they are idle but carrying resources at full capticity, instead of trying to gather, then realising again they are full, and going back to the dropsite. Reviewed by: @Freagarach Comments by: @Angen, @wraitii Differential Revision: https://code.wildfiregames.com/D2791 This was SVN commit r24172. --- .../public/simulation/components/UnitAI.js | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 9288a7bf7c..af5023829b 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -488,6 +488,31 @@ UnitAI.prototype.UnitFsmSpec = { }, "Order.Gather": function(msg) { + if (!this.CanGather(this.order.data.target)) + { + this.SetNextState("INDIVIDUAL.GATHER.FINDINGNEWTARGET"); + return; + } + + // If the unit is full go to the nearest dropsite instead of trying to gather. + // Unless our target is a treasure which we cannot be full enough with (we can't carry treasures). + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + if (msg.data.type.generic !== "treasure" && cmpResourceGatherer && !cmpResourceGatherer.CanCarryMore(msg.data.type.generic)) + { + let nearestDropsite = this.FindNearestDropsite(msg.data.type.generic); + if (nearestDropsite) + this.PushOrderFront("ReturnResource", { + "target": nearestDropsite, + "force": false, + "type": msg.data.type + }); + // Players expect the unit to move, so walk to the target instead of trying to gather. + else if (!this.FinishOrder()) + this.WalkToTarget(msg.data.target, false); + + return; + } + if (this.MustKillGatherTarget(this.order.data.target)) { // Make sure we can attack the target, else we'll get very stuck @@ -5475,7 +5500,7 @@ UnitAI.prototype.SetupTradeRoute = function(target, source, route, queued) this.workOrders.length && this.workOrders[0].type == "Trade") { let cmpTrader = Engine.QueryInterface(this.entity, IID_Trader); - if (cmpTrader.HasBothMarkets() && + if (cmpTrader.HasBothMarkets() && (cmpTrader.GetFirstMarket() == target && cmpTrader.GetSecondMarket() == source || cmpTrader.GetFirstMarket() == source && cmpTrader.GetSecondMarket() == target)) {