add 'get machines by type' to SSmachines (#28979)

This commit is contained in:
warriorstar-orion
2025-04-16 17:17:54 +00:00
committed by GitHub
parent e5a1f31e6d
commit fa1faf6054
49 changed files with 109 additions and 73 deletions
+2 -2
View File
@@ -174,8 +174,8 @@ SUBSYSTEM_DEF(air)
setup_overlays() // Assign icons and such for gas-turf-overlays
setup_turfs()
setup_atmos_machinery(GLOB.machines)
setup_pipenets(GLOB.machines)
setup_atmos_machinery(SSmachines.get_by_type(/obj/machinery/atmospherics))
setup_pipenets(SSmachines.get_by_type(/obj/machinery/atmospherics))
for(var/obj/machinery/atmospherics/A in machinery_to_construct)
A.initialize_atmos_network()
+38 -1
View File
@@ -9,6 +9,12 @@ SUBSYSTEM_DEF(machines)
offline_implications = "Machinery will no longer process. Shuttle call recommended."
cpu_display = SS_CPUDISPLAY_HIGH
/// Associative list of all machines that exist.
VAR_PRIVATE/list/machines_by_type = list()
/// All machines, not just those that are processing.
VAR_PRIVATE/list/all_machines = list()
var/list/processing = list()
var/list/currentrun = list()
/// All regional powernets (/datum/regional_powernet) in the world
@@ -21,6 +27,37 @@ SUBSYSTEM_DEF(machines)
makepowernets()
fire()
/// Registers a machine with the machine subsystem; should only be called by the machine itself during its creation.
/datum/controller/subsystem/machines/proc/register_machine(obj/machinery/machine)
LAZYADD(machines_by_type[machine.type], machine)
all_machines |= machine
/// Removes a machine from the machine subsystem; should only be called by the machine itself inside Destroy.
/datum/controller/subsystem/machines/proc/unregister_machine(obj/machinery/machine)
var/list/existing = machines_by_type[machine.type]
existing -= machine
if(!length(existing))
machines_by_type -= machine.type
all_machines -= machine
/// Gets a list of all machines that are either the passed type or a subtype.
/datum/controller/subsystem/machines/proc/get_by_type(obj/machinery/machine_type, subtypes = TRUE)
if(!ispath(machine_type))
machine_type = machine_type.type
if(!ispath(machine_type, /obj/machinery))
CRASH("called SSmachines.get_by_type with a non-machine type [machine_type]")
. = list()
if(machine_type in machines_by_type)
. |= machines_by_type[machine_type]
if(!subtypes)
return
for(var/next_type in subtypesof(machine_type))
var/list/found_machines = machines_by_type[next_type]
if(found_machines)
. |= found_machines
/datum/controller/subsystem/machines/get_metrics()
. = ..()
var/list/cust = list()
@@ -39,7 +76,7 @@ SUBSYSTEM_DEF(machines)
propagate_network(PC, PC.powernet)
/datum/controller/subsystem/machines/get_stat_details()
return "Machines: [length(processing)] | Powernets: [length(powernets)] | Deferred: [length(deferred_powernet_rebuilds)]"
return "Machines: [length(all_machines)] | Powernets: [length(powernets)] | Deferred: [length(deferred_powernet_rebuilds)]"
/datum/controller/subsystem/machines/proc/process_defered_powernets(resumed = 0)
if(!resumed)
@@ -14,7 +14,7 @@ SUBSYSTEM_DEF(late_mapping)
GLOB.air_alarms = sortAtom(GLOB.air_alarms)
GLOB.apcs = sortAtom(GLOB.apcs)
for(var/obj/machinery/computer/shuttle/console in GLOB.machines)
for(var/obj/machinery/computer/shuttle/console in SSmachines.get_by_type(/obj/machinery/computer/shuttle))
if(console.find_destinations_in_late_mapping)
console.connect()