Skip to content

Commit

Permalink
Weird Atom Init Issues VS. One Lizard (#2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaFire15 authored Dec 6, 2024
1 parent 439725f commit f2f7999
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 15 deletions.
4 changes: 2 additions & 2 deletions code/controllers/subsystem/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ SUBSYSTEM_DEF(mapping)
var/obj/structure/overmap/OM = instance_overmap(config.ship_type)
pass(OM)
// Free boarding overmap/mining level
add_new_zlevel("Overmap treadmill [++world.maxz]", ZTRAITS_OVERMAP)
OM.free_treadmills += world.maxz
var/datum/space_level/overmap_z1 = add_new_zlevel("Overmap treadmill [length(z_list)+1]", ZTRAITS_OVERMAP)
OM.free_treadmills += overmap_z1.z_value

LoadStationRoomTemplates()
LoadStationRooms()
Expand Down
3 changes: 3 additions & 0 deletions nsv13/code/__DEFINES/overmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ GLOBAL_LIST_INIT(overmap_impact_sounds, list('nsv13/sound/effects/ship/freespace
#define SHIELD_ABSORB 1 //!Shield absorbed hit.
#define SHIELD_FORCE_DEFLECT 2 //!Shield absorbed hit and is redirecting projectile with slightly turned vector.
#define SHIELD_FORCE_REFLECT 3 //!Shield absorbed hit and is redirecting projectile in reverse direction.

//Interior instancing comsig, aka cursed things.
#define COMSIG_INTERIOR_DONE_LOADING "interior_done_loading"
10 changes: 10 additions & 0 deletions nsv13/code/__HELPERS/overmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@ Another get_angle that works better with the looping edges of the overmap
else if(CX<0)
.+=360

/**
* I am genuinely unsure what this is actually meant to do that normal z add does not do.
* If ANYONE actually knows if there is some important reason the procs I changed used this please tell me ~Delta
**/
/datum/controller/subsystem/mapping/proc/add_new_initialized_zlevel(name, traits = list(), z_type = /datum/space_level, orbital_body_type)
add_new_zlevel(name, traits)
SSatoms.InitializeAtoms(block(locate(1,1,world.maxz),locate(world.maxx,world.maxy,world.maxz)))
setup_map_transitions(z_list[world.maxz])
/**
* Generates a new z level with behavior specific to overmaps and returns its space level datum.
*/
/datum/controller/subsystem/mapping/proc/add_new_overmap_zlevel()
. = add_new_zlevel("Overmap treadmill [length(z_list)+1]", ZTRAITS_OVERMAP)
setup_map_transitions(.)
25 changes: 25 additions & 0 deletions nsv13/code/controllers/subsystem/starsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ SUBSYSTEM_DEF(star_system)
var/obj/structure/overmap/mining_ship = null //The mining ship
var/saving = FALSE

///Kind of cursed list that tracks which of our overmap interiors have been initialized yet.
var/list/overmap_interior_queue = list() //Ratvar save me from this.
///Are we already busy?
var/initing_interior = FALSE

/datum/controller/subsystem/star_system/fire() //Overmap combat events control system, adds weight to combat events over time spent out of combat
handle_interior_inits() //Cursed. I don't like this.
if(time_limit && world.time >= time_limit)
var/datum/faction/winner = get_winner()
if(istype(SSticker.mode, /datum/game_mode/pvp))
Expand Down Expand Up @@ -71,6 +77,25 @@ SUBSYSTEM_DEF(star_system)
saving = FALSE
. = ..()

///Absolutely cursed proc handling ship interior init queues.
/datum/controller/subsystem/star_system/proc/handle_interior_inits()
set waitfor = FALSE
if(initing_interior)
return
if(SSatoms.initialized_changed)
return
if(!length(overmap_interior_queue))
return
initing_interior = TRUE
var/obj/structure/overmap/shipinterior_candidate = overmap_interior_queue[1]
shipinterior_candidate.instance_interior()
SEND_SIGNAL(shipinterior_candidate, COMSIG_INTERIOR_DONE_LOADING)
overmap_interior_queue -= shipinterior_candidate
initing_interior = FALSE

/datum/controller/subsystem/star_system/proc/queue_for_interior_load(obj/structure/overmap/to_interior_load)
overmap_interior_queue += to_interior_load

/**
Returns a faction datum by its name (case insensitive!)
*/
Expand Down
19 changes: 16 additions & 3 deletions nsv13/code/modules/overmap/fighters/fighters_launcher.dm
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,27 @@ d) the ships[] list of ssstarsystem is acting up again.
return FALSE
if(istype(OM, /obj/structure/overmap/asteroid))
var/obj/structure/overmap/asteroid/AS = OM
if(AS.interior_status == INTERIOR_READY)
return transfer_from_overmap(AS)
AS.interior_mode = INTERIOR_DYNAMIC // We don't actually want it to create one until we're ready but we do need entry points
AS.instance_interior()
AS.docking_points = AS.interior_entry_points
return transfer_from_overmap(OM)
DC.docking_cooldown = TRUE
RegisterSignal(AS, COMSIG_INTERIOR_DONE_LOADING, PROC_REF(on_dock_interior_load_finish))
SSstar_system.queue_for_interior_load(AS)
return TRUE //We have to assume this will end up being a correct docking.
if(mass < OM.mass) //If theyre bigger than us and have docking points, and we want to dock.
return transfer_from_overmap(OM)
return FALSE

///Listens for the interior loading to finish and finishes docking once it does.
/obj/structure/overmap/small_craft/proc/on_dock_interior_load_finish(obj/structure/overmap/docking_target)
SIGNAL_HANDLER
UnregisterSignal(docking_target, COMSIG_INTERIOR_DONE_LOADING)
docking_target.docking_points = docking_target.interior_entry_points
var/obj/item/fighter_component/docking_computer/DC = loadout.get_slot(HARDPOINT_SLOT_DOCKING)
if(DC)
DC.docking_cooldown = FALSE
INVOKE_ASYNC(src, PROC_REF(transfer_from_overmap), docking_target)

/obj/structure/overmap/small_craft/proc/transfer_from_overmap(obj/structure/overmap/OM)
if(!length(OM.docking_points))
return FALSE
Expand Down
33 changes: 23 additions & 10 deletions nsv13/code/modules/overmap/overmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,15 @@ Proc to spool up a new Z-level for a player ship and assign it a treadmill.
if(!_path)
_path = /obj/structure/overmap/nanotrasen/heavy_cruiser/starter
RETURN_TYPE(/obj/structure/overmap)
SSmapping.add_new_initialized_zlevel("Overmap ship level [++world.maxz]", ZTRAITS_OVERMAP)
var/datum/space_level/new_ship_z = SSmapping.add_new_zlevel("Overmap ship level [length(SSmapping.z_list)+1]", ZTRAITS_OVERMAP)
if(!folder || !interior_map_files)
SSmapping.setup_map_transitions(new_ship_z) //We usually recalculate transitions later, but not if there's no interior.
repopulate_sorted_areas()
smooth_zlevel(world.maxz)
log_game("Z-level [world.maxz] loaded for overmap treadmills.")
var/turf/exit = get_turf(locate(round(world.maxx * 0.5, 1), round(world.maxy * 0.5, 1), world.maxz)) //Plop them bang in the center of the system.
smooth_zlevel(new_ship_z.z_value)
log_game("Z-level [new_ship_z.z_value] loaded for overmap treadmills.")
var/turf/exit = get_turf(locate(round(world.maxx * 0.5, 1), round(world.maxy * 0.5, 1), new_ship_z.z_value)) //Plop them bang in the center of the system.
var/obj/structure/overmap/OM = new _path(exit) //Ship'll pick up the info it needs, so just domp eet at the exit turf.
OM.reserved_z = world.maxz
OM.reserved_z = new_ship_z.z_value
OM.overmap_flags |= OVERMAP_FLAG_ZLEVEL_CARRIER
OM.current_system = SSstar_system.find_system(OM)
if(OM.role == MAIN_OVERMAP) //If we're the main overmap, we'll cheat a lil' and apply our status to all of the Zs under "station"
Expand Down Expand Up @@ -444,12 +446,23 @@ Proc to spool up a new Z-level for a player ship and assign it a treadmill.
interior_mode = (possible_interior_maps?.len) ? INTERIOR_EXCLUSIVE : NO_INTERIOR
//Allows small ships to have a small interior.
if(INTERIOR_DYNAMIC)
instance_interior()
post_load_interior()
RegisterSignal(src, COMSIG_INTERIOR_DONE_LOADING, PROC_REF(after_init_load_interior))
SSstar_system.queue_for_interior_load(src)

apply_weapons()
RegisterSignal(src, list(COMSIG_FTL_STATE_CHANGE, COMSIG_SHIP_KILLED), PROC_REF(dump_locks)) // Setup lockon handling
//We have a lot of types but not that many weapons per ship, so let's just worry about the ones we do have
if(interior_mode != INTERIOR_DYNAMIC)
apply_weapons()
for(var/firemode = 1; firemode <= MAX_POSSIBLE_FIREMODE; firemode++)
var/datum/ship_weapon/SW = weapon_types[firemode]
if(istype(SW) && (SW.allowed_roles & OVERMAP_USER_ROLE_GUNNER))
weapon_numkeys_map += firemode

///Listens for when the interior is done initing and finishes up some variables when it is.
/obj/structure/overmap/proc/after_init_load_interior()
SIGNAL_HANDLER
UnregisterSignal(src, COMSIG_INTERIOR_DONE_LOADING)
apply_weapons()
for(var/firemode = 1; firemode <= MAX_POSSIBLE_FIREMODE; firemode++)
var/datum/ship_weapon/SW = weapon_types[firemode]
if(istype(SW) && (SW.allowed_roles & OVERMAP_USER_ROLE_GUNNER))
Expand Down Expand Up @@ -972,8 +985,8 @@ Proc to spool up a new Z-level for a player ship and assign it a treadmill.
return reserved_z
if(ftl_drive)
if(!free_treadmills?.len)
SSmapping.add_new_initialized_zlevel("Overmap treadmill [++world.maxz]", ZTRAITS_OVERMAP)
reserved_z = world.maxz
var/datum/space_level/new_level = SSmapping.add_new_overmap_zlevel()
reserved_z = new_level.z_value
else
var/_z = pick_n_take(free_treadmills)
reserved_z = _z
Expand Down

0 comments on commit f2f7999

Please sign in to comment.