Files
Yogstation/code/controllers/subsystem/machines.dm
cowbot92 af54f9e6f8 [Semi-Port] New Heretic Path: Knock (#20763)
* woo hoo

haha

* lore next

then we're done

* ok

lore done

* i didnt forget this time

hahaha

* fix lint?

maybe

* linter angy

maybe

* updated comment

time to go raid yippie

* typo

ha

* yes

forgot this

* ok

whatever

* Updates sprites

yay
2023-11-03 14:21:08 -05:00

85 lines
2.6 KiB
Plaintext

SUBSYSTEM_DEF(machines)
name = "Machines"
init_order = INIT_ORDER_MACHINES
flags = SS_KEEP_TIMING
wait = 2 SECONDS
var/list/processing = list()
var/list/currentrun = list()
var/list/powernets = list()
/// Assosciative list of all machines that exist.
VAR_PRIVATE/list/machines_by_type = list()
/datum/controller/subsystem/machines/Initialize()
makepowernets()
fire()
return SS_INIT_SUCCESS
/datum/controller/subsystem/machines/proc/makepowernets()
for(var/datum/powernet/PN in powernets)
qdel(PN)
powernets.Cut()
for(var/obj/structure/cable/PC in GLOB.cable_list)
if(!PC.powernet)
var/datum/powernet/NewPN = new(PC.loc.z)
NewPN.add_cable(PC)
propagate_network(PC,PC.powernet)
/datum/controller/subsystem/machines/stat_entry(msg)
msg = "M:[length(processing)]|PN:[length(powernets)]"
return ..()
/datum/controller/subsystem/machines/get_metrics()
. = ..()
.["machines"] = length(processing)
.["powernets"] = length(powernets)
/datum/controller/subsystem/machines/fire(resumed = 0)
if (!resumed)
for(var/datum/powernet/Powernet in powernets)
Powernet.reset() //reset the power state.
src.currentrun = processing.Copy()
//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)
if(thing.use_power)
thing.auto_use_power() //add back the power state
else
processing -= thing
if (!QDELETED(thing))
thing.datum_flags &= ~DF_ISPROCESSING
if (MC_TICK_CHECK)
return
/datum/controller/subsystem/machines/proc/setup_template_powernets(list/cables)
for(var/A in cables)
var/obj/structure/cable/PC = A
if(!PC.powernet)
var/datum/powernet/NewPN = new(PC.loc.z)
NewPN.add_cable(PC)
propagate_network(PC,PC.powernet)
/datum/controller/subsystem/machines/Recover()
if (istype(SSmachines.processing))
processing = SSmachines.processing
if (istype(SSmachines.powernets))
powernets = SSmachines.powernets
/// 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