From 797f0e56774a75ecab7390499264e88fb24dd21d Mon Sep 17 00:00:00 2001 From: MewMew Date: Wed, 29 Apr 2020 15:07:55 +0200 Subject: [PATCH 1/2] map reset fix --- maps/mountain_fortress_v2/locomotive.lua | 6 ++---- maps/mountain_fortress_v2/main.lua | 26 ++++++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/maps/mountain_fortress_v2/locomotive.lua b/maps/mountain_fortress_v2/locomotive.lua index c2332962..8149daa8 100644 --- a/maps/mountain_fortress_v2/locomotive.lua +++ b/maps/mountain_fortress_v2/locomotive.lua @@ -91,11 +91,9 @@ end function Public.set_player_spawn_and_refill_fish() if not global.locomotive_cargo then return end if not global.locomotive_cargo.valid then return end - --global.locomotive_cargo.health = global.locomotive_cargo.health + 6 - --global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = math.random(1, 2)}) local position = global.locomotive_cargo.surface.find_non_colliding_position("stone-furnace", global.locomotive_cargo.position, 16, 2) - if not position then return end - game.forces.player.set_spawn_position({x = position.x, y = position.y}, global.locomotive_cargo.surface) + if position then game.forces.player.set_spawn_position({x = position.x, y = position.y}, global.locomotive_cargo.surface) end + return true end return Public diff --git a/maps/mountain_fortress_v2/main.lua b/maps/mountain_fortress_v2/main.lua index ca58f4c6..8c176f64 100644 --- a/maps/mountain_fortress_v2/main.lua +++ b/maps/mountain_fortress_v2/main.lua @@ -40,6 +40,17 @@ local treasure_chest_messages = { "We has found the precious!", } +local function game_over() + game.print("The Fish Wagon was destroyed!!") + local wave_defense_table = WD.get_table() + wave_defense_table.game_lost = true + wave_defense_table.target = nil + global.game_reset_tick = game.tick + 1800 + for _, player in pairs(game.connected_players) do + player.play_sound{path="utility/game_lost", volume_modifier=0.80} + end +end + local function set_difficulty() local wave_defense_table = WD.get_table() local player_count = #game.connected_players @@ -274,17 +285,10 @@ local function on_pre_player_left_game(event) end end -local function on_entity_died(event) - local wave_defense_table = WD.get_table() - if not event.entity.valid then return end +local function on_entity_died(event) + if not event.entity.valid then return end if event.entity == global.locomotive_cargo then - game.print("The cargo was destroyed!") - wave_defense_table.game_lost = true - wave_defense_table.target = nil - global.game_reset_tick = game.tick + 1800 - for _, player in pairs(game.connected_players) do - player.play_sound{path="utility/game_lost", volume_modifier=0.75} - end + game_over() event.entity.surface.spill_item_stack(event.entity.position,{name = "raw-fish", count = 512}, false) return end @@ -435,7 +439,7 @@ local function tick() local tick = game.tick if tick % 30 == 0 then if tick % 1800 == 0 then - Locomotive.set_player_spawn_and_refill_fish() + if not Locomotive.set_player_spawn_and_refill_fish() and not global.game_reset_tick then game_over() end local surface = game.surfaces[global.active_surface_index] local position = surface.find_non_colliding_position("stone-furnace", Collapse.get_position(), 128, 1) if position then From fd5184b43c44526f07474bc3a4a2adcf45aeaa0f Mon Sep 17 00:00:00 2001 From: MewMew Date: Wed, 29 Apr 2020 15:56:57 +0200 Subject: [PATCH 2/2] fixes --- modules/collapse.lua | 13 ++++++++----- modules/immersive_cargo_wagons/functions.lua | 9 ++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/collapse.lua b/modules/collapse.lua index 3b8bac94..3a43789c 100644 --- a/modules/collapse.lua +++ b/modules/collapse.lua @@ -47,9 +47,9 @@ local function print_debug(a) print("Collapse error #" .. a) end -local function set_collapse_tiles() - game.forces.player.chart(collapse.surface, collapse.area) - collapse.tiles = collapse.surface.find_tiles_filtered({area = collapse.area}) +local function set_collapse_tiles(surface) + game.forces.player.chart(surface, collapse.area) + collapse.tiles = surface.find_tiles_filtered({area = collapse.area}) if not collapse.tiles then return end collapse.size_of_tiles = #collapse.tiles if collapse.size_of_tiles > 0 then table_shuffle_table(collapse.tiles) end @@ -57,21 +57,24 @@ local function set_collapse_tiles() local v = collapse.vector local area = collapse.area collapse.area = {{area[1][1] + v[1], area[1][2] + v[2]}, {area[2][1] + v[1], area[2][2] + v[2]}} + game.forces.player.chart(surface, collapse.area) end local function progress() + local surface = collapse.surface + local tiles = collapse.tiles if not tiles then - set_collapse_tiles() + set_collapse_tiles(surface) tiles = collapse.tiles end if not tiles then return end - local surface = collapse.surface for _ = 1, collapse.amount, 1 do local tile = tiles[collapse.size_of_tiles] if not tile then collapse.tiles = nil return end collapse.size_of_tiles = collapse.size_of_tiles - 1 + if not tile.valid then return end if collapse.kill then local position = {tile.position.x + 0.5, tile.position.y + 0.5} for _, e in pairs(surface.find_entities_filtered({area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}})) do diff --git a/modules/immersive_cargo_wagons/functions.lua b/modules/immersive_cargo_wagons/functions.lua index 660cc259..ae163fdc 100644 --- a/modules/immersive_cargo_wagons/functions.lua +++ b/modules/immersive_cargo_wagons/functions.lua @@ -511,10 +511,13 @@ end function Public.reconstruct_all_trains(icw) icw.trains = {} for unit_number, wagon in pairs(icw.wagons) do - if wagon.entity and wagon.entity.valid then - local carriages = wagon.entity.train.carriages - Public.construct_train(icw, carriages) + if not wagon.entity or not wagon.entity.valid then + icw.wagons[unit_number] = nil + Public.request_reconstruction(icw) + return end + local carriages = wagon.entity.train.carriages + Public.construct_train(icw, carriages) end delete_empty_surfaces(icw) end