From ad87febd2548dc5b3914220dc390db97692f5bf2 Mon Sep 17 00:00:00 2001 From: leper Date: Thu, 10 May 2012 22:02:59 +0000 Subject: [PATCH] Improve gathering behaviour if the target is exhausted. This was SVN commit r11827. --- .../public/simulation/components/UnitAI.js | 88 ++++++++----------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 29c212c9c7..da123a41b6 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -1051,21 +1051,9 @@ var UnitFsmSpec = { return; } - // If the target is exhausted, we switch to a new target - if (status.exhausted) - { - var nearby = this.FindNearbyResource(function (ent, type, template) { - return ( - type.specific == resourceType.specific - && (type.specific != "meat" || resourceTemplate == template) - ); - }); - if (nearby) - { - this.PerformGather(nearby, false, false); - return; - } - } + // We can gather more from this target, do so in the next timer + if (!status.exhausted) + return; } else { @@ -1090,42 +1078,42 @@ var UnitFsmSpec = { this.SetNextState("APPROACHING"); return; } - - // We're already in range, or can't get anywhere near it. - - // Give up on this order and try our next queued order - if (this.FinishOrder()) - return; - - // No remaining orders - pick a useful default behaviour - - // Try to find a new resource of the same specific type near our current position: - // Also don't switch to a different type of huntable animal - var nearby = this.FindNearbyResource(function (ent, type, template) { - return ( - type.specific == resourceType.specific - && (type.specific != "meat" || resourceTemplate == template) - ); - }); - if (nearby) - { - this.PerformGather(nearby, false, false); - return; - } - - // Nothing else to gather - if we're carrying anything then we should - // drop it off, and if not then we might as well head to the dropsite - // anyway because that's a nice enough place to congregate and idle - - var nearby = this.FindNearestDropsite(resourceType.generic); - if (nearby) - { - this.PushOrderFront("ReturnResource", { "target": nearby, "force": false }); - return; - } - - // No dropsites - just give up } + + // We're already in range, can't get anywhere near it or the target is exhausted. + + // Give up on this order and try our next queued order + if (this.FinishOrder()) + return; + + // No remaining orders - pick a useful default behaviour + + // Try to find a new resource of the same specific type near our current position: + // Also don't switch to a different type of huntable animal + var nearby = this.FindNearbyResource(function (ent, type, template) { + return ( + type.specific == resourceType.specific + && (type.specific != "meat" || resourceTemplate == template) + ); + }); + if (nearby) + { + this.PerformGather(nearby, false, false); + return; + } + + // Nothing else to gather - if we're carrying anything then we should + // drop it off, and if not then we might as well head to the dropsite + // anyway because that's a nice enough place to congregate and idle + + var nearby = this.FindNearestDropsite(resourceType.generic); + if (nearby) + { + this.PushOrderFront("ReturnResource", { "target": nearby, "force": false }); + return; + } + + // No dropsites - just give up }, }, },