Files
Yogstation/code/modules/mapping/space_management/space_reservation.dm
Ling 17c5a68c33 Backports several SSmapping improvements (#17208)
* Optimizes SSmapping

* Turfs inside area are stored

https://github.com/tgstation/tgstation/pull/70966

* Add async reserving of turfs

* Fix bug

* Fix shuttle init
2022-12-31 15:41:47 +00:00

75 lines
2.0 KiB
Plaintext

//Yes, they can only be rectangular.
//Yes, I'm sorry.
/datum/turf_reservation
var/list/reserved_turfs = list()
var/width = 0
var/height = 0
var/bottom_left_coords[3]
var/top_right_coords[3]
var/wipe_reservation_on_release = TRUE
var/turf_type = /turf/open/space
/datum/turf_reservation/transit
turf_type = /turf/open/space/transit
/datum/turf_reservation/proc/Release()
var/list/reserved_copy = reserved_turfs.Copy()
SSmapping.used_turfs -= reserved_turfs
reserved_turfs = list()
// Makes the linter happy, even tho we don't await this
INVOKE_ASYNC(SSmapping, /datum/controller/subsystem/mapping/proc/reserve_turfs, reserved_copy)
/datum/turf_reservation/proc/Reserve(width, height, zlevel)
if(width > world.maxx || height > world.maxy || width < 1 || height < 1)
return FALSE
var/list/avail = SSmapping.unused_turfs["[zlevel]"]
var/turf/BL
var/turf/TR
var/list/turf/final = list()
var/passing = FALSE
for(var/i in avail)
CHECK_TICK
BL = i
if(!(BL.flags_1 & UNUSED_RESERVATION_TURF_1))
continue
if(BL.x + width > world.maxx || BL.y + height > world.maxy)
continue
TR = locate(BL.x + width - 1, BL.y + height - 1, BL.z)
if(!(TR.flags_1 & UNUSED_RESERVATION_TURF_1))
continue
final = block(BL, TR)
if(!final)
continue
passing = TRUE
for(var/I in final)
var/turf/checking = I
if(!(checking.flags_1 & UNUSED_RESERVATION_TURF_1))
passing = FALSE
break
if(!passing)
continue
break
if(!passing || !istype(BL) || !istype(TR))
return FALSE
bottom_left_coords = list(BL.x, BL.y, BL.z)
top_right_coords = list(TR.x, TR.y, TR.z)
for(var/i in final)
var/turf/T = i
reserved_turfs |= T
T.flags_1 &= ~UNUSED_RESERVATION_TURF_1
SSmapping.unused_turfs["[T.z]"] -= T
SSmapping.used_turfs[T] = src
T.ChangeTurf(turf_type, turf_type)
src.width = width
src.height = height
return TRUE
/datum/turf_reservation/New()
LAZYADD(SSmapping.turf_reservations, src)
/datum/turf_reservation/Destroy()
Release()
LAZYREMOVE(SSmapping.turf_reservations, src)
return ..()