mirror of
https://github.com/peter-tanner/spidertron-squad-control.git
synced 2024-11-30 11:00:17 +08:00
0.1.0: Initial commit, basic features
This commit is contained in:
commit
522383bb23
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 npc_strider
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
5
changelog.txt
Normal file
5
changelog.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.1.0
|
||||
Date: 2020-08-14
|
||||
Features:
|
||||
- Initial release: Adds shortcut to command a squad of spidertrons
|
2
clean_changelog.sh
Normal file
2
clean_changelog.sh
Normal file
|
@ -0,0 +1,2 @@
|
|||
sed -i -e 's/\t/ /g' -e 's/\s*$//' changelog.txt
|
||||
#from factorioforums: https://forums.factorio.com/viewtopic.php?f=25&t=67140
|
90
control.lua
Normal file
90
control.lua
Normal file
|
@ -0,0 +1,90 @@
|
|||
--[[ 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.lua
|
||||
* Spiderbot.
|
||||
--]]
|
||||
|
||||
local function spiderbot_select(event)
|
||||
local index = event.player_index
|
||||
local spiders = event.entities
|
||||
if event.item == "squad-spidertron-remote-sel" and #spiders > 0 then
|
||||
global.spidercontrol_spidersquad[index] = spiders
|
||||
local player = game.players[index]
|
||||
local stack = {
|
||||
name="squad-spidertron-remote",
|
||||
count=1
|
||||
}
|
||||
-- game.print(spiders[1])
|
||||
if player.cursor_stack.can_set_stack(stack) then
|
||||
player.cursor_stack.set_stack(stack)
|
||||
player.cursor_stack.connected_entity=spiders[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function validate_spiders(index)
|
||||
local c=0
|
||||
for i, spider in pairs(global.spidercontrol_spidersquad[index]) do
|
||||
if not spider.valid then
|
||||
global.spidercontrol_spidersquad[index][i] = nil
|
||||
c=c+1
|
||||
end
|
||||
end
|
||||
if c > 0 then
|
||||
game.players[index].print(c .. " units were destroyed since the last position command was sent")
|
||||
end
|
||||
end
|
||||
|
||||
local function spiderbot_designate(event)
|
||||
local index = event.player_index
|
||||
local player = game.players[index]
|
||||
if player.cursor_stack.valid_for_read and player.cursor_stack.name == "squad-spidertron-remote" then
|
||||
validate_spiders(index)
|
||||
local spidersquad = global.spidercontrol_spidersquad[index]
|
||||
local xbar=0
|
||||
local ybar=0
|
||||
local c=0
|
||||
for _, spider in pairs(spidersquad) do
|
||||
c=c+1
|
||||
-- game.print(spider.position)
|
||||
xbar=xbar+spider.position.x
|
||||
ybar=ybar+spider.position.y
|
||||
end
|
||||
xbar=xbar/c
|
||||
ybar=ybar/c
|
||||
|
||||
dy=event.position.y-ybar
|
||||
dx=event.position.x-xbar
|
||||
|
||||
for _, spider in pairs(spidersquad) do
|
||||
local position = spider.position
|
||||
spider.autopilot_destination = {position.x+dx, position.y+dy}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function initialize()
|
||||
if global.spidercontrol_spidersquad == nil then
|
||||
global.spidercontrol_spidersquad = {}
|
||||
end
|
||||
end
|
||||
|
||||
script.on_init(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)
|
||||
|
||||
script.on_event(defines.events.on_player_alt_selected_area, spiderbot_select)
|
||||
script.on_event(defines.events.on_player_selected_area, spiderbot_select)
|
||||
script.on_event(defines.events.on_player_used_spider_remote, spiderbot_designate)
|
||||
|
||||
script.on_event("squad-spidertron-remote", function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local stack = {name="squad-spidertron-remote-sel",count=1}
|
||||
if player.clean_cursor() and player.cursor_stack.can_set_stack(stack) then
|
||||
player.get_inventory(2).remove("squad-spidertron-remote-sel")
|
||||
player.get_inventory(2).remove("squad-spidertron-remote")
|
||||
player.cursor_stack.set_stack(stack)
|
||||
end
|
||||
end)
|
9
data.lua
Normal file
9
data.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
--[[ 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
|
||||
*
|
||||
* data.lua
|
||||
* Data
|
||||
--]]
|
||||
|
||||
require("shortcuts")
|
11
info.json
Normal file
11
info.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "Spider_Control",
|
||||
"version": "0.1.0",
|
||||
"factorio_version": "1.0",
|
||||
"title": "Spidertron squad control",
|
||||
"author": "npc_strider(morley376)",
|
||||
"contact": "",
|
||||
"homepage": "http://steamcommunity.com/id/morley376",
|
||||
"dependencies": ["base >= 1.0.0"],
|
||||
"description": "spidertron squad controls so you don't have to use 100 remotes to control your spider army"
|
||||
}
|
92
shortcuts.lua
Normal file
92
shortcuts.lua
Normal file
|
@ -0,0 +1,92 @@
|
|||
--[[ 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
|
||||
*
|
||||
* shortcuts.lua
|
||||
* Shortcuts and required items etc for the spider controls
|
||||
--]]
|
||||
|
||||
data:extend(
|
||||
{
|
||||
{
|
||||
type = "shortcut",
|
||||
name = "squad-spidertron-remote",
|
||||
order = "a[squad-spidertron-remote]",
|
||||
action = "create-blueprint-item",
|
||||
localised_name = "Spidertron squad remote",
|
||||
associated_control_input = "squad-spidertron-remote",
|
||||
technology_to_unlock = "spidertron",
|
||||
item_to_create = "squad-spidertron-remote-sel",
|
||||
style = "red",
|
||||
icon =
|
||||
{
|
||||
filename = "__base__/graphics/icons/spidertron.png",
|
||||
priority = "extra-high-no-scale",
|
||||
size = 64,
|
||||
scale = 1,
|
||||
flags = {"icon"}
|
||||
},
|
||||
-- small_icon =
|
||||
-- {
|
||||
-- filename = "__Shortcuts__/graphics/artillery-targeting-remote-x24.png",
|
||||
-- priority = "extra-high-no-scale",
|
||||
-- size = 24,
|
||||
-- scale = 1,
|
||||
-- flags = {"icon"}
|
||||
-- },
|
||||
-- disabled_small_icon =
|
||||
-- {
|
||||
-- filename = "__Shortcuts__/graphics/artillery-targeting-remote-x24-white.png",
|
||||
-- priority = "extra-high-no-scale",
|
||||
-- size = 24,
|
||||
-- scale = 1,
|
||||
-- flags = {"icon"}
|
||||
-- },
|
||||
},
|
||||
{
|
||||
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
|
||||
},
|
||||
{
|
||||
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
|
||||
},
|
||||
{
|
||||
type = "custom-input",
|
||||
name = "squad-spidertron-remote",
|
||||
localised_name = "Spidertron squad remote",
|
||||
key_sequence = "ALT + X",
|
||||
consuming = "game-only"
|
||||
}
|
||||
})
|
BIN
thumbnail.png
Normal file
BIN
thumbnail.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 233 KiB |
Loading…
Reference in New Issue
Block a user