1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Diggy updates for Factorio .18.27 (#1061)

* Diggy updates for Factorio .18.27

* Updated with Soggs suggestions and tested again.  Thanks Soggs.

* improved on_entity_died event handling

* Changes to on_entity_died event handling based on feedback

* Ensure loot is also suppressed for rocks that die by being damaged

* Remove unused local variable from simple_room_generator.lua

* Fix exploding reactor generating stone drops and freezing game.  Using entity.destroy() again where it is better suited and for performance.

* Minor cleanup

* Readability

* Additional readibility

* Minor indentation cleanup
This commit is contained in:
BlueRock (on discord) 2020-06-04 10:34:30 -04:00 committed by GitHub
parent c9660efcc9
commit 3e08ea6b6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 10 deletions

View File

@ -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

View File

@ -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)

View File

@ -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
@ -182,7 +193,8 @@ function DiggyHole.register(cfg)
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()

View File

@ -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)