diff --git a/config.lua b/config.lua index 89ca6500..d179918f 100644 --- a/config.lua +++ b/config.lua @@ -305,7 +305,9 @@ global.config = { -- adds craftable loaders. loaders = true, -- turns on entity info aka alt-mode on first joining - set_alt_on_create = true + set_alt_on_create = true, + -- prevents personal construction robots from being mined by other players + save_bots = true }, -- adds a useless button with the biter percentage evolution_progress = { diff --git a/features/redmew_qol.lua b/features/redmew_qol.lua index ac29ef28..316a59c1 100644 --- a/features/redmew_qol.lua +++ b/features/redmew_qol.lua @@ -139,6 +139,45 @@ local loader_check_token = end ) +--- Sets construction robots that are not part of a roboport to unminabe +-- if the player selecting them are not the owner of them. +local function preserve_bot(event) + local player = Game.get_player_by_index(event.player_index) + local entity = player.selected + + if entity == nil or not entity.valid then + return + end + + if entity.name ~= 'construction-robot' then + return + end + local logistic_network = entity.logistic_network + + if logistic_network == nil or not logistic_network.valid then + --prevents an orphan bot from being unremovable + entity.minable = false + return + end + + -- All valid logistic networks should have at least one cell + local cell = logistic_network.cells[1] + local owner = cell.owner + + --checks if construction-robot is part of a mobile logistic network + if owner.name ~= 'player' then + return + end + + --checks if construction-robot is owned by the player that has selected it + if owner.player.name == player.name then + entity.minable = true + return + end + + entity.minable = false +end + -- Event registers local function register_random_train_color() @@ -295,4 +334,8 @@ if config.loaders then Event.add(defines.events.on_research_finished, enable_loaders) end +if config.save_bots then + Event.add(defines.events.on_selected_entity_changed, preserve_bot) +end + return Public