From 0dda3b579c50a087d108428ac8de5aa23d21d518 Mon Sep 17 00:00:00 2001 From: mimo Date: Sun, 20 Dec 2015 21:30:34 +0000 Subject: [PATCH] drop resources before switching to next queued order, fixes #1670 This was SVN commit r17521. --- .../public/simulation/components/ResourceGatherer.js | 9 ++++++++- .../data/mods/public/simulation/components/UnitAI.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/binaries/data/mods/public/simulation/components/ResourceGatherer.js b/binaries/data/mods/public/simulation/components/ResourceGatherer.js index 13ca2f3aa0..acd5fbdd7a 100644 --- a/binaries/data/mods/public/simulation/components/ResourceGatherer.js +++ b/binaries/data/mods/public/simulation/components/ResourceGatherer.js @@ -305,7 +305,14 @@ ResourceGatherer.prototype.GetTargetGatherRate = function(target) ResourceGatherer.prototype.CanCarryMore = function(type) { let amount = (this.carrying[type] || 0); - return (amount < this.GetCapacity(type)); + return amount < this.GetCapacity(type); +}; + + +ResourceGatherer.prototype.IsCarrying = function(type) +{ + let amount = (this.carrying[type] || 0); + return amount > 0; }; /** diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index a30de208d3..a9369e707a 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -2350,6 +2350,16 @@ UnitAI.prototype.UnitFsmSpec = { var herdPos = this.order.data.initPos; // Give up on this order and try our next queued order + // but first check what is our next order and, if needed, insert a returnResource order + let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); + if (cmpResourceGatherer.IsCarrying(resourceType.generic) && + this.orderQueue.length > 1 && this.orderQueue[1] !== "ReturnResource" && + (this.orderQueue[1].type !== "Gather" || this.orderQueue[1].data.type.generic !== resourceType.generic)) + { + let nearby = this.FindNearestDropsite(resourceType.generic); + if (nearby) + this.orderQueue.splice(1, 0, { "type": "ReturnResource", "data": { "target": nearby, "force": false } }); + } if (this.FinishOrder()) return;