diff --git a/code/__defines/subsystems.dm b/code/__defines/subsystems.dm index e4a3c243e2..f300ba14fd 100644 --- a/code/__defines/subsystems.dm +++ b/code/__defines/subsystems.dm @@ -26,5 +26,6 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G #define INIT_ORDER_DECALS 16 #define INIT_ORDER_ATOMS 15 #define INIT_ORDER_MACHINES 10 +#define INIT_ORDER_SHUTTLES 3 #define INIT_ORDER_LIGHTING 0 #define INIT_ORDER_AIR -1 diff --git a/code/controllers/Processes/Shuttle.dm b/code/controllers/Processes/Shuttle.dm deleted file mode 100644 index a10586d76d..0000000000 --- a/code/controllers/Processes/Shuttle.dm +++ /dev/null @@ -1,9 +0,0 @@ -/datum/controller/process/Shuttle/setup() - name = "shuttle controller" - schedule_interval = 20 // every 2 seconds - - if(!shuttle_controller) - shuttle_controller = new - -/datum/controller/process/Shuttle/doWork() - shuttle_controller.process() diff --git a/code/controllers/shuttle_controller.dm b/code/controllers/shuttle_controller.dm deleted file mode 100644 index f68957ddb5..0000000000 --- a/code/controllers/shuttle_controller.dm +++ /dev/null @@ -1,39 +0,0 @@ - -var/global/datum/shuttle_controller/shuttle_controller - - -/datum/shuttle_controller - var/list/shuttles //maps shuttle tags to shuttle datums, so that they can be looked up. - var/list/process_shuttles //simple list of shuttles, for processing - -/datum/shuttle_controller/proc/process() - //process ferry shuttles - for (var/datum/shuttle/shuttle in process_shuttles) - if(istype(shuttle, /datum/shuttle/ferry)) - var/datum/shuttle/ferry/F = shuttle - if(F.process_state || F.always_process) - F.process() - else - shuttle.process() - - -//This is called by gameticker after all the machines and radio frequencies have been properly initialized -/datum/shuttle_controller/proc/setup_shuttle_docks() -// for(var/shuttle_tag in shuttles) -// var/datum/shuttle/shuttle = shuttles[shuttle_tag] - for(var/shuttle_type in subtypesof(/datum/shuttle)) - var/datum/shuttle/shuttle = shuttle_type - if(initial(shuttle.category) == shuttle_type) - continue - shuttle = new shuttle() - shuttle.init_docking_controllers() - shuttle.dock() //makes all shuttles docked to something at round start go into the docked state - - for(var/obj/machinery/embedded_controller/C in machines) - if(istype(C.program, /datum/computer/file/embedded_program/docking)) - C.program.tag = null //clear the tags, 'cause we don't need 'em anymore - -/datum/shuttle_controller/New() - shuttles = list() - process_shuttles = list() - diff --git a/code/controllers/subsystems/shuttles.dm b/code/controllers/subsystems/shuttles.dm new file mode 100644 index 0000000000..2037857dce --- /dev/null +++ b/code/controllers/subsystems/shuttles.dm @@ -0,0 +1,68 @@ +// +// SSshuttles subsystem - Handles initialization and processing of shuttles. +// + +// This global variable exists for legacy support so we don't have to rename every shuttle_controller to SSshuttles yet. +var/global/datum/controller/subsystem/shuttles/shuttle_controller + +SUBSYSTEM_DEF(shuttles) + name = "Shuttles" + wait = 2 SECONDS + priority = 5 + init_order = INIT_ORDER_SHUTTLES + flags = SS_KEEP_TIMING|SS_NO_TICK_CHECK + runlevels = RUNLEVEL_GAME|RUNLEVEL_POSTGAME + + var/list/shuttles = list() // Maps shuttle tags to shuttle datums, so that they can be looked up. + var/list/process_shuttles = list() // Simple list of shuttles, for processing + var/list/current_run = list() // Shuttles remaining to process this fire() tick + +/datum/controller/subsystem/shuttles/Initialize(timeofday) + global.shuttle_controller = src + setup_shuttle_docks() + return ..() + +/datum/controller/subsystem/shuttles/fire(resumed = 0) + do_process_shuttles(resumed) + +/datum/controller/subsystem/shuttles/stat_entry() + var/msg = list() + msg += "AS:[shuttles.len]|" + msg += "PS:[process_shuttles.len]|" + ..(jointext(msg, null)) + +/datum/controller/subsystem/shuttles/proc/do_process_shuttles(resumed = 0) + if (!resumed) + src.current_run = process_shuttles.Copy() + + var/list/current_run = src.current_run // Cache for sanic speed + while(current_run.len) + var/datum/shuttle/S = current_run[current_run.len] + current_run.len-- + if(istype(S) && !QDELETED(S)) + if(istype(S, /datum/shuttle/ferry)) // Ferry shuttles get special treatment + var/datum/shuttle/ferry/F = S + if(F.process_state || F.always_process) + F.process() + else + S.process() + else + process_shuttles -= S + if(MC_TICK_CHECK) + return + +// This should be called after all the machines and radio frequencies have been properly initialized +/datum/controller/subsystem/shuttles/proc/setup_shuttle_docks() + // Find all declared shuttle datums and initailize them. + for(var/shuttle_type in subtypesof(/datum/shuttle)) + var/datum/shuttle/shuttle = shuttle_type + if(initial(shuttle.category) == shuttle_type) + continue + shuttle = new shuttle() + shuttle.init_docking_controllers() + shuttle.dock() //makes all shuttles docked to something at round start go into the docked state + CHECK_TICK + + for(var/obj/machinery/embedded_controller/C in machines) + if(istype(C.program, /datum/computer/file/embedded_program/docking)) + C.program.tag = null //clear the tags, 'cause we don't need 'em anymore diff --git a/code/game/gamemodes/gameticker.dm b/code/game/gamemodes/gameticker.dm index 85ae732989..15113de8ab 100644 --- a/code/game/gamemodes/gameticker.dm +++ b/code/game/gamemodes/gameticker.dm @@ -132,8 +132,6 @@ var/global/datum/controller/gameticker/ticker callHook("roundstart") - shuttle_controller.setup_shuttle_docks() - // TODO - Leshana - Dear God Fix This. Fix all of this. Not just this line, this entire proc. This entire file! spawn(0)//Forking here so we dont have to wait for this to finish mode.post_setup() diff --git a/code/modules/shuttles/shuttle.dm b/code/modules/shuttles/shuttle.dm index 56fc64c016..374f7b38e5 100644 --- a/code/modules/shuttles/shuttle.dm +++ b/code/modules/shuttles/shuttle.dm @@ -1,5 +1,5 @@ -//These lists are populated in /datum/shuttle_controller/New() -//Shuttle controller is instantiated in master_controller.dm. +//These lists are populated in /datum/controller/subsystem/shuttles/proc/setup_shuttle_docks() +//Shuttle subsystem is instantiated in shuttles.dm. //shuttle moving state defines are in setup.dm diff --git a/polaris.dme b/polaris.dme index 0bd64f42a9..2bee39be99 100644 --- a/polaris.dme +++ b/polaris.dme @@ -147,7 +147,6 @@ #include "code\controllers\hooks.dm" #include "code\controllers\master.dm" #include "code\controllers\master_controller.dm" -#include "code\controllers\shuttle_controller.dm" #include "code\controllers\subsystem.dm" #include "code\controllers\verbs.dm" #include "code\controllers\voting.dm" @@ -164,7 +163,6 @@ #include "code\controllers\Processes\planet.dm" #include "code\controllers\Processes\radiation.dm" #include "code\controllers\Processes\scheduler.dm" -#include "code\controllers\Processes\Shuttle.dm" #include "code\controllers\Processes\sun.dm" #include "code\controllers\Processes\supply.dm" #include "code\controllers\Processes\ticker.dm" @@ -180,6 +178,7 @@ #include "code\controllers\subsystems\lighting.dm" #include "code\controllers\subsystems\machines.dm" #include "code\controllers\subsystems\orbits.dm" +#include "code\controllers\subsystems\shuttles.dm" #include "code\datums\ai_law_sets.dm" #include "code\datums\ai_laws.dm" #include "code\datums\beam.dm"