From 7ba4b1ffc84a046946afcc635995c37b2c2f308d Mon Sep 17 00:00:00 2001 From: Freagarach Date: Fri, 9 Apr 2021 06:25:47 +0000 Subject: [PATCH] Split dropping resources from approaching in UnitAI. Allows for non-moving entities to drop resources. (When someone checks those cases in the order.) (Also makes it easier for us to implement a duration for the dropping in the future, might we ever want to.) Differential revision: D3817 This was SVN commit r25215. --- .../public/simulation/components/UnitAI.js | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index c1cd263833..53b60f9f54 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -2761,11 +2761,15 @@ UnitAI.prototype.UnitFsmSpec = { }, "MovementUpdate": function(msg) { - // Check the dropsite is in range and we can return our resource there - // (we didn't get stopped before reaching it) + if (msg.likelyFailure || this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer)) + this.SetNextState("DROPPINGRESOURCES"); + }, + }, + + "DROPPINGRESOURCES": { + "enter": function() { let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); - if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && - this.CanReturnResource(this.order.data.target, true, cmpResourceGatherer)) + if (this.CanReturnResource(this.order.data.target, true, cmpResourceGatherer)) { cmpResourceGatherer.CommitResources(this.order.data.target); @@ -2775,26 +2779,17 @@ UnitAI.prototype.UnitFsmSpec = { // Our next order should always be a Gather, // so just switch back to that order. this.FinishOrder(); - return; + return true; } - - if (msg.obstructed) - return; - - // If we are here: we are in range but not carrying the right resources (or resources at all), - // the dropsite was destroyed, or we couldn't reach it, or ownership changed. - // Look for a new one. - let genericType = cmpResourceGatherer.GetMainCarryingType(); - let nearby = this.FindNearestDropsite(genericType); - if (nearby) - { - this.FinishOrder(); - this.PushOrderFront("ReturnResource", { "target": nearby, "force": false }); - return; - } - - // Oh no, couldn't find any drop sites. Give up on returning. + let nearby = this.FindNearestDropsite(cmpResourceGatherer.GetMainCarryingType()); this.FinishOrder(); + if (nearby) + this.PushOrderFront("ReturnResource", { "target": nearby, "force": false }); + + return true; + }, + + "leave": function() { }, }, },