diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 54874bc9e16b1..1155ea88bed97 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -130,6 +130,7 @@ #define INIT_ORDER_ATOMS 30 #define INIT_ORDER_LANGUAGE 25 #define INIT_ORDER_MACHINES 20 +#define INIT_ORDER_TURRETS 17 #define INIT_ORDER_SKILLS 15 #define INIT_ORDER_TIMER 1 #define INIT_ORDER_DEFAULT 0 diff --git a/code/controllers/subsystem/turrets.dm b/code/controllers/subsystem/turrets.dm new file mode 100644 index 0000000000000..634f6327e4588 --- /dev/null +++ b/code/controllers/subsystem/turrets.dm @@ -0,0 +1,41 @@ +SUBSYSTEM_DEF(turrets) + name = "Turrets" + wait = 5 + init_order = INIT_ORDER_MACHINES + flags = SS_KEEP_TIMING + runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME + var/list/processing = list() + var/list/currentrun = list() + +/datum/controller/subsystem/turrets/get_metrics() + . = ..() + var/list/cust = list() + cust["processing"] = length(processing) + .["custom"] = cust + +/datum/controller/subsystem/turrets/stat_entry(msg) + msg = "M:[length(processing)]]" + return ..() + + +/datum/controller/subsystem/turrets/fire(resumed = 0) + if (!resumed) + src.currentrun = processing.Copy() + + //cache for sanic speed (lists are references anyways) + var/list/currentrun = src.currentrun + + var/seconds = wait * 0.1 + while(currentrun.len) + var/obj/machinery/thing = currentrun[currentrun.len] + currentrun.len-- + if(QDELETED(thing) || thing.process(seconds) == PROCESS_KILL) + processing -= thing + if (!QDELETED(thing)) + thing.datum_flags &= ~DF_ISPROCESSING + if (MC_TICK_CHECK) + return + +/datum/controller/subsystem/turrets/Recover() + if (istype(SSturrets.processing)) + processing = SSmachines.processing diff --git a/code/game/machinery/porta_turret/portable_turret.dm b/code/game/machinery/porta_turret/portable_turret.dm index 6b0057a25eaf5..c3c39c72e34a0 100644 --- a/code/game/machinery/porta_turret/portable_turret.dm +++ b/code/game/machinery/porta_turret/portable_turret.dm @@ -41,6 +41,7 @@ DEFINE_BITFIELD(turret_flags, list( integrity_failure = 0.5 armor = list("melee" = 50, "bullet" = 30, "laser" = 30, "energy" = 30, "bomb" = 30, "bio" = 0, "rad" = 0, "fire" = 90, "acid" = 90) base_icon_state = "standard" + subsystem_type = /datum/controller/subsystem/turrets /// Scan range of the turret for locating targets var/scan_range = 7 /// For turrets inside other objects @@ -77,7 +78,7 @@ DEFINE_BITFIELD(turret_flags, list( var/has_cover = TRUE /// The cover that is covering this turret var/obj/machinery/porta_turret_cover/cover = null - /// Ticks until next shot (1.5 ?) + /// Ticks until next shot (1.5 ?) If this needs to go below 5, use SSFastProcess var/shot_delay = 15 /// Turret flags about who is turret allowed to shoot var/turret_flags = TURRET_FLAG_SHOOT_CRIMINALS | TURRET_FLAG_SHOOT_ANOMALOUS diff --git a/shiptest.dme b/shiptest.dme index 187540e66a26a..7515bfcece790 100644 --- a/shiptest.dme +++ b/shiptest.dme @@ -393,6 +393,7 @@ #include "code\controllers\subsystem\title.dm" #include "code\controllers\subsystem\traumas.dm" #include "code\controllers\subsystem\turf_fire.dm" +#include "code\controllers\subsystem\turrets.dm" #include "code\controllers\subsystem\verb_manager.dm" #include "code\controllers\subsystem\vis_overlays.dm" #include "code\controllers\subsystem\vote.dm"