Skip to content

Damaged buildings and checking the find

The fourth kind of search looks for what needs repairing. And on the way, why the answer sometimes sticks

tick 0
Unit Bind0
type
Unit Locate1
locateflagenemy?oreout Xout YoutFoundoutBuild
Sensor2
=
in
Sensor3
=
in
Stop4
@counter0number
damagedXnullnull
damagedYnullnull
foundnullnull
damagednullnull
healthnullnull
limitnullnull
ulocate damaged core true @copper damagedX damagedY found damaged

There are two duos on the map, and one of them is damaged: it has 60 health out of 250. That is the one the search finds — its intact neighbour does not count.

damaged looks only at your own buildings: it does not use the “flag” and “is it theirs” fields at all. It finds the building nearest the unit whose health is below its maximum.

That is exactly what a repairer needs:

ubind @poly
ulocate damaged core true @copper x y found aim
jump 0 equal found 0
ucontrol approach x y 4 0 0

The poly flies up to the damaged building, and repairs it by itself in the game: repairing is its own business and needs no order. All the program has to do is bring it to the work.

That is a general rule for all four kinds of search, not a quirk of damaged.

The answer does not refresh every iteration

Section titled “The answer does not refresh every iteration”

ulocate, like uradar, recomputes its find once every 40 ticks, and in between gives back the previous answer. The reason is simple: walking the whole map is expensive, and a program spins several hundred times a second.

A couple of habits follow from that:

  • do not try to “refresh” a search by repeating the instruction several times in a row: the answer will be the same;
  • do not be surprised that a repaired building counts as damaged for another two thirds of a second.

ulocate has a fourth kind of search — spawn, the point where enemy waves appear. It works the same way: coordinates plus “found”, with no building.

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.