mirror of
https://github.com/peter-tanner/spidertron-squad-control.git
synced 2024-11-30 11:00:17 +08:00
0.2.0: Add follow mode
This commit is contained in:
parent
9d56dad154
commit
0c60f31266
|
@ -9,3 +9,9 @@ Version: 0.1.1
|
|||
Date: 2020-08-15
|
||||
Bugfixes:
|
||||
- Fixed issue clearing inventory of 'residual' remotes with non-god controllers (*Facepalm*)
|
||||
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.2.0
|
||||
Date: 2020-08-15
|
||||
Features:
|
||||
- Adds follow mode for your squad to follow you either on foot or in a vehicle
|
||||
|
|
106
control.lua
106
control.lua
|
@ -37,32 +37,45 @@ local function validate_spiders(index)
|
|||
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 function squad_center(spidersquad)
|
||||
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
|
||||
return {xbar,ybar}
|
||||
end
|
||||
|
||||
dy=event.position.y-ybar
|
||||
dx=event.position.x-xbar
|
||||
local function spiderbot_designate(index, position_)
|
||||
validate_spiders(index)
|
||||
local spidersquad = global.spidercontrol_spidersquad[index]
|
||||
|
||||
local posbar = squad_center(spidersquad)
|
||||
|
||||
local dx=position_.x-posbar[1]
|
||||
local dy=position_.y-posbar[2]
|
||||
|
||||
for _, spider in pairs(spidersquad) do
|
||||
local position = spider.position
|
||||
spider.autopilot_destination = {position.x+dx, position.y+dy}
|
||||
end
|
||||
end
|
||||
|
||||
local function spiderbot_follow(player)
|
||||
if player.character then
|
||||
if player.is_shortcut_toggled("squad-spidertron-follow") then
|
||||
player.set_shortcut_toggled("squad-spidertron-follow", false)
|
||||
else
|
||||
player.set_shortcut_toggled("squad-spidertron-follow", true)
|
||||
end
|
||||
else
|
||||
player.print({"", {"error.error-message-box-title"}, ": ", {"player-doesnt-exist", {"gui.character"}}, " (", {"controller.god"}, "): ", {"gui-mod-info.status-disabled"}})
|
||||
end
|
||||
end
|
||||
|
||||
local function initialize()
|
||||
|
@ -77,7 +90,21 @@ script.on_configuration_changed(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(defines.events.on_player_used_spider_remote, function (event)
|
||||
local index = event.player_index
|
||||
local player = game.players[index]
|
||||
local cursor_stack = player.cursor_stack
|
||||
if cursor_stack.valid_for_read and cursor_stack.name == "squad-spidertron-remote" and event.success then
|
||||
player.set_shortcut_toggled("squad-spidertron-follow", false)
|
||||
spiderbot_designate(index, event.position)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_lua_shortcut, function (event)
|
||||
if event.prototype_name == "squad-spidertron-follow" then
|
||||
spiderbot_follow(game.players[event.player_index])
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event("squad-spidertron-remote", function(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
@ -91,3 +118,62 @@ script.on_event("squad-spidertron-remote", function(event)
|
|||
player.cursor_stack.set_stack(stack)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event("squad-spidertron-follow", function(event)
|
||||
spiderbot_follow(game.players[event.player_index])
|
||||
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_diagonal = math.sqrt(mov_offset^2/2)
|
||||
|
||||
local update_interval = settings.global["spidertron-follow-update-interval"].value
|
||||
|
||||
script.on_nth_tick(update_interval, function (event)
|
||||
for _, player in pairs(game.players) do
|
||||
if player.is_shortcut_toggled("squad-spidertron-follow") and global.spidercontrol_spidersquad[player.index] then
|
||||
local index = player.index
|
||||
local pos = player.position
|
||||
local pos_x = pos.x
|
||||
local pos_y = pos.y
|
||||
if player.walking_state.walking then
|
||||
local dir = player.walking_state.direction
|
||||
local def_dir = defines.direction
|
||||
if dir == def_dir.north then
|
||||
pos_y = pos_y - mov_offset
|
||||
elseif dir == def_dir.northeast then
|
||||
-- game.print("ne")
|
||||
pos_x = pos_x + mov_offset_diagonal
|
||||
pos_y = pos_y - mov_offset_diagonal
|
||||
elseif dir == def_dir.east then
|
||||
-- game.print("e")
|
||||
pos_x = pos_x + mov_offset
|
||||
elseif dir == def_dir.southeast then
|
||||
-- game.print("se")
|
||||
pos_x = pos_x + mov_offset_diagonal
|
||||
pos_y = pos_y + mov_offset_diagonal
|
||||
elseif dir == def_dir.south then
|
||||
-- game.print("s")
|
||||
pos_y = pos_y + mov_offset
|
||||
elseif dir == def_dir.southwest then
|
||||
-- game.print("sw")
|
||||
pos_x = pos_x - mov_offset_diagonal
|
||||
pos_y = pos_y + mov_offset_diagonal
|
||||
elseif dir == def_dir.west then
|
||||
-- game.print("w")
|
||||
pos_x = pos_x - mov_offset
|
||||
else -- northwest
|
||||
-- game.print("nw")
|
||||
pos_x = pos_x - mov_offset_diagonal
|
||||
pos_y = pos_y - mov_offset_diagonal
|
||||
end
|
||||
end
|
||||
spiderbot_designate(index, {x=pos_x, y=pos_y})
|
||||
if player.vehicle then
|
||||
local vehicle = player.vehicle
|
||||
if vehicle.type == "spider-vehicle" then
|
||||
vehicle.autopilot_destination = squad_center(global.spidercontrol_spidersquad[index])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"name": "Spider_Control",
|
||||
"version": "0.1.1",
|
||||
"version": "0.2.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"
|
||||
"description": "adds a spidertron squad remote so you don't have to use 100 remotes to control your spider army. also adds a follow mode for your spider army"
|
||||
}
|
31
settings.lua
Normal file
31
settings.lua
Normal file
|
@ -0,0 +1,31 @@
|
|||
--[[ 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
|
||||
*
|
||||
* settings.lua
|
||||
* Mod settings
|
||||
--]]
|
||||
|
||||
|
||||
data:extend({
|
||||
-- server
|
||||
{
|
||||
type = "double-setting",
|
||||
name = "spidertron-follow-prediction-distance",
|
||||
localised_name = "Follow prediction distance",
|
||||
localised_description = "When in follow mode, the movement targets of the spider bot will be this far ahead of the player's position. Minimum value: 0.0, Maximum value: 500.0, Default value: 20.0",
|
||||
setting_type = "runtime-global",
|
||||
default_value = 20.0,
|
||||
minimum_value = 0.0,
|
||||
maximum_value = 500.0,
|
||||
},
|
||||
{
|
||||
type = "int-setting",
|
||||
name = "spidertron-follow-update-interval",
|
||||
localised_name = "Follow update interval",
|
||||
localised_description = "Rate at which the follow mode updates the target positions of the spidertrons. This value is in ticks. Larger values are less laggy but result in less responsive squad movement. Minimum value: 5, Default value: 20",
|
||||
setting_type = "runtime-global",
|
||||
default_value = 20,
|
||||
minimum_value = 5
|
||||
}
|
||||
})
|
|
@ -6,9 +6,9 @@
|
|||
* Shortcuts and required items etc for the spider controls
|
||||
--]]
|
||||
|
||||
data:extend(
|
||||
{
|
||||
{
|
||||
require('util')
|
||||
|
||||
local shortcut_remote = {
|
||||
type = "shortcut",
|
||||
name = "squad-spidertron-remote",
|
||||
order = "a[squad-spidertron-remote]",
|
||||
|
@ -42,7 +42,34 @@ data:extend(
|
|||
-- scale = 1,
|
||||
-- flags = {"icon"}
|
||||
-- },
|
||||
},
|
||||
}
|
||||
|
||||
local shortcut_follow = util.table.deepcopy(shortcut_remote)
|
||||
shortcut_follow.name = "squad-spidertron-follow"
|
||||
shortcut_follow.action = "lua"
|
||||
shortcut_follow.localised_name = "Follow player"
|
||||
shortcut_follow.associated_control_input = "squad-spidertron-follow"
|
||||
shortcut_follow.style = "blue"
|
||||
shortcut_follow.toggleable = true
|
||||
|
||||
local input_remote = {
|
||||
type = "custom-input",
|
||||
name = "squad-spidertron-remote",
|
||||
localised_name = "Spidertron squad remote",
|
||||
key_sequence = "ALT + X",
|
||||
consuming = "none"
|
||||
}
|
||||
|
||||
local input_follow = util.table.deepcopy(input_remote)
|
||||
input_follow.name = "squad-spidertron-follow"
|
||||
input_follow.localised_name = "Follow player"
|
||||
input_follow.key_sequence = "ALT + C"
|
||||
|
||||
data:extend(
|
||||
{
|
||||
shortcut_remote,
|
||||
shortcut_follow,
|
||||
|
||||
{
|
||||
type = "selection-tool",
|
||||
name = "squad-spidertron-remote-sel",
|
||||
|
@ -82,11 +109,7 @@ data:extend(
|
|||
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"
|
||||
}
|
||||
|
||||
input_remote,
|
||||
input_follow
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user