Vending Machine Export IC10
From Unofficial Stationeers Wiki
This solution will export a given quantity of the specified item from a vending machine.
Contents
Required Items
- 1 x Vending Machine
- 1 x Integrated Circuit (IC10)
- 1 x IC Housing
- 1 x Stacker
- 1 x Sorter
- 2 x Logic Memory
- Cables and Chutes
Source code: |
---|
#Vending machine item exporter alias rTemp r0 alias rTemp2 r1 alias rSorterBusy r6 alias rSorterOutput r7 alias rBusy r2 alias rReqHash r9 alias rReqCount r10 alias rMaxUnitStack r11 alias rStackerCount r12 alias rStackerSetting r13 alias dVender d0 alias dStacker d1 alias dSorter d2 alias dMemHash d3 alias dMemCount d4 #alias dStartExport d5 main: yield l rBusy dMemCount Setting beqz rBusy main l rBusy dMemHash Setting beqz rBusy main jal _Configuration l rReqCount dMemCount Setting l rReqHash dMemHash Setting s dMemCount Setting 0 jal _ExportItem j main _Configuration: s dSorter Mode 0 s dStacker Mode 1 s dStacker ClearMemory 1 s dSorter ClearMemory 1 s dVender ClearMemory 1 j ra _ExportItem: push ra ExportItemLoop: ls rTemp dStacker 2 Quantity s dVender RequestHash rReqHash #wait for item to arrive ls rTemp2 dStacker 2 Quantity breq rTemp rTemp2 -1 ls rStackerCount dStacker 2 Quantity ls rMaxUnitStack dStacker 2 MaxQuantity jal _WaitForDevices s db Setting rMaxUnitStack min rStackerSetting rReqCount rMaxUnitStack min rStackerSetting rStackerSetting rStackerCount breq rStackerCount rMaxUnitStack 2 bgt rReqCount rStackerCount ExportItemLoop s dStacker Setting rStackerSetting move rSorterOutput 0 jal _RunStacker ls rStackerCount dStacker 2 Quantity sub rReqCount rReqCount rStackerSetting bgtz rReqCount ExportItemLoop #done, route any leftovers to the vender beqz rStackerCount ExportItemExit s dStacker Setting rStackerCount move rSorterOutput 1 jal _RunStacker #wait for item to arrive l rTemp dVender ImportCount l rTemp2 dVender ImportCount breq rTemp rTemp2 -1 ExportItemExit: pop ra j ra _RunStacker: push ra s dSorter Output rSorterOutput l rTemp dSorter ImportCount s dStacker Output 1 #wait for item to arrive l rTemp2 dSorter ImportCount breq rTemp rTemp2 -1 jal _WaitForDevices pop ra j ra _WaitForDevices: yield ls rBusy dSorter 0 Occupied bgtz rBusy _WaitForDevices ls rBusy dSorter 1 Occupied bgtz rBusy _WaitForDevices ls rBusy dSorter 2 Occupied bgtz rBusy _WaitForDevices ls rBusy dVender 0 Occupied bgtz rBusy _WaitForDevices ls rBusy dVender 1 Occupied bgtz rBusy _WaitForDevices #if the stacker is full so we skip it beq rStackerCount rMaxUnitStack WaitEnd ls rBusy dStacker 0 Occupied bgtz rBusy _WaitForDevices ls rBusy dStacker 1 Occupied bgtz rBusy _WaitForDevices WaitEnd: j ra |
Setup
- Place all components listed above and connect them using Cables and Chutes as shown in the picture. (For cables just connect everything)
- Load the code into the IC and turn everything on
Usage
- Set the two memory modules with the quantity and the hash of the item.
- Unless busy, the IC will set the quantity memory to zero and start the export process.
- Excess items will be routed back into the vending machine.
NOTE: The IC can handle split stacks of small quantities in the vending machine or exporting more than one stack. It does NOT handle having insufficient items in the vending machine and will halt until you fill it and export it manually (or reset the whole process)
How It Works
Control And Initialization
- Wait until both memory modules have a non-zero value, then configure the sorter and stacker with the right mode and reset their counters. Reset the memory module for quantity.
Main ExportItem Loop
- Request the item from the vender and wait for it to arrive into the stacker, then run _WaitForDevices to make sure nothing is busy.
- Calculate the setting for the stacker depending on the remaining items, the quantity inside the stacker and the maximum stacking size (in manual mode, it won't do anything until the Output parameter is set to 1)
- Either make another request from the vender, or flush the stacker if it's full.
- Make more requests if there are remaining items, or empty the stacker and route any excess items back into the vender.
_RunStacker
- Set the output of the sorter, run the stacker and wait for the item to arrive in the sorter.
_WaitForDevices
- Makes sure none of the devices have occupied import/export slots - the exception being the stacker, since it may have a full processing slot and items stuck in the import slot (for example when the vender exports 30 coal twice in a row. 50 will be in the processing slot and 10 in import.)