This commit is contained in:
2025-12-30 11:00:06 +01:00
parent 24fefbcbea
commit b67054f3de
5 changed files with 86 additions and 26 deletions

View File

@@ -1,8 +1,45 @@
local function split_string_to_map(str, separator)
local parts = {}
for part in string.gmatch(str, "([^" .. separator .. "]+)") do
-- Trim leading/trailing whitespace:
part = part:gsub("^%s*(.-)%s*$", "%1")
parts[part] = true
end
return parts
end
local no_alarm_entities = {}
local no_ghost_possible_entities = {
["car"] = true,
["tank"] = true,
["construction-robot"] = true,
["logistic-robot"] = true,
["player"] = true
}
local function build_no_alarm_table(setting_value)
no_alarm_entities = split_string_to_map(setting_value, ",")
end
script.on_init(function()
build_no_alarm_table(settings.global["no-alarm-entities"].value)
end)
script.on_load(function()
build_no_alarm_table(settings.global["no-alarm-entities"].value)
end)
script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
if event.setting == "no-alarm-entities" then
build_no_alarm_table(settings.global["no-alarm-entities"].value)
end
end)
script.on_event(defines.events.on_entity_damaged, function(event)
local entity = event.entity
-- Check if the damaged entity is a stone wall or a construction robot
if entity and entity.valid and (entity.name == "stone-wall" or entity.name == "construction-robot") then
-- Check if the damaged entity is in our list of no-alarm entities
if entity and entity.valid and no_alarm_entities[entity.name] then
-- Check if the damage would destroy the entity
if event.final_health <= 0 then
local surface = entity.surface
@@ -17,8 +54,8 @@ script.on_event(defines.events.on_entity_damaged, function(event)
-- Check if the force has researched ghost placement
if force.technologies["construction-robotics"] and force.technologies["construction-robotics"].researched then
-- Don't create a ghost for construction robots (not possible)
if name == "construction-robot" then
-- Don't create a ghost for entities that cannot have a ghost
if no_ghost_possible_entities[name] then
return
end