alert settings and bugfixes

This commit is contained in:
Peter 2020-11-29 13:36:20 +08:00
parent f9436c315b
commit f9d4f4375c
7 changed files with 93 additions and 57 deletions

View File

@ -6,6 +6,16 @@
* General/commonly used/important functions. * 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() function SpidertronWaypointsCompatibility()
-- Compatability for Spidertron Waypoints -- Compatability for Spidertron Waypoints
if remote.interfaces["SpidertronWaypoints"] then if remote.interfaces["SpidertronWaypoints"] then
@ -22,8 +32,9 @@ end
function GiveStack(player, stack) function GiveStack(player, stack)
if player.clear_cursor() and player.cursor_stack and player.cursor_stack.can_set_stack(stack) then if player.clear_cursor() and player.cursor_stack and player.cursor_stack.can_set_stack(stack) then
if player.get_main_inventory() then if player.get_main_inventory() then
player.get_main_inventory().remove("squad-spidertron-remote-sel") local inv = player.get_main_inventory()
player.get_main_inventory().remove("squad-spidertron-remote") inv.remove("squad-spidertron-remote-sel")
inv.remove("squad-spidertron-remote")
end end
player.cursor_stack.set_stack(stack) player.cursor_stack.set_stack(stack)
return true return true
@ -83,15 +94,15 @@ local function resetSprites(indices)
end end
end end
-- Original GotoPlayer function before waypoints compat. -- 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 = global.spidercontrol_player_s[index].active
local active_n = #active local active_n = #active
local active_updated = Goto(active, position) local active_updated = Goto(active, position)
global.spidercontrol_player_s[index].active = active_updated global.spidercontrol_player_s[index].active = active_updated
if (active_n > #active_updated) then if (active_n > #active_updated) then
local str = (active_n - #active_updated) .. " units were destroyed or mined" local str = "[img=utility/warning_icon] " .. (active_n - #active_updated) .. " units were destroyed or mined"
game.players[index].print(str) AlertPlayer(game.players[index], str)
end end
end end
@ -101,12 +112,16 @@ local function GotoPlayerSW(index, position)
local linear = player.is_shortcut_toggled("spidertron-remote-waypoint") local linear = player.is_shortcut_toggled("spidertron-remote-waypoint")
local cyclic = player.is_shortcut_toggled("spidertron-remote-patrol") local cyclic = player.is_shortcut_toggled("spidertron-remote-patrol")
if (cyclic) then if (cyclic) then
if player.is_shortcut_toggled("squad-spidertron-follow") then
return
end
active[1].spider.autopilot_destination = nil active[1].spider.autopilot_destination = nil
local patrol = global.spidercontrol_spidertronwaypoints_patrol[index] local patrol = global.spidercontrol_spidertronwaypoints_patrol[index]
if (patrol) then if (patrol) then
local start = rendering.get_target(patrol[1]).position local start = rendering.get_target(patrol[1]).position
if (util.distance(position, start) < 5) then if (util.distance(position, start) < 5) then
for j = 1, #active do for j = 1, #active do
if (active[j] and active[j].spider.valid) then
local waypoints = {} local waypoints = {}
for i = 1, #patrol do for i = 1, #patrol do
local position = IJAdd( local position = IJAdd(
@ -118,6 +133,7 @@ local function GotoPlayerSW(index, position)
remote.call("SpidertronWaypoints", "assign_patrol", active[j].spider, waypoints) remote.call("SpidertronWaypoints", "assign_patrol", active[j].spider, waypoints)
end end
end
resetSprites(patrol) resetSprites(patrol)
global.spidercontrol_player_s[index].active = {} global.spidercontrol_player_s[index].active = {}
UpdateGuiList(player) UpdateGuiList(player)
@ -142,7 +158,7 @@ local function GotoPlayerSW(index, position)
resetSprites(global.spidercontrol_spidertronwaypoints_patrol[index]) resetSprites(global.spidercontrol_spidertronwaypoints_patrol[index])
global.spidercontrol_spidertronwaypoints_patrol[index] = nil global.spidercontrol_spidertronwaypoints_patrol[index] = nil
else else
GotoPlayer_(index, position) GotoPlayerUpdate(index, position)
resetSprites(global.spidercontrol_spidertronwaypoints_patrol[index]) resetSprites(global.spidercontrol_spidertronwaypoints_patrol[index])
global.spidercontrol_spidertronwaypoints_patrol[index] = nil global.spidercontrol_spidertronwaypoints_patrol[index] = nil
@ -153,9 +169,8 @@ function GotoPlayer(index, position)
if SPIDERTRON_WAYPOINTS then if SPIDERTRON_WAYPOINTS then
GotoPlayerSW(index, position) GotoPlayerSW(index, position)
else else
GotoPlayer_(index, position) GotoPlayerUpdate(index, position)
end end
end end
function GotoEntity(index) function GotoEntity(index)
@ -171,12 +186,12 @@ function GotoEntity(index)
global.spidercontrol_linked_s[index].s = active_updated global.spidercontrol_linked_s[index].s = active_updated
if (active_n > #active_updated) then 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) game.forces[t.force].print(str)
end end
if (#active_updated == 0) then 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 game.forces[t.force].print(str) -- using force comms because this could be the death of a spidertron, not only removal
end end
else else
@ -188,9 +203,9 @@ function GotoEntity(index)
end end
if (e) then if (e) then
local pos = e.position 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 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 end
global.spidercontrol_linked_s = Remove(global.spidercontrol_linked_s, {index}) global.spidercontrol_linked_s = Remove(global.spidercontrol_linked_s, {index})

View File

@ -10,10 +10,17 @@ require("control.functions")
local function giveTwoTool(index, stack0, stack1) local function giveTwoTool(index, stack0, stack1)
local d = global.spidercontrol_player_s[index].active 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] local player = game.players[index]
if GiveStack(player, stack0) then if GiveStack(player, stack0) then
player.cursor_stack.connected_entity = d[1].spider player.cursor_stack.connected_entity = s
end end
else else
GiveStack(game.players[index], stack1) GiveStack(game.players[index], stack1)

View File

@ -164,7 +164,7 @@ script.on_event(defines.events.on_gui_click, function(event)
UpdateGuiList(player) UpdateGuiList(player)
destroyRenameGui(get_frame_flow_(player, "center")) destroyRenameGui(get_frame_flow_(player, "center"))
else 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
end end
elseif (name == "delete-active") then elseif (name == "delete-active") then

View File

@ -9,10 +9,12 @@
local function spidertronWaypointsOverride(s) local function spidertronWaypointsOverride(s)
if SPIDERTRON_WAYPOINTS then if SPIDERTRON_WAYPOINTS then
for i = 1, #s do for i = 1, #s do
if (s[i] and s[i].spider) then
remote.call("SpidertronWaypoints", "clear_waypoints", s[i].spider.unit_number) remote.call("SpidertronWaypoints", "clear_waypoints", s[i].spider.unit_number)
end end
end end
end end
end
function SpiderbotFollow(player) function SpiderbotFollow(player)
if player.character then if player.character then
@ -22,11 +24,14 @@ function SpiderbotFollow(player)
GotoPlayer(index, player.position) GotoPlayer(index, player.position)
spidertronWaypointsOverride(global.spidercontrol_player_s[index].active) spidertronWaypointsOverride(global.spidercontrol_player_s[index].active)
else else
if SPIDERTRON_WAYPOINTS and player.is_shortcut_toggled("spidertron-remote-patrol") then
return
end
player.set_shortcut_toggled("squad-spidertron-follow", true) player.set_shortcut_toggled("squad-spidertron-follow", true)
global.spidercontrol_player_s[player.index].p_pos = nil global.spidercontrol_player_s[player.index].p_pos = nil
end end
else 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
end end
@ -55,13 +60,12 @@ function UpdateFollow()
end end
end end
-- player.print("running" .. game.tick)
if player.walking_state.walking then if player.walking_state.walking then
local dir = player.walking_state.direction local dir = player.walking_state.direction
pos = IJAhead(pos, dir, mov_offset) pos = IJAhead(pos, dir, mov_offset)
end end
GotoPlayer(index, pos) GotoPlayer(index, pos)
spidertronWaypointsOverride(active) spidertronWaypointsOverride(global.spidercontrol_player_s[index].active)
global.spidercontrol_player_s[index].p_pos = player.position global.spidercontrol_player_s[index].p_pos = player.position
end end
end end

View File

@ -51,13 +51,14 @@ end
local function link(index, vehicle) local function link(index, vehicle)
local player = game.players[index] 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 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 pos = selected.position
local scale = 1.5 local scale = 1.5
local force = player.force 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 sprite = drawSprite(selected, scale, force)
local s = util.table.deepcopy(global.spidercontrol_player_s[index].active) local s = util.table.deepcopy(global.spidercontrol_player_s[index].active)
for i = 1, #s do 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 -- Probably should print the squad ID, the target entity id and other information
GiveStack(player, {name="squad-spidertron-unlink-tool",count=1}) GiveStack(player, {name="squad-spidertron-unlink-tool",count=1})
UpdateGuiList(player) UpdateGuiList(player)
AlertPlayer(player, {"", "[img=virtual-signal/signal-info] Linked ".. n .. " spiders to ", selected.localised_name, " near [gps=" .. pos.x .. "," .. pos.y .. "]"})
end
end end
vehicle.autopilot_destination = vehicle.position -- Just to look better vehicle.autopilot_destination = vehicle.position -- Just to look better
end end

View File

@ -12,28 +12,28 @@ require("control.2dvec")
local function messageSpiders(target, s, force, n) local function messageSpiders(target, s, force, n)
if target.valid then if target.valid then
local pos = target.position 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 else
local e = FirstValid(s) local e = FirstValid(s)
if e then if e then
local pos = e.position 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 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 end
end end
local function messageS(target, s, force) local function messageS(target, s, force)
if target.valid then if target.valid then
local pos = target.position 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 else
local e = FirstValid(s) local e = FirstValid(s)
if e then if e then
local pos = e.position 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 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 end
end end
@ -62,7 +62,6 @@ function SpiderDeSelect(spiders, force)
s[j].spider.autopilot_destination = nil s[j].spider.autopilot_destination = nil
rem_id[#rem_id+1] = k rem_id[#rem_id+1] = k
rem_s[#rem_s+1] = j rem_s[#rem_s+1] = j
-- game.print("REMOVE["..i.."]["..j.."]")
end end
end end
if (#rem_id > 0) then if (#rem_id > 0) then

View File

@ -73,5 +73,13 @@ data:extend({
SETTING_LINK, SETTING_LINK,
SETTING_UNLINK 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
} }
}) })