From f9ce50bb89e6677a2b3eca4cf0266fde8b8c9626 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 10 Mar 2023 03:40:47 +0100 Subject: [PATCH] [MIRROR] Fixes not being dumped in space after jumping off the shuttle [MDB IGNORE] (#19402) * Fixes not being dumped in space after jumping off the shuttle * Update transit.dm --------- Co-authored-by: Time-Green Co-authored-by: Gandalf <9026500+Gandalf2k15@users.noreply.github.com> --- code/game/turfs/open/space/transit.dm | 41 ++++----------- .../space_management/space_reservation.dm | 52 ++++++++++++++++++- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/code/game/turfs/open/space/transit.dm b/code/game/turfs/open/space/transit.dm index 2f4c49fe5b1..b4c713de751 100644 --- a/code/game/turfs/open/space/transit.dm +++ b/code/game/turfs/open/space/transit.dm @@ -12,9 +12,6 @@ update_appearance() RegisterSignal(src, COMSIG_TURF_RESERVATION_RELEASED, PROC_REF(launch_contents)) - for(var/atom/movable/movable in src) - throw_atom(movable) - /turf/open/space/transit/Destroy() //Signals are NOT removed from turfs upon replacement, and we get replaced ALOT, so unregister our signal UnregisterSignal(src, COMSIG_TURF_RESERVATION_RELEASED) @@ -44,51 +41,31 @@ var/turf/location = gone.loc if(istype(location, /turf/open/space) && !istype(location, src.type))//they got forced out of transit area into default space tiles - throw_atom(gone) //launch them into game space, away from transitspace + dump_in_space(gone) //launch them into game space, away from transitspace ///Get rid of all our contents, called when our reservation is released (which in our case means the shuttle arrived) /turf/open/space/transit/proc/launch_contents(datum/turf_reservation/reservation) SIGNAL_HANDLER for(var/atom/movable/movable in contents) - throw_atom(movable) + dump_in_space(movable) -/turf/open/space/transit/proc/throw_atom(atom/movable/AM) - if(!AM || istype(AM, /obj/docking_port) || istype(AM, /obj/effect/abstract)) - return +///Dump a movable in a random valid spacetile +/proc/dump_in_space(atom/movable/dumpee) var/max = world.maxx-TRANSITIONEDGE var/min = 1+TRANSITIONEDGE var/list/possible_transtitons = list() - for(var/A in SSmapping.z_list) - var/datum/space_level/D = A - if (D.linkage == CROSSLINKED) - possible_transtitons += D.z_value + for(var/datum/space_level/level as anything in SSmapping.z_list) + if (level.linkage == CROSSLINKED) + possible_transtitons += level.z_value if(!length(possible_transtitons)) //No space to throw them to - try throwing them onto mining possible_transtitons = SSmapping.levels_by_trait(ZTRAIT_MINING) if(!length(possible_transtitons)) //Just throw them back on station, if not just runtime. possible_transtitons = SSmapping.levels_by_trait(ZTRAIT_STATION) - var/_z = pick(possible_transtitons) - //now select coordinates for a border turf - var/_x - var/_y - switch(dir) - if(SOUTH) - _x = rand(min,max) - _y = max - if(WEST) - _x = max - _y = rand(min,max) - if(EAST) - _x = min - _y = rand(min,max) - else - _x = rand(min,max) - _y = min - - var/turf/T = locate(_x, _y, _z) - AM.forceMove(T) + //move the dumpee to a random coordinate turf + dumpee.forceMove(locate(rand(min,max), rand(min,max), pick(possible_transtitons))) /turf/open/space/transit/CanBuildHere() return SSshuttle.is_in_shuttle_bounds(src) diff --git a/code/modules/mapping/space_management/space_reservation.dm b/code/modules/mapping/space_management/space_reservation.dm index bb32d91fbca..fff31893d0e 100644 --- a/code/modules/mapping/space_management/space_reservation.dm +++ b/code/modules/mapping/space_management/space_reservation.dm @@ -1,17 +1,22 @@ - //Yes, they can only be rectangular. //Yes, I'm sorry. /datum/turf_reservation var/list/reserved_turfs = list() + ///Turfs around the reservation for cordoning var/list/cordon_turfs = list() + ///Area of turfs next to the cordon to fill with pre_cordon_area's + var/list/pre_cordon_turfs = list() var/width = 0 var/height = 0 var/bottom_left_coords[3] var/top_right_coords[3] var/turf_type = /turf/open/space + ///Distance away from the cordon where we can put a "sort-cordon" and run some extra code (see make_repel). 0 makes nothing happen + var/pre_cordon_distance = 0 /datum/turf_reservation/transit turf_type = /turf/open/space/transit + pre_cordon_distance = 7 /datum/turf_reservation/proc/Release() var/list/reserved_copy = reserved_turfs.Copy() @@ -40,6 +45,15 @@ if(!(cordon_turf.flags_1 & UNUSED_RESERVATION_TURF)) return FALSE cordon_turfs = possible_turfs + + pre_cordon_turfs.Cut() + + if(pre_cordon_distance) + var/turf/offset_turf = locate(BL.x + pre_cordon_distance, BL.y + pre_cordon_distance, BL.z) + var/list/to_add = CORNER_OUTLINE(offset_turf, width - pre_cordon_distance * 2, height - pre_cordon_distance * 2) //we step-by-stop move inwards from the outer cordon + for(var/turf/turf_being_added as anything in to_add) + pre_cordon_turfs |= turf_being_added //add one by one so we can filter out duplicates + return TRUE /// Actually generates the cordon around the reservation, and marking the cordon turfs as reserved @@ -56,6 +70,42 @@ SSmapping.unused_turfs["[cordon_turf.z]"] -= cordon_turf SSmapping.used_turfs[cordon_turf] = src + //swap the area with the pre-cordoning area + for(var/turf/pre_cordon_turf as anything in pre_cordon_turfs) + make_repel(pre_cordon_turf) + +///Register signals in the cordon "danger zone" to do something with whoever trespasses +/datum/turf_reservation/proc/make_repel(turf/pre_cordon_turf) + SHOULD_CALL_PARENT(TRUE) + //Okay so hear me out. If we place a special turf IN the reserved area, it will be overwritten, so we can't do that + //But signals are preserved even between turf changes, so even if we register a signal now it will stay even if that turf is overriden by the template + RegisterSignals(pre_cordon_turf, list(COMSIG_PARENT_QDELETING, COMSIG_TURF_RESERVATION_RELEASED), PROC_REF(on_stop_repel)) + +/datum/turf_reservation/proc/on_stop_repel(turf/pre_cordon_turf) + SHOULD_CALL_PARENT(TRUE) + SIGNAL_HANDLER + + stop_repel(pre_cordon_turf) + +///Unregister all the signals we added in RegisterRepelSignals +/datum/turf_reservation/proc/stop_repel(turf/pre_cordon_turf) + UnregisterSignal(pre_cordon_turf, list(COMSIG_PARENT_QDELETING, COMSIG_TURF_RESERVATION_RELEASED)) + +/datum/turf_reservation/transit/make_repel(turf/pre_cordon_turf) + ..() + + RegisterSignal(pre_cordon_turf, COMSIG_ATOM_ENTERED, PROC_REF(space_dump)) + +/datum/turf_reservation/transit/stop_repel(turf/pre_cordon_turf) + ..() + + UnregisterSignal(pre_cordon_turf, COMSIG_ATOM_ENTERED) + +/datum/turf_reservation/transit/proc/space_dump(atom/source, atom/movable/enterer) + SIGNAL_HANDLER + + dump_in_space(enterer) + /datum/turf_reservation/proc/Reserve(width, height, zlevel) src.width = width src.height = height