mirror of
https://github.com/peter-tanner/spidertron-squad-control.git
synced 2024-12-02 20:10:17 +08:00
spidertron link tool 1
This commit is contained in:
parent
398ed6fc87
commit
a7d3854217
|
@ -36,7 +36,13 @@ Date: 2020-08-17
|
||||||
|
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Version: 0.3.2
|
Version: 0.3.2
|
||||||
Date: 2020-08-17
|
Date: 2020-08-18
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
- Fixed leader spidertron death causing a crash
|
- Fixed leader spidertron death causing a crash
|
||||||
- Fixed incorrect global table initialization when a vanilla game receives the mode (which fixes crash on vehicle exit and spidertron exit in a previously vanilla game)
|
- Fixed incorrect global table initialization when a vanilla game receives the mode (which fixes crash on vehicle exit and spidertron exit in a previously vanilla game)
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------------------------
|
||||||
|
Version: 0.3.3
|
||||||
|
Date: 2020-08-23
|
||||||
|
Bugfixes:
|
||||||
|
- Hotfix: fixed missing check for invalid entity
|
||||||
|
|
231
control.lua
231
control.lua
|
@ -20,6 +20,21 @@ local function give_tool(player, stack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function give_link_tool(index)
|
||||||
|
local d = global.spidercontrol_spidersquad[index]
|
||||||
|
if d then
|
||||||
|
if #d.spiders > 0 and d.spiders[1].spider_entity.valid then --- NEED TO CHECK THIS!!!!!!!!!!!!!!!!! CAN WE REMOVE IT?
|
||||||
|
local player = game.players[index]
|
||||||
|
if give_tool(player, {name="squad-spidertron-link-tool",count=1}) then
|
||||||
|
player.cursor_stack.connected_entity=d.spiders[1].spider_entity
|
||||||
|
end
|
||||||
|
-- give_tool(player, {name="spidertron-link-tool",count=1})
|
||||||
|
else
|
||||||
|
give_tool(game.players[index], {name="squad-spidertron-unlink-tool",count=1})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function squad_center(spidersquad)
|
local function squad_center(spidersquad)
|
||||||
local xbar=0
|
local xbar=0
|
||||||
local ybar=0
|
local ybar=0
|
||||||
|
@ -51,31 +66,89 @@ local function spiderbot_select(event)
|
||||||
if give_tool(player, {name="squad-spidertron-remote",count=1}) then
|
if give_tool(player, {name="squad-spidertron-remote",count=1}) then
|
||||||
player.cursor_stack.connected_entity=spiders[1]
|
player.cursor_stack.connected_entity=spiders[1]
|
||||||
end
|
end
|
||||||
|
elseif event.item == "squad-spidertron-unlink-tool" and #spiders > 0 then
|
||||||
|
if #global.spidercontrol_linked_squads > 0 then
|
||||||
|
-- This is highly unoptimised, because we're searching through the list of all spidertrons and comparing it to the spidertrons in the selection box. Not quite the worst case, because everytime we get a match we remove it from the search list and we terminate the search when nothing is left in the search list. Can have a large UPS impact spike for bases with many squads that are very large, when a large selection of spidertrons are to be unlinked
|
||||||
|
-- Is there a way to attach an attribute directly to an entity, so that we don't need to search the whole global table?? That would improve speed by a lot
|
||||||
|
local ids = {}
|
||||||
|
local force = game.players[index].force.index
|
||||||
|
for i=1, #spiders do
|
||||||
|
ids[#ids+1] = spiders[i].unit_number
|
||||||
|
end
|
||||||
|
for i,t in pairs(global.spidercontrol_linked_squads) do
|
||||||
|
if #ids == 0 then break end
|
||||||
|
if force == t.force then
|
||||||
|
local pos = t.target.position
|
||||||
|
local c = 0
|
||||||
|
for j, spider in pairs(t.spiders) do
|
||||||
|
if #ids == 0 then break end
|
||||||
|
|
||||||
|
for k,id in pairs(ids) do
|
||||||
|
if spider.spider_entity.unit_number == id then
|
||||||
|
global.spidercontrol_linked_squads[i].spiders[j] = nil
|
||||||
|
table.remove(ids,k)
|
||||||
|
c = c + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if c > 0 then
|
||||||
|
if t.target and t.target.valid then
|
||||||
|
game.forces[t.force].print({"", c.." spidertrons have been unlinked from a ", t.target.localised_name, " near [gps="..pos.x..","..pos.y.."]"})
|
||||||
|
else
|
||||||
|
game.forces[t.force].print(c.." spidertrons have been unlinked from an entity near [gps="..pos.x..","..pos.y.."]")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function validate_spiders(index)
|
local function validate_spiders(t, msg)
|
||||||
local c=0
|
local c=0
|
||||||
if global.spidercontrol_spidersquad[index] then
|
if t then
|
||||||
--for i, spider_ in pairs(global.spidercontrol_spidersquad[index].spiders) do
|
--for i, spider_ in pairs(t.spiders) do
|
||||||
for i, spider in pairs(global.spidercontrol_spidersquad[index].spiders) do
|
for i, spider in pairs(t.spiders) do
|
||||||
if not spider.spider_entity or not spider.spider_entity.valid then
|
local spider_entity = spider.spider_entity
|
||||||
global.spidercontrol_spidersquad[index].spiders[i] = nil
|
if not spider_entity or not spider_entity.valid then
|
||||||
|
t.spiders[i] = nil
|
||||||
c=c+1
|
c=c+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if c > 0 then
|
if c > 0 then
|
||||||
game.players[index].print(c .. " units were destroyed or mined since the last position command was sent") --this is causing crashes for one user. states that the player does not exist (why?) needs more research
|
local str = c .. " units were destroyed or mined since the last position command was sent"
|
||||||
|
if type(msg) == "boolean" and msg == true then -- This is for messaging when a unit is destroyed
|
||||||
|
local pos = t.target.position
|
||||||
|
game.forces[t.force].print(str..". Position is near [gps="..pos.x..","..pos.y.."]")
|
||||||
|
else
|
||||||
|
game.players[msg].print(str) --this is causing crashes for one user. states that the player does not exist (why?) needs more research
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
elseif type(msg) ~= "boolean" then
|
||||||
|
global.spidercontrol_spidersquad[msg] = {spiders={}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function spiderbot_designate(index, position)
|
local function spiderbot_designate(index, position, force)
|
||||||
if validate_spiders(index) then
|
local d_
|
||||||
local d_ = global.spidercontrol_spidersquad[index]
|
local msg
|
||||||
|
if force then
|
||||||
|
d_ = global.spidercontrol_linked_squads[index]
|
||||||
|
msg = true
|
||||||
|
else
|
||||||
|
d_ = global.spidercontrol_spidersquad[index]
|
||||||
|
msg = index
|
||||||
|
end
|
||||||
|
|
||||||
|
if validate_spiders(d_, msg) then
|
||||||
local spidersquad = d_.spiders
|
local spidersquad = d_.spiders
|
||||||
local leader = d_.spider_leader
|
local leader
|
||||||
|
local follow
|
||||||
|
if not force then
|
||||||
|
leader = d_.spider_leader
|
||||||
|
follow = game.players[index].is_shortcut_toggled("squad-spidertron-follow")
|
||||||
|
end
|
||||||
local l_d = {0,0}
|
local l_d = {0,0}
|
||||||
if leader then
|
if leader then
|
||||||
if spidersquad[leader] and spidersquad[leader].spider_entity.valid then
|
if spidersquad[leader] and spidersquad[leader].spider_entity.valid then
|
||||||
|
@ -89,7 +162,6 @@ local function spiderbot_designate(index, position)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local follow = game.players[index].is_shortcut_toggled("squad-spidertron-follow")
|
|
||||||
for i, spider_ in pairs(spidersquad) do
|
for i, spider_ in pairs(spidersquad) do
|
||||||
if i ~= leader or not follow then
|
if i ~= leader or not follow then
|
||||||
local spider = spider_.spider_entity
|
local spider = spider_.spider_entity
|
||||||
|
@ -115,6 +187,7 @@ end
|
||||||
local function initialize()
|
local function initialize()
|
||||||
if global.spidercontrol_spidersquad == nil then
|
if global.spidercontrol_spidersquad == nil then
|
||||||
game.print("Create tables for spidertron control mod")
|
game.print("Create tables for spidertron control mod")
|
||||||
|
global.spidercontrol_linked_squads = {}
|
||||||
global.spidercontrol_spidersquad = {}
|
global.spidercontrol_spidersquad = {}
|
||||||
for _, player in pairs(game.players) do
|
for _, player in pairs(game.players) do
|
||||||
global.spidercontrol_spidersquad[player.index] = {spider_leader = nil, spiders={}}
|
global.spidercontrol_spidersquad[player.index] = {spider_leader = nil, spiders={}}
|
||||||
|
@ -122,6 +195,27 @@ local function initialize()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function squad_leader_state(index)
|
||||||
|
local player = game.players[index]
|
||||||
|
if player.vehicle and player.vehicle.type == "spider-vehicle" then
|
||||||
|
local unit_no = player.vehicle.unit_number
|
||||||
|
if validate_spiders(global.spidercontrol_spidersquad[index], index) then
|
||||||
|
local d = global.spidercontrol_spidersquad[index].spiders
|
||||||
|
if d then
|
||||||
|
for i, spider in pairs(d) do
|
||||||
|
-- game.print(spider.spider_entity.unit_number)
|
||||||
|
if spider.spider_entity.unit_number == unit_no then
|
||||||
|
global.spidercontrol_spidersquad[index].spider_leader = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif player.vehicle == nil and global.spidercontrol_spidersquad[index] ~= nil then -- Why is it possible for this to be nil?
|
||||||
|
global.spidercontrol_spidersquad[index].spider_leader = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
script.on_init(initialize)
|
script.on_init(initialize)
|
||||||
script.on_configuration_changed(initialize)
|
script.on_configuration_changed(initialize)
|
||||||
--commands.add_command("spiderbot_initialize_variables", "debug: ensure that all global tables are not nil (should not happen in a normal game)", initialize)
|
--commands.add_command("spiderbot_initialize_variables", "debug: ensure that all global tables are not nil (should not happen in a normal game)", initialize)
|
||||||
|
@ -134,17 +228,20 @@ script.on_event(defines.events.on_player_used_spider_remote, function(event)
|
||||||
local player = game.players[index]
|
local player = game.players[index]
|
||||||
local cursor_stack = player.cursor_stack
|
local cursor_stack = player.cursor_stack
|
||||||
if cursor_stack then -- how can a player use a remote without a cursor_stack though???
|
if cursor_stack then -- how can a player use a remote without a cursor_stack though???
|
||||||
if cursor_stack.valid_for_read and cursor_stack.name == "squad-spidertron-remote" and event.success then
|
if cursor_stack.valid_for_read and event.success then
|
||||||
|
local cname = cursor_stack.name
|
||||||
|
if cname == "squad-spidertron-remote" then
|
||||||
player.set_shortcut_toggled("squad-spidertron-follow", false)
|
player.set_shortcut_toggled("squad-spidertron-follow", false)
|
||||||
spiderbot_designate(index, event.position)
|
spiderbot_designate(index, event.position)
|
||||||
elseif cursor_stack.valid_for_read and cursor_stack.name == "spidertron-remote" and event.success then -- WARNING: We're only overriding for the player's spidertron if it's the vanilla spidertron remote. Does not cover modded remotes!
|
elseif cname == "spidertron-remote" then -- WARNING: We're only overriding for the player's spidertron if it's the vanilla spidertron remote. Does not cover modded remotes!
|
||||||
-- Alter dy and dx
|
-- Alter dy and dx
|
||||||
local unit_no = event.vehicle.unit_number
|
local unit_no = event.vehicle.unit_number
|
||||||
local d_ = global.spidercontrol_spidersquad[index]
|
local d_ = global.spidercontrol_spidersquad[index] -- Note : Decided against doing checks on a linked squad because it would involve checking that table which can be massively large (larger than player table)
|
||||||
|
if validate_spiders(d_, index) then
|
||||||
local spidersquad = d_.spiders
|
local spidersquad = d_.spiders
|
||||||
local leader = d_.spider_leader
|
local leader = d_.spider_leader
|
||||||
|
|
||||||
if spidersquad then -- HELLO: if you are reading this and have an idea how to optimize it pls let me know (Not really critical as it's not in the tick loop, but could be problematic for very large squads )
|
-- HELLO: if you are reading this and have an idea how to optimize it pls let me know (Not really critical as it's not in the tick loop, but could be problematic for very large squads )
|
||||||
for i, spider in pairs(spidersquad) do --something something premature debugging evil, but seriously the amount of loops are worrying (for large squds).
|
for i, spider in pairs(spidersquad) do --something something premature debugging evil, but seriously the amount of loops are worrying (for large squds).
|
||||||
if i ~= leader and spider.spider_entity.unit_number == unit_no then -- Don't alter dy and dx for the squad leader (leads to infinite walking)
|
if i ~= leader and spider.spider_entity.unit_number == unit_no then -- Don't alter dy and dx for the squad leader (leads to infinite walking)
|
||||||
local dest = event.position
|
local dest = event.position
|
||||||
|
@ -179,29 +276,27 @@ script.on_event(defines.events.on_player_used_spider_remote, function(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif cname == "squad-spidertron-link-tool" then
|
||||||
|
if player.selected and player.selected.valid then
|
||||||
|
local selected = player.selected
|
||||||
|
local pos = selected.position
|
||||||
|
player.print({"", "Linked ".. #global.spidercontrol_spidersquad[index].spiders .. " spiders to ", selected.localised_name, " near [gps=" .. pos.x .. "," .. pos.y .. "]"})
|
||||||
|
global.spidercontrol_linked_squads[#global.spidercontrol_linked_squads+1] = {
|
||||||
|
force=player.force.index,
|
||||||
|
target=selected,
|
||||||
|
spiders=util.table.deepcopy(global.spidercontrol_spidersquad[index].spiders)
|
||||||
|
}
|
||||||
|
global.spidercontrol_spidersquad[index] = {spider_leader = nil, spiders = {}} -- We're taking away player control of this squad!
|
||||||
|
-- Probably should print the squad ID, the target entity id and other information
|
||||||
|
else
|
||||||
|
local vehicle = event.vehicle
|
||||||
|
vehicle.autopilot_destination = vehicle.position
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function squad_leader_state(index)
|
|
||||||
local player = game.players[index]
|
|
||||||
if player.vehicle and player.vehicle.type == "spider-vehicle" then
|
|
||||||
local unit_no = player.vehicle.unit_number
|
|
||||||
local d = global.spidercontrol_spidersquad[index].spiders
|
|
||||||
if d then
|
|
||||||
for i, spider in pairs(d) do
|
|
||||||
-- game.print(spider.spider_entity.unit_number)
|
|
||||||
if spider.spider_entity.valid and spider.spider_entity.unit_number == unit_no then
|
|
||||||
global.spidercontrol_spidersquad[index].spider_leader = i
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif player.vehicle == nil then
|
|
||||||
global.spidercontrol_spidersquad[index].spider_leader = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
script.on_event(defines.events.on_player_driving_changed_state, function (event)
|
script.on_event(defines.events.on_player_driving_changed_state, function (event)
|
||||||
squad_leader_state(event.player_index)
|
squad_leader_state(event.player_index)
|
||||||
end)
|
end)
|
||||||
|
@ -211,15 +306,18 @@ script.on_event(defines.events.on_player_died, function(event)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
script.on_event(defines.events.on_lua_shortcut, function (event)
|
script.on_event(defines.events.on_lua_shortcut, function (event)
|
||||||
if event.prototype_name == "squad-spidertron-follow" then
|
local name = event.prototype_name
|
||||||
|
if name == "squad-spidertron-follow" then
|
||||||
local index = event.player_index
|
local index = event.player_index
|
||||||
squad_leader_state(index)
|
squad_leader_state(index)
|
||||||
spiderbot_follow(game.players[index])
|
spiderbot_follow(game.players[index])
|
||||||
|
elseif name == "squad-spidertron-link-tool" then
|
||||||
|
give_link_tool(event.player_index)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
script.on_event(defines.events.on_player_created, function (event)
|
script.on_event(defines.events.on_player_created, function (event)
|
||||||
global.spidercontrol_spidersquad[event.player_index] = {spiders={}}
|
global.spidercontrol_spidersquad[event.player_index] = {spider_leader = nil, spiders = {}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
script.on_event("squad-spidertron-remote", function(event)
|
script.on_event("squad-spidertron-remote", function(event)
|
||||||
|
@ -235,17 +333,49 @@ script.on_event("squad-spidertron-switch-modes", function(event)
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
local cursor_stack = player.cursor_stack
|
local cursor_stack = player.cursor_stack
|
||||||
if cursor_stack and cursor_stack.valid_for_read then
|
if cursor_stack and cursor_stack.valid_for_read then
|
||||||
if cursor_stack.name == "squad-spidertron-remote" then
|
local name = cursor_stack.name
|
||||||
|
if name == "squad-spidertron-remote" then
|
||||||
give_tool(player, {name="squad-spidertron-remote-sel",count=1})
|
give_tool(player, {name="squad-spidertron-remote-sel",count=1})
|
||||||
elseif cursor_stack.name == "squad-spidertron-remote-sel" then
|
elseif name == "squad-spidertron-remote-sel" then
|
||||||
local e = global.spidercontrol_spidersquad[event.player_index]
|
local e = global.spidercontrol_spidersquad[event.player_index]
|
||||||
if e.spiders[1] and e.spiders[1].spider_entity.valid and give_tool(player, {name="squad-spidertron-remote",count=1}) then
|
if e.spiders[1] and e.spiders[1].spider_entity.valid and give_tool(player, {name="squad-spidertron-remote",count=1}) then
|
||||||
player.cursor_stack.connected_entity=e.spiders[1].spider_entity
|
player.cursor_stack.connected_entity=e.spiders[1].spider_entity
|
||||||
end
|
end
|
||||||
|
-- -- Link pair
|
||||||
|
elseif name == "squad-spidertron-link-tool" then
|
||||||
|
give_tool(player, {name="squad-spidertron-unlink-tool",count=1})
|
||||||
|
elseif name == "squad-spidertron-unlink-tool" then
|
||||||
|
give_link_tool(event.player_index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
script.on_event("squad-spidertron-link-tool", function(event)
|
||||||
|
give_link_tool(event.player_index)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- -- - This stuff handles the link tool
|
||||||
|
-- script.on_event(defines.events.on_put_item, 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
|
||||||
|
-- if cursor_stack.name == "spidertron-link-tool" then
|
||||||
|
|
||||||
|
-- game.print("HELLO")
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
-- end)
|
||||||
|
|
||||||
|
-- script.on_event(defines.events.on_built_entity, function(event)
|
||||||
|
-- if event.created_entity.name == "spidertron-link-tool" then
|
||||||
|
-- event.created_entity.destroy()
|
||||||
|
-- -- give_tool(player, {name="spidertron-link-tool",count=1}) -- Not using because this can cause UPS lag if someone click-drags it within placement range!
|
||||||
|
-- game.print("HELLO")
|
||||||
|
-- end
|
||||||
|
-- end)
|
||||||
|
|
||||||
|
|
||||||
local mov_offset = settings.global["spidertron-follow-prediction-distance"].value --This is so the player stays within the spider squad when moving
|
local mov_offset = settings.global["spidertron-follow-prediction-distance"].value --This is so the player stays within the spider squad when moving
|
||||||
local mov_offset_diagonal = math.sqrt(mov_offset^2/2)
|
local mov_offset_diagonal = math.sqrt(mov_offset^2/2)
|
||||||
|
@ -293,7 +423,8 @@ script.on_nth_tick(update_interval, function(event)
|
||||||
for _, player in pairs(game.players) do
|
for _, player in pairs(game.players) do
|
||||||
if player.is_shortcut_toggled("squad-spidertron-follow") and player.controller_type ~= 0 then -- 0 => defines.character.ghost (DEAD)
|
if player.is_shortcut_toggled("squad-spidertron-follow") and player.controller_type ~= 0 then -- 0 => defines.character.ghost (DEAD)
|
||||||
local index = player.index
|
local index = player.index
|
||||||
if global.spidercontrol_spidersquad[index].spiders[1] then
|
local chk = global.spidercontrol_spidersquad[index]
|
||||||
|
if chk and chk.spiders and #chk.spiders > 0 then
|
||||||
local p_pos = player.position
|
local p_pos = player.position
|
||||||
local pos = p_pos
|
local pos = p_pos
|
||||||
if player.walking_state.walking then
|
if player.walking_state.walking then
|
||||||
|
@ -304,4 +435,24 @@ script.on_nth_tick(update_interval, function(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if #global.spidercontrol_linked_squads > 0 then -- Might put this on another update_interval loop so the lag can be adjusted accordingly. Use the old modulo trick for that.
|
||||||
|
for i,t in pairs(global.spidercontrol_linked_squads) do
|
||||||
|
-- local t = global.spidercontrol_linked_squads[i]
|
||||||
|
if t.spiders then
|
||||||
|
if t.target.valid then
|
||||||
|
if #t.spiders > 0 then
|
||||||
|
spiderbot_designate(i, t.target.position, true)
|
||||||
|
else
|
||||||
|
local pos = t.target.position
|
||||||
|
game.forces[t.force].print({"", "Spidertron squad has been destroyed or unlinked from ", t.target.localised_name, " near [gps="..pos.x..","..pos.y.."]"}) -- using force comms because this could be the death of a spidertron, not only removal
|
||||||
|
table.remove(global.spidercontrol_linked_squads,i)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local pos = t.spiders[1].spider_entity.position
|
||||||
|
game.forces[t.force].print("Target entity of spidertron squad has been destroyed or removed near [gps="..pos.x..","..pos.y.."]")
|
||||||
|
table.remove(global.spidercontrol_linked_squads,i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end)
|
end)
|
BIN
graphics/icons/spidertron-link-tool-mask.png
Normal file
BIN
graphics/icons/spidertron-link-tool-mask.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 281 B |
BIN
graphics/icons/spidertron-link-tool.png
Normal file
BIN
graphics/icons/spidertron-link-tool.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
BIN
graphics/icons/spidertron-unlink-tool.png
Normal file
BIN
graphics/icons/spidertron-unlink-tool.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Spider_Control",
|
"name": "Spider_Control",
|
||||||
"version": "0.3.2",
|
"version": "0.4.0",
|
||||||
"factorio_version": "1.0",
|
"factorio_version": "1.0",
|
||||||
"title": "Spidertron squad control",
|
"title": "Spidertron squad control",
|
||||||
"author": "npc_strider(morley376)",
|
"author": "npc_strider(morley376)",
|
||||||
|
|
6
make.sh
Normal file
6
make.sh
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
v=$(grep "\"version\"" info.json | sed 's|.*:||;s|[",]||g;s| ||g')
|
||||||
|
n=$(grep "\"name\"" info.json | sed 's|.*:||;s|[",]||g;s| ||g')
|
||||||
|
#echo ${n}_${v}.zip
|
||||||
|
|
||||||
|
powershell -c "\$files = Get-ChildItem -Path . -Exclude .git,*.sh
|
||||||
|
Compress-Archive -Path \$files -DestinationPath ../${n}_${v}.zip"
|
3
migrations/Spider_Control_0.4.0.lua
Normal file
3
migrations/Spider_Control_0.4.0.lua
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
if global.spidercontrol_linked_squads == nil then
|
||||||
|
global.spidercontrol_linked_squads = {}
|
||||||
|
end
|
137
shortcuts.lua
137
shortcuts.lua
|
@ -8,6 +8,57 @@
|
||||||
|
|
||||||
require('util')
|
require('util')
|
||||||
|
|
||||||
|
local item_remote_sel = {
|
||||||
|
type = "selection-tool",
|
||||||
|
name = "squad-spidertron-remote-sel",
|
||||||
|
icon = "__base__/graphics/icons/spidertron-remote.png",
|
||||||
|
-- icon_color_indicator_mask = "__base__/graphics/icons/spidertron-remote-mask.png",
|
||||||
|
icon_size = 64, icon_mipmaps = 4,
|
||||||
|
subgroup = "other",
|
||||||
|
flags = {"hidden", "not-stackable", "only-in-cursor"},
|
||||||
|
order = "b[personal-transport]-c[spidertron]-b[squad-remote]",
|
||||||
|
stack_size = 1,
|
||||||
|
stackable = false,
|
||||||
|
selection_color = { r = 1, g = 0, b = 0 },
|
||||||
|
alt_selection_color = { r = 1, g = 0, b = 0 },
|
||||||
|
selection_mode = {"same-force", "entity-with-health"},
|
||||||
|
alt_selection_mode = {"same-force", "entity-with-health"},
|
||||||
|
selection_cursor_box_type = "copy",
|
||||||
|
alt_selection_cursor_box_type = "copy",
|
||||||
|
entity_type_filters = {"spider-vehicle"},
|
||||||
|
tile_filters = {"lab-dark-1"},
|
||||||
|
entity_filter_mode = "whitelist",
|
||||||
|
tile_filter_mode = "whitelist",
|
||||||
|
alt_entity_type_filters = {"spider-vehicle"},
|
||||||
|
alt_tile_filters = {"lab-dark-1"},
|
||||||
|
alt_entity_filter_mode = "whitelist",
|
||||||
|
alt_tile_filter_mode = "whitelist",
|
||||||
|
always_include_tiles = false
|
||||||
|
}
|
||||||
|
|
||||||
|
local item_unlink_sel = util.table.deepcopy(item_remote_sel)
|
||||||
|
item_unlink_sel.name = "squad-spidertron-unlink-tool"
|
||||||
|
item_unlink_sel.icon = "__Spider_Control__/graphics/icons/spidertron-unlink-tool.png"
|
||||||
|
|
||||||
|
local item_remote = {
|
||||||
|
type = "spidertron-remote",
|
||||||
|
name = "squad-spidertron-remote",
|
||||||
|
localised_name = "Spidertron squad remote",
|
||||||
|
icon = "__base__/graphics/icons/spidertron-remote.png",
|
||||||
|
icon_color_indicator_mask = "__base__/graphics/icons/spidertron-remote-mask.png",
|
||||||
|
icon_size = 64, icon_mipmaps = 4,
|
||||||
|
subgroup = "other",
|
||||||
|
flags = {"hidden", "not-stackable", "only-in-cursor"},
|
||||||
|
order = "b[personal-transport]-c[spidertron]-b[remote]",
|
||||||
|
stack_size = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
local item_link = util.table.deepcopy(item_remote)
|
||||||
|
item_link.name = "squad-spidertron-link-tool"
|
||||||
|
item_link.localised_name = "Spidertron link tool"
|
||||||
|
item_link.icon = "__Spider_Control__/graphics/icons/spidertron-link-tool.png"
|
||||||
|
item_link.icon_color_indicator_mask = "__Spider_Control__/graphics/icons/spidertron-link-tool-mask.png"
|
||||||
|
|
||||||
local shortcut_remote = {
|
local shortcut_remote = {
|
||||||
type = "shortcut",
|
type = "shortcut",
|
||||||
name = "squad-spidertron-remote",
|
name = "squad-spidertron-remote",
|
||||||
|
@ -47,11 +98,18 @@ local shortcut_remote = {
|
||||||
local shortcut_follow = util.table.deepcopy(shortcut_remote)
|
local shortcut_follow = util.table.deepcopy(shortcut_remote)
|
||||||
shortcut_follow.name = "squad-spidertron-follow"
|
shortcut_follow.name = "squad-spidertron-follow"
|
||||||
shortcut_follow.action = "lua"
|
shortcut_follow.action = "lua"
|
||||||
shortcut_follow.localised_name = "Follow player"
|
shortcut_follow.localised_name = "Spidertron follow player"
|
||||||
shortcut_follow.associated_control_input = "squad-spidertron-follow"
|
shortcut_follow.associated_control_input = "squad-spidertron-follow"
|
||||||
shortcut_follow.style = "blue"
|
shortcut_follow.style = "blue"
|
||||||
shortcut_follow.toggleable = true
|
shortcut_follow.toggleable = true
|
||||||
|
|
||||||
|
local shortcut_link = util.table.deepcopy(shortcut_remote)
|
||||||
|
shortcut_link.name = "squad-spidertron-link-tool"
|
||||||
|
shortcut_link.action = "lua"
|
||||||
|
shortcut_link.localised_name = "Link spidertrons to entity"
|
||||||
|
shortcut_link.associated_control_input = "squad-spidertron-link-tool"
|
||||||
|
shortcut_link.style = "green"
|
||||||
|
|
||||||
local input_remote = {
|
local input_remote = {
|
||||||
type = "custom-input",
|
type = "custom-input",
|
||||||
name = "squad-spidertron-remote",
|
name = "squad-spidertron-remote",
|
||||||
|
@ -70,52 +128,57 @@ input_switch_modes.name = "squad-spidertron-switch-modes"
|
||||||
input_switch_modes.localised_name = "Switch modes (between selecting and commanding)"
|
input_switch_modes.localised_name = "Switch modes (between selecting and commanding)"
|
||||||
input_switch_modes.key_sequence = "mouse-button-2"
|
input_switch_modes.key_sequence = "mouse-button-2"
|
||||||
|
|
||||||
|
local input_link = util.table.deepcopy(input_remote)
|
||||||
|
input_link.name = "squad-spidertron-link-tool"
|
||||||
|
input_link.localised_name = "Link spidertron squad to entity"
|
||||||
|
input_link.key_sequence = "ALT + Z"
|
||||||
|
|
||||||
data:extend(
|
data:extend(
|
||||||
{
|
{
|
||||||
shortcut_remote,
|
shortcut_remote,
|
||||||
shortcut_follow,
|
shortcut_follow,
|
||||||
|
shortcut_link,
|
||||||
|
|
||||||
|
item_remote_sel,
|
||||||
|
item_unlink_sel,
|
||||||
|
|
||||||
{
|
{
|
||||||
type = "selection-tool",
|
type = "simple-entity",
|
||||||
name = "squad-spidertron-remote-sel",
|
name = "spidertron-link-tool",
|
||||||
icon = "__base__/graphics/icons/spidertron-remote.png",
|
icon = "__base__/graphics/icons/ship-wreck/small-ship-wreck.png",
|
||||||
-- icon_color_indicator_mask = "__base__/graphics/icons/spidertron-remote-mask.png",
|
icon_size = 32,
|
||||||
icon_size = 64, icon_mipmaps = 4,
|
flags = {"placeable-off-grid"},
|
||||||
subgroup = "other",
|
selectable_in_game = false,
|
||||||
flags = {"hidden", "not-stackable", "only-in-cursor"},
|
map_color = {r=0, g=0, b=0},
|
||||||
order = "b[personal-transport]-c[spidertron]-b[squad-remote]",
|
order = "a[spidertron-link-tool]",
|
||||||
stack_size = 1,
|
max_health = 1,
|
||||||
stackable = false,
|
collision_box = {{0, 0}, {0, 0}},
|
||||||
selection_color = { r = 1, g = 0, b = 0 },
|
collision_mask = {"layer-13"},
|
||||||
alt_selection_color = { r = 1, g = 0, b = 0 },
|
picture =
|
||||||
selection_mode = {"same-force", "entity-with-health"},
|
{
|
||||||
alt_selection_mode = {"same-force", "entity-with-health"},
|
filename = "__core__/graphics/empty.png",
|
||||||
selection_cursor_box_type = "copy",
|
width = 1,
|
||||||
alt_selection_cursor_box_type = "copy",
|
height= 1
|
||||||
entity_type_filters = {"spider-vehicle"},
|
}
|
||||||
tile_filters = {"lab-dark-1"},
|
|
||||||
entity_filter_mode = "whitelist",
|
|
||||||
tile_filter_mode = "whitelist",
|
|
||||||
alt_entity_type_filters = {"spider-vehicle"},
|
|
||||||
alt_tile_filters = {"lab-dark-1"},
|
|
||||||
alt_entity_filter_mode = "whitelist",
|
|
||||||
alt_tile_filter_mode = "whitelist",
|
|
||||||
always_include_tiles = false
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "spidertron-remote",
|
type = "item",
|
||||||
name = "squad-spidertron-remote",
|
name = "spidertron-link-tool",
|
||||||
localised_name = "Spidertron squad remote",
|
icon = "__base__/graphics/technology/laser.png",
|
||||||
icon = "__base__/graphics/icons/spidertron-remote.png",
|
icon_size = 128,
|
||||||
icon_color_indicator_mask = "__base__/graphics/icons/spidertron-remote-mask.png",
|
flags = {"only-in-cursor", "hidden"},
|
||||||
icon_size = 64, icon_mipmaps = 4,
|
place_result = "spidertron-link-tool",
|
||||||
subgroup = "other",
|
subgroup = "capsule",
|
||||||
flags = {"hidden", "not-stackable", "only-in-cursor"},
|
order = "zz",
|
||||||
order = "b[personal-transport]-c[spidertron]-b[remote]",
|
stack_size = 1,
|
||||||
stack_size = 1
|
stackable = false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
item_remote,
|
||||||
|
item_link,
|
||||||
|
|
||||||
input_remote,
|
input_remote,
|
||||||
input_follow,
|
input_follow,
|
||||||
input_switch_modes
|
input_switch_modes,
|
||||||
|
input_link
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user