1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-03 13:12:11 +02:00

More safe way to fix ghost desync

This commit is contained in:
blubFisch 2022-10-08 18:47:26 +01:00
parent 819b90362c
commit 2dd5843932

View File

@ -808,10 +808,6 @@ local function kill_force(force_name, cause)
end
for _, e in pairs(surface.find_entities_filtered({force = force_name})) do
if e.valid then
e.force = game.forces['neutral']
if e.create_ghost_on_death ~= nil then
e.create_ghost_on_death = false
end
local damage = math_random() * 2.5 - 0.5
if damage > 0 then
if damage >= 1 or e.health == nil then
@ -882,6 +878,14 @@ local function kill_force(force_name, cause)
end
end
local function on_forces_merged()
-- Remove any ghosts that have been moved into neutral after a town is destroyed. This caused desyncs before.
for _, e in pairs(game.surfaces.nauvis.find_entities_filtered({force = 'neutral', type = "entity-ghost"})) do
if e.valid then
e.destroy()
end
end
end
local function setup_neutral_force()
local force = game.forces['neutral']
@ -1155,5 +1159,5 @@ Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_post_entity_died, on_post_entity_died)
Event.add(defines.events.on_console_command, on_console_command)
Event.add(defines.events.on_console_chat, on_console_chat)
Event.add(defines.events.on_forces_merged, on_forces_merged)
return Public