mirror of
https://github.com/peter-tanner/spidertron-squad-control.git
synced 2024-11-30 11:00:17 +08:00
alert settings and bugfixes
This commit is contained in:
parent
f9436c315b
commit
f9d4f4375c
|
@ -6,6 +6,16 @@
|
|||
* General/commonly used/important functions.
|
||||
--]]
|
||||
|
||||
function AlertPlayer(player, str)
|
||||
local enabled = settings.get_player_settings(player)["spidertron-alerts"].value
|
||||
if (enabled) then
|
||||
player.print(str)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function SpidertronWaypointsCompatibility()
|
||||
-- Compatability for Spidertron Waypoints
|
||||
if remote.interfaces["SpidertronWaypoints"] then
|
||||
|
@ -22,8 +32,9 @@ end
|
|||
function GiveStack(player, stack)
|
||||
if player.clear_cursor() and player.cursor_stack and player.cursor_stack.can_set_stack(stack) then
|
||||
if player.get_main_inventory() then
|
||||
player.get_main_inventory().remove("squad-spidertron-remote-sel")
|
||||
player.get_main_inventory().remove("squad-spidertron-remote")
|
||||
local inv = player.get_main_inventory()
|
||||
inv.remove("squad-spidertron-remote-sel")
|
||||
inv.remove("squad-spidertron-remote")
|
||||
end
|
||||
player.cursor_stack.set_stack(stack)
|
||||
return true
|
||||
|
@ -83,15 +94,15 @@ local function resetSprites(indices)
|
|||
end
|
||||
end
|
||||
-- Original GotoPlayer function before waypoints compat.
|
||||
local function GotoPlayer_(index, position)
|
||||
function GotoPlayerUpdate(index, position)
|
||||
local active = global.spidercontrol_player_s[index].active
|
||||
local active_n = #active
|
||||
local active_updated = Goto(active, position)
|
||||
global.spidercontrol_player_s[index].active = active_updated
|
||||
|
||||
if (active_n > #active_updated) then
|
||||
local str = (active_n - #active_updated) .. " units were destroyed or mined"
|
||||
game.players[index].print(str)
|
||||
local str = "[img=utility/warning_icon] " .. (active_n - #active_updated) .. " units were destroyed or mined"
|
||||
AlertPlayer(game.players[index], str)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -101,12 +112,16 @@ local function GotoPlayerSW(index, position)
|
|||
local linear = player.is_shortcut_toggled("spidertron-remote-waypoint")
|
||||
local cyclic = player.is_shortcut_toggled("spidertron-remote-patrol")
|
||||
if (cyclic) then
|
||||
if player.is_shortcut_toggled("squad-spidertron-follow") then
|
||||
return
|
||||
end
|
||||
active[1].spider.autopilot_destination = nil
|
||||
local patrol = global.spidercontrol_spidertronwaypoints_patrol[index]
|
||||
if (patrol) then
|
||||
local start = rendering.get_target(patrol[1]).position
|
||||
if (util.distance(position, start) < 5) then
|
||||
for j = 1, #active do
|
||||
if (active[j] and active[j].spider.valid) then
|
||||
local waypoints = {}
|
||||
for i = 1, #patrol do
|
||||
local position = IJAdd(
|
||||
|
@ -118,6 +133,7 @@ local function GotoPlayerSW(index, position)
|
|||
|
||||
remote.call("SpidertronWaypoints", "assign_patrol", active[j].spider, waypoints)
|
||||
end
|
||||
end
|
||||
resetSprites(patrol)
|
||||
global.spidercontrol_player_s[index].active = {}
|
||||
UpdateGuiList(player)
|
||||
|
@ -142,7 +158,7 @@ local function GotoPlayerSW(index, position)
|
|||
resetSprites(global.spidercontrol_spidertronwaypoints_patrol[index])
|
||||
global.spidercontrol_spidertronwaypoints_patrol[index] = nil
|
||||
else
|
||||
GotoPlayer_(index, position)
|
||||
GotoPlayerUpdate(index, position)
|
||||
|
||||
resetSprites(global.spidercontrol_spidertronwaypoints_patrol[index])
|
||||
global.spidercontrol_spidertronwaypoints_patrol[index] = nil
|
||||
|
@ -153,9 +169,8 @@ function GotoPlayer(index, position)
|
|||
if SPIDERTRON_WAYPOINTS then
|
||||
GotoPlayerSW(index, position)
|
||||
else
|
||||
GotoPlayer_(index, position)
|
||||
GotoPlayerUpdate(index, position)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function GotoEntity(index)
|
||||
|
@ -171,12 +186,12 @@ function GotoEntity(index)
|
|||
global.spidercontrol_linked_s[index].s = active_updated
|
||||
|
||||
if (active_n > #active_updated) then
|
||||
local str = (active_n - #active_updated) .. " units were destroyed or mined near [gps="..pos.x..","..pos.y.."], linked to "..entity.localised_name
|
||||
local str = {"", "[img=utility/warning_icon] " .. (active_n - #active_updated) .. " units were destroyed or mined near [gps="..pos.x..","..pos.y.."], linked to ", entity.localised_name}
|
||||
game.forces[t.force].print(str)
|
||||
end
|
||||
|
||||
if (#active_updated == 0) then
|
||||
local str = {"", "Spidertron squad has been destroyed or unlinked from ", entity.localised_name, " near [gps="..pos.x..","..pos.y.."]"}
|
||||
local str = {"", "[img=utility/warning_icon] Spidertron squad has been destroyed or unlinked from ", entity.localised_name, " near [gps="..pos.x..","..pos.y.."]"}
|
||||
game.forces[t.force].print(str) -- using force comms because this could be the death of a spidertron, not only removal
|
||||
end
|
||||
else
|
||||
|
@ -188,9 +203,9 @@ function GotoEntity(index)
|
|||
end
|
||||
if (e) then
|
||||
local pos = e.position
|
||||
game.forces[t.force].print("Target entity of spidertron squad has been destroyed or removed near [gps="..pos.x..","..pos.y.."]")
|
||||
game.forces[t.force].print("[img=utility/warning_icon] Target entity of spidertron squad has been destroyed or removed near [gps="..pos.x..","..pos.y.."]")
|
||||
else
|
||||
game.forces[t.force].print("Target entity of spidertron squad has been destroyed or removed")
|
||||
game.forces[t.force].print("[img=utility/warning_icon] Target entity of spidertron squad has been destroyed or removed")
|
||||
end
|
||||
|
||||
global.spidercontrol_linked_s = Remove(global.spidercontrol_linked_s, {index})
|
||||
|
|
|
@ -10,10 +10,17 @@ require("control.functions")
|
|||
|
||||
local function giveTwoTool(index, stack0, stack1)
|
||||
local d = global.spidercontrol_player_s[index].active
|
||||
if (#d > 0 and d[1].spider.valid) then
|
||||
local s
|
||||
for i = 1, #d do
|
||||
if (d[i].spider.valid) then
|
||||
s = d[i].spider
|
||||
break
|
||||
end
|
||||
end
|
||||
if (s) then
|
||||
local player = game.players[index]
|
||||
if GiveStack(player, stack0) then
|
||||
player.cursor_stack.connected_entity = d[1].spider
|
||||
player.cursor_stack.connected_entity = s
|
||||
end
|
||||
else
|
||||
GiveStack(game.players[index], stack1)
|
||||
|
|
|
@ -164,7 +164,7 @@ script.on_event(defines.events.on_gui_click, function(event)
|
|||
UpdateGuiList(player)
|
||||
destroyRenameGui(get_frame_flow_(player, "center"))
|
||||
else
|
||||
player.print("You have too many saved templates! Remove some before adding more. Maximum amount is "..limit)
|
||||
player.print("[img=utility/danger_icon] You have too many saved templates! Remove some before adding more. Maximum amount is "..limit)
|
||||
end
|
||||
end
|
||||
elseif (name == "delete-active") then
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
local function spidertronWaypointsOverride(s)
|
||||
if SPIDERTRON_WAYPOINTS then
|
||||
for i = 1, #s do
|
||||
if (s[i] and s[i].spider) then
|
||||
remote.call("SpidertronWaypoints", "clear_waypoints", s[i].spider.unit_number)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SpiderbotFollow(player)
|
||||
|
@ -22,11 +24,14 @@ function SpiderbotFollow(player)
|
|||
GotoPlayer(index, player.position)
|
||||
spidertronWaypointsOverride(global.spidercontrol_player_s[index].active)
|
||||
else
|
||||
if SPIDERTRON_WAYPOINTS and player.is_shortcut_toggled("spidertron-remote-patrol") then
|
||||
return
|
||||
end
|
||||
player.set_shortcut_toggled("squad-spidertron-follow", true)
|
||||
global.spidercontrol_player_s[player.index].p_pos = nil
|
||||
end
|
||||
else
|
||||
player.print({"", {"error.error-message-box-title"}, ": ", {"player-doesnt-exist", {"gui.character"}}, " (", {"controller.god"}, "): ", {"gui-mod-info.status-disabled"}})
|
||||
player.print({"", "[img=utility/danger_icon] ", {"error.error-message-box-title"}, ": ", {"player-doesnt-exist", {"gui.character"}}, " (", {"controller.god"}, "): ", {"gui-mod-info.status-disabled"}})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -55,13 +60,12 @@ function UpdateFollow()
|
|||
end
|
||||
end
|
||||
|
||||
-- player.print("running" .. game.tick)
|
||||
if player.walking_state.walking then
|
||||
local dir = player.walking_state.direction
|
||||
pos = IJAhead(pos, dir, mov_offset)
|
||||
end
|
||||
GotoPlayer(index, pos)
|
||||
spidertronWaypointsOverride(active)
|
||||
spidertronWaypointsOverride(global.spidercontrol_player_s[index].active)
|
||||
global.spidercontrol_player_s[index].p_pos = player.position
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,13 +51,14 @@ end
|
|||
|
||||
local function link(index, vehicle)
|
||||
local player = game.players[index]
|
||||
local n = #global.spidercontrol_player_s[index].active
|
||||
if player.selected and player.selected.valid and n > 0 then
|
||||
local selected = player.selected
|
||||
if (selected and selected.valid) then
|
||||
GotoPlayerUpdate(index, selected.position)
|
||||
local n = #global.spidercontrol_player_s[index].active
|
||||
if (n > 0) then
|
||||
local pos = selected.position
|
||||
local scale = 1.5
|
||||
local force = player.force
|
||||
player.print({"", "Linked ".. n .. " spiders to ", selected.localised_name, " near [gps=" .. pos.x .. "," .. pos.y .. "]"})
|
||||
local sprite = drawSprite(selected, scale, force)
|
||||
local s = util.table.deepcopy(global.spidercontrol_player_s[index].active)
|
||||
for i = 1, #s do
|
||||
|
@ -73,6 +74,8 @@ local function link(index, vehicle)
|
|||
-- Probably should print the squad ID, the target entity id and other information
|
||||
GiveStack(player, {name="squad-spidertron-unlink-tool",count=1})
|
||||
UpdateGuiList(player)
|
||||
AlertPlayer(player, {"", "[img=virtual-signal/signal-info] Linked ".. n .. " spiders to ", selected.localised_name, " near [gps=" .. pos.x .. "," .. pos.y .. "]"})
|
||||
end
|
||||
end
|
||||
vehicle.autopilot_destination = vehicle.position -- Just to look better
|
||||
end
|
||||
|
|
|
@ -12,28 +12,28 @@ require("control.2dvec")
|
|||
local function messageSpiders(target, s, force, n)
|
||||
if target.valid then
|
||||
local pos = target.position
|
||||
game.forces[force].print({"", n.." spidertrons have been unlinked from a ", target.localised_name, " near [gps="..pos.x..","..pos.y.."]"})
|
||||
game.forces[force].print({"", "[img=utility/warning_icon] "..n.." spidertrons have been unlinked from a ", target.localised_name, " near [gps="..pos.x..","..pos.y.."]"})
|
||||
else
|
||||
local e = FirstValid(s)
|
||||
if e then
|
||||
local pos = e.position
|
||||
game.forces[force].print(n.." spidertrons have been unlinked from an entity near [gps="..pos.x..","..pos.y.."]")
|
||||
game.forces[force].print("[img=utility/warning_icon] "..n.." spidertrons have been unlinked from an entity near [gps="..pos.x..","..pos.y.."]")
|
||||
else
|
||||
game.forces[force].print(n.." spidertrons have been unlinked from an entity")
|
||||
game.forces[force].print("[img=utility/warning_icon] "..n.." spidertrons have been unlinked from an entity")
|
||||
end
|
||||
end
|
||||
end
|
||||
local function messageS(target, s, force)
|
||||
if target.valid then
|
||||
local pos = target.position
|
||||
game.forces[force].print({"", "Spidertron squad has been unlinked from ", target.localised_name, " near [gps="..pos.x..","..pos.y.."]"}) -- using force comms because this could be the death of a spidertron, not only removal
|
||||
game.forces[force].print({"", "[img=utility/warning_icon] Spidertron squad has been unlinked from ", target.localised_name, " near [gps="..pos.x..","..pos.y.."]"}) -- using force comms because this could be the death of a spidertron, not only removal
|
||||
else
|
||||
local e = FirstValid(s)
|
||||
if e then
|
||||
local pos = e.position
|
||||
game.forces[force].print({"", "Spidertron squad has been unlinked from a target near [gps="..pos.x..","..pos.y.."]"})
|
||||
game.forces[force].print({"", "[img=utility/warning_icon] Spidertron squad has been unlinked from a target near [gps="..pos.x..","..pos.y.."]"})
|
||||
else
|
||||
game.forces[force].print({"", "Spidertron squad has been unlinked from a target"})
|
||||
game.forces[force].print({"", "[img=utility/warning_icon] Spidertron squad has been unlinked from a target"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -62,7 +62,6 @@ function SpiderDeSelect(spiders, force)
|
|||
s[j].spider.autopilot_destination = nil
|
||||
rem_id[#rem_id+1] = k
|
||||
rem_s[#rem_s+1] = j
|
||||
-- game.print("REMOVE["..i.."]["..j.."]")
|
||||
end
|
||||
end
|
||||
if (#rem_id > 0) then
|
||||
|
|
|
@ -73,5 +73,13 @@ data:extend({
|
|||
SETTING_LINK,
|
||||
SETTING_UNLINK
|
||||
}
|
||||
},
|
||||
{
|
||||
type = "bool-setting",
|
||||
name = "spidertron-alerts",
|
||||
localised_name = "Spidertron alerts",
|
||||
localised_description = "If enabled an alert is given when a spidertron is removed or destroyed from a player squad. Default value: true",
|
||||
setting_type = "runtime-per-user",
|
||||
default_value = true
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user