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:
parent
e43513fcc1
commit
7ab0f10bb9
@ -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 = {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user