mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-05 15:05:57 +02:00
A point-and-click method to call AOE functions (#1295)
Allows players to point and click to call strike and barrage instead of using text commands. Co-authored-by: James Gillham <jrdgillham@gmail.com>
This commit is contained in:
parent
a6e2823d06
commit
93b800583c
@ -79,12 +79,34 @@ local function ammo_changed(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_allowed_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.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
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function on_player_deconstructed_area(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
if is_trusted(player) then
|
||||
return
|
||||
end
|
||||
player.remove_item({name = 'deconstruction-planner', count = 1000})
|
||||
|
||||
-- Added to allow guests to use the decon planner as a targetting remote for crash site air strike or barrage commands
|
||||
-- see crash_site.features.deconstruction_targetting.lua
|
||||
if is_allowed_deconstruction_planner(player.cursor_stack) then
|
||||
return
|
||||
end
|
||||
|
||||
--Make them think they arent noticed
|
||||
Utils.silent_action_warning(
|
||||
|
@ -26,6 +26,10 @@ crash_site_airstrike_insufficient_currency_error=To send an air strike, load __1
|
||||
crash_site_airstrike_friendly_fire_error=You don't want to do that, no enemies found in the target area.
|
||||
crash_site_airstrike_damage_upgrade_success=__1__ has upgraded Airstrike Damage to level __2__
|
||||
crash_site_airstrike_radius_upgrade_success=__1__ has updgraded Airstrike Radius to level __2__
|
||||
crash_site_airstrike_planner_label=Poison strike targetting remote.
|
||||
crash_site_airstrike_planner_description=Use this deconstruction planner to easily launch a poison strike with a click. Put it in your hotbar for easy access.
|
||||
crash_site_barrage_planner_label=Barrage targetting remote.
|
||||
crash_site_barrage_planner_description=Use this deconstruction planner to easily launch an artillery barrage with a click. Put it in your hotbar for easy access.
|
||||
crash_site_barrage_invalid=Invalid co-ordinates.
|
||||
crash_site_barrage=Launch a barrage of heat seeking rockets against the enemy.
|
||||
crash_site_barrage_count=Upgrade the barrage damage to to level __1__\n\nTo use barrage place explosive rockets in the spawn chest then type /barrage followed by a gps position\n\nDamage upgrades increase the number of rockets launched.\n\nCurrent level: __2__\nCurrent rocket count: __3__\nCurrent cost: __4__ rockets
|
||||
|
@ -569,6 +569,9 @@ function Public.control(config)
|
||||
end
|
||||
end
|
||||
|
||||
Public.call_strike = strike
|
||||
Public.call_barrage= barrage
|
||||
|
||||
Event.add(Retailer.events.on_market_purchase, function(event)
|
||||
|
||||
local market_id = event.group_name
|
||||
@ -629,8 +632,18 @@ function Public.control(config)
|
||||
}
|
||||
item.price = math.floor(math.exp(airstrike_data.radius_level ^ 0.8) / 2) * 1000
|
||||
Retailer.set_item(market_id, item) -- this updates the retailer with the new item values.
|
||||
elseif name == 'airstrike_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 = 'Poison strike targetting remote'
|
||||
cursor_stack.blueprint_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'}
|
||||
end
|
||||
end
|
||||
|
||||
if item.type == 'barrage' then
|
||||
local radius_level = barrage_data.radius_level -- max radius of the strike area
|
||||
local count_level = barrage_data.count_level -- the number of poison capsules launched at the enemy
|
||||
@ -678,6 +691,15 @@ function Public.control(config)
|
||||
}
|
||||
item.price = math.floor(math.exp(barrage_data.radius_level ^ 0.8) / 2) * 1000
|
||||
Retailer.set_item(market_id, item) -- this updates the retailer with the new item values.
|
||||
elseif name == 'barrage_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 = 'Barrage targetting remote'
|
||||
cursor_stack.blueprint_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'}
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -0,0 +1,56 @@
|
||||
local Event = require 'utils.event'
|
||||
local Commands = require 'map_gen.maps.crash_site.commands'
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
-- 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
|
||||
end
|
||||
|
||||
local icon_name = player.cursor_stack.blueprint_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)
|
||||
elseif icon_name == "explosive-rocket" then
|
||||
Commands.call_barrage(args,player)
|
||||
end
|
||||
end
|
||||
end)
|
@ -3,6 +3,7 @@ require 'map_gen.maps.crash_site.events'
|
||||
require 'map_gen.maps.crash_site.weapon_balance'
|
||||
require 'map_gen.maps.crash_site.features.rocket_tanks'
|
||||
require 'map_gen.maps.crash_site.features.vehicle_repair_beams'
|
||||
require 'map_gen.maps.crash_site.features.deconstruction_targetting'
|
||||
require 'features.fish_burps'
|
||||
|
||||
local b = require 'map_gen.shared.builders'
|
||||
@ -770,6 +771,15 @@ local function init(config)
|
||||
upgrade_rate = 0.5,
|
||||
upgrade_base_cost = 500,
|
||||
upgrade_cost_base = 2,
|
||||
{
|
||||
price = 0,
|
||||
stack_limit = 1,
|
||||
type= 'airstrike',
|
||||
name = 'airstrike_planner',
|
||||
name_label = {'command_description.crash_site_airstrike_planner_label', 1},
|
||||
sprite = 'virtual-signal/signal-A',
|
||||
description = {'command_description.crash_site_airstrike_planner_description', 1, 0, "n/a", "n/a"},
|
||||
},
|
||||
{
|
||||
price = 1000,
|
||||
stack_limit = 1,
|
||||
@ -788,6 +798,15 @@ local function init(config)
|
||||
sprite = 'virtual-signal/signal-A',
|
||||
description = {'command_description.crash_site_airstrike_radius', 1, 0, 5}
|
||||
},
|
||||
{
|
||||
price = 0,
|
||||
stack_limit = 1,
|
||||
type= 'barrage',
|
||||
name = 'barrage_planner',
|
||||
name_label = {'command_description.crash_site_barrage_planner_label', 1},
|
||||
sprite = 'virtual-signal/signal-B',
|
||||
description = {'command_description.crash_site_barrage_planner_description', 1, 0, "n/a", "n/a"},
|
||||
},
|
||||
{
|
||||
price = 1000,
|
||||
stack_limit = 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user