From 05baeae5bdcffeba678484a7c7c6df4be3554e8d Mon Sep 17 00:00:00 2001 From: sanderd17 Date: Wed, 1 Jan 2014 18:17:47 +0000 Subject: [PATCH] fix units not dropping resources when they are already at the resource dropsite (e.g. fields right next to a farmstead). Fixes #2336 This was SVN commit r14472. --- .../public/simulation/components/UnitAI.js | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 7aa1d7a885..269a0f5f76 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -601,22 +601,37 @@ var UnitFsmSpec = { }, "Order.ReturnResource": function(msg) { + // Check if the dropsite is already in range + if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) + { + var cmpResourceDropsite = Engine.QueryInterface(this.order.data.target, IID_ResourceDropsite); + if (cmpResourceDropsite) + { + // Dump any resources we can + var dropsiteTypes = cmpResourceDropsite.GetTypes(); + + Engine.QueryInterface(this.entity, IID_ResourceGatherer).CommitResources(dropsiteTypes); + + // Our next order should always be a Gather, + // so just switch back to that order + this.FinishOrder(); + return; + } + } // Try to move to the dropsite if (this.MoveToTargetRange(this.order.data.target, IID_ResourceGatherer)) { // We've started walking to the target this.SetNextState("INDIVIDUAL.RETURNRESOURCE.APPROACHING"); - } - else - { - // Oops, we can't reach the dropsite. - // Maybe we should try to pick another dropsite, to find an - // accessible one? - // For now, just give up. - this.StopMoving(); - this.FinishOrder(); return; } + // Oops, we can't reach the dropsite. + // Maybe we should try to pick another dropsite, to find an + // accessible one? + // For now, just give up. + this.StopMoving(); + this.FinishOrder(); + return; }, "Order.Trade": function(msg) {