2020-11-28 22:31:57 +08:00
|
|
|
--[[ Copyright (c) 2020 npc_strider
|
|
|
|
* For direct use of code or graphics, credit is appreciated. See LICENSE.txt for more information.
|
|
|
|
* This mod may contain modified code sourced from base/core Factorio
|
|
|
|
*
|
|
|
|
* control/give_remote.lua
|
|
|
|
* Gives the various remotes (link tool, unlink tool, squad remote, selection tool) to the player.
|
|
|
|
--]]
|
|
|
|
|
2020-11-28 01:37:34 +08:00
|
|
|
require("control.functions")
|
|
|
|
|
2020-11-29 01:17:37 +08:00
|
|
|
local function giveTwoTool(index, stack0, stack1)
|
2020-11-28 01:37:34 +08:00
|
|
|
local d = global.spidercontrol_player_s[index].active
|
2020-11-29 13:36:20 +08:00
|
|
|
local s
|
|
|
|
for i = 1, #d do
|
|
|
|
if (d[i].spider.valid) then
|
|
|
|
s = d[i].spider
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (s) then
|
2020-11-28 01:37:34 +08:00
|
|
|
local player = game.players[index]
|
2020-11-29 01:17:37 +08:00
|
|
|
if GiveStack(player, stack0) then
|
2020-11-29 13:36:20 +08:00
|
|
|
player.cursor_stack.connected_entity = s
|
2020-11-28 01:37:34 +08:00
|
|
|
end
|
|
|
|
else
|
2020-11-29 01:17:37 +08:00
|
|
|
GiveStack(game.players[index], stack1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GiveLinkTool(index, settings)
|
|
|
|
local player = game.players[index]
|
|
|
|
local value = settings["spidertron-default-link-remote"].value
|
|
|
|
if value == SETTING_LINK then
|
|
|
|
GiveStack(player, {name = "squad-spidertron-link-tool", count = 1})
|
|
|
|
elseif value == SETTING_UNLINK then
|
|
|
|
GiveStack(player, {name = "squad-spidertron-unlink-tool", count = 1})
|
|
|
|
else -- value == AUTOMATIC
|
|
|
|
giveTwoTool(index,
|
|
|
|
{name="squad-spidertron-link-tool",count=1},
|
|
|
|
{name="squad-spidertron-unlink-tool",count=1}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GiveSquadTool(index, settings)
|
|
|
|
local player = game.players[index]
|
|
|
|
local value = settings["spidertron-default-squad-remote"].value
|
|
|
|
if value == SETTING_REMOTE_SEL then
|
|
|
|
GiveStack(player, {name = "squad-spidertron-remote-sel", count = 1})
|
|
|
|
elseif value == SETTING_LINK then
|
|
|
|
GiveStack(player, {name = "squad-spidertron-remote", count = 1})
|
|
|
|
else -- value == AUTOMATIC
|
|
|
|
giveTwoTool(
|
|
|
|
index,
|
|
|
|
{name="squad-spidertron-remote",count=1},
|
|
|
|
{name="squad-spidertron-remote-sel",count=1}
|
|
|
|
)
|
2020-11-28 01:37:34 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
script.on_event("squad-spidertron-switch-modes", function(event)
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
local cursor_stack = player.cursor_stack
|
|
|
|
if cursor_stack and cursor_stack.valid_for_read then
|
|
|
|
local name = cursor_stack.name
|
|
|
|
if name == "squad-spidertron-remote" then
|
|
|
|
GiveStack(player, {name="squad-spidertron-remote-sel",count=1})
|
|
|
|
elseif name == "squad-spidertron-remote-sel" then
|
|
|
|
local e = global.spidercontrol_player_s[event.player_index].active
|
|
|
|
if e[1] and e[1].spider.valid and GiveStack(player, {name="squad-spidertron-remote",count=1}) then
|
|
|
|
player.cursor_stack.connected_entity = e[1].spider
|
|
|
|
end
|
|
|
|
-- -- Link pair
|
|
|
|
elseif name == "squad-spidertron-link-tool" then
|
|
|
|
GiveStack(player, {name="squad-spidertron-unlink-tool",count=1})
|
|
|
|
elseif name == "squad-spidertron-unlink-tool" then
|
2020-11-29 01:17:37 +08:00
|
|
|
GiveStack(player, {name = "squad-spidertron-link-tool", count = 1})
|
2020-11-28 01:37:34 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
-- script.on_event(defines.events.on_lua_shortcut, function (event)
|
|
|
|
-- local name = event.prototype_name
|
|
|
|
-- if name == "squad-spidertron-follow" then
|
|
|
|
-- local index = event.player_index
|
|
|
|
-- squad_leader_state(index)
|
|
|
|
-- spiderbot_follow(game.players[index])
|
|
|
|
-- elseif name == "squad-spidertron-link-tool" then
|
2020-11-29 01:17:37 +08:00
|
|
|
-- GiveStack(player, {name = "squad-spidertron-link-tool", count = 1})
|
2020-11-28 01:37:34 +08:00
|
|
|
-- end
|
|
|
|
-- end)
|
|
|
|
|