mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-17 21:08:08 +02:00
A deconstruction planner control to easily group spiders to follow a leader (#1304)
This commit is contained in:
parent
a14a16e481
commit
71c8e7b9ff
@ -433,6 +433,9 @@ global.config = {
|
||||
print_to_force = true, -- print a message to force chat when that force finishes a new research.
|
||||
print_to_discord = true, -- print a message to the discord channel when the player force finishes a new research.
|
||||
ignore_script = false -- ignore researches unlocked by commands or by code.
|
||||
},
|
||||
spidertron_group_control = {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,9 @@ end
|
||||
if config.research_printer.enabled then
|
||||
require 'features.research_printer'
|
||||
end
|
||||
if config.spidertron_group_control.enabled then
|
||||
require 'features.spidertron_group_control'
|
||||
end
|
||||
|
||||
-- GUIs
|
||||
-- The order determines the order they appear from left to right.
|
||||
@ -156,7 +159,6 @@ end
|
||||
if config.radio.enabled or _DEBUG then
|
||||
require 'features.gui.radio'
|
||||
end
|
||||
|
||||
if config.score.enabled then
|
||||
require 'features.gui.score'
|
||||
end
|
||||
|
125
features/spidertron_group_control.lua
Normal file
125
features/spidertron_group_control.lua
Normal file
@ -0,0 +1,125 @@
|
||||
-- Functions to allow players to select a group of spidertrons with a deconstruction planner and then assign them to follow another spidertron
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local spider_army = {}
|
||||
|
||||
Global.register(
|
||||
{spider_army = spider_army},
|
||||
function(tbl)
|
||||
spider_army = tbl.spider_army
|
||||
end
|
||||
)
|
||||
|
||||
local function is_targetting_deconstruction_planner(cursor_stack)
|
||||
if not cursor_stack or not cursor_stack.valid or not cursor_stack.valid_for_read then
|
||||
return false
|
||||
end
|
||||
|
||||
if cursor_stack.name ~= "deconstruction-planner" then
|
||||
return false
|
||||
end
|
||||
|
||||
if cursor_stack.tile_selection_mode ~= defines.deconstruction_item.tile_selection_mode.never then
|
||||
return false
|
||||
end
|
||||
|
||||
local filters = cursor_stack.entity_filters
|
||||
if #filters ~= 1 or filters[1] ~= 'sand-rock-big' then
|
||||
return false
|
||||
end
|
||||
|
||||
-- check if the player has given the decon planner an icon. This is how we will determine their intention
|
||||
if not cursor_stack.blueprint_icons or not cursor_stack.blueprint_icons[1] or not cursor_stack.blueprint_icons[1].signal.name then
|
||||
return false
|
||||
end
|
||||
|
||||
local icon_name = cursor_stack.blueprint_icons[1].signal.name
|
||||
if icon_name ~= "spidertron" then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_player_deconstructed_area , function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
local cursor_stack = player.cursor_stack
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
-- check they actually have a decon planner in their cursor that is setup to be a targetting deconstruction planner.
|
||||
if not is_targetting_deconstruction_planner(cursor_stack) then
|
||||
return
|
||||
end
|
||||
|
||||
local left_top = event.area.left_top
|
||||
local right_bottom = event.area.right_bottom
|
||||
local width = math.abs(left_top.x - right_bottom.x)
|
||||
local height = math.abs(left_top.y - right_bottom.y)
|
||||
|
||||
-- A single (small area) click is interpretted as instruction to assign a group of spiders to follow a spider
|
||||
if width <= 1 and height <= 1 then
|
||||
local spidertrons = spider_army[player.name]
|
||||
if not spidertrons then
|
||||
player.surface.create_entity {
|
||||
name = 'flying-text',
|
||||
text = {'spidertron_group_control.none_selected'},
|
||||
position = left_top,
|
||||
render_player_index = player.index
|
||||
}
|
||||
return
|
||||
end
|
||||
local target_spider = player.surface.find_entities_filtered{name="spidertron", area={{left_top.x-1,left_top.y-1}, {right_bottom.x+1,right_bottom.y+1}}, limit=1}
|
||||
if #target_spider == 1 then
|
||||
for i, spidertron in pairs(spidertrons) do
|
||||
if spidertron and spidertron.valid then
|
||||
spidertron.follow_target = target_spider[1]
|
||||
end
|
||||
end
|
||||
spider_army[player.name] = {} -- clear spidertrons from table once they've been assigned to follow another spidey lad
|
||||
cursor_stack.label = "No [img=item.spidertron] selected. Drag the planner over [img=item.spidertron] you own."
|
||||
else
|
||||
player.surface.create_entity {
|
||||
name = 'flying-text',
|
||||
text = {'spidertron_group_control.none_found'},
|
||||
position = left_top,
|
||||
render_player_index = player.index
|
||||
}
|
||||
end
|
||||
else -- else the area is bigger than 1x1 and so we assume the player is selecting which spiders to assign
|
||||
local spidertrons = player.surface.find_entities_filtered{area = {left_top, right_bottom}, name="spidertron"}
|
||||
local spidertrons_valid = {}
|
||||
if #spidertrons > 0 then
|
||||
for i, spidertron in pairs(spidertrons) do
|
||||
if spidertron.last_user.name == player.name then
|
||||
spidertrons_valid[#spidertrons_valid + 1] = spidertron
|
||||
-- Draw a circle over the spidertron's body to show it's part of the selection.
|
||||
rendering.draw_circle {
|
||||
color = {r = 0.5, g = 0, b = 0, a = 1},
|
||||
radius = 0.5,
|
||||
width = 3,
|
||||
filled = false,
|
||||
target = {spidertron.position.x,spidertron.position.y-2},
|
||||
surface = spidertron.surface,
|
||||
time_to_live = 60*4,
|
||||
players = {player.name}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
spider_army[player.name] = spidertrons_valid
|
||||
cursor_stack.label = #spidertrons_valid..' selected. Click a spidertron for them to follow.'
|
||||
else
|
||||
cursor_stack.label = "Select a group of spidertrons that belong to you! 0 selected."
|
||||
end
|
||||
-- Flying text to appear at top left of selection area showing player how many spidertrons they selected
|
||||
player.surface.create_entity {
|
||||
name = 'flying-text',
|
||||
text = {'spidertron_group_control.spidertrons_selected',#spidertrons_valid},
|
||||
position = left_top,
|
||||
render_player_index = player.index
|
||||
}
|
||||
end
|
||||
end)
|
@ -45,6 +45,8 @@ crash_site_barrage_radius_upgrade_success=__1__ has updgraded Rocket Barrage Rad
|
||||
crash_site_rocket_tanks_name_label=Rocket Tanks Fire Interval __1__
|
||||
crash_site_rocket_tank_upgrade_success=__1__ has upgraded Rocket Tank interval to level __2__
|
||||
crash_site_rocket_tanks_description= Upgrade the rocket tank firing interval to reduce the time between rockets.\n\nPlace rockets in the tank inventory to have them automatically target enemy worms and nests.
|
||||
crash_site_spider_army_decon_label= Spidertron Army Grouping Planner
|
||||
crash_site_spider_army_decon_description=Use this deconstruction planner to quickly group spidertrons into an army. First, group select an area containing your spidertrons. Second, single left click a target spidertron for your group to follow.
|
||||
max_level=(MAX LEVEL)
|
||||
dataset_copy=Copies a dataset
|
||||
dataset_move=Moves a dataset
|
||||
|
@ -190,4 +190,9 @@ banned_inventory_location=[color=blue][Corpse][/color] __1__ has been banned. Th
|
||||
|
||||
[landfill_remover]
|
||||
rank_too_low=You must be auto trusted or above to use the deconstruction planner on landfill.
|
||||
missing_research=[technology=landfill] required before landfill can be removed with the deconstruction planner.
|
||||
missing_research=[technology=landfill] required before landfill can be removed with the deconstruction planner.
|
||||
|
||||
[spidertron_group_control]
|
||||
none_found=No [img=item.spidertron] found
|
||||
none_selected=No [img=item.spidertron] selected. Drag the planner over [img=item.spidertron] you own.
|
||||
spidertrons_selected=+__1__ [img=item.spidertron]
|
@ -603,7 +603,7 @@ function Public.control(config)
|
||||
end
|
||||
|
||||
local item = event.item
|
||||
if item.type ~= 'airstrike' and item.type~= 'barrage' then
|
||||
if item.type ~= 'airstrike' and item.type~= 'barrage' and item.type~= 'spidertron' then
|
||||
return
|
||||
end
|
||||
|
||||
@ -724,6 +724,16 @@ function Public.control(config)
|
||||
cursor_stack.entity_filters = {'sand-rock-big'}
|
||||
end
|
||||
end
|
||||
if item.type == 'spidertron' and item.name=='spidertron_planner' then
|
||||
local player = event.player
|
||||
player.clear_cursor()
|
||||
local cursor_stack = player.cursor_stack
|
||||
cursor_stack.set_stack({name = 'deconstruction-planner'})
|
||||
cursor_stack.label = "Select a group of spidertrons that belong to you! 0 selected."
|
||||
cursor_stack.blueprint_icons = {{index = 1, signal = {type = 'item', name = 'spidertron'}}}
|
||||
cursor_stack.tile_selection_mode = defines.deconstruction_item.tile_selection_mode.never
|
||||
cursor_stack.entity_filters = {'sand-rock-big'}
|
||||
end
|
||||
end)
|
||||
|
||||
Command.add('spy', {
|
||||
|
@ -835,6 +835,15 @@ local function init(config)
|
||||
sprite = 'virtual-signal/signal-R',
|
||||
description = {'command_description.crash_site_rocket_tanks_description'}
|
||||
},
|
||||
{
|
||||
price = 0,
|
||||
stack_limit = 1,
|
||||
type = 'spidertron',
|
||||
name = 'spidertron_planner',
|
||||
name_label = {'command_description.crash_site_spider_army_decon_label', 1},
|
||||
sprite = 'virtual-signal/signal-S',
|
||||
description = {'command_description.crash_site_spider_army_decon_description'}
|
||||
},
|
||||
{name = 'wood', price = 1},
|
||||
{name = 'coal', price = 1.25},
|
||||
{name = 'stone', price = 2},
|
||||
|
Loading…
x
Reference in New Issue
Block a user