stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 257

Day 257 of 365 · Pro · Month 9: Logistics and greenhouse

Harvest logistics

From the Harvie into storage: count slots in a loop, Sum for real quantities, detect a jam at the export and stop the Harvie when the store is full.

Lesson 18 min Week 37

What you learn today

  • Collect the harvest
  • Count storage
  • Avoid overflow

The Harvie puts every harvest into its export slot. From there it goes on through a chute, in the simplest case into a fridge. If that fills up, everything backs up to the Harvie, and the next ripe plant cannot be harvested.

The way of the harvest

  1. The Harvie harvests, the produce lands in slot 1 (export).
  2. Through the export port it goes into a chute.
  3. At the end there is a store: fridge (StructureFridgeBig, 15 slots) or locker (StructureStorageLocker, 30 slots).

A fridge slows down the decay of food. That makes it the better choice for the harvest.

Counting the store

Every slot reports Quantity (number of items) and Occupied. For the sum over all slots you walk through the slot numbers with a loop. lbns with Sum adds each number over all fridges of the same name. Here Sum is right, because quantities really add up.

move total 0
move used 0
move idx 0
count:
lbns tmp FRIDGE HASH("Vorrat") idx Quantity Sum
add total total tmp
lbns tmp FRIDGE HASH("Vorrat") idx Occupied Sum
add used used tmp
add idx idx 1
blt idx SLOTS count

15 passes with six instructions are 90 instructions, which fits into one tick. With a locker of 30 slots it would be 180. Then the loop spreads over two ticks by itself, because the chip pauses after 128 instructions. So always evaluate the result only after the loop.

Avoiding overflow

Occupied with Sum counts the occupied slots. If all are occupied, the store is full – more precisely: almost full, because a stack can still grow. For the Harvie a simple rule is enough:

  • store full or Harvie export slot occupied → Harvie off, light on.
  • An occupied export slot means: the chute takes nothing more.
sge stop used CAPACITY                            # all occupied
lbns tmp HARVIE HASH("Ernter") 1 Occupied Average   # export full?
sgtz tmp tmp
or stop stop tmp
Warning

Sum returns 0 without a matching device, not NaN. A removed fridge then looks like an empty one – and the Harvie harvests into nowhere. Check presence separately, for example with PrefabHash and Average: without a device that gives NaN.

Tip

Two fridges of the same name have 30 slots together, but the loop still only runs over the numbers 0 to 14 – lbns adds each number over both. That is why there are two defines: SLOTS for the loop, CAPACITY for the total.

Diagram

A locker with numbered slots Locker (d0) Slot 0 Iron ore Occ 1 Qty 5 Slot 1 Copper ore Occ 1 Qty 12 Slot 2 empty Occ 0 Qty 0 Slot 3 empty Occ 0 Qty 0 ls r0 d0 0 Occupied r0 = 1 ls r1 d0 1 Quantity r1 = 12 Slots count from 0. Values in a slot are called LogicSlotTypes.
lbns with Sum adds one slot number over all fridges of the same name, the loop walks through all numbers.

Exercise

Task

The Harvie “Ernter” delivers into the fridge “Vorrat” (15 slots). Write a chip that every tick:

  • counts all 15 slots and shows the total number of items on the display “Vorrat”
  • switches the Harvie off and the light “Lager” on when all slots are occupied, the Harvie's export slot 1 is occupied or the fridge is missing
  • otherwise switches the Harvie on and the light off
  • shows −1 without the fridge

Hints

Hint 1

Loop with idx from 0 to 14, inside two lbns … Sum for Quantity and Occupied.

Hint 2

Full: sge stop used CAPACITY. Jam: lbns on slot 1 of the Harvie.

Hint 3

Presence: lbn tmp FRIDGE HASH("Vorrat") PrefabHash Average and snan.

Quiz

4 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere