mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-02-09 13:37:05 +02:00
Fix targeting module
This commit is contained in:
parent
db57033243
commit
afdda61854
@ -653,7 +653,7 @@ function Public.control(config)
|
||||
cursor_stack.label = 'Poison strike targetting remote'
|
||||
cursor_stack.preview_icons = {{index = 1, signal = {type = 'item', name = 'poison-capsule'}}}
|
||||
cursor_stack.tile_selection_mode = defines.deconstruction_item.tile_selection_mode.never
|
||||
cursor_stack.entity_filters = {'sand-rock-big'}
|
||||
cursor_stack.entity_filters = {'big-rock'}
|
||||
end
|
||||
end
|
||||
|
||||
@ -712,7 +712,7 @@ function Public.control(config)
|
||||
cursor_stack.label = 'Barrage targetting remote'
|
||||
cursor_stack.preview_icons = {{index = 1, signal = {type = 'item', name = 'explosive-rocket'}}}
|
||||
cursor_stack.tile_selection_mode = defines.deconstruction_item.tile_selection_mode.never
|
||||
cursor_stack.entity_filters = {'sand-rock-big'}
|
||||
cursor_stack.entity_filters = {'big-rock'}
|
||||
end
|
||||
end
|
||||
if item.type == 'spidertron' and item.name=='spidertron_planner' then
|
||||
|
@ -1,7 +1,11 @@
|
||||
-- This module allows to auto target enemy structures with a deconstruction planner in hand.
|
||||
-- To correctly set it up, the planner has to be in player's inventory (not just a shortcut from player's blueprints)
|
||||
-- Deconstruction planner has to be set to deconstruct only "Big Rock", and must have either exp. rockets or poison capsules as 1st icon in preview
|
||||
-- The decons planner are available for free at the spawn market
|
||||
local Event = require 'utils.event'
|
||||
local Commands = require 'map_gen.maps.crash_site.commands'
|
||||
|
||||
local function is_targetting_deconstruction_planner(cursor_stack)
|
||||
local function is_targeting_deconstruction_planner(cursor_stack)
|
||||
if not cursor_stack or not cursor_stack.valid or not cursor_stack.valid_for_read then
|
||||
return false
|
||||
end
|
||||
@ -15,42 +19,42 @@ local function is_targetting_deconstruction_planner(cursor_stack)
|
||||
end
|
||||
|
||||
local filters = cursor_stack.entity_filters
|
||||
if #filters ~= 1 or filters[1] ~= 'sand-rock-big' then
|
||||
if #filters ~= 1 or filters[1].name ~= 'big-rock' then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
Event.add(defines.events. on_player_deconstructed_area , function(event)
|
||||
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
|
||||
-- check they actually have a decon planner in their cursor that is setup to be a targeting deconstruction planner.
|
||||
if not is_targeting_deconstruction_planner(cursor_stack) then
|
||||
return
|
||||
end
|
||||
|
||||
-- check if the player has given the decon planner an icon. This is how we will determine their intention
|
||||
if not cursor_stack.preview_icons or not cursor_stack.preview_icons[1] or not cursor_stack.preview_icons[1].signal.name then
|
||||
log(cursor_stack.preview_icons[1].signal.name)
|
||||
return
|
||||
end
|
||||
|
||||
local icon_name = player.cursor_stack.preview_icons[1].signal.name
|
||||
local left_top = event.area.left_top
|
||||
local right_bottom = event.area.right_bottom
|
||||
|
||||
-- only continue if they do a small click. We don't want them selecting a huge area
|
||||
if (math.abs(left_top.x - right_bottom.x) < 1) and (math.abs(left_top.y - right_bottom.y) < 1) then
|
||||
local args = {}
|
||||
args.location = "[gps="..math.floor(left_top.x)..","..math.floor(left_top.y)..","..player.surface.name.."]"
|
||||
if icon_name == "poison-capsule" then
|
||||
Commands.call_strike(args,player)
|
||||
Commands.call_strike(args, player)
|
||||
elseif icon_name == "explosive-rocket" then
|
||||
Commands.call_barrage(args,player)
|
||||
Commands.call_barrage(args, player)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -937,7 +937,7 @@ local function init(config)
|
||||
inserter = inserter,
|
||||
chest = chest,
|
||||
[4] = {entity = {name = 'requester-chest', force = 'player', callback = 'chest'}},
|
||||
[25] = {entity = {name = 'burner-inserter', direction = 2, callback = 'inserter'}},
|
||||
[25] = {entity = {name = 'burner-inserter', direction = 4, callback = 'inserter'}},
|
||||
[27] = {entity = {name = 'electric-furnace', callback = 'factory'}},
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ end
|
||||
---@param params table
|
||||
---@field surface LuaSurfaceIdentification will create the text only for those on the same surface
|
||||
function Game.create_local_flying_text(params)
|
||||
local surface = game.get_surface(params.surface)
|
||||
local surface = game.get_surface(params.surface.name or params.surface.index or params.surface)
|
||||
if not surface then
|
||||
return
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user