Skip to content

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 0

Now its @flag holds a seven. Any processor can read it:

sensor tag @unit @flag
tick 0
Unit Bind0
type
Sensor1
=
in
Jump -> 62
if
Operation3
=
Unit Control4
typevalue
End5
Operation6
=
End7
@counter0number
tagnullnull
lastTagnullnull
taggednullnull

The 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 @poly
sensor tag @unit @flag
jump 0 notEqual tag 0
ucontrol flag 1 0 0 0 0

While 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.

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 1 carries copper, tag 2 mines, tag 3 repairs. 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.

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.