mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2025-12-30 20:13:53 +00:00
Unifies engine and static poi loading into one system.
This commit is contained in:
@@ -155,142 +155,3 @@
|
||||
var/datum/map_template/template = new(file, name)
|
||||
template.load_new_z(orientation)
|
||||
|
||||
// Very similar to the /tg/ version.
|
||||
/proc/seed_submaps(var/list/z_levels, var/budget = 0, var/whitelist = /area/space, var/desired_map_template_type = null)
|
||||
set background = TRUE
|
||||
|
||||
if(!z_levels || !z_levels.len)
|
||||
admin_notice("seed_submaps() was not given any Z-levels.", R_DEBUG)
|
||||
return
|
||||
|
||||
for(var/zl in z_levels)
|
||||
var/turf/T = locate(1, 1, zl)
|
||||
if(!T)
|
||||
admin_notice("Z level [zl] does not exist - Not generating submaps", R_DEBUG)
|
||||
return
|
||||
|
||||
var/overall_sanity = 100 // If the proc fails to place a submap more than this, the whole thing aborts.
|
||||
var/list/potential_submaps = list() // Submaps we may or may not place.
|
||||
var/list/priority_submaps = list() // Submaps that will always be placed.
|
||||
|
||||
// Lets go find some submaps to make.
|
||||
for(var/map in SSmapping.map_templates)
|
||||
var/datum/map_template/MT = SSmapping.map_templates[map]
|
||||
if(!MT.allow_duplicates && MT.loaded > 0) // This probably won't be an issue but we might as well.
|
||||
continue
|
||||
if(!istype(MT, desired_map_template_type)) // Not the type wanted.
|
||||
continue
|
||||
if(MT.discard_prob && prob(MT.discard_prob))
|
||||
continue
|
||||
if(MT.cost && MT.cost < 0) // Negative costs always get spawned.
|
||||
priority_submaps += MT
|
||||
else
|
||||
potential_submaps += MT
|
||||
|
||||
CHECK_TICK
|
||||
|
||||
var/list/loaded_submap_names = list()
|
||||
var/list/template_groups_used = list() // Used to avoid spawning three seperate versions of the same PoI.
|
||||
|
||||
// Now lets start choosing some.
|
||||
while(budget > 0 && overall_sanity > 0)
|
||||
overall_sanity--
|
||||
var/datum/map_template/chosen_template = null
|
||||
|
||||
if(potential_submaps.len)
|
||||
if(priority_submaps.len) // Do these first.
|
||||
chosen_template = pick(priority_submaps)
|
||||
else
|
||||
chosen_template = pick(potential_submaps)
|
||||
|
||||
else // We're out of submaps.
|
||||
admin_notice("Submap loader had no submaps to pick from with [budget] left to spend.", R_DEBUG)
|
||||
break
|
||||
|
||||
CHECK_TICK
|
||||
|
||||
// Can we afford it?
|
||||
if(chosen_template.cost > budget)
|
||||
priority_submaps -= chosen_template
|
||||
potential_submaps -= chosen_template
|
||||
continue
|
||||
|
||||
// Did we already place down a very similar submap?
|
||||
if(chosen_template.template_group && (chosen_template.template_group in template_groups_used))
|
||||
priority_submaps -= chosen_template
|
||||
potential_submaps -= chosen_template
|
||||
continue
|
||||
|
||||
// If so, try to place it.
|
||||
var/specific_sanity = 100 // A hundred chances to place the chosen submap.
|
||||
while(specific_sanity > 0)
|
||||
specific_sanity--
|
||||
|
||||
var/orientation
|
||||
if(chosen_template.fixed_orientation || !config.random_submap_orientation)
|
||||
orientation = 0
|
||||
else
|
||||
orientation = pick(list(0, 90, 180, 270))
|
||||
|
||||
chosen_template.preload_size(chosen_template.mappath, orientation)
|
||||
var/width_border = TRANSITIONEDGE + SUBMAP_MAP_EDGE_PAD + round(((orientation%180) ? chosen_template.height : chosen_template.width) / 2) // %180 catches East/West (90,270) rotations on true, North/South (0,180) rotations on false
|
||||
var/height_border = TRANSITIONEDGE + SUBMAP_MAP_EDGE_PAD + round(((orientation%180) ? chosen_template.width : chosen_template.height) / 2)
|
||||
var/z_level = pick(z_levels)
|
||||
var/turf/T = locate(rand(width_border, world.maxx - width_border), rand(height_border, world.maxy - height_border), z_level)
|
||||
var/valid = TRUE
|
||||
|
||||
for(var/turf/check in chosen_template.get_affected_turfs(T,TRUE,orientation))
|
||||
var/area/new_area = get_area(check)
|
||||
if(!(istype(new_area, whitelist)))
|
||||
valid = FALSE // Probably overlapping something important.
|
||||
// to_world("Invalid due to overlapping with area [new_area.type] at ([check.x], [check.y], [check.z]), when attempting to place at ([T.x], [T.y], [T.z]).")
|
||||
break
|
||||
CHECK_TICK
|
||||
|
||||
CHECK_TICK
|
||||
|
||||
if(!valid)
|
||||
continue
|
||||
|
||||
admin_notice("Submap \"[chosen_template.name]\" placed at ([T.x], [T.y], [T.z])\n", R_DEBUG)
|
||||
|
||||
// Do loading here.
|
||||
chosen_template.load(T, centered = TRUE, orientation=orientation) // This is run before the main map's initialization routine, so that can initilize our submaps for us instead.
|
||||
|
||||
CHECK_TICK
|
||||
|
||||
// For pretty maploading statistics.
|
||||
if(loaded_submap_names[chosen_template.name])
|
||||
loaded_submap_names[chosen_template.name] += 1
|
||||
else
|
||||
loaded_submap_names[chosen_template.name] = 1
|
||||
|
||||
// To avoid two 'related' similar submaps existing at the same time.
|
||||
if(chosen_template.template_group)
|
||||
template_groups_used += chosen_template.template_group
|
||||
|
||||
// To deduct the cost.
|
||||
if(chosen_template.cost >= 0)
|
||||
budget -= chosen_template.cost
|
||||
|
||||
// Remove the submap from our options.
|
||||
if(chosen_template in priority_submaps) // Always remove priority submaps.
|
||||
priority_submaps -= chosen_template
|
||||
else if(!chosen_template.allow_duplicates)
|
||||
potential_submaps -= chosen_template
|
||||
|
||||
break // Load the next submap.
|
||||
|
||||
var/list/pretty_submap_list = list()
|
||||
for(var/submap_name in loaded_submap_names)
|
||||
var/count = loaded_submap_names[submap_name]
|
||||
if(count > 1)
|
||||
pretty_submap_list += "[count] <b>[submap_name]</b>"
|
||||
else
|
||||
pretty_submap_list += "<b>[submap_name]</b>"
|
||||
|
||||
if(!overall_sanity)
|
||||
admin_notice("Submap loader gave up with [budget] left to spend.", R_DEBUG)
|
||||
else
|
||||
admin_notice("Submaps loaded.", R_DEBUG)
|
||||
admin_notice("Loaded: [english_list(pretty_submap_list)]", R_DEBUG)
|
||||
|
||||
Reference in New Issue
Block a user