From de6fb86efb671bb16e7745c91649ce236467f7b4 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sat, 26 Oct 2024 01:25:43 +0200 Subject: [PATCH] Fix minor issues --- maps/mountain_fortress_v3/functions.lua | 8 ++++++++ .../icw/linked_chests.lua | 19 +++++++++++-------- maps/mountain_fortress_v3/icw/main.lua | 1 + maps/mountain_fortress_v3/locomotive.lua | 14 ++++++++++---- .../locomotive/market.lua | 4 ++++ .../locomotive/spawn_locomotive.lua | 18 ++++++++++++++++-- maps/mountain_fortress_v3/table.lua | 3 ++- maps/mountain_fortress_v3/terrain.lua | 2 +- modules/burden.lua | 8 ++++---- modules/floaty_chat.lua | 2 +- utils/alert.lua | 13 +++++++++---- utils/commands.lua | 1 + utils/commands/where.lua | 2 +- 13 files changed, 69 insertions(+), 26 deletions(-) diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index a98fb41ca..9507cc9ea 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1193,12 +1193,20 @@ function Public.set_difficulty() elseif player_count >= 11 then mining_bonus = 0 -- back to 0% with more than 11 players end + if mining_bonus < 0 then + mining_bonus = 0 + end + force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + mining_bonus Public.set('mining_bonus', mining_bonus) -- Setting mining_bonus globally so it remembers how much to reduce else force.manual_mining_speed_modifier = force.manual_mining_speed_modifier - mining_bonus Public.set('disable_mining_boost', true) end + + if force.manual_mining_speed_modifier < 0 then + force.manual_mining_speed_modifier = 0 + end end end diff --git a/maps/mountain_fortress_v3/icw/linked_chests.lua b/maps/mountain_fortress_v3/icw/linked_chests.lua index 750e4cc67..c4b4ea3b6 100644 --- a/maps/mountain_fortress_v3/icw/linked_chests.lua +++ b/maps/mountain_fortress_v3/icw/linked_chests.lua @@ -372,6 +372,9 @@ end local function get_all_chests(unit_number) local t = {} local loco_surface = WPT.get('loco_surface') + if not loco_surface then + return t + end local containers = this.main_containers for check_unit_number, container in pairs(containers) do if container.chest and container.chest.valid and container.share.name ~= '' and container.share.name ~= container.unit_number and container.chest.surface.index == loco_surface.index then @@ -842,13 +845,13 @@ local function update_gui() local content = container.chest.get_inventory(defines.inventory.chest).get_contents() - for item_name, item_count in pairs(content) do - if item_name ~= 'count' then - if not items[item_name] then + for _, data in pairs(content) do + if data.name ~= 'count' then + if not items[data.name] then total = total + 1 - items[item_name] = item_count + items[data.name] = data.count else - items[item_name] = items[item_name] + item_count + items[data.name] = items[data.name] + data.count end end end @@ -999,9 +1002,9 @@ local function content_mismatches(source, destination) local mismatch = false - for source_item_name, _ in pairs(source_inventory) do - for destination_item_name, _ in pairs(destination_inventory) do - if source_item_name ~= destination_item_name then + for _, source_items in pairs(source_inventory) do + for _, destination_items in pairs(destination_inventory) do + if source_items.name ~= destination_items.name then mismatch = true end end diff --git a/maps/mountain_fortress_v3/icw/main.lua b/maps/mountain_fortress_v3/icw/main.lua index 829a0c4bd..4b72da35d 100644 --- a/maps/mountain_fortress_v3/icw/main.lua +++ b/maps/mountain_fortress_v3/icw/main.lua @@ -5,6 +5,7 @@ local Public = {} Public.reset = ICW.reset Public.get_table = ICW.get +Public.get = ICW.get local function on_entity_died(event) local entity = event.entity diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index 5b015ba32..a822a3f92 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -307,8 +307,8 @@ local function give_passive_xp(data) end end end - elseif player.afk_time > 1800 and player.character and player.surface.index == loco_surface.index then - player.character_personal_logistic_requests_enabled = false + elseif player.afk_time > 1800 and player.character and player.surface.index == loco_surface.index and player.get_requester_point() then + player.get_requester_point().enabled = false end ::pre_exit:: end @@ -408,7 +408,12 @@ local function get_driver_action(entity) return end - local player = driver.player + local player + if driver and driver.valid and driver.is_player() then + player = driver + else + player = driver.player + end if not player or not player.valid then return end @@ -493,7 +498,8 @@ local function validate_index() local icw_table = ICW.get_table() local icw_locomotive = Public.get('icw_locomotive') - if not icw_locomotive or not icw_locomotive.valid then + if not icw_locomotive then + Event.raise(Public.events.on_locomotive_cargo_missing) return end local loco_surface = icw_locomotive.surface diff --git a/maps/mountain_fortress_v3/locomotive/market.lua b/maps/mountain_fortress_v3/locomotive/market.lua index ac9ffd3c6..33147d220 100644 --- a/maps/mountain_fortress_v3/locomotive/market.lua +++ b/maps/mountain_fortress_v3/locomotive/market.lua @@ -1526,6 +1526,10 @@ local function gui_closed(event) end local function on_gui_selection_state_changed(event) + if not event.element or not event.element.valid then + return + end + local name = event.element.name local player = game.get_player(event.player_index) local selected_index = event.element.selected_index diff --git a/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua b/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua index df3f5abff..ed5c72fcb 100644 --- a/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua @@ -2,7 +2,7 @@ local Public = require 'maps.mountain_fortress_v3.table' local ICW = require 'maps.mountain_fortress_v3.icw.main' local Task = require 'utils.task_token' local MapFunctions = require 'utils.tools.map_functions' - +local Event = require 'utils.event' local random = math.random local floor = math.floor @@ -205,7 +205,7 @@ function Public.locomotive_spawn(surface, position, reversed) ) end - local s = 'entity/character-corpse' + local s = 'entity/fish' for y = -1, 0, 0.05 do local scale = random(50, 100) * 0.01 @@ -230,6 +230,7 @@ function Public.locomotive_spawn(surface, position, reversed) local locomotive = ICW.register_wagon(this.locomotive) if not locomotive then + print('Failed to register locomotive') return end @@ -274,4 +275,17 @@ function Public.locomotive_spawn(surface, position, reversed) game.forces.player.set_spawn_position({ this.locomotive.position.x - 5, this.locomotive.position.y }, locomotive.surface) end +Event.add(Public.events.on_locomotive_cargo_missing, function () + local locomotive_cargo = Public.get('locomotive_cargo') + if not locomotive_cargo or not locomotive_cargo.valid then + return + end + + local wagons = ICW.get('wagons') + if wagons[locomotive_cargo.unit_number] then + log('Locomotive cargo missing, setting new cargo') + Public.set('icw_locomotive', wagons[locomotive_cargo.unit_number]) + end +end) + return Public diff --git a/maps/mountain_fortress_v3/table.lua b/maps/mountain_fortress_v3/table.lua index 86f1241cd..1069c4835 100644 --- a/maps/mountain_fortress_v3/table.lua +++ b/maps/mountain_fortress_v3/table.lua @@ -38,7 +38,8 @@ local dataset_key_dev = 'mtn_v3_table_dev' Public.events = { reset_map = Event.generate_event_name('reset_map'), on_entity_mined = Event.generate_event_name('on_entity_mined'), - on_market_item_purchased = Event.generate_event_name('on_market_item_purchased') + on_market_item_purchased = Event.generate_event_name('on_market_item_purchased'), + on_locomotive_cargo_missing = Event.generate_event_name('on_locomotive_cargo_missing'), } local scenario_name = 'nauvis' diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index 31fefdfb1..c5d0939a5 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -351,7 +351,7 @@ local function place_wagon(data, adjusted_zones) direction = 0 else location = surface.find_tiles_filtered({ area = { { position.x - r1, position.y }, { position.x + r2, position.y + 2 } } }) - direction = 2 + direction = 4 end for _, tile in pairs(location) do diff --git a/modules/burden.lua b/modules/burden.lua index e94a64401..f27bb6393 100644 --- a/modules/burden.lua +++ b/modules/burden.lua @@ -27,13 +27,13 @@ local function compute_fullness(player) local num_stacks = 0 local contents = inv.get_contents() - for item, count in pairs(contents) do + for _, items in pairs(contents) do local stack_size = 1 - if prototypes.item[item].stackable then - stack_size = prototypes.item[item].stack_size + if prototypes.item[items.name].stackable then + stack_size = prototypes.item[items.name].stack_size end - num_stacks = num_stacks + count / stack_size + num_stacks = num_stacks + items.count / stack_size end return num_stacks / max_stacks diff --git a/modules/floaty_chat.lua b/modules/floaty_chat.lua index ad4e367d5..85561bbd7 100644 --- a/modules/floaty_chat.lua +++ b/modules/floaty_chat.lua @@ -41,7 +41,7 @@ local function on_console_chat(event) return end - if player.character.surface ~= player.surface.index then return end + if player.character.surface.index ~= player.surface.index then return end this.player_floaty_chat[player.index] = rendering.draw_text { diff --git a/utils/alert.lua b/utils/alert.lua index 2306b07e3..519e6f2a9 100644 --- a/utils/alert.lua +++ b/utils/alert.lua @@ -164,11 +164,16 @@ local function zoom_to_pos(event) if is_spamming then return end - local player = event.player + local player = event.player local element = event.element - local position = Gui.get_data(element) + local target = Gui.get_data(element) - player.zoom_to_world(position, 0.5) + if not target or not target.valid then + return + end + + if target.character ~= nil then target = target.character end + player.centered_on = target end local close_alert = Public.close_alert @@ -285,7 +290,7 @@ function Public.alert_all_players_location(player, message, color, duration) style = 'slot_button' } - Gui.set_data(sprite, player.position) + Gui.set_data(sprite, player) local label = container.add { diff --git a/utils/commands.lua b/utils/commands.lua index f88ba8822..3a1a7a59b 100644 --- a/utils/commands.lua +++ b/utils/commands.lua @@ -577,6 +577,7 @@ Public.new('get', 'Hover over an object to get its name.') player.print('[color=orange]Name:[/color] ' .. entity.name) player.print('[color=orange]Type:[/color] ' .. entity.type) player.print('[color=orange]Force:[/color] ' .. entity.force.name) + player.print('[color=orange]Direction:[/color] ' .. entity.direction) player.print('[color=orange]Destructible:[/color] ' .. (entity.destructible and 'true' or 'false')) player.print('[color=orange]Minable:[/color] ' .. (entity.minable and 'true' or 'false')) player.print('[color=orange]Unit Number:[/color] ' .. (entity.unit_number or 'nil')) diff --git a/utils/commands/where.lua b/utils/commands/where.lua index 26a909cdb..1da7b6791 100644 --- a/utils/commands/where.lua +++ b/utils/commands/where.lua @@ -44,7 +44,7 @@ local function remove_player_data(player) local player_data = this.players[player.index] if player_data then if player_data.render_object then - rendering.destroy(player_data.render_object) + player_data.render_object.destroy() end this.players[player.index] = nil