From a21ae8de1ba169a6f3f1db404880cdadb49ef515 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Fri, 6 Jan 2023 13:19:34 -0800 Subject: [PATCH] Ensures area contents respects world.maxx/y expanding (#72283) ## About The Pull Request It never like, happens, and if it ever did we'd yell at the guy who did it But if we're gonna pretend we support expanding in the maploader, we should support it structurally too --- code/game/world.dm | 24 +++++++++++++++++++++++- code/modules/mapping/reader.dm | 26 +++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/code/game/world.dm b/code/game/world.dm index f0496c9b46e..f1cef7089a0 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -360,12 +360,34 @@ GLOBAL_VAR(restart_counter) else hub_password = "SORRYNOPASSWORD" +// If this is called as a part of maploading you cannot call it on the newly loaded map zs, because those get handled later on in the pipeline +/world/proc/increaseMaxX(new_maxx, max_zs_to_load = maxz) + if(new_maxx <= maxx) + return + var/old_max = world.maxx + maxx = new_maxx + if(!max_zs_to_load) + return + var/area/global_area = GLOB.areas_by_type[world.area] // We're guaranteed to be touching the global area, so we'll just do this + var/list/to_add = block(locate(old_max + 1, 1, 1), locate(maxx, maxy, max_zs_to_load)) + global_area.contained_turfs += to_add + +/world/proc/increaseMaxY(new_maxy, max_zs_to_load = maxz) + if(new_maxy <= maxy) + return + var/old_maxy = maxy + maxy = new_maxy + if(!max_zs_to_load) + return + var/area/global_area = GLOB.areas_by_type[world.area] // We're guarenteed to be touching the global area, so we'll just do this + var/list/to_add = block(locate(1, old_maxy + 1, 1), locate(maxx, maxy, max_zs_to_load)) + global_area.contained_turfs += to_add + /world/proc/incrementMaxZ() maxz++ SSmobs.MaxZChanged() SSidlenpcpool.MaxZChanged() - /world/proc/change_fps(new_value = 20) if(new_value <= 0) CRASH("change_fps() called with [new_value] new_value.") diff --git a/code/modules/mapping/reader.dm b/code/modules/mapping/reader.dm index 9e5ab17593c..77250dcf826 100644 --- a/code/modules/mapping/reader.dm +++ b/code/modules/mapping/reader.dm @@ -319,8 +319,12 @@ var/relative_y = first_column.ycrd var/highest_y = relative_y + y_relative_to_absolute - if(!cropMap && highest_y > world.maxy) - world.maxy = highest_y // Expand Y here. X is expanded later on + if(!cropMap && highest_y > world.maxx) + if(new_z) + // Need to avoid improperly loaded area/turf_contents + world.increaseMaxY(highest_y, max_zs_to_load = z_offset - 1) + else + world.increaseMaxY(highest_y) expanded_y = TRUE // Skip Y coords that are above the smallest of the three params @@ -353,7 +357,11 @@ var/delta = max(final_x - x_delta_with, 0) final_x -= delta if(final_x > world.maxx && !cropMap) - world.maxx = final_x + if(new_z) + // Need to avoid improperly loaded area/turf_contents + world.increaseMaxX(final_x, max_zs_to_load = z_offset - 1) + else + world.increaseMaxX(final_x) expanded_x = TRUE var/lowest_x = max(x_lower, 1 - x_relative_to_absolute) @@ -443,7 +451,11 @@ var/ycrd = relative_y + y_relative_to_absolute var/zcrd = gset.zcrd + z_offset - 1 if(!cropMap && ycrd > world.maxy) - world.maxy = ycrd // Expand Y here. X is expanded in the loop below + if(new_z) + // Need to avoid improperly loaded area/turf_contents + world.increaseMaxY(ycrd, max_zs_to_load = z_offset - 1) + else + world.increaseMaxY(ycrd) expanded_y = TRUE var/zexpansion = zcrd > world.maxz var/no_afterchange = no_changeturf @@ -495,7 +507,11 @@ final_x -= delta x_target = x_step_count * key_len if(final_x > world.maxx && !cropMap) - world.maxx = final_x + if(new_z) + // Need to avoid improperly loaded area/turf_contents + world.increaseMaxX(final_x, max_zs_to_load = z_offset - 1) + else + world.increaseMaxX(final_x) expanded_x = TRUE // We're gonna track the first and last pairs of coords we find