Files
Paradise/code/modules/space_management/zlevel_manager.dm
Charlie Nolan d3584b1d1c LINDA -> MILLA (#25328)
* LINDA -> MILLA

* Tiles now change their atmos mode properly.

* Fixed a bug that made walls generate supercold air when deconstructed/destroyed.

* Apply suggestions from code review

Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
Co-authored-by: GDN <96800819+GDNgit@users.noreply.github.com>
Signed-off-by: Charlie Nolan <funnyman3595@gmail.com>

* Begone, var!

* MILLA -> milla

* Lint.

* More lint.

* Prevent negative/NaN atmos from spreading.

* Made fires start more reliably.

* Undef what the rest should not see.

* Enums are nice.

* Match LINDA better.

* Debugging verbs.

* Debug verb fixes.

* Labelled more lavaland stuff with ATMOS_MODE_LAVALAND

* Block superconductivity on a couple more things for Lavaland.

* Updated milla.dll

* Lavaland map fixes.

* Missed a spot.

* Begone, var! (again)

* Add libmilla_ci.so for continuous integration tests.

* Install/contributing instructions for MILLA.

* Directional plasmaglass windows on shuttles shouldn't stop protecting from heat after moving.

* Banish bad naming.

* Better naming and debug stats for SSair.

* Apply suggestions from code review

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Signed-off-by: Charlie Nolan <funnyman3595@gmail.com>

* Magic numbers and formatting.

* Don't screw up the temperature during reactions.

* Efficiency and readability.

* Fix hotspots.

* Removed redundant safety (MILLA will already output an error)

* Optimizations.

* oops

* TGS build script update.

* Change API of gas_mixture and how you get one from a turf.

* Get in there.

* so many vars

* MILLA binary updates.

* Lint

* Made MT cost more honest.

* Gave MILLA a read-only mode.

* More read-only vs synchronized mode work.

* Even more.

* Synchronize disposals.

* Updated a bunch of stuff to use SSair.synchronize or GM.synchronize.

* MILLA <3 Tracy

* lint

* cargo fmt

* more lint

* Test needed MILLA sync.

* Silence atmos machinery that's behaving as intended, but continue objecting to other potential failures to synchronize.

* Push new MILLA DLL

* Build MILLA

* Update PR instructions for MILLA.

* Add some fancy plasmaglass windows to the Lifebringers' ship.

* The golems remembered that they should insulate *all* their engines.

* First round of TM bugfixes.

* Build MILLA

* fix two lavaland ruin turf types

* bunch more maps

* fixes milla ci and makes the interesting turf verb better

* Solid turfs can no longer conduct heat (for now...)

* Made indoor tiles in beach and winter biodomes not lavaland air.

* Re-added random IT teleport, adjusted warning message

* Fixed a tinted window on Lavaland to be a plasglass window instead.

* Made firelocks and holofans heatproof

* Made RPD auto-wrench pipes if you have a wrench in your offhand.

* Runtime fixes.

* Made visuals update more reliably.

* Lint

* Update .github/CONTRIBUTING.md

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Signed-off-by: Charlie Nolan <funnyman3595@gmail.com>

* Build MILLA

* The Syndicate have installed tiny fans on their research base.

* The syndicate have figured out how to make plastitanium windows heatproof.

* This is getting out of hand. Now there are two of them.

* Un-break the auto-wrenching that I broke before committing.

* Build MILLA

* Build MILLA

* Massive MILLA refactor, assorted bugfixes.

* Build MILLA

* Explicit typing.

* Less sleeping/blocking.

* Build MILLA

* Yes, yes, this part can sleep.

* Build MILLA

* SSair reporting improvements.

* Build MILLA

* Please do not dock twice and splat yourself.

* Build MILLA

* Pls to not make SM go nuts.

* Build MILLA

* Build MILLA

* Added stricter lower bounds on plasmafire, fixing perpetually-burning SM.

* Build MILLA

* Lint

* Temporary logging, begone.

* Build MILLA

* Prevent hotspot strobing.

* Add in radiate_to_spess behavior.

* Build MILLA

* progress

* Compiling is good.

* bugfixes

* Progress.

* Ruins update.

* This one exists.

* Fixup temporary hotspots to last longer than one tick.

* Add/fix comments.

* Cut the slash.

* Fix test.

* No sleep for you.

* Build MILLA

* Prevent nested MILLA safety from runtiming.

* Build MILLA

* Runtime fix.

* Build MILLA

* Fix canisters not updating icon when gas contents change.

* Build MILLA

* Build MILLA

* Fixed an issue that made mechs very cold on environment air.

* Build MILLA

* oops

* Build MILLA

* Walls can make loud noises again.

* Build MILLA

* Fixes a rare runtime.

* Build MILLA

* Update .github/DOWNLOADING.md

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Signed-off-by: Charlie Nolan <funnyman3595@gmail.com>

* Review suggestions

* Lint

* Build MILLA

* bound_mixtures now only contains mixtures that can be written

* Build MILLA

* Apply suggestions from code review

Co-authored-by: Matt <116982774+Burzah@users.noreply.github.com>
Signed-off-by: Charlie Nolan <funnyman3595@gmail.com>

* Build MILLA

* Restore the original async behavior of pyro anomalies.

* Build MILLA

* Build MILLA

* Make the safety assertion in /datum/milla_safe safer.

* Build MILLA

---------

Signed-off-by: Charlie Nolan <funnyman3595@gmail.com>
Co-authored-by: FunnyMan3595 (Charlie Nolan) <funnyman@google.com>
Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
Co-authored-by: GDN <96800819+GDNgit@users.noreply.github.com>
Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Co-authored-by: paradisess13[bot] <165046124+paradisess13[bot]@users.noreply.github.com>
Co-authored-by: warriorstar-orion <orion@snowfrost.garden>
Co-authored-by: GDN <Roanrichards1@Gmail.com>
2024-06-09 07:18:11 +00:00

176 lines
5.2 KiB
Plaintext

GLOBAL_DATUM_INIT(space_manager, /datum/zlev_manager, new())
/datum/zlev_manager
// A list of z-levels
var/list/z_list = list()
var/list/levels_by_name = list()
var/list/heaps = list()
// Levels that need their transitions rebuilt
var/list/unbuilt_space_transitions = list()
var/datum/spacewalk_grid/linkage_map
var/initialized = 0
var/list/areas_in_z = list()
// Populate our space level list
// and prepare space transitions
/datum/zlev_manager/proc/initialize()
var/num_official_z_levels = length(GLOB.map_transition_config)
var/k = 1
// First take care of "Official" z levels, without visiting levels outside of the list
for(var/list/features in GLOB.map_transition_config)
if(k > world.maxz)
CRASH("More map attributes pre-defined than existent z levels - [num_official_z_levels]")
var/name = features["name"]
var/linking = features["linkage"]
var/list/attributes = features["attributes"]
attributes = attributes.Copy() // Clone the list so it can't be changed on accident
milla_init_z(k)
var/datum/space_level/S = new /datum/space_level(k, name, transition_type = linking, traits = attributes)
z_list["[k]"] = S
levels_by_name[name] = S
k++
// Then, we take care of unmanaged z levels
// They get the default linkage of SELFLOOPING
for(var/i = k, i <= world.maxz, i++)
milla_init_z(k)
z_list["[i]"] = new /datum/space_level(i)
initialized = 1
/datum/zlev_manager/proc/get_zlev(z)
if(!("[z]" in z_list))
throw EXCEPTION("Unmanaged z level: '[z]'")
else
return z_list["[z]"]
/datum/zlev_manager/proc/get_zlev_by_name(A)
if(!(A in levels_by_name))
throw EXCEPTION("Non-existent z level: '[A]'")
return levels_by_name[A]
/*
* "Dirt" management
* "Dirt" is used to keep track of whether a z level should automatically have
* stuff on it initialize or not - If you're loading a map, place
* a freeze on the z levels it touches so as to prevent atmos from exploding,
* among other things
*/
// Returns whether the given z level has a freeze on initialization
/datum/zlev_manager/proc/is_zlevel_dirty(z)
var/datum/space_level/our_z = get_zlev(z)
return (our_z.dirt_count > 0)
// Increases the dirt count on a z level
/datum/zlev_manager/proc/add_dirt(z)
var/datum/space_level/our_z = get_zlev(z)
if(our_z.dirt_count == 0)
log_debug("Placing an init freeze on z-level '[our_z.zpos]'!")
our_z.dirt_count++
// Decreases the dirt count on a z level
/datum/zlev_manager/proc/remove_dirt(z)
var/datum/space_level/our_z = get_zlev(z)
our_z.dirt_count--
if(our_z.dirt_count == 0)
our_z.resume_init()
if(our_z.dirt_count < 0)
log_debug("WARNING: Imbalanced dirt removal")
our_z.dirt_count = 0
/datum/zlev_manager/proc/postpone_init(z, thing)
var/datum/space_level/our_z = get_zlev(z)
our_z.init_list.Add(thing)
/**
*
* SPACE ALLOCATION
*
*/
// For when you need the z-level to be at a certain point
/datum/zlev_manager/proc/increase_max_zlevel_to(new_maxz)
if(world.maxz>=new_maxz)
return
while(world.maxz<new_maxz)
add_new_zlevel("Anonymous Z level [world.maxz]")
// Increments the max z-level by one
// For convenience's sake returns the z-level added
/datum/zlev_manager/proc/add_new_zlevel(name, linkage = SELFLOOPING, traits = list(BLOCK_TELEPORT))
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_NEW_Z, args)
if(name in levels_by_name)
throw EXCEPTION("Name already in use: [name]")
world.maxz++
var/our_z = world.maxz
milla_init_z(our_z)
var/datum/space_level/S = new /datum/space_level(our_z, name, transition_type = linkage, traits = traits)
levels_by_name[name] = S
z_list["[our_z]"] = S
return our_z
/datum/zlev_manager/proc/cut_levels_downto(new_maxz)
if(world.maxz <= new_maxz)
return
while(world.maxz>new_maxz)
kill_topmost_zlevel()
// Decrements the max z-level by one
// not normally used, but hey the swapmap loader wanted it
/datum/zlev_manager/proc/kill_topmost_zlevel()
var/our_z = world.maxz
var/datum/space_level/S = get_zlev(our_z)
z_list.Remove(S)
qdel(S)
world.maxz--
// An internally-used proc used for heap-zlevel management
/datum/zlev_manager/proc/add_new_heap()
world.maxz++
var/our_z = world.maxz
var/datum/space_level/yup = new /datum/space_level/heap(our_z, traits = list(BLOCK_TELEPORT, ADMIN_LEVEL))
z_list["[our_z]"] = yup
return yup
// This is what you can call to allocate a section of space
// Later, I'll add an argument to let you define the flags on the region
/datum/zlev_manager/proc/allocate_space(width, height)
if(width > world.maxx || height > world.maxy)
throw EXCEPTION("Too much space requested! \[[width],[height]\]")
if(!length(heaps))
heaps.len++
heaps[length(heaps)] = add_new_heap()
var/datum/space_level/heap/our_heap
var/weve_got_vacancy = 0
for(our_heap in heaps)
weve_got_vacancy = our_heap.request(width, height)
if(weve_got_vacancy)
break // We're sticking with the present value of `our_heap` - it's got room
// This loop will also run out if no vacancies are found
if(!weve_got_vacancy)
heaps.len++
our_heap = add_new_heap()
heaps[length(heaps)] = our_heap
return our_heap.allocate(width, height)
/datum/zlev_manager/proc/free_space(datum/space_chunk/C)
if(!istype(C))
return
var/datum/space_level/heap/heap = z_list["[C.zpos]"]
if(!istype(heap))
throw EXCEPTION("Attempted to free chunk at invalid z-level ([C.x],[C.y],[C.zpos]) [C.width]x[C.height]")
heap.free(C)