Skip to content

Buildings by flag

A building cannot be searched for by type, but it can be searched for by role: core, turret, store, generator

tick 0
Unit Bind0
type
Unit Locate1
locateflagenemy?oreout Xout YoutFoundoutBuild
Unit Locate2
locateflagenemy?oreout Xout YoutFoundoutBuild
Unit Locate3
locateflagenemy?oreout Xout YoutFoundoutBuild
Stop4
@counter0number
enemyXnullnull
enemyYnullnull
enemyFoundnullnull
enemysnullnull
oursXnullnull
oursYnullnull
allyFoundnullnull
oursnullnull
storeXnullnull
storeYnullnull
storeFoundnullnull
storenullnull
ulocate building turret true @copper enemyX enemyY enemyFound enemys
ulocate building turret false @copper oursX oursY allyFound ours

Two lines differing by one word: the first finds an enemy turret on tile 18, the second ours on tile six. It is the third field that decides whose building to look for.

Field What is in it when searching for a building
first building
second the flag: what kind of building it is by role
third true — theirs, false — ours
fourth an item — not needed for this kind of search
fifth and sixth the coordinates of what was found
seventh whether it was found
eighth the building itself, as an object

You cannot search for “a duo” or “a container” — you search for a building with the right flag. The flags are set in advance, in the game itself, and there are ten of them:

Flag Who carries it
core the core
storage container, vault
generator anything that produces power
turret any turret
factory factories: smelters, presses, mixers
repair repair point
battery battery
reactor reactor
drill any drill
shield force projector

A building can carry more than one: a thorium reactor is flagged both generator and reactor — it can be searched for either way.

ulocate gives back not only coordinates but the building as an object — and that is the most valuable part. From then on it is treated like any building:

ulocate building core false @copper x y found core
sensor copperLeft core @copper
sensor intact core @health

No link to that building is needed: sensor reads unlinked blocks too. control, though, does not — it requires a link.

A building’s coordinate is not always whole

Section titled “A building’s coordinate is not always whole”

Look at storeX in the example: 10.5, although the container stands on tile ten.

That is how it should be. A block with an even side — 2×2, 4×4 — has its centre not in the middle of a tile but on its corner, so its coordinates come out with a half. ulocate gives exactly the building’s centre, as sensor @x does.

For ucontrol move that is even handier: the unit flies to the middle of the store rather than to its corner.

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.