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

Day 222 of 365 · Pro · Month 8: Production

Checking raw materials

Before the start the chip counts the ingots in storage, calculates the job's need, reports the shortfall and locks the lathe until there is enough.

Lesson 20 min Week 32

What you learn today

  • Check stock before starting
  • Report missing parts
  • Lock

Half done is worse than not started: 30 iron frames ordered, after 18 the iron runs out, and the lathe hangs with a half-finished job. It is better to check beforehand whether the stock is enough.

Counting the stock

The ingots lie in a locker “Eisenlager”. A locker (StructureStorageLocker) has 30 slots. lbns reads one slot of all lockers with that name – the slot index may be a register. A loop adds up all slots:

count:
lbns tmp LOCKER HASH("Eisenlager") i Quantity Sum
add stock stock tmp
add i i 1
blt i SLOTS count

Sum is right here: piece counts add up. If two lockers with that name stand there, Sum counts both. An empty slot returns 0. The 30 passes cost 120 instructions – that just fits into one tick.

The job's need

The quantity comes from a dial “Auftrag”. According to the recipe data an iron frame needs 4 iron. So the need is quantity times 4, the shortfall the need minus the stock – but never negative:

sub short need stock
max short short 0

Locking

If something is missing, the chip sets Lock on the lathe. Then it cannot be operated by hand either until the stock is enough. A player sees the light “Fehlt” and the shortfall and knows what to fetch.

Starting by button only works without the lock. bnez tmp start jumps back before it when locked.

Warning

If the dial is missing, the need becomes NaN, and max with NaN stays NaN. A NaN in short would be dangerous: sgtz returns 0 for it, and the lock would open. That is why the chip explicitly turns NaN into −1, and the lock checks “not equal to 0” instead of “greater than 0”.

If the locker is missing, Sum simply counts 0 ingots. Then the whole need is missing, and the lathe stays locked – exactly right.

Exercise

Task

Count the ingots in all 30 slots of the lockers “Eisenlager”. The dial “Auftrag” gives the quantity, each piece needs 4 iron. Show the shortfall (never negative, −1 with a missing dial) on “Fehlmenge”. If it is not 0, the chip locks the lathe “Drehbank” (Lock 1) and the light “Fehlt” is on. Only without the lock does a press on “Start” start the lathe with Activate 1.

Hints

Hint 1

Counting loop: lbns tmp LOCKER HASH("Eisenlager") i Quantity Sum, add, add i i 1, blt.

Hint 2

Shortfall: sub, max … 0, then turn NaN into −1 with snan and select.

Hint 3

Lock with sne tmp short 0; start only after bnez tmp start.

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