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.
This commit is contained in:
parent
6023a273df
commit
7ba4b1ffc8
@ -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() {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user