drop resources before switching to next queued order, fixes #1670

This was SVN commit r17521.
This commit is contained in:
mimo
2015-12-20 21:30:34 +00:00
parent d4d05c6236
commit 0dda3b579c
2 changed files with 18 additions and 1 deletions
@@ -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;
};
/**
@@ -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;