1
0
forked from 0ad/0ad

Do not attempt to gather when full on that resource.

After this change, units will move directly to the nearest resource
dropsite when they are idle but carrying resources at full capticity,
instead of trying to gather, then realising again they are full, and
going back to the dropsite.

Reviewed by: @Freagarach
Comments by: @Angen, @wraitii
Differential Revision: https://code.wildfiregames.com/D2791
This was SVN commit r24172.
This commit is contained in:
Stan 2020-11-12 11:01:42 +00:00
parent 66cc595c53
commit 6d187f2145

View File

@ -488,6 +488,31 @@ UnitAI.prototype.UnitFsmSpec = {
},
"Order.Gather": function(msg) {
if (!this.CanGather(this.order.data.target))
{
this.SetNextState("INDIVIDUAL.GATHER.FINDINGNEWTARGET");
return;
}
// If the unit is full go to the nearest dropsite instead of trying to gather.
// Unless our target is a treasure which we cannot be full enough with (we can't carry treasures).
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
if (msg.data.type.generic !== "treasure" && cmpResourceGatherer && !cmpResourceGatherer.CanCarryMore(msg.data.type.generic))
{
let nearestDropsite = this.FindNearestDropsite(msg.data.type.generic);
if (nearestDropsite)
this.PushOrderFront("ReturnResource", {
"target": nearestDropsite,
"force": false,
"type": msg.data.type
});
// Players expect the unit to move, so walk to the target instead of trying to gather.
else if (!this.FinishOrder())
this.WalkToTarget(msg.data.target, false);
return;
}
if (this.MustKillGatherTarget(this.order.data.target))
{
// Make sure we can attack the target, else we'll get very stuck
@ -5475,7 +5500,7 @@ UnitAI.prototype.SetupTradeRoute = function(target, source, route, queued)
this.workOrders.length && this.workOrders[0].type == "Trade")
{
let cmpTrader = Engine.QueryInterface(this.entity, IID_Trader);
if (cmpTrader.HasBothMarkets() &&
if (cmpTrader.HasBothMarkets() &&
(cmpTrader.GetFirstMarket() == target && cmpTrader.GetSecondMarket() == source ||
cmpTrader.GetFirstMarket() == source && cmpTrader.GetSecondMarket() == target))
{