Auto-launch silos from test surfaces (already implemented, want me to contribute?)
I had a problem while designing a Fulgora factory in a test lab: In order to test to make sure the throughput of all the parts of my factory were aligned, I needed my rocket silo to consume ingredients continually, as though it would be launching continually. I realized this was pretty trivial to do as a simple mod. It just looks for silos on every EE_TESTSURFACE and if they're in the rocket_ready state it just calls launch_rocket() on them and they head off just fine even thought they don't have a destination. Would you be interested for me to make a PR, including an option in the preferences pane to enable this behaviour?
The only thing I'm not happy with about my implementation is there's no way to enable or disable the behaviour for individual silos. I had considered making it so that this behaviour would only work on silos that had the 'logistics requests from space platforms' toggle turned on, but after digging through all the API docs and looking at all of the Space Age 'mod' files, I cannot for the life of me find where and how that toggle is implemented! Another option is to make it check for a circuit condition.
What do you think?
I would rather have it togglable per-silo. I will add this to the backlog.
I figured out where the "logistics requests from space platforms" setting is stored. Each silo has 3 LuaLogisticsPoint objects, one of them is mode 3 (defines.logistic_mode.requester) which has a single section that is of type defines.logistic_section_type.transitional_request_controlled. That section will be enabled or disabled based on the value of the setting. Here's a full, working script.
-- control.lua
function is_silo_requests_active(silo)
for l,logistics_point in pairs(silo.get_logistic_point()) do
if logistics_point.mode == defines.logistic_mode.requester then
for m,section in pairs(logistics_point.sections) do
if section.type == defines.logistic_section_type.transitional_request_controlled then
return section.active
end
end
end
end
return false
end
function launch_test_surface_rockets()
local ee_prefix="EE_TESTSURFACE_"
for k, ee_surface in pairs(game.surfaces) do
if string.sub(ee_surface.name, 1, string.len(ee_prefix)) == ee_prefix then
for k, silo in pairs(ee_surface.find_entities_filtered{name = 'rocket-silo'}) do
if silo.rocket_silo_status == defines.rocket_silo_status.rocket_ready and is_silo_requests_active(silo) then -- rocket ready
log("Silo ready to launch found on " .. ee_surface.name .. ". Auto-launching now")
silo.launch_rocket()
end
end
end
end
end
script.on_event(defines.events.on_tick, function(event)
if (game.tick % 60) == 0 then
launch_test_surface_rockets()
end
end)
Oh, that is a very elegant solution, I like it!
I will implement it.
Hah, used my professional experience digging into the guts of an under-documented piece of code to figure out how it ticks.
I might replace the string.sub with a string.find for clarity. I suspect there are also more expressive ways of implementing what I wrote. I don't know lua very well.