v0.5.0: artillery toggle, grid overlay, max rate and tree killer

Fixed issue with nanobots
This commit is contained in:
Peter 2019-03-23 15:24:40 +08:00
parent 58197dca55
commit 08fd8b76d1
25 changed files with 307 additions and 47 deletions

View File

@ -1,11 +1,13 @@
---------------------------------------------------------------------------------------------------
Version: 0.5.0
Date: 22. 03. 2019
Date: 23. 03. 2019
Features:
- Add selection tool to disable rail artillery
- Add a shortcut for the tree/rock deconstruction planner
- Customizable tile grid overlay, with adjustable widths & more
- Add mod support for max rate calculator
Bugfixes:
- Fixed conflict with Nanobots mod
- Fixed conflict with Nanobots mod. When both are installed the Nanobots mod takes priority over this mod.
---------------------------------------------------------------------------------------------------
Version: 0.4.0
Date: 10. 03. 2019

View File

@ -66,45 +66,14 @@ local function toggle_light(player)
end
end
local function shortcut_type(event)
local prototype_name = event.prototype_name
if not game.active_mods["Nanobots"] then
if prototype_name == "night-vision-equipment" then
update_state(event, "night-vision-equipment")
return
elseif prototype_name == "belt-immunity-equipment" then
update_state(event, "belt-immunity-equipment")
return
elseif prototype_name == "active-defense-equipment" then
update_state(event, "active-defense-equipment")
return
end
end
if prototype_name == "flashlight-toggle" then
toggle_light(game.players[event.player_index])
elseif prototype_name == "big-zoom" then
local player = game.players[event.player_index]
if settings.global["disable-zoom"].value == true then
player.zoom = settings.get_player_settings(player)["zoom-level"].value
else
player.print({"", {"error.error-message-box-title"}, ": ", {"controls.alt-zoom-out"}, " ", {"gui-mod-info.status-disabled"}})
end
elseif prototype_name == "signal-flare" then
local player = game.players[event.player_index]
if settings.global["disable-zoom"].value == true then
player.force.print({"", "[img=virtual-signal.signal-danger] [color=1,0.1,0.1]", {"entity-name.player"}, " " .. player.name .. " [gps=" .. math.floor(player.position.x+0.5) .. "," .. math.floor(player.position.y+0.5) .. "][/color] [img=virtual-signal.signal-danger]"})
else
player.print({"", {"error.error-message-box-title"}, ": ", {"technology-name.military"}, " ", {"entity-name.beacon"}, " ", {"gui-mod-info.status-disabled"}})
end
end
end
local function update_inventory(event) -- removes spare remotes
local item_prototypes = game.item_prototypes
local inventory = game.players[event.player_index].get_inventory(defines.inventory.player_main)
if inventory and inventory.valid then
inventory.remove("artillery-targeting-remote")
inventory.remove("artillery-jammer-tool")
inventory.remove("discharge-defense-remote")
inventory.remove("shortcuts-deconstruction-planner")
if item_prototypes["resource-monitor"] then
inventory.remove("resource-monitor")
end
@ -215,31 +184,118 @@ local function artillery_swap(wagon,new_name)
local damage = wagon.damage_dealt
local health = wagon.health
wagon.destroy()
local new_wagon = game.surfaces[surface].create_entity{name=new_name, position=position, direction=direction, force=force, kills=kills, damage=damage, create_build_effect_smoke=false}
local new_wagon = game.surfaces[surface].create_entity{name=new_name, position=position, direction=direction, force=force, create_build_effect_smoke=false}
if new_wagon then
new_wagon.kills = kills
new_wagon.damage_dealt = damage
new_wagon.health = health
for i=1,(#shellcount) do
if new_wagon.can_insert({name=shellname[i],count=shellcount[i]}) == true then
new_wagon.insert({name=shellname[i],count=shellcount[i]})
end
end
else
game.print("ERROR: Artillery wagon failed to convert (this is not supposed to occur)")
end
return new_wagon
end
local function jam_artillery(event)
if event.item == "artillery-jammer-tool" and event.entities ~= nil then
local player = game.players[event.player_index]
local i = 0
local j = 0
for _, wagon in pairs(event.entities) do
local name = wagon.name
if wagon.valid and wagon.type == "artillery-wagon" and not (string.sub(name,1,9) == "disabled-") then
i=i+1
local new_name = ("disabled-" .. name)
local new_wagon = artillery_swap(wagon,new_name)
rendering.draw_sprite{sprite="virtual-signal.signal-disabled", x_scale=1.5, y_scale=1.5, target_offset={0.0,-0.5}, render_layer="entity-info-icon", target=new_wagon, surface=new_wagon.surface, forces={new_wagon.force}}
elseif wagon.valid and wagon.type == "artillery-wagon" and (string.sub(name,1,9) == "disabled-") then
j=j+1
local new_name = (string.sub(name,10,#name))
artillery_swap(wagon,new_name)
end
end
if game.is_multiplayer() == true then
if i ~= 0 and j == 0 then
player.force.print("Player " .. player.name .. " on surface " .. player.surface.name .. " has disabled " .. i .. " artillery wagons")
elseif i == 0 and j ~= 0 then
player.force.print("Player " .. player.name .. " on surface " .. player.surface.name .. " has enabled " .. j .. " artillery wagons")
elseif i ~= 0 and j ~= 0 then
player.force.print("Player " .. player.name .. " on surface " .. player.surface.name .. " has enabled " .. j .. " and disabled " .. i .. " artillery wagons")
end
end
end
end
local function draw_grid(player_index)
local player = game.players[player_index]
if global.shortcuts_grid[player_index] == nil then
global.shortcuts_grid[player_index] = {}
end
-- game.print(#global.shortcuts_grid[player_index])
if #global.shortcuts_grid[player_index] == 0 then
player.set_shortcut_toggled("draw-grid", true)
-- Opts
local settings = settings.get_player_settings(player)
local radius = settings["grid-radius"].value
local step = settings["grid-step"].value
local thinn_width = settings["grid-line-width"].value
local thicc_width = settings["grid-chunk-line-width"].value
local chunk_align = settings["grid-chunk-align"].value
local ground_grid = settings["grid-ground"].value
local center_x = math.floor(player.position.x)
local center_y = math.floor(player.position.y)
if chunk_align == true then
center_x = math.floor(player.position.x/32)*32
center_y = math.floor(player.position.y/32)*32
end
-- game.print(center_x .. ", " .. center_y)
for i=-radius,(radius),step do
if (center_x+i) % 32 == 0 then
width = thicc_width
else
width = thinn_width
end
local line = rendering.draw_line{
color = {r = 0, g = 0, b = 0, a = 1},
width = width,
from = {center_x+i,center_y+radius},
to = {center_x+i,center_y-radius},
surface = player.surface,
players = {player},
draw_on_ground = ground_grid
}
global.shortcuts_grid[player_index][#global.shortcuts_grid[player_index]+1] = line
if (center_y+i) % 32 == 0 then
width = thicc_width
else
width = thinn_width
end
local line = rendering.draw_line{
color = {r = 0, g = 0, b = 0, a = 1},
width = width,
from = {center_x+radius,center_y+i},
to = {center_x-radius,center_y+i},
-- from = {center_x+radius,center_y+i}, -- this looks pretty cool (although not a grid)
-- to = {center_x-i,center_y+radius},
surface = player.surface,
players = {player},
draw_on_ground = ground_grid
}
global.shortcuts_grid[player_index][#global.shortcuts_grid[player_index]+1] = line
end
else
player.set_shortcut_toggled("draw-grid", false)
local grid = global.shortcuts_grid[player_index]
for i=1,(#grid) do
rendering.destroy(grid[i])
grid[i] = nil
end
end
end
@ -250,6 +306,9 @@ local function initialize()
if global.shortcuts_armor == nil then
global.shortcuts_armor = {}
end
if global.shortcuts_grid == nil then
global.shortcuts_grid = {}
end
end
script.on_event(defines.events.on_player_armor_inventory_changed, function(event)
@ -268,6 +327,49 @@ script.on_event(defines.events.on_player_removed_equipment, function(event)
end
end)
local function shortcut_type(event)
local prototype_name = event.prototype_name
if not game.active_mods["Nanobots"] then
if prototype_name == "night-vision-equipment" then
update_state(event, "night-vision-equipment")
return
elseif prototype_name == "belt-immunity-equipment" then
update_state(event, "belt-immunity-equipment")
return
elseif prototype_name == "active-defense-equipment" then
update_state(event, "active-defense-equipment")
return
end
end
if prototype_name == "big-zoom" then
local player = game.players[event.player_index]
if settings.global["disable-zoom"].value == true then
player.zoom = settings.get_player_settings(player)["zoom-level"].value
else
player.print({"", {"error.error-message-box-title"}, ": ", {"controls.alt-zoom-out"}, " ", {"gui-mod-info.status-disabled"}})
end
elseif prototype_name == "draw-grid" then
draw_grid(event.player_index)
elseif prototype_name == "tree-killer" then
local player = game.players[event.player_index]
if player.cursor_stack.valid_for_read == false then
if player.cursor_stack.can_set_stack({name="shortcuts-deconstruction-planner"}) then
player.cursor_stack.set_stack({name="shortcuts-deconstruction-planner"})
player.cursor_stack.trees_and_rocks_only = true
end
end
elseif prototype_name == "flashlight-toggle" then
toggle_light(game.players[event.player_index])
elseif prototype_name == "signal-flare" then
local player = game.players[event.player_index]
if settings.global["disable-zoom"].value == true then
player.force.print({"", "[img=virtual-signal.signal-danger] [color=1,0.1,0.1]", {"entity-name.player"}, " " .. player.name .. " [gps=" .. math.floor(player.position.x+0.5) .. "," .. math.floor(player.position.y+0.5) .. "][/color] [img=virtual-signal.signal-danger]"})
else
player.print({"", {"error.error-message-box-title"}, ": ", {"technology-name.military"}, " ", {"entity-name.beacon"}, " ", {"gui-mod-info.status-disabled"}})
end
end
end
script.on_event(defines.events.on_lua_shortcut, shortcut_type)
script.on_event(defines.events.on_player_main_inventory_changed, update_inventory)
@ -288,4 +390,5 @@ end)
script.on_event(defines.events.on_player_selected_area, jam_artillery)
script.on_init(initialize)
script.on_configuration_changed(initialize)
script.on_configuration_changed(initialize)
commands.add_command("shortcuts_initialize_variables", "debug: ensure that all global tables are not nil (should not happen in a normal game)", initialize)

View File

@ -146,4 +146,9 @@ for i=1,(#disabled_turret),1 do
if disabled_turret_item[i] then
data:extend({disabled_turret_item[i]})
end
end
end
local decon_spec = util.table.deepcopy(data.raw["deconstruction-item"]["deconstruction-planner"])
decon_spec.name = "shortcuts-deconstruction-planner"
decon_spec.localised_name = {"item-name.deconstruction-planner"}
data:extend({decon_spec})

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -6,5 +6,5 @@
"author": "npc_strider(morley376)",
"contact": "",
"homepage": "http://steamcommunity.com/id/morley376",
"description": "Adds in a shortcut button for the artillery remote discharge defense remote, and toggles for night-vision-equipment, belt-immunity-equipment, personal-laser-defense and the player lamp. Shortcuts also for YARM, orbital ion cannon and outpost planner. Suggest any new shortcut ideas to the discussion page."
"description": "Adds a host of useful shortcuts to improve QOL. Shortcuts for the artillery remote, discharge defense remote, tree deconstructor, and toggles for equipment and the player lamp. Additionally adds in a customizable grid overlay, far zoom and a artillery wagon toggle. Mod support for YARM, orbital ion cannon, outpost planner and max rate calculator. Suggest any new shortcut ideas to the discussion page."
}

View File

@ -1,4 +1,5 @@
data:extend({
-- player
{
type = "double-setting",
name = "zoom-level",
@ -8,6 +9,54 @@ data:extend({
minimum_value = 0.0,
maximum_value = 16.0,
},
{
type = "double-setting",
name = "grid-chunk-line-width",
localised_name = {"", {"gui.grid"}, " Chunk ", {"gui-map-editor-tool.line-selection"}, " ", {"gui-map-generator.map-width"}},
setting_type = "runtime-per-user",
default_value = 5,
minimum_value = 0.0
},
{
type = "double-setting",
name = "grid-line-width",
localised_name = {"", {"gui.grid"}, " ", {"gui-map-editor-tool.line-selection"}, " ", {"gui-map-generator.map-width"}},
setting_type = "runtime-per-user",
default_value = 0.25,
minimum_value = 0.0
},
{
type = "bool-setting",
name = "grid-chunk-align",
localised_name = {"", {"gui.grid"}, " ", {"gui-map-editor-clone-editor.snap-to-chunk"}},
setting_type = "runtime-per-user",
default_value = true
},
{
type = "bool-setting",
name = "grid-ground",
localised_name = {"", {"gui-graphics-settings.graphics-quality-low"}, " ", {"gui.grid"}},
setting_type = "runtime-per-user",
default_value = true
},
{
type = "int-setting",
name = "grid-radius",
localised_name = {"", {"gui.grid"}, " ", {"description.range"}},
setting_type = "runtime-per-user",
default_value = 128,
minimum_value = 0
},
{
type = "int-setting",
name = "grid-step",
localised_name = {"", {"gui.grid"}, " ", {"gui-map-generator.scale"}},
setting_type = "runtime-per-user",
default_value = 1,
minimum_value = 0
},
-- server
{
type = "bool-setting",
name = "disable-zoom",

View File

@ -4,11 +4,11 @@ data:extend(
{
type = "selection-tool",
name = "artillery-jammer-tool",
icon = "__base__/graphics/icons/deconstruction-planner.png",
icon = "__Shortcuts__/graphics/artillery-jammer-remote.png",
icon_size = 32,
flags = {"hidden"},
subgroup = "other",
order = "c[automated-construction]-a[deconstruction-planner]",
order = "c[automated-construction]-a[artillery-jammer-tool]",
stack_size = 1,
stackable = false,
selection_color = { r = 1, g = 0, b = 0 },
@ -18,14 +18,15 @@ data:extend(
selection_cursor_box_type = "copy",
alt_selection_cursor_box_type = "copy",
entity_type_filters = {"artillery-wagon"},
tile_filters = {},
tile_filters = {"lab-dark-1"},
entity_filter_mode = "whitelist",
tile_filter_mode = "whitelist",
alt_entity_type_filters = {"artillery-wagon"},
alt_tile_filters = {},
alt_tile_filters = {"lab-dark-1"},
alt_entity_filter_mode = "whitelist",
alt_tile_filter_mode = "whitelist",
show_in_library = false
show_in_library = false,
always_include_tiles = false
},
-- all shortcuts
{
@ -62,6 +63,106 @@ data:extend(
flags = {"icon"}
},
},
{
type = "shortcut",
name = "draw-grid",
order = "a[draw-grid]",
action = "lua",
localised_name = {"gui.grid"},
style = "blue",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/grid-x32-white.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/grid-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/grid-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "artillery-jammer-remote",
order = "a[artillery-jammer-remote]",
action = "create-blueprint-item",
localised_name = {"", {"gui-mod-info.toggle"}, " ", {"entity-name.artillery-wagon"}, " ", {"damage-type-name.fire"}},
technology_to_unlock = "artillery",
item_to_create = "artillery-jammer-tool",
style = "red",
icon =
{
filename = "__Shortcuts__/graphics/artillery-jammer-remote-x32-white.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/artillery-jammer-remote-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/artillery-jammer-remote-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "tree-killer",
order = "a[tree-killer]",
action = "lua",
localised_name = {"", {"item-name.deconstruction-planner"}, " (", {"gui-deconstruction.whitelist-trees-and-rocks"}, ")"},
technology_to_unlock = "construction-robotics",
style = "red",
icon =
{
filename = "__Shortcuts__/graphics/tree-killer-x32-white.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/tree-killer-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/tree-killer-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "discharge-defense-remote",
@ -340,7 +441,7 @@ data:extend(
style = "blue",
icon =
{
filename = "__Shortcuts__/graphics/ion-cannon-targeter-x32-white.png",
filename = "__Shortcuts__/graphics/max-rate-calculator-x32-white.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
@ -348,7 +449,7 @@ data:extend(
},
small_icon =
{
filename = "__Shortcuts__/graphics/ion-cannon-targeter-x24.png",
filename = "__Shortcuts__/graphics/max-rate-calculator-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
@ -356,7 +457,7 @@ data:extend(
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/ion-cannon-targeter-x24-white.png",
filename = "__Shortcuts__/graphics/max-rate-calculator-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,