Following the idea of user1337 I came with the following idea:
- When a worker is harvesting, remember which mineral field it did it from
- When a worker finished harvesting, remove its cargo and repeat the harvesting order, for the same mineral field, again.
- Have a "stack count" remembering how many times the above point occured. When a threshold is reached, allow the unit to return normally.
- The amount of returned minerals should be multiplied by the amount of stack count.
The first point is to remember, in the unit, which mineral field it is gathering from. The information will be used later when returning. See the question/answer Probe returning: From which mineral field it gathered resources? and Custom variables/fields for units?
(Trigger) onStartGettingResources
Events
TriggerAddEventUnitAbility(null, "ProbeHarvest", 0, c_abilHarvestStageHarvest, false)
TriggerAddEventUnitAbility(null, "DroneHarvest", 0, c_abilHarvestStageHarvest, false)
TriggerAddEventUnitAbility(null, "SCVHarvest", 0, c_abilHarvestStageHarvest, false)
Local Variables
minerals <unit>
EventUnitTargetUnit()
Actions
StoreUnitWithUnit(EventUnit(), "miningFrom", minerals) //custom function for custom "fields" in a unit
The second trigger should occur when a worker finished harvesting. Experiments have shown it is best triggered by change of the unit behavior triggered when it started carrying minerals. Triggering it on ability stage ApproachDropOff
causes short animation stuttering.
(Trigger) onProbeGetResources
Events
TriggerAddEventUnitBehaviorChange(null, "CarryMineralFieldMinerals", c_unitBehaviorChangeActivate)
Conditions
Comparison(UnitGetType(EventUnit()), ==, "Probe")
Actions
GatherResourcesStack("ProbeHarvest", 0) //custom function, see below
.... //Similar triggers for SCV and Drone
(Global variable) g_gatherStackCount <constant int>
4
(Action definition) GatherResourcesStack
Parameters
gatherCommand <Ability Command - Unit>
Local Variables
mineralPatch <unit>
GetUnitWithUnit(EventUnit(), "miningFrom")
stackCount <int>
GetIntWithUnit(EventUnit(), "minigStackCount")
Actions
SetVariable(stackCount, ArithmeticInt(stackCount, +, 1))
IfThenElse()
if
Comparison(stackCount, <, g_gatherStackCount)
then
UnitSetPropertyFixed(EventUnit(), c_unitPropCarriedMinerals, 0.0)
StoreIntWithUnit(EventUnit(), "miningStackCount", stackCount)
UnitBehaviorRemove(EventUnit(), "CarryMineralFieldMinerals", 1)
UnitIssueOrder(EventUnit(), OrderTargetingUnit(gatherCommand, mineralPatch), c_orderQueueReplace)
else
StoreIntWithUnit(EventUnit(), "miningStackCount", 0)
UnitSetPropertyFixed(EventUnit(), c_unitPropCarriedMinerals,
ArithmeticReal(
UnitGetPropertyFixed(EventUnit(), c_unitPropCarriedMinerals, c_unitPropCurrent),
*, g_gatherStackCount
)
)
UnitBehaviorRemove(... , "CarryMineralFieldMinerals",1
), but the worker is still making an empty trip back-and-forth. Any ideas how to reissue the gathering order on the mineral patch?