; Motor
:global double craft_inventory
:local int tier
:local double count
:local double rods
:local double plates
tier = global.int.get("craft_tier:3.8")
count = global.double.get("craft_count:3.8")
gotoif(99, tier < 1 | tier > 10 | count < 1.0)
; ingots
rods = count * 2.0 + max(0.0, ceil((count - craft_inventory * count("screw", tier))/4.0))
;rods: produce("ingot", tier, ceil((rods - craft_inventory * count("rod", tier))/2.0), "shaper")
;wires: produce("ingot", tier, ceil((count - craft_inventory * (count("cable", tier) + count("wire", tier)))/2.0), "refinery")
;plates: produce("ingot", tier, count * 4.0 - craft_inventory * count("plate", tier), "presser")
gotoif(ingots, count <= count("rubber", 1))
global.int.set("craft_status", 412)
global.int.set("craft_require_tier", -1)
global.double.set("craft_require_count", count)
ingots: global.int.set("craft_tier:ingot", tier)
global.double.set("craft_count:ingot", max(0.0, ceil((rods - craft_inventory * count("rod", tier))/2.0)) + max(0.0, ceil((count - craft_inventory * (count("cable", tier) + count("wire", tier)))/2.0)) + max(0.0, count * 4.0 - craft_inventory * count("plate", tier)))
executesync("craft ingot")
gotoif(99, global.int.get("craft_status") > 199)
global.int.set("craft_status:3.8", 1)
execute("craft 3:8:rods")
execute("craft 3:8:wire")
; plates
;plates = count * 4.0
gotoif(wait, count * 4.0 <= craft_inventory * count("plate", tier))
waitwhile(active("presser"))
produce("ingot", tier, count * 4.0 - craft_inventory * count("plate", tier), "presser")
wait: waituntil(global.int.get("craft_status:3.8") >= 7 & count("plate", tier) >= count * 4.0 & count("rod", tier) >= count * 2.0 & count("screw", tier) >= count & count("wire", tier) >= count)
craft("motor", tier, count)