Oh, so much to do~.
Determine what end products are craftable
Determine what materials are required for those products
Determine what elements are required for those materials
Have planets produce elements at random rates.
Set a cap for how much a planet can store total.
Have asteroids produce elements at random rates.
set a cap for how much an asteroid can store total
Have factories convert materials/elements on their planet/space-station to chosen end products/materials
Factories stop producing once materials run out
Factories on planets will not convert if the product is worth less than it's components at local prices.
Ship automatically converts some recipes, like Air, consuming any available resources\