Skip to content

Commit

Permalink
Sabre insanity, also known as one proc adjustment that might possibly…
Browse files Browse the repository at this point in the history
… fix stuff (now includes ~300% more proc adjustments) (BeeStation#2666)
  • Loading branch information
DeltaFire15 authored and IndusRobot committed Dec 16, 2024
1 parent 08dc767 commit 1d5a088
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
11 changes: 8 additions & 3 deletions nsv13/code/controllers/subsystem/starsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,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))
Expand Down Expand Up @@ -358,9 +359,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.
Expand Down Expand Up @@ -737,7 +742,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
Expand Down
23 changes: 18 additions & 5 deletions nsv13/code/modules/overmap/FTL/ftl_jump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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.
Expand All @@ -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.
Expand Down
19 changes: 15 additions & 4 deletions nsv13/code/modules/overmap/fighters/fighters_launcher.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()


/*
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) 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.
if(!ignore_position && !is_near_boundary())
return FALSE
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -357,8 +368,8 @@
var/turf/T = get_turf(pick(OM.docking_points))
forceMove(T)
if(current_system)
current_system.remove_ship(src, T)
OM.overmaps_in_ship |= src
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)
DC.docking_mode = FALSE
Expand Down
17 changes: 17 additions & 0 deletions nsv13/code/modules/overmap/overmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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 some things 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)
Expand Down Expand Up @@ -975,3 +978,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
4 changes: 3 additions & 1 deletion nsv13/code/modules/overmap/weapons/plasma_gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1d5a088

Please sign in to comment.