mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-04 09:42:30 +02:00
First shot at #608
This commit is contained in:
parent
c6b21bf840
commit
3a56ee1e5c
@ -389,6 +389,12 @@ global.config = {
|
||||
-- enables the redmew settings GUI
|
||||
redmew_settings = {
|
||||
enabled = true
|
||||
},
|
||||
-- when biter corpses in an area are above a threshold, remove the desired amount
|
||||
biter_corpse_util = {
|
||||
enabled = true,
|
||||
radius = 3, -- radius to search around dying entities
|
||||
corpse_threshold = 10 -- number of corpses allowed on surface, inside radius
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,9 @@ end
|
||||
if config.player_quick_bars.enabled then
|
||||
require 'features.player_quick_bars'
|
||||
end
|
||||
if config.biter_corpse_util.enabled then
|
||||
require 'features.biter_corpse_util'
|
||||
end
|
||||
|
||||
-- GUIs
|
||||
-- The order determines the order they appear from left to right.
|
||||
|
52
features/biter_corpse_util.lua
Normal file
52
features/biter_corpse_util.lua
Normal file
@ -0,0 +1,52 @@
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local biter_utils_conf = global.config.biter_corpse_util
|
||||
|
||||
local random = math.random
|
||||
|
||||
-- currently no on_corpse_spawned event, using on_entity_died instead
|
||||
|
||||
local function biter_died(event)
|
||||
local entity = event.entity
|
||||
if entity.valid then
|
||||
local dying_force = entity.force
|
||||
-- ignore player owned entities
|
||||
if dying_force == 'player' then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = entity.surface
|
||||
|
||||
-- More than the desired number of corpses?
|
||||
if surface.count_entities_filtered {
|
||||
position = entity.position,
|
||||
radius = biter_utils_conf.radius,
|
||||
type = 'corpse',
|
||||
force = 'neutral'
|
||||
} > biter_utils_conf.corpse_threshold then
|
||||
-- Get the actual entities
|
||||
local corpse_list = surface.find_entities_filtered {
|
||||
position = entity.position,
|
||||
radius = biter_utils_conf.radius,
|
||||
type = 'corpse',
|
||||
force = 'neutral'
|
||||
}
|
||||
|
||||
local num_to_remove = #corpse_list - biter_utils_conf.corpse_threshold
|
||||
local random_offset = random(#corpse_list)
|
||||
|
||||
-- Starting at a random number, remove enough entities to be under the threshold
|
||||
for i = random_offset, num_to_remove + random_offset do
|
||||
--modulus + 1 to ensure we are not past the end of the table
|
||||
if entity == corpse_list[(i % #corpse_list) + 1] then
|
||||
game.print('Collision')
|
||||
else
|
||||
corpse_list[(i % #corpse_list) + 1].destroy()
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_entity_died, biter_died)
|
Loading…
Reference in New Issue
Block a user