Files
Alexis 21b4095dfd [MDB IGNORE] [IDB IGNORE] Upstream Sync - 04/17/2026 (#5453)
Upstream 04/17/2026

fixes https://github.com/Bubberstation/Bubberstation/issues/5549

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com>
Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com>
Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com>
Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com>
Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com>
Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com>
Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com>
Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com>
Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com>
Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com>
Co-authored-by: loganuk <fakeemail123@aol.com>
Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com>
Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com>
Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com>
Co-authored-by: Lucy <lucy@absolucy.moe>
Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com>
Co-authored-by: Isratosh <Isratosh@hotmail.com>
Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com>
Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com>
Co-authored-by: Alexander V. <volas@ya.ru>
Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com>
Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
Co-authored-by: Cameron Lennox <killer65311@gmail.com>
Co-authored-by: Tim <timothymtorres@gmail.com>
Co-authored-by: Iamgoofball <iamgoofball@gmail.com>
Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com>
Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com>
Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com>
Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com>
Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com>
Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com>
Co-authored-by: Josh <josh.adam.powell@gmail.com>
Co-authored-by: Josh Powell <josh.powell@softwire.com>
Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com>
Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com>
Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com>
Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
2026-05-16 00:56:00 +02:00

188 lines
6.4 KiB
Plaintext

SUBSYSTEM_DEF(machines)
name = "Machines"
dependencies = list(
/datum/controller/subsystem/atoms,
)
ss_flags = SS_KEEP_TIMING
wait = 2 SECONDS
/// Assosciative 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/processing_early = list()
var/list/processing_late = list()
var/list/processing_apcs = list()
var/list/currentrun = list()
var/current_part = SSMACHINES_MACHINES_EARLY
var/list/apc_steps = list(
SSMACHINES_APCS_EARLY,
SSMACHINES_APCS_ENVIRONMENT,
SSMACHINES_APCS_LIGHTS,
SSMACHINES_APCS_EQUIPMENT,
SSMACHINES_APCS_LATE
)
///List of all powernets on the server.
var/list/datum/powernet/powernets = list()
/datum/controller/subsystem/machines/Initialize()
makepowernets()
fire()
return SS_INIT_SUCCESS
/// 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_machines_by_type_and_subtypes(obj/machinery/machine_type)
if(!ispath(machine_type))
machine_type = machine_type.type
if(!ispath(machine_type, /obj/machinery))
CRASH("called get_machines_by_type_and_subtypes with a non-machine type [machine_type]")
var/list/machines = list()
for(var/next_type in typesof(machine_type))
var/list/found_machines = machines_by_type[next_type]
if(found_machines)
machines += found_machines
return machines
/// Gets a list of all machines that are the exact passed type.
/datum/controller/subsystem/machines/proc/get_machines_by_type(obj/machinery/machine_type)
if(!ispath(machine_type))
machine_type = machine_type.type
if(!ispath(machine_type, /obj/machinery))
CRASH("called get_machines_by_type with a non-machine type [machine_type]")
var/list/machines = machines_by_type[machine_type]
return machines?.Copy() || list()
/datum/controller/subsystem/machines/proc/get_all_machines()
return all_machines.Copy()
/datum/controller/subsystem/machines/proc/makepowernets()
for(var/datum/powernet/power_network as anything in powernets)
qdel(power_network)
powernets.Cut()
for(var/obj/structure/cable/power_cable as anything in GLOB.cable_list)
if(!power_cable.powernet)
var/datum/powernet/new_powernet = new()
new_powernet.add_cable(power_cable)
propagate_network(power_cable, power_cable.powernet)
/datum/controller/subsystem/machines/stat_entry(msg)
msg = "\n M:[length(all_machines)]|MT:[length(machines_by_type)]|PM:[length(processing)]|PN:[length(powernets)]"
return ..()
/datum/controller/subsystem/machines/fire(resumed = FALSE)
if (!resumed)
for(var/datum/powernet/powernet as anything in powernets)
powernet.reset() //reset the power state.
current_part = SSMACHINES_MACHINES_EARLY
src.currentrun = processing_early.Copy()
//Processing machines that get the priority power draw
if(current_part == SSMACHINES_MACHINES_EARLY)
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/obj/machinery/thing = currentrun[currentrun.len]
currentrun.len--
if(QDELETED(thing) || thing.process_early(wait * 0.1) == PROCESS_KILL)
processing_early -= thing
thing.datum_flags &= ~DF_ISPROCESSING
if (MC_TICK_CHECK)
return
current_part = apc_steps[1]
src.currentrun = processing_apcs.Copy()
//Processing APCs
while(current_part in apc_steps)
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/obj/machinery/power/apc/apc = currentrun[currentrun.len]
currentrun.len--
if(QDELETED(apc))
processing_apcs -= apc
apc.datum_flags &= ~DF_ISPROCESSING
switch(current_part)
if(SSMACHINES_APCS_EARLY)
apc.early_process(wait * 0.1)
if(SSMACHINES_APCS_LATE)
apc.charge_channel(null, wait * 0.1)
apc.late_process(wait * 0.1)
else
apc.charge_channel(current_part, wait * 0.1)
if(MC_TICK_CHECK)
return
var/next_index = apc_steps.Find(current_part) + 1
if (next_index > apc_steps.len)
current_part = SSMACHINES_MACHINES
src.currentrun = processing.Copy()
break
current_part = apc_steps[next_index]
src.currentrun = processing_apcs.Copy()
//Processing all machines
if(current_part == SSMACHINES_MACHINES)
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/obj/machinery/thing = currentrun[currentrun.len]
currentrun.len--
if(QDELETED(thing) || thing.process(wait * 0.1) == PROCESS_KILL)
processing -= thing
thing.datum_flags &= ~DF_ISPROCESSING
if (MC_TICK_CHECK)
return
current_part = SSMACHINES_MACHINES_LATE
src.currentrun = processing_late.Copy()
//Processing machines that record the power usage statistics
if(current_part == SSMACHINES_MACHINES_LATE)
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/obj/machinery/thing = currentrun[currentrun.len]
currentrun.len--
if(QDELETED(thing) || thing.process_late(wait * 0.1) == PROCESS_KILL)
processing_late -= thing
thing.datum_flags &= ~DF_ISPROCESSING
if (MC_TICK_CHECK)
return
/datum/controller/subsystem/machines/proc/setup_template_powernets(list/cables)
var/obj/structure/cable/PC
for(var/A in 1 to cables.len)
PC = cables[A]
if(!PC.powernet)
var/datum/powernet/NewPN = new()
NewPN.add_cable(PC)
propagate_network(PC,PC.powernet)
/datum/controller/subsystem/machines/Recover()
if(islist(SSmachines.processing))
processing = SSmachines.processing
if(islist(SSmachines.powernets))
powernets = SSmachines.powernets
if(islist(SSmachines.all_machines))
all_machines = SSmachines.all_machines
if(islist(SSmachines.machines_by_type))
machines_by_type = SSmachines.machines_by_type