mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-27 01:51:50 +00:00
* Initialize and LateInitialize runs correctly at round start (#54594) I've been pulling my hair out on this one. Ever since I started my ntnet project, I could never get LateInitalize to work right. Apparently it has never worked right. How it was set up before on server start Station map loads, Does NOT run Initialize(mapload = TRUE) Generates space, lavaland/icebox ruins Loads a ruin, DOES run Initialize(mapload = TRUE) EXCEPT on areas End of mapping system Atom system Initialized and it checks and runs Initialize(mapload = TRUE) on world You see the issue? Initialize and by extension LateInitialize is run in blocks. Worst, LateInitialize is run on turfs FIRST in ruins BEFORE Initialize is ever run on the other atoms. While there isn't much in Area, there is map_generator so I am sure it caused some grief for map creators. The NEW order now is Station map loads, Does NOT run Initialize(mapload = TRUE) Generates space, lavaland/icebox ruins Loads a ruin, Does NOT run Initialize(mapload = TRUE) End of mapping system Atom system Initialized and it checks and runs Initialize(mapload = TRUE) on world Also if you dynamicly load a map, like snowdin or such, it will Initialize all atoms at once and then run LateInitialize properly * Initialize and LateInitialize runs correctly at round start Co-authored-by: WarlockD <warlockd@gmail.com>
154 lines
4.5 KiB
Plaintext
154 lines
4.5 KiB
Plaintext
/datum/map_template
|
|
var/name = "Default Template Name"
|
|
var/width = 0
|
|
var/height = 0
|
|
var/mappath = null
|
|
var/loaded = 0 // Times loaded this round
|
|
var/datum/parsed_map/cached_map
|
|
var/keep_cached_map = FALSE
|
|
|
|
/datum/map_template/New(path = null, rename = null, cache = FALSE)
|
|
if(path)
|
|
mappath = path
|
|
if(mappath)
|
|
preload_size(mappath, cache)
|
|
if(rename)
|
|
name = rename
|
|
|
|
/datum/map_template/proc/preload_size(path, cache = FALSE)
|
|
var/datum/parsed_map/parsed = new(file(path))
|
|
var/bounds = parsed?.bounds
|
|
if(bounds)
|
|
width = bounds[MAP_MAXX] // Assumes all templates are rectangular, have a single Z level, and begin at 1,1,1
|
|
height = bounds[MAP_MAXY]
|
|
if(cache)
|
|
cached_map = parsed
|
|
return bounds
|
|
|
|
/datum/parsed_map/proc/initTemplateBounds()
|
|
var/list/obj/machinery/atmospherics/atmos_machines = list()
|
|
var/list/obj/structure/cable/cables = list()
|
|
var/list/atom/atoms = list()
|
|
var/list/area/areas = list()
|
|
|
|
var/list/turfs = block(
|
|
locate(
|
|
bounds[MAP_MINX],
|
|
bounds[MAP_MINY],
|
|
bounds[MAP_MINZ]
|
|
),
|
|
locate(
|
|
bounds[MAP_MAXX],
|
|
bounds[MAP_MAXY],
|
|
bounds[MAP_MAXZ]
|
|
)
|
|
)
|
|
for(var/L in turfs)
|
|
var/turf/B = L
|
|
areas |= B.loc
|
|
for(var/A in B)
|
|
atoms += A
|
|
if(istype(A, /obj/structure/cable))
|
|
cables += A
|
|
continue
|
|
if(istype(A, /obj/machinery/atmospherics))
|
|
atmos_machines += A
|
|
|
|
SSmapping.reg_in_areas_in_z(areas)
|
|
SSatoms.InitializeAtoms(areas + turfs + atoms)
|
|
// NOTE, now that Initialize and LateInitialize run correctly, do we really
|
|
// need these two below?
|
|
SSmachines.setup_template_powernets(cables)
|
|
SSair.setup_template_machinery(atmos_machines)
|
|
|
|
//calculate all turfs inside the border
|
|
var/list/template_and_bordering_turfs = block(
|
|
locate(
|
|
max(bounds[MAP_MINX]-1, 1),
|
|
max(bounds[MAP_MINY]-1, 1),
|
|
bounds[MAP_MINZ]
|
|
),
|
|
locate(
|
|
min(bounds[MAP_MAXX]+1, world.maxx),
|
|
min(bounds[MAP_MAXY]+1, world.maxy),
|
|
bounds[MAP_MAXZ]
|
|
)
|
|
)
|
|
for(var/t in template_and_bordering_turfs)
|
|
var/turf/affected_turf = t
|
|
affected_turf.air_update_turf(TRUE)
|
|
affected_turf.levelupdate()
|
|
|
|
/datum/map_template/proc/load_new_z()
|
|
var/x = round((world.maxx - width) * 0.5) + 1
|
|
var/y = round((world.maxy - height) * 0.5) + 1
|
|
|
|
var/datum/space_level/level = SSmapping.add_new_zlevel(name, list(ZTRAIT_AWAY = TRUE))
|
|
var/datum/parsed_map/parsed = load_map(file(mappath), x, y, level.z_value, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS), placeOnTop=TRUE)
|
|
var/list/bounds = parsed.bounds
|
|
if(!bounds)
|
|
return FALSE
|
|
|
|
repopulate_sorted_areas()
|
|
|
|
//initialize things that are normally initialized after map load
|
|
parsed.initTemplateBounds()
|
|
smooth_zlevel(world.maxz)
|
|
log_game("Z-level [name] loaded at [x],[y],[world.maxz]")
|
|
|
|
return level
|
|
|
|
/datum/map_template/proc/load(turf/T, centered = FALSE)
|
|
if(centered)
|
|
T = locate(T.x - round(width/2) , T.y - round(height/2) , T.z)
|
|
if(!T)
|
|
return
|
|
if(T.x+width > world.maxx)
|
|
return
|
|
if(T.y+height > world.maxy)
|
|
return
|
|
|
|
var/list/border = block(locate(max(T.x-1, 1), max(T.y-1, 1), T.z),
|
|
locate(min(T.x+width+1, world.maxx), min(T.y+height+1, world.maxy), T.z))
|
|
for(var/L in border)
|
|
var/turf/turf_to_disable = L
|
|
SSair.remove_from_active(turf_to_disable) //stop processing turfs along the border to prevent runtimes, we return it in initTemplateBounds()
|
|
turf_to_disable.atmos_adjacent_turfs?.Cut()
|
|
|
|
// Accept cached maps, but don't save them automatically - we don't want
|
|
// ruins clogging up memory for the whole round.
|
|
var/datum/parsed_map/parsed = cached_map || new(file(mappath))
|
|
cached_map = keep_cached_map ? parsed : null
|
|
if(!parsed.load(T.x, T.y, T.z, cropMap=TRUE, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS), placeOnTop=TRUE))
|
|
return
|
|
var/list/bounds = parsed.bounds
|
|
if(!bounds)
|
|
return
|
|
|
|
if(!SSmapping.loading_ruins) //Will be done manually during mapping ss init
|
|
repopulate_sorted_areas()
|
|
|
|
//initialize things that are normally initialized after map load
|
|
parsed.initTemplateBounds()
|
|
|
|
log_game("[name] loaded at [T.x],[T.y],[T.z]")
|
|
return bounds
|
|
|
|
/datum/map_template/proc/post_load()
|
|
return
|
|
|
|
/datum/map_template/proc/get_affected_turfs(turf/T, centered = FALSE)
|
|
var/turf/placement = T
|
|
if(centered)
|
|
var/turf/corner = locate(placement.x - round(width/2), placement.y - round(height/2), placement.z)
|
|
if(corner)
|
|
placement = corner
|
|
return block(placement, locate(placement.x+width-1, placement.y+height-1, placement.z))
|
|
|
|
|
|
//for your ever biggening badminnery kevinz000
|
|
//❤ - Cyberboss
|
|
/proc/load_new_z_level(file, name)
|
|
var/datum/map_template/template = new(file, name)
|
|
template.load_new_z()
|