From 823e0c237b198b609b3b3ff67bddd23b2af17e9b Mon Sep 17 00:00:00 2001 From: DeltaFire <46569814+DeltaFire15@users.noreply.github.com> Date: Sun, 26 May 2024 22:33:09 +0200 Subject: [PATCH 1/4] sigh --- nsv13/code/controllers/subsystem/starsystem.dm | 9 +++++++-- .../overmap/fighters/fighters_launcher.dm | 17 ++++++++++++++--- .../code/modules/overmap/weapons/plasma_gun.dm | 4 +++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/nsv13/code/controllers/subsystem/starsystem.dm b/nsv13/code/controllers/subsystem/starsystem.dm index 0a4f35dde2e..44031c4455d 100644 --- a/nsv13/code/controllers/subsystem/starsystem.dm +++ b/nsv13/code/controllers/subsystem/starsystem.dm @@ -253,6 +253,7 @@ Returns a faction datum by its name (case insensitive!) if(sys.name == id) return sys +///AVOID using this if possible, go by the objects current_system var if you can. Do not trust the weird ships[] list unless you HAVE to (e.g. you haven't set the system yet) /datum/controller/subsystem/star_system/proc/find_system(obj/O) //Used to determine what system a ship is currently in. Famously used to determine the starter system that you've put the ship in. var/datum/star_system/system if(isovermap(O)) @@ -355,9 +356,13 @@ Returns a faction datum by its name (case insensitive!) highestTickets = F.tickets return winner -/datum/controller/subsystem/star_system/proc/add_ship(obj/structure/overmap/OM, turf/target) +/datum/controller/subsystem/star_system/proc/add_ship(obj/structure/overmap/OM, turf/target, datum/star_system/system_override) ships[OM] = list("ship" = OM, "x" = 0, "y" = 0, "current_system" = system_by_id(OM.starting_system), "last_system" = system_by_id(OM.starting_system), "target_system" = null, "from_time" = 0, "to_time" = 0, "occupying_z" = OM.z) - var/datum/star_system/curr = ships[OM]["current_system"] + var/datum/star_system/curr + if(!system_override) + curr = ships[OM]["current_system"] + else + curr = system_override curr.add_ship(OM, target) //Welcome to bracket hell. diff --git a/nsv13/code/modules/overmap/fighters/fighters_launcher.dm b/nsv13/code/modules/overmap/fighters/fighters_launcher.dm index cca65805662..61531e2f7d1 100644 --- a/nsv13/code/modules/overmap/fighters/fighters_launcher.dm +++ b/nsv13/code/modules/overmap/fighters/fighters_launcher.dm @@ -267,9 +267,20 @@ speed_limit = 20 //Let them accelerate to hyperspeed due to the launch, and temporarily break the speed limit. addtimer(VARSET_CALLBACK(src, speed_limit, initial(speed_limit)), 5 SECONDS) //Give them 5 seconds of super speed mode before we take it back from them -/obj/structure/overmap/small_craft/proc/handle_moved() +/obj/structure/overmap/small_craft/proc/handle_moved() //Sooo we call this every single tile we move. Is there no better way? (There probably is) + //SIGNAL_HANDLER //This should be a signal handler but the proc it calls sleeps and I am not asyncing *this*. check_overmap_elegibility() +//FIXME: +/* +Working theories: +a) something is being fucky with the reserved_z 0 of the fighter being used +b) asteroid reserved areas for their zs are fucked. +c) something is being fucked with the last overmap var. +d) something weird is going on with e.g. the aetherwhisp ruin, asteroids that do not delete once left. - might be if it gets destroyed by damage after the ship leaves? what is get_turf(null)? +//ATD: They DID dock to other rocks before, and the one before bricking was one that remained loaded. +*/ + /obj/structure/overmap/small_craft/proc/check_overmap_elegibility(ignore_position = FALSE, ignore_cooldown = FALSE) //What we're doing here is checking if the fighter's hitting the bounds of the Zlevel. If they are, we need to transfer them to overmap space. if(!ignore_position && !is_near_boundary()) return FALSE @@ -305,7 +316,7 @@ get_reserved_z() if(current_system) // No I can't use ?, because if it's null we use the previous value instead starting_system = current_system.name //Just fuck off it works alright? - SSstar_system.add_ship(src, get_turf(OM)) + SSstar_system.add_ship(src, get_turf(OM), current_system) if(current_system && !LAZYFIND(current_system.system_contents, src)) LAZYADD(current_system.system_contents, src) @@ -367,6 +378,6 @@ to_chat(pilot, "Docking complete. Gun safeties have been engaged automatically.") SEND_SIGNAL(src, COMSIG_FTL_STATE_CHANGE) if(reserved_z) - free_treadmills += reserved_z + free_treadmills += reserved_z //THIS IS SUPER UNSAFE!! What if the fighter was holding a z with other player ships on it?? Should realloc it to another eligible overmap in system if that is the case! reserved_z = null return TRUE diff --git a/nsv13/code/modules/overmap/weapons/plasma_gun.dm b/nsv13/code/modules/overmap/weapons/plasma_gun.dm index 98e35f509e1..5fec3945d80 100644 --- a/nsv13/code/modules/overmap/weapons/plasma_gun.dm +++ b/nsv13/code/modules/overmap/weapons/plasma_gun.dm @@ -377,7 +377,9 @@ return var/obj/structure/overmap/target_lock var/target_distance - var/datum/star_system/target_system = SSstar_system.find_system(overmap_firer) + var/datum/star_system/target_system = overmap_firer.current_system + if(!target_system) + return var/list/targets = target_system.system_contents for(var/obj/structure/overmap/ship in targets) if(QDELETED(ship) && ship.mass != MASS_TINY) //It destroys itself when its target is destroyed, ignoring destroyed fighters From cb5de9f4eff6f3b12bbf0c7036d965be737fa1da Mon Sep 17 00:00:00 2001 From: DeltaFire <46569814+DeltaFire15@users.noreply.github.com> Date: Mon, 27 May 2024 18:29:40 +0200 Subject: [PATCH 2/4] ~ --- nsv13/code/modules/overmap/fighters/fighters_launcher.dm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nsv13/code/modules/overmap/fighters/fighters_launcher.dm b/nsv13/code/modules/overmap/fighters/fighters_launcher.dm index 61531e2f7d1..de8da6b66cf 100644 --- a/nsv13/code/modules/overmap/fighters/fighters_launcher.dm +++ b/nsv13/code/modules/overmap/fighters/fighters_launcher.dm @@ -274,10 +274,11 @@ //FIXME: /* Working theories: -a) something is being fucky with the reserved_z 0 of the fighter being used -b) asteroid reserved areas for their zs are fucked. -c) something is being fucked with the last overmap var. +a) something is being weird with the reserved_z 0 of the fighter being used +b) asteroid reserved areas for their zs are not being handled properly. +c) something is being odd with the last overmap var. d) something weird is going on with e.g. the aetherwhisp ruin, asteroids that do not delete once left. - might be if it gets destroyed by damage after the ship leaves? what is get_turf(null)? +e) the ships[] list of ssstarsystem is acting up again, aka the current working hypothesis. //ATD: They DID dock to other rocks before, and the one before bricking was one that remained loaded. */ From 2c31e2992b07c70c2693eec1e94df9b9618245c0 Mon Sep 17 00:00:00 2001 From: DeltaFire <46569814+DeltaFire15@users.noreply.github.com> Date: Sat, 13 Jul 2024 03:28:53 +0200 Subject: [PATCH 3/4] even more experimental stuff --- .../code/controllers/subsystem/starsystem.dm | 2 +- nsv13/code/modules/overmap/FTL/ftl_jump.dm | 23 +++++++++++++++---- .../overmap/fighters/fighters_launcher.dm | 15 ++++++------ nsv13/code/modules/overmap/overmap.dm | 17 ++++++++++++++ 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/nsv13/code/controllers/subsystem/starsystem.dm b/nsv13/code/controllers/subsystem/starsystem.dm index 44031c4455d..366242bf860 100644 --- a/nsv13/code/controllers/subsystem/starsystem.dm +++ b/nsv13/code/controllers/subsystem/starsystem.dm @@ -680,7 +680,7 @@ Returns a faction datum by its name (case insensitive!) for(var/mob/M in OM.mobs_in_ship) M?.client?.color = null if(dist <= 2) - OM.current_system?.remove_ship(OM) + OM.current_system?.remove_ship(OM, is_ftl_jump = FALSE) for(var/area/crushed as() in OM.linked_areas) if(istype(crushed, /area/space)) continue diff --git a/nsv13/code/modules/overmap/FTL/ftl_jump.dm b/nsv13/code/modules/overmap/FTL/ftl_jump.dm index ce78db84359..f0efb31aad7 100644 --- a/nsv13/code/modules/overmap/FTL/ftl_jump.dm +++ b/nsv13/code/modules/overmap/FTL/ftl_jump.dm @@ -81,7 +81,7 @@ contents_positions = null contents_positions = list() -/datum/star_system/proc/remove_ship(obj/structure/overmap/OM, turf/new_location) +/datum/star_system/proc/remove_ship(obj/structure/overmap/OM, turf/new_location, is_ftl_jump = TRUE) var/list/other_player_ships = list() for(var/atom/X in system_contents) if(istype(X, /obj/structure/overmap)) @@ -95,7 +95,8 @@ OM.reserved_z = temp OM.forceMove(new_location ? new_location : locate(OM.x, OM.y, OM.reserved_z)) //Annnd actually kick them out of the current system. system_contents -= OM - ftl_pull_small_craft(OM) + if(is_ftl_jump) + ftl_pull_small_craft(OM) return //Early return here. This means that another player ship is already holding the system, and we really don't need to double-check for this. OM.forceMove(new_location ? new_location : locate(OM.x, OM.y, OM.reserved_z)) //Annnd actually kick them out of the current system. @@ -104,16 +105,28 @@ if(!OM.reserved_z) //If this isn't actually a big ship with its own interior, do not pull ships, as only those get their own reserved z. return if(other_player_ships.len) //There's still other ships here, only pull ships of our own faction. - ftl_pull_small_craft(OM) + if(is_ftl_jump) + ftl_pull_small_craft(OM) return + for(var/atom/movable/X in system_contents) //Do a last check for safety so we don't stasis a player ship that slid by our other checks somehow. if(istype(X, /obj/structure/overmap)) var/obj/structure/overmap/ship = X if(ship != OM && ship.reserved_z) //If there's somehow a player ship in the system that is somehow not in other_player_ships, emergency return. message_admins("Somehow [ship] got by the initial checks for system exits. This probably shouldn't happen, yell at a coder and / or check ftl.dm") - ftl_pull_small_craft(OM) + if(is_ftl_jump) + ftl_pull_small_craft(OM) return - ftl_pull_small_craft(OM, FALSE) + if(is_ftl_jump) + ftl_pull_small_craft(OM, FALSE) + else //We are leaving the overmap while holding system and with no other current holders, which risks nullspacing + for(var/obj/structure/overmap/last_chance in system_contents) + if(!last_chance.spec_pre_system_unload()) + continue + last_chance.reserved_z = OM.reserved_z //We are about to nullspace something that should preserve z. Hand over your z instead. + OM.reserved_z = null + return + for(var/atom/movable/X in system_contents) contents_positions[X] = list("x" = X.x, "y" = X.y) //Cache the ship's position so we can regenerate it later. X.moveToNullspace() //Anything that's an NPC should be stored safely in nullspace until we return. diff --git a/nsv13/code/modules/overmap/fighters/fighters_launcher.dm b/nsv13/code/modules/overmap/fighters/fighters_launcher.dm index de8da6b66cf..2417666ffec 100644 --- a/nsv13/code/modules/overmap/fighters/fighters_launcher.dm +++ b/nsv13/code/modules/overmap/fighters/fighters_launcher.dm @@ -271,15 +271,14 @@ //SIGNAL_HANDLER //This should be a signal handler but the proc it calls sleeps and I am not asyncing *this*. check_overmap_elegibility() -//FIXME: + /* -Working theories: -a) something is being weird with the reserved_z 0 of the fighter being used +Welcome to the "uh oh" zone because fighters travelling from and to overmaps is a bit volatile. +Last time things broke it was caused by d), but if small ship docking starts being weird again, check these four possible weak points first: +a) something is being weird with the reserved_z of the fighter being used. b) asteroid reserved areas for their zs are not being handled properly. c) something is being odd with the last overmap var. -d) something weird is going on with e.g. the aetherwhisp ruin, asteroids that do not delete once left. - might be if it gets destroyed by damage after the ship leaves? what is get_turf(null)? -e) the ships[] list of ssstarsystem is acting up again, aka the current working hypothesis. -//ATD: They DID dock to other rocks before, and the one before bricking was one that remained loaded. +d) the ships[] list of ssstarsystem is acting up again. */ /obj/structure/overmap/small_craft/proc/check_overmap_elegibility(ignore_position = FALSE, ignore_cooldown = FALSE) //What we're doing here is checking if the fighter's hitting the bounds of the Zlevel. If they are, we need to transfer them to overmap space. @@ -369,7 +368,7 @@ e) the ships[] list of ssstarsystem is acting up again, aka the current working var/turf/T = get_turf(pick(OM.docking_points)) forceMove(T) if(current_system) - current_system.remove_ship(src, T) + current_system.remove_ship(src, T, is_ftl_jump = FALSE) OM.overmaps_in_ship += src bound_width = initial(bound_width) bound_height = initial(bound_height) @@ -379,6 +378,6 @@ e) the ships[] list of ssstarsystem is acting up again, aka the current working to_chat(pilot, "Docking complete. Gun safeties have been engaged automatically.") SEND_SIGNAL(src, COMSIG_FTL_STATE_CHANGE) if(reserved_z) - free_treadmills += reserved_z //THIS IS SUPER UNSAFE!! What if the fighter was holding a z with other player ships on it?? Should realloc it to another eligible overmap in system if that is the case! + free_treadmills += reserved_z reserved_z = null return TRUE diff --git a/nsv13/code/modules/overmap/overmap.dm b/nsv13/code/modules/overmap/overmap.dm index 86da1c84a30..13601f2f92e 100644 --- a/nsv13/code/modules/overmap/overmap.dm +++ b/nsv13/code/modules/overmap/overmap.dm @@ -537,9 +537,12 @@ Proc to spool up a new Z-level for a player ship and assign it a treadmill. M.forceMove(T) M.apply_damage(200) kill_boarding_level() + if(current_system) + current_system.remove_ship(src, is_ftl_jump = FALSE) //bit risky call since we already do the thing before but probably should still work. if(reserved_z) free_treadmills += reserved_z reserved_z = null + current_system = null //I'm not sure why we never dropped this variable. return ..() /obj/structure/overmap/forceMove(atom/destination) @@ -973,3 +976,17 @@ Proc to spool up a new Z-level for a player ship and assign it a treadmill. var/_z = pick_n_take(free_treadmills) reserved_z = _z return reserved_z + +///Special proc called right before a system is nullspaced and a last chance to assume a z. Returns TRUE if the ship should not be unloaded. +/obj/structure/overmap/proc/spec_pre_system_unload() + if(!ai_controlled && length(mobs_in_ship)) + return TRUE + return FALSE + +/obj/structure/overmap/small_craft/spec_pre_system_unload() + . = ..() + if(.) + return + if(ftl_drive) + return TRUE + return FALSE From 466d73f3c077ccf3ab1dff0ee8818344612a8163 Mon Sep 17 00:00:00 2001 From: DeltaFire <46569814+DeltaFire15@users.noreply.github.com> Date: Sat, 13 Jul 2024 03:36:04 +0200 Subject: [PATCH 4/4] clarify --- nsv13/code/modules/overmap/overmap.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nsv13/code/modules/overmap/overmap.dm b/nsv13/code/modules/overmap/overmap.dm index cac46dbcdf7..6184028ce4e 100644 --- a/nsv13/code/modules/overmap/overmap.dm +++ b/nsv13/code/modules/overmap/overmap.dm @@ -538,7 +538,7 @@ Proc to spool up a new Z-level for a player ship and assign it a treadmill. M.apply_damage(200) kill_boarding_level() if(current_system) - current_system.remove_ship(src, is_ftl_jump = FALSE) //bit risky call since we already do the thing before but probably should still work. + current_system.remove_ship(src, is_ftl_jump = FALSE) //bit risky call since we already do some things before but probably should still work. if(reserved_z) free_treadmills += reserved_z reserved_z = null