diff --git a/comfy_panel/poll.lua b/comfy_panel/poll.lua index ac459809..0e5afbbd 100644 --- a/comfy_panel/poll.lua +++ b/comfy_panel/poll.lua @@ -1015,6 +1015,10 @@ Gui.on_click( function(event) local player = event.player local data = Gui.get_data(event.element) + if not data or not data.valid then + return + end + local frame = data.frame local poll = data.previous_data diff --git a/control.lua b/control.lua index e66122ee..a2986382 100644 --- a/control.lua +++ b/control.lua @@ -15,7 +15,6 @@ require 'utils.datastore.jail_data' require 'utils.datastore.quickbar_data' require 'utils.datastore.message_on_join_data' require 'utils.datastore.player_tag_data' -require 'utils.profiler' require 'chatbot' require 'commands' require 'antigrief' @@ -88,10 +87,10 @@ require 'modules.autostash' --require 'maps.biter_battles.biter_battles' --![[A map that imitating MF, defending rocket silos instead of trains]]-- --- require 'maps.amap.main' +--require 'maps.amap.main' --![[Guide a Train through rough terrain, while defending it from the biters]]-- --- require 'maps.mountain_fortress_v3.main' +--require 'maps.mountain_fortress_v3.main' --require 'maps.mountain_fortress_v2.main' --require 'maps.mountain_fortress' @@ -236,6 +235,7 @@ require 'modules.autostash' if _DUMP_ENV then require 'utils.dump_env' + require 'utils.profiler' end local function on_player_created(event) diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index 9e7ff1c9..1bd248a3 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -18,7 +18,7 @@ local Alert = require 'utils.alert' local Task = require 'utils.task' local Score = require 'comfy_panel.score' local Token = require 'utils.token' -local HS = require 'maps.mountain_fortress_v3.highscore' +-- local HS = require 'maps.mountain_fortress_v3.highscore' local Discord = require 'utils.discord' local Core = require "utils.core" local Diff = require "modules.difficulty_vote_by_amount" @@ -100,13 +100,13 @@ local reset_game = local this = data.this local Reset_map = data.reset_map if this.soft_reset then - HS.set_scores() + -- HS.set_scores() this.game_reset_tick = nil Reset_map() return end if this.restart then - HS.set_scores() + -- HS.set_scores() local message = ({'entity.reset_game'}) Server.to_discord_bold(message, true) Server.start_scenario('Mountain_Fortress_v3') @@ -114,7 +114,7 @@ local reset_game = return end if this.shutdown then - HS.set_scores() + -- HS.set_scores() local message = ({'entity.shutdown_game'}) Server.to_discord_bold(message, true) Server.stop_scenario() @@ -1210,17 +1210,20 @@ local function show_mvps(player) local tier = WPT.get("pickaxe_tier") local pick_tier = pickaxe_tiers[tier] - Server.to_discord_named_embed(send_ping_to_channel, '**Statistics!**\\n\\n' - .. 'Time played: '..time_played..'\\n' - .. 'Game Difficulty: '..diff.name..'\\n' - .. 'Highest wave: '..format_number(wave, true)..'\\n' - .. 'Total connected players: '..total_players..'\\n' - .. 'Threat: '..format_number(threat, true)..'\\n' - .. 'Pickaxe Upgrade: '..pick_tier..' (' ..tier.. ')\\n' - .. 'Collapse Speed: '..collapse_speed..'\\n' - .. 'Collapse Amount: '..collapse_amount..'\\n' - ) - WPT.set('sent_to_discord', true) + local server_name = Server.check_server_name('Mtn Fortress') + if server_name then + Server.to_discord_named_embed(send_ping_to_channel, '**Statistics!**\\n\\n' + .. 'Time played: '..time_played..'\\n' + .. 'Game Difficulty: '..diff.name..'\\n' + .. 'Highest wave: '..format_number(wave, true)..'\\n' + .. 'Total connected players: '..total_players..'\\n' + .. 'Threat: '..format_number(threat, true)..'\\n' + .. 'Pickaxe Upgrade: '..pick_tier..' (' ..tier.. ')\\n' + .. 'Collapse Speed: '..collapse_speed..'\\n' + .. 'Collapse Amount: '..collapse_amount..'\\n' + ) + WPT.set('sent_to_discord', true) + end end end end diff --git a/maps/mountain_fortress_v3/ic/functions.lua b/maps/mountain_fortress_v3/ic/functions.lua index d8ab92d6..30cb5873 100644 --- a/maps/mountain_fortress_v3/ic/functions.lua +++ b/maps/mountain_fortress_v3/ic/functions.lua @@ -13,6 +13,10 @@ local function validate_entity(entity) return false end + if type(entity) == 'boolean' then + return false + end + return true end @@ -896,6 +900,10 @@ function Public.use_door_with_entity(ic, player, door) return end + if not validate_entity(car.entity) then + return + end + local owner = game.players[car.owner] local list = get_trusted_system(ic, owner) if owner and owner.valid and owner.index ~= player.index and player.connected then diff --git a/maps/mountain_fortress_v3/ic/gui.lua b/maps/mountain_fortress_v3/ic/gui.lua index 3a5419ff..7bde5ecd 100644 --- a/maps/mountain_fortress_v3/ic/gui.lua +++ b/maps/mountain_fortress_v3/ic/gui.lua @@ -94,6 +94,10 @@ local function transfer_player_table(player, new_player) end local function remove_main_frame(main_frame) + if not main_frame or not main_frame.valid then + return + end + Gui.remove_data_recursively(main_frame) main_frame.destroy() end diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index 4f8bcd15..67721bbc 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -144,7 +144,17 @@ local set_loco_tiles = end end - MapFunctions.draw_noise_tile_circle(position, 'blue-refined-concrete', surface, 15) + if random(1, 6) == 1 then + MapFunctions.draw_noise_tile_circle(position, 'blue-refined-concrete', surface, 18) + elseif random(1, 5) == 1 then + MapFunctions.draw_noise_tile_circle(position, 'black-refined-concrete', surface, 18) + elseif random(1, 4) == 1 then + MapFunctions.draw_noise_tile_circle(position, 'cyan-refined-concrete', surface, 18) + elseif random(1, 3) == 1 then + MapFunctions.draw_noise_tile_circle(position, 'hazard-concrete-right', surface, 18) + else + MapFunctions.draw_noise_tile_circle(position, 'blue-refined-concrete', surface, 18) + end for i = 1, #cargo_boxes, 1 do if not p[i] then diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index 0261ad4c..918ba394 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -3,7 +3,7 @@ require 'modules.rpg.main' local Functions = require 'maps.mountain_fortress_v3.functions' local BuriedEnemies = require 'maps.mountain_fortress_v3.buried_enemies' -local HS = require 'maps.mountain_fortress_v3.highscore' +-- local HS = require 'maps.mountain_fortress_v3.highscore' local Discord = require 'utils.discord' local IC = require 'maps.mountain_fortress_v3.ic.table' local ICMinimap = require 'maps.mountain_fortress_v3.ic.minimap' @@ -110,6 +110,16 @@ local is_position_near_tbl = function(position, tbl) return status end +local announce_new_map = + Token.register( + function() + local server_name = Server.check_server_name('Mtn Fortress') + if server_name then + Server.to_discord_named_raw(send_ping_to_channel, role_to_mention .. ' ** Mtn Fortress was just reset! **') + end + end +) + function Public.reset_map() local Diff = Difficulty.get() local this = WPT.get() @@ -253,7 +263,7 @@ function Public.reset_map() Task.start_queue() Task.set_queue_speed(16) - HS.get_scores() + -- HS.get_scores() if is_game_modded() then game.difficulty_settings.technology_price_multiplier = 0.5 @@ -264,7 +274,7 @@ function Public.reset_map() this.market_announce = game.tick + 1200 this.game_lost = false - Server.to_discord_named_raw(send_ping_to_channel, role_to_mention .. ' ** Mtn Fortress was just reset! **') + Task.set_timeout_in_ticks(25, announce_new_map) end local is_locomotive_valid = function() @@ -314,18 +324,18 @@ local has_the_game_ended = function() game.print(({'main.reset_in', cause_msg, this.game_reset_tick / 60}), {r = 0.22, g = 0.88, b = 0.22}) end - local diff_name = Difficulty.get('name') + -- local diff_name = Difficulty.get('name') if this.soft_reset and this.game_reset_tick == 0 then this.game_reset_tick = nil - HS.set_scores(diff_name) + -- HS.set_scores(diff_name) Public.reset_map() return end if this.restart and this.game_reset_tick == 0 then if not this.announced_message then - HS.set_scores(diff_name) + -- HS.set_scores(diff_name) game.print(({'entity.notify_restart'}), {r = 0.22, g = 0.88, b = 0.22}) local message = 'Soft-reset is disabled! Server will restart from scenario to load new changes.' Server.to_discord_bold(table.concat {'*** ', message, ' ***'}) @@ -336,7 +346,7 @@ local has_the_game_ended = function() end if this.shutdown and this.game_reset_tick == 0 then if not this.announced_message then - HS.set_scores(diff_name) + -- HS.set_scores(diff_name) game.print(({'entity.notify_shutdown'}), {r = 0.22, g = 0.88, b = 0.22}) local message = 'Soft-reset is disabled! Server will shutdown. Most likely because of updates.' Server.to_discord_bold(table.concat {'*** ', message, ' ***'}) diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index fe9fbc05..651a2a81 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -2350,6 +2350,7 @@ end local function border_chunk(data) local entities = data.entities local decoratives = data.decoratives + local tiles = data.tiles local x, y = Public.increment_value(data) @@ -2358,6 +2359,13 @@ local function border_chunk(data) if random(1, ceil(pos.y + pos.y) + 64) == 1 then entities[#entities + 1] = {name = trees[random(1, #trees)], position = pos} end + + if random(1, 10) == 1 then + tiles[#tiles + 1] = {name = 'red-desert-' .. random(1, 3), position = pos} + else + tiles[#tiles + 1] = {name = 'dirt-' .. math.random(1, 6), position = pos} + end + local scrap_mineable_entities, scrap_mineable_entities_index = get_scrap_mineable_entities() if not is_out_of_map(pos) then diff --git a/maps/planet_prison.lua b/maps/planet_prison.lua index 2838bf0f..d4b02b5f 100644 --- a/maps/planet_prison.lua +++ b/maps/planet_prison.lua @@ -20,7 +20,7 @@ local Color = require 'utils.color_presets' local this = { remove_offline_players = { players = {}, - time = 18000, + time = 216000, -- 1h enabled = true } } @@ -1325,7 +1325,9 @@ local function mined_wreckage(e) end local cand = candidates[CommonFunctions.rand_range(1, count)] - e.buffer.insert(cand) + if e.buffer and cand then + e.buffer.insert(cand) + end end local function on_player_mined_entity(e) @@ -1335,7 +1337,7 @@ local function on_player_mined_entity(e) end mined_wreckage(e) - ClaimsFunctions.on_player_mined_entity(ent) + -- ClaimsFunctions.on_player_mined_entity(ent) end local function on_player_died(e) @@ -1578,7 +1580,7 @@ local function on_entity_died(e) hostile_death(e) character_death(e) - ClaimsFunctions.on_entity_died(e.entity) + -- ClaimsFunctions.on_entity_died(e.entity) if valid_ents[e.entity.name] then e.entity.destroy() @@ -1617,7 +1619,7 @@ local function on_built_entity(e) return end - ClaimsFunctions.on_built_entity(ent) + -- ClaimsFunctions.on_built_entity(ent) merchant_exploit_check(ent) end @@ -1786,17 +1788,4 @@ Event.add(defines.events.on_tick, on_tick) Event.add(defines.events.on_tick, on_tick_reset) Event.add(defines.events.on_rocket_launched, on_rocket_launched) -setmetatable( - _G, - { - __newindex = function(_, n, v) - log('Desync warning: attempt to write to undeclared var ' .. n) - global[n] = v - end, - __index = function(_, n) - return global[n] - end - } -) - return Public diff --git a/maps/planet_prison/mod/claims.lua b/maps/planet_prison/mod/claims.lua index 26c4e89b..eaecdb1d 100644 --- a/maps/planet_prison/mod/claims.lua +++ b/maps/planet_prison/mod/claims.lua @@ -45,7 +45,9 @@ local function claim_new_claim(ent) this._claims_info[ent.force.name].collections = {} end - insert(this._claims_info[ent.force.name].collections, point) + if this._claims_info[ent.force.name].collections then + this._claims_info[ent.force.name].collections[#this._claims_info[ent.force.name].collections + 1] = point + end end local function claim_on_build_entity(ent) @@ -53,6 +55,10 @@ local function claim_on_build_entity(ent) local force = ent.force.name local data = this._claims_info[force] + if not max_dist then + return + end + if data == nil then claim_new_claim(ent) return @@ -89,6 +95,10 @@ local function claim_on_build_entity(ent) end local function claims_in_markers(name) + if not this._claim_markers then + return false + end + for _, marker in pairs(this._claim_markers) do if name == marker then return true diff --git a/modules/show_inventory.lua b/modules/show_inventory.lua index 23da9f17..6e70eaeb 100644 --- a/modules/show_inventory.lua +++ b/modules/show_inventory.lua @@ -351,7 +351,12 @@ local function update_gui() if valid then if success then if target and target.valid then - local main = target.get_main_inventory().get_contents() + local main = target.get_main_inventory() + if not main then + return + end + + main = main.get_contents() local armor = target.get_inventory(defines.inventory.character_armor).get_contents() local guns = target.get_inventory(defines.inventory.character_guns).get_contents() local ammo = target.get_inventory(defines.inventory.character_ammo).get_contents() diff --git a/utils/debug/command.lua b/utils/debug/command.lua index 6f4ee00f..f481fad4 100644 --- a/utils/debug/command.lua +++ b/utils/debug/command.lua @@ -14,6 +14,10 @@ commands.add_command( return end + if (player.name ~= 'Gerkiz' and not _DEBUG) then + return + end + DebugView.open_debug(player) end ) diff --git a/utils/debug/main_view.lua b/utils/debug/main_view.lua index 99ce2ea4..1ba9f470 100644 --- a/utils/debug/main_view.lua +++ b/utils/debug/main_view.lua @@ -5,13 +5,16 @@ local Public = {} local pages = { require 'utils.debug.public_global_view', - require 'utils.debug.global_view', - require 'utils.debug.gui_data_view', - require 'utils.debug.package_view', - require 'utils.debug._g_view', - require 'utils.debug.event_view' + require 'utils.debug.global_view' } +if _DEBUG then + pages[#pages + 1] = require 'utils.debug.gui_data_view' + pages[#pages + 1] = require 'utils.debug.package_view' + pages[#pages + 1] = require 'utils.debug._g_view' + pages[#pages + 1] = require 'utils.debug.event_view' +end + local main_frame_name = Gui.uid_name() local close_name = Gui.uid_name() local tab_name = Gui.uid_name() diff --git a/utils/debug/package_view.lua b/utils/debug/package_view.lua index 242186ca..329014e0 100644 --- a/utils/debug/package_view.lua +++ b/utils/debug/package_view.lua @@ -125,6 +125,10 @@ Gui.on_click( local top_panel = element.parent.parent local data = Gui.get_data(top_panel) + if not data or not data.valid then + return + end + local text_box = data.text_box local variable_type = type(variable) diff --git a/utils/debug/public_global_view.lua b/utils/debug/public_global_view.lua index c2ea8bef..4c9970b9 100644 --- a/utils/debug/public_global_view.lua +++ b/utils/debug/public_global_view.lua @@ -123,6 +123,9 @@ Gui.on_click( function(event) local element = event.element local data = Gui.get_data(element) + if not data or not data.valid then + return + end local input_text_box = data.input_text_box diff --git a/utils/global.lua b/utils/global.lua index 04c005c4..6e05aa51 100644 --- a/utils/global.lua +++ b/utils/global.lua @@ -1,11 +1,12 @@ local Event = require 'utils.event_core' local Token = require 'utils.token' -local Global = { - names = {} -} +local Global = {} local concat = table.concat +local names = {} +Global.names = names + function Global.register(tbl, callback) if _LIFECYCLE ~= _STAGE.control then error('can only be called during the control stage', 2) @@ -14,7 +15,7 @@ function Global.register(tbl, callback) local filepath = debug.getinfo(2, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) local token = Token.register_global(tbl) - Global.names[token] = concat {token, ' - ', filepath} + names[token] = concat {token, ' - ', filepath} Event.on_load( function() @@ -32,7 +33,7 @@ function Global.register_init(tbl, init_handler, callback) local filepath = debug.getinfo(2, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) local token = Token.register_global(tbl) - Global.names[token] = concat {token, ' - ', filepath} + names[token] = concat {token, ' - ', filepath} Event.on_init( function() diff --git a/utils/gui.lua b/utils/gui.lua index ef497e29..f5902038 100644 --- a/utils/gui.lua +++ b/utils/gui.lua @@ -5,16 +5,12 @@ local SpamProtection = require 'utils.spam_protection' local tostring = tostring local next = next -local concat = table.concat local Gui = {} local data = {} local element_map = {} -local names = {} -Gui.names = names - Gui.token = Global.register( {data = data, element_map = element_map}, @@ -28,16 +24,7 @@ local on_visible_handlers = {} local on_pre_hidden_handlers = {} function Gui.uid_name() - local info = debug.getinfo(2, 'Sl') - local filepath = info.source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) - local line = info.currentline - - local token = tostring(Token.uid()) - - local name = concat {token, ' - ', filepath, ':line:', line} - names[token] = name - - return token + return tostring(Token.uid()) end function Gui.uid() @@ -54,9 +41,7 @@ function Gui.set_data(element, value) return end - local index = element.index - values[index] = nil - element_map[index] = nil + values[element.index] = nil if next(values) == nil then data[player_index] = nil @@ -67,9 +52,7 @@ function Gui.set_data(element, value) data[player_index] = values end - local index = element.index - values[index] = value - element_map[index] = element + values[element.index] = value end end local set_data = Gui.set_data @@ -266,11 +249,61 @@ Gui.on_player_show_top = custom_handler_factory(on_visible_handlers) -- Adds a player field to the event table. Gui.on_pre_player_hide_top = custom_handler_factory(on_pre_hidden_handlers) -function Gui.data() - return data +if _DEBUG then + local concat = table.concat + + local names = {} + Gui.names = names + + function Gui.uid_name() + local info = debug.getinfo(2, 'Sl') + local filepath = info.source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) + local line = info.currentline + + local token = tostring(Token.uid()) + + local name = concat {token, ' - ', filepath, ':line:', line} + names[token] = name + + return token + end + + function Gui.set_data(element, value) + local player_index = element.player_index + local values = data[player_index] + + if value == nil then + if not values then + return + end + + local index = element.index + values[index] = nil + element_map[index] = nil + + if next(values) == nil then + data[player_index] = nil + end + else + if not values then + values = {} + data[player_index] = values + end + + local index = element.index + values[index] = value + element_map[index] = element + end + end + set_data = Gui.set_data + + function Gui.data() + return data + end + + function Gui.element_map() + return element_map + end end -function Gui.element_map() - return element_map -end return Gui diff --git a/utils/server.lua b/utils/server.lua index da7a4666..15e803f4 100644 --- a/utils/server.lua +++ b/utils/server.lua @@ -741,6 +741,21 @@ function Public.get_server_name() return start_data.server_name or '' end +--- Gets the server's name and matches it against a string. +-- This is the current server's name, in the case the save has been loaded on multiple servers. +-- @param string +-- @return string +function Public.check_server_name(string) + if start_data.server_name then + local server_name = start_data.server_name + local str = string.match(server_name, string) + if str then + return true + end + end + return false +end + --- Gets the server's start time as a unix epoch timestamp. nil if not known. -- @return number? function Public.get_start_time()