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

Added logic for toggling minable robots (#790)

* Added logic for toggling minable robots

* Added aditional checks to prevent indexing nil

* Moved to Redmew-QoL

* Indent

* Moved to redmew-qol
This commit is contained in:
Simon 2019-03-04 13:02:50 +01:00 committed by GitHub
parent e43513fcc1
commit 7ab0f10bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

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

View File

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