Skip to content

u.gather(target): send a worker to mine or gather gas - #84

Closed
mstephenhunt wants to merge 1 commit into
scm-js:mainfrom
mstephenhunt:worker-gather
Closed

mstephenhunt wants to merge 1 commit into
scm-js:mainfrom
mstephenhunt:worker-gather

Conversation

@mstephenhunt

@mstephenhunt mstephenhunt commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Not ready to merge

@jeany55 This is my first attempt to create a new function call to make it easier for other people to implement quality of life features. But I want to make sure I actually understand this, really I just threw Claude at it.

My manual tests show this working perfectly, which is encourging!

Why

I wanted newly built workers to start mining on their own when their building is rallied to a mineral patch or a gas building. In Brood War a rallied worker walks there and stands idle, and the Order action can only move, patrol or attack. So a map has no way to give a worker a gather order without writing it into the unit's memory.

What changes

  • u.gather(target) gives a worker the order a right-click would: MoveToMinerals for a mineral field, MoveToGas for a gas building. It writes the order id, order state 0 and the order target.
  • u.orderTarget, u.orderTargetX, u.orderTargetY are new read-only fields. A just-trained worker rallied onto a patch has a Move order to the patch's centre and no target unit. One rallied onto its own player's gas building has Follow with that building as the target. These fields let a program tell those cases apart.
  • Ledger rows for the three new accesses, docs/ir.md, and emitter tests.

The program I built this for uses one on.order listener. It catches an SCV or Probe whose previous order was Nothing, or a Drone leaving ZergBirth, and calls gather when the rally is on a mineral field or on the owner's own finished gas building.

Testing

  • Typecheck, build and the test suite pass (1354 tests), including new emitter tests for gather on a mineral field and on a gas building.
  • In scmjs map trace:
    • Staged SCVs, Probes and Drones reach MiningMinerals or HarvestGas, and their owner's ore or gas rises. Without the program they never do.
    • Rallies on ground, on an unfinished gas building, on another player's gas building, and on a bare geyser leave the worker alone.
    • Workers trained by a computer player come out in the states above.
  • Played in StarCraft: Remastered, on a map where one human player owns a base of each race. Rallied workers of all three races mine minerals and gather gas. Rallies on ground or on an unfinished Refinery behave normally. A worker given another order as it comes out obeys it. No EUD error.

…m a gas building

A right-click's order, written to the worker: MoveToMinerals (85) for a mineral field, MoveToGas (81) for a
gas building, order state 0 and the order target. Three read-only fields go with it, u.orderTarget and
u.orderTargetX / u.orderTargetY, so a program can see where a just-trained worker is headed (a rally on a
patch gives Move to the patch's centre; one on the player's own gas building gives Follow with that target).

Played in StarCraft: Remastered: rallied SCVs, Probes and Drones mine and gather gas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mstephenhunt

Copy link
Copy Markdown
Contributor Author

Superseded by #88, which adds the trigscript/workers autoMining() library on top of u.gather.

@mstephenhunt
mstephenhunt deleted the worker-gather branch November 13, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant