diff --git a/map_gen/maps/diggy/feature/alien_spawner.lua b/map_gen/maps/diggy/feature/alien_spawner.lua index 5e6b3471..fa136537 100644 --- a/map_gen/maps/diggy/feature/alien_spawner.lua +++ b/map_gen/maps/diggy/feature/alien_spawner.lua @@ -76,7 +76,7 @@ local do_alien_mining = Token.register(function(params) for rock_index = rock_count, 1, -1 do local rock = rocks[rock_index] - raise_event(defines.events.on_entity_died, {entity = rock}) + raise_event(defines.events.script_raised_destroy, {entity = rock, cause = "alien_emerges"}) destroy_rock(create_particle, particle_count, rock.position) rock.destroy() end diff --git a/map_gen/maps/diggy/feature/diggy_cave_collapse.lua b/map_gen/maps/diggy/feature/diggy_cave_collapse.lua index 4175c704..8b843f3e 100644 --- a/map_gen/maps/diggy/feature/diggy_cave_collapse.lua +++ b/map_gen/maps/diggy/feature/diggy_cave_collapse.lua @@ -279,6 +279,19 @@ local function on_entity_died(event) end end +local function script_raised_destroy(event) + local cause = event.cause + if cause and not (cause == "room_clearing" or cause == "die_faster" or cause == "alien_emerges") then + return + end + local entity = event.entity + local name = entity.name + local strength = support_beam_entities[name] + if strength then + stress_map_add(entity.surface, entity.position, strength, false, player_index) + end +end + local function on_built_entity(event) local entity = event.created_entity local strength = support_beam_entities[entity.name] @@ -386,6 +399,7 @@ function DiggyCaveCollapse.register(cfg) Event.add(defines.events.on_built_entity, on_built_entity) Event.add(Template.events.on_placed_entity, on_placed_entity) Event.add(defines.events.on_entity_died, on_entity_died) + Event.add(defines.events.script_raised_destroy, script_raised_destroy) Event.add(defines.events.on_player_mined_entity, on_mined_entity) Event.add(Template.events.on_void_removed, on_void_removed) Event.add(defines.events.on_surface_created, on_surface_created) diff --git a/map_gen/maps/diggy/feature/diggy_hole.lua b/map_gen/maps/diggy/feature/diggy_hole.lua index 5e3a8e83..05847853 100644 --- a/map_gen/maps/diggy/feature/diggy_hole.lua +++ b/map_gen/maps/diggy/feature/diggy_hole.lua @@ -164,12 +164,23 @@ function DiggyHole.register(cfg) if not is_diggy_rock(name) then return end - diggy_hole(entity) - if event.cause then - destroy_rock(entity.surface.create_particle, 10, entity.position) + if event.loot then + event.loot.clear() end + diggy_hole(entity) end) + Event.add(defines.events.script_raised_destroy, function (event) + local entity = event.entity + local name = entity.name + if not is_diggy_rock(name) then + return + end + diggy_hole(entity) + end) + + -- Checks for when a diggy rock is about to die due to damage and destroys it instead + -- better performance than entity.die() especially when large amounts of rocks are damaged, i.e. due to damaged reactor or nuke Event.add(defines.events.on_entity_damaged, function (event) local entity = event.entity local name = entity.name @@ -181,8 +192,9 @@ function DiggyHole.register(cfg) if not is_diggy_rock(name) then return end - - raise_event(defines.events.on_entity_died, {entity = entity, cause = event.cause, force = event.force}) + + raise_event(defines.events.script_raised_destroy, {entity = entity, cause = "die_faster"}) + destroy_rock(entity.surface.create_particle, 10, entity.position) entity.destroy() end) @@ -205,9 +217,7 @@ function DiggyHole.register(cfg) local force = event.robot.force if health < 1 then - raise_event(defines.events.on_entity_died, {entity = entity, force = force}) - mine_rock(create_particle, 6, position) - entity.destroy() + entity.die(force) return end entity.destroy() diff --git a/map_gen/maps/diggy/feature/simple_room_generator.lua b/map_gen/maps/diggy/feature/simple_room_generator.lua index 946a61bb..945c6250 100644 --- a/map_gen/maps/diggy/feature/simple_room_generator.lua +++ b/map_gen/maps/diggy/feature/simple_room_generator.lua @@ -35,7 +35,7 @@ local do_mine = Token.register(function(params) for i = rock_count, 1, -1 do local rock = rocks[i] - raise_event(on_entity_died, {entity = rock}) + raise_event(defines.events.script_raised_destroy, {entity = rock, cause = "room_clearing"}) rock.destroy() end end)