Skip to content

Items: take and drop

A unit is a portable storage slot: one kind of item, a few places and a compulsory delay between trips

tick 0
Unit Bind0
type
Unit Control1
typefromitemamount
Sensor2
=
in
Sensor3
=
in
Sensor4
=
in
@counter0number
cargonullnull
whatnullnull
inStorenullnull
ucontrol itemTake container1 @copper 10 0 0

The poly takes copper out of the store: cargo grows, inStore shrinks. Once the unit is full — and a poly has thirty places — taking stops changing anything.

Field itemTake itemDrop
second where from: a building where to: a building
third which item how many to hand over
fourth how many to take

The difference in fields is no accident: only one kind of item can be taken, and which one has to be said; what a unit hands over is whatever it has — there is nothing to choose from.

Only up close. Transfer works within about six tiles of the building — roughly as far as a player can drag things by hand. The unit is brought in with move first, and only then given the transfer order.

No more often than once every one and a half seconds. Ninety ticks pass between one unit’s two transfers. An order given sooner simply does nothing: no error, no half transfer.

Only your own. Another team’s store will not give to a unit and will not accept from it — the order silently does nothing.

Unlike a store, a unit has one cargo slot: it carries copper or graphite, but not both at once. Take copper and then try to take graphite, and there will be no graphite.

Property What it gives
@totalItems how much it carries in total
@firstItem what exactly it carries: @copper, @graphite or emptiness
@itemCapacity how much fits: 30 on a poly, 20 on a mono, 60 on a mega
tick 0
Unit Bind0
type
Sensor1
=
in
Jump -> 62
if
Unit Control3
typexy
Unit Control4
typefromitemamount
End5
Unit Control6
typexy
Unit Control7
typetoamount
Sensor8
=
in
@counter0number
cargonullnull
deliverednullnull

Here is a whole ferry program. It looks at its cargo and decides where to fly: empty — to the store for copper, full — to the recipient.

ubind @poly
sensor cargo @unit @totalItems
jump 6 greaterThanEq cargo 30
ucontrol move 5 4 0 0 0
ucontrol itemTake container1 @copper 30 0 0
end
ucontrol move 15 4 0 0 0
ucontrol itemDrop container2 30 0 0 0

Three trips and ninety copper have moved into the second store. Note that there is no within and no waiting here at all: the transfer order is issued every iteration and fires by itself as soon as the unit arrives and the delay has passed. Such a ferry is shorter and more reliable than a program that honestly waits for arrival.

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.