1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Merge pull request #1169 from grilledham/remove_combat_robot_corpse

Add combat robots to corpse remover.
This commit is contained in:
grilledham 2021-02-08 22:14:43 +00:00 committed by GitHub
commit adeb487245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,7 @@
-- dependencies
local Event = require 'utils.event'
local Token = require 'utils.token'
local Task = require 'utils.task'
local Global = require 'utils.global'
local Queue = require 'utils.queue'
@ -18,13 +20,7 @@ Global.register(corpse_queue, function(tbl)
biter_corpse_remover = global.config.biter_corpse_remover
end)
local function entity_died(event)
local prototype_type = event.prototype.type
if prototype_type ~= 'unit' and prototype_type ~= 'turret' then
return
end
local corpses = event.corpses
local function process_corpses(corpses)
for i = 1, #corpses do
local corpse = corpses[i]
if corpse.valid then
@ -41,4 +37,39 @@ local function entity_died(event)
end
end
local combat_robot_corpse_map = {
['distractor'] = 'distractor-remnants',
['defender'] = 'defender-remnants',
['destroyer'] = 'destroyer-remnants',
}
local combat_robot_callback = Token.register(function(data)
local position = data.position
local surface = game.get_surface(data.surface_index)
if not surface or not surface.valid then
return
end
local corpse_name = combat_robot_corpse_map[data.prototype.name]
if not corpse_name then
return
end
local corpses = surface.find_entities_filtered{position = position, radius = 5, name = corpse_name}
process_corpses(corpses)
end)
local function entity_died(event)
local prototype_type = event.prototype.type
if prototype_type == 'combat-robot' then
Task.set_timeout_in_ticks(60, combat_robot_callback, event)
return
end
if prototype_type == 'unit' or prototype_type == 'turret' then
process_corpses(event.corpses)
end
end
Event.add(defines.events.on_post_entity_died, entity_died)