How to kill all biters, spawners, and worms?
Posted: Mon Apr 08, 2019 9:41 pm
I'm trying to update BitersBegone after the mod author said she doesn't have time to do so herself. The mod has two pieces: kill all biters on install, and prevent new biters from forming.
The old method of killing all biters works fine:
(keeping track of how many entities are destroyed so it can print statistics)
This is slow, though, so it's suitable for running the first time a map is loaded after installing a mod, but not suitable for frequent use.
The old method of preventing new biters doesn't seem to work, though:
Also, this method never worked when combined with RSO or another biter creation algorithm, so the original author of Biters Begone! added a method for deleting biters on a new chunk creation event. So for example if we do this:
where clear_biters() is the first block of code, this stops any new biters from forming. However, this is slow. So instead you can pass in the area of the event and do this:
This is reasonably fast, but it has two problems. First, it doesn't kill worms and spawners at the edge of the area. This can be solved by expanding the bounding box:
A second problem it is not quite fast enough, so you get stutters when exploring a lot of new area on a large map.
Looking for alternate ways to kill off all the biters, there is LuaForce::kill_all_units(), but this doesn't kill worms or spawners, just the biters themselves.
Is there any simple solution for quickly killing off all the worms and spawners?
1) a fast way to go from LuaForce to a list of all entities, not just the units
2) a fast way to go from an area to all of the entities in that area (my guess is filtering the entities by area is not optimized)
3) a reliable way to prevent the worms or spawners from ever being created
4) another method I haven't thought of?
Thanks!
The old method of killing all biters works fine:
Code: Select all
for _, surface in pairs(game.surfaces) do
for _, entity in pairs(surface.find_entities_filtered({force="enemy"})) do
if entity.destroy() then num = num + 1 end
end
end
This is slow, though, so it's suitable for running the first time a map is loaded after installing a mod, but not suitable for frequent use.
The old method of preventing new biters doesn't seem to work, though:
Code: Select all
for _, type in pairs(data.raw) do
for _, prototype in pairs(type) do
if prototype.autoplace and prototype.autoplace.force == "enemy" then
prototype.autoplace.peaks = {}
end
end
end
Code: Select all
script.on_event(defines.events.on_chunk_generated, function(event)
clear_biters()
end)
Code: Select all
clear_biters(area)...
for _, surface in pairs(game.surfaces) do
for _, entity in pairs(surface.find_entities_filtered({force="enemy", area=area})) do
if entity.destroy() then num = num + 1 end
end
end
...
script.on_event(defines.events.on_chunk_generated, function(event)
clear_biters(event.area)
end)
Code: Select all
if area then
expanded_area = {}
expanded_area["left_top"] = {}
expanded_area["left_top"]["x"] = area.left_top.x - 16
expanded_area["left_top"]["y"] = area.left_top.y - 16
expanded_area["right_bottom"] = {}
expanded_area["right_bottom"]["x"] = area.right_bottom.x + 16
expanded_area["right_bottom"]["y"] = area.right_bottom.y + 16
end
Looking for alternate ways to kill off all the biters, there is LuaForce::kill_all_units(), but this doesn't kill worms or spawners, just the biters themselves.
Is there any simple solution for quickly killing off all the worms and spawners?
1) a fast way to go from LuaForce to a list of all entities, not just the units
2) a fast way to go from an area to all of the entities in that area (my guess is filtering the entities by area is not optimized)
3) a reliable way to prevent the worms or spawners from ever being created
4) another method I haven't thought of?
Thanks!