Starcraft – How to make worker carry multiple resources

galaxy-editorstarcraft-2

I want to make a rather simple (?) change: I would like Probes (or other workers) to be able to carry multiple minerals at the same time. I would expect the probe to:

  • approach the mineral field
  • gather minerals
  • gather minerals again
  • … and again…
  • and then carry it back to the base

Originally I thought it is a simple data change of the worker:
I thought it could be simple as changing the behavior Carry Mineral Field Minerals->(Basic) Stats; Maximum Stack Count from 1 to 5.
Unfortunately, as soon as a probe gathers the minerals, it automatically returns.

After giving it more thought I figured there may be some built-in trigger, checking if the worker is already carrying minerals – and if that is so – issuing a "Return" order.
Since then I have been digging into available triggers, scripts, unpacking Liberty and Swarm mods, but so far – I could find nothing.

Any ideas? Pointers?

I am new to modding and I don't plan to do anything big. Just want to hack this for some experimentation…

I know how to increase gather time and how to make probe just carry more minerals in a single patch… but I want to specifically make the probe retrigger the gathering multiple times before it returns (and add some delay in between)

Also, I don't care what happens when mixing minerals with gas or any other resource.

Best Answer

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
                )
            )