Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -533,6 +533,33 @@ }, "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); + // Oh no, couldn't find any dropsites. Give up on gathering. + if (!nearestDropsite) + { + this.FinishOrder(); + return; + } + + this.PushOrderFront("ReturnResource", { + "target": nearestDropsite, + "force": false, + "type": msg.data.type + }); + return; + } + // If the target is still alive, we need to kill it first if (this.MustKillGatherTarget(this.order.data.target)) {