The flag as a tag
Every unit has a number the game never uses. Without it two processors will pull one squad apart
The walk hands out units in a circle, and the program gets somebody new every time. Worse, the same walk runs in the neighbouring processor — and hands it the very same units. To divide a squad, a unit is tagged:
ucontrol flag 7 0 0 0 0Now its @flag holds a seven. Any processor can read it:
sensor tag @unit @flagThe program hands out numbers: whoever has no tag (zero) gets the next one, whoever has one is
skipped. Three polys get one, two and three, and lastTag stops at three: there is nobody left
to tag.
The tag is always set, not set when needed
Section titled “The tag is always set, not set when needed”It is easy to decide tagging is for complicated cases: “I have one processor, I will just take
mine by walking the list”. That will not work. ubind @poly in every processor walks the
shared list of all the team’s polys, and each has its own counter. Two processors without
tags will inevitably take the same unit and will take it from
each other — silently, without a single error.
So tagging is not a technique for later but the ordinary shape of a program about units:
ubind @polysensor tag @unit @flagjump 0 notEqual tag 0ucontrol flag 1 0 0 0 0While units have no tag the processor sorts them out; tagged ones it skips. The ones that are not its own — those whose tag is somebody else’s — it will never touch.
What it is for
Section titled “What it is for”A flag is the only memory that lives on the unit itself, not in a processor and not in a cell. Every use of it follows from that:
- dividing a squad. Tag
1carries copper, tag2mines, tag3repairs. Every processor looks at the flag and skips the others; - not grabbing the same one twice. Having tagged a unit, the program sees it is already busy — even if it forgot about it between iterations;
- handing a unit to another processor. One tags, the other reads: talking through a flag is cheaper than through a memory cell, and the tag is always on the unit;
- counting your own. A walk plus a tag check tells you how many units have already been assigned.
What a flag cannot do
Section titled “What a flag cannot do”An enemy cannot see the flag — as with everything else on another team’s units. The flag is not shown in the game: no number over the unit, no highlight. And buildings have no flag: there the role of a tag is played by a memory cell or the block’s configuration.
And the numbers have to be agreed on by you: the game will not give two processors different tags, it simply stores a number. Two authors who both chose a one get the same muddle as with no tags at all.
Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.