diff --git a/code/__DEFINES/controllers/_subsystem-init.dm b/code/__DEFINES/controllers/_subsystem-init.dm index 12aaff4db93b..410f30e79b5e 100644 --- a/code/__DEFINES/controllers/_subsystem-init.dm +++ b/code/__DEFINES/controllers/_subsystem-init.dm @@ -88,5 +88,4 @@ #define INIT_ORDER_OVERLAY 200 #define INIT_ORDER_TITLESCREEN 150 -#define INIT_ORDER_NIGHTSHIFT 75 #define INIT_ORDER_CHAT -100 //! Should be last to ensure chat remains smooth during init. diff --git a/code/__DEFINES/controllers/_subsystem-priority.dm b/code/__DEFINES/controllers/_subsystem-priority.dm index cd006fa47cdc..297142ed0734 100644 --- a/code/__DEFINES/controllers/_subsystem-priority.dm +++ b/code/__DEFINES/controllers/_subsystem-priority.dm @@ -24,7 +24,6 @@ #define FIRE_PRIORITY_PING 5 #define FIRE_PRIORITY_SHUTTLES 5 #define FIRE_PRIORITY_PLANTS 5 -#define FIRE_PRIORITY_NIGHTSHIFT 6 #define FIRE_PRIORITY_VOTE 9 #define FIRE_PRIORITY_VIS 10 #define FIRE_PRIORITY_SERVER_MAINT 10 diff --git a/code/controllers/subsystem/nightshift.dm b/code/controllers/subsystem/nightshift.dm index f0fa4f7388b1..c8219453f1e0 100644 --- a/code/controllers/subsystem/nightshift.dm +++ b/code/controllers/subsystem/nightshift.dm @@ -1,10 +1,6 @@ SUBSYSTEM_DEF(nightshift) name = "Night Shift" - init_order = INIT_ORDER_NIGHTSHIFT - init_stage = INIT_STAGE_LATE - priority = FIRE_PRIORITY_NIGHTSHIFT - wait = 60 SECONDS - subsystem_flags = SS_NO_TICK_CHECK + wait = 10 MINUTES /// Set from configuration - enabled nightshift flags. var/nightshift_level = NONE @@ -16,9 +12,11 @@ SUBSYSTEM_DEF(nightshift) var/nightshift_end_time = 7 HOURS + 30 MINUTES //7:30 AM, station time var/nightshift_first_check = 30 SECONDS - var/overridden //Overridden by a C&C console. - var/high_security_mode = FALSE + var/list/currentrun + + /// Override by a C&C console + var/overridden /datum/controller/subsystem/nightshift/Initialize() if (!CONFIG_GET(flag/nightshifts_enabled)) @@ -26,7 +24,10 @@ SUBSYSTEM_DEF(nightshift) return SS_INIT_SUCCESS /datum/controller/subsystem/nightshift/fire(resumed = FALSE) - if(world.time - round_duration_in_ds < nightshift_first_check) + if(resumed) + update_nightshift(resumed = TRUE) + return + if(world.time - SSticker.round_start_time < nightshift_first_check) return check_nightshift() @@ -34,14 +35,19 @@ SUBSYSTEM_DEF(nightshift) var/announce_z if((LEGACY_MAP_DATUM).station_levels.len) announce_z = pick((LEGACY_MAP_DATUM).station_levels) - priority_announcement.Announce(message, new_title = "Automated Lighting System Announcement", new_sound = 'sound/misc/notice2.ogg', zlevel = announce_z) + priority_announcement.Announce( + message, + new_title = "Automated Lighting System Announcement", + new_sound = 'sound/misc/notice2.ogg', + zlevel = announce_z + ) /datum/controller/subsystem/nightshift/proc/check_nightshift(check_canfire=FALSE) //This is called from elsewhere, like setting the alert levels if(overridden || (check_canfire && !can_fire)) return var/emergency = GLOB.security_level > SEC_LEVEL_GREEN var/announcing = TRUE - var/time = station_time_in_ds + var/time = station_time() // more accurate since it counts for gametime offset var/night_time = (time < nightshift_end_time) || (time > nightshift_start_time) if(high_security_mode != emergency) high_security_mode = emergency @@ -56,19 +62,23 @@ SUBSYSTEM_DEF(nightshift) if(nightshift_active != night_time) update_nightshift(night_time, announcing) -/datum/controller/subsystem/nightshift/proc/update_nightshift(active, announce = TRUE) - nightshift_active = active - if(announce) - if(active) - announce("Good evening, crew. To reduce power consumption and stimulate the circadian rhythms of some species, all of the non-essential lights have been dimmed for the night.") - else - announce("Good morning, crew. As it is now day time, all of the non-essential lights have been restored to their former brightness.") +/datum/controller/subsystem/nightshift/proc/update_nightshift(active, announce = TRUE, resumed = FALSE, forced = FALSE) + if(!resumed) + currentrun = GLOB.apcs.Copy() + nightshift_active = active + if(announce) + if (active) + announce("Good evening, crew. To reduce power consumption and stimulate the circadian rhythms of some species, all of the non-essential lights have been dimmed for the night.") + else + announce("Good morning, crew. As it is now day time, all of the non-essential lights have been restored to their former brightness.") SSlighting.pause_instant() - for(var/obj/machinery/power/apc/apc in GLOB.apcs) - if(apc.z in (LEGACY_MAP_DATUM).station_levels) - apc.set_nightshift(active && (apc.area.nightshift_level & nightshift_level), TRUE) - CHECK_TICK + for(var/obj/machinery/power/apc/APC as anything in currentrun) + currentrun -= APC + if (APC.area && (APC.z in (LEGACY_MAP_DATUM).station_levels)) + APC.set_nightshift(nightshift_active && (APC.area.nightshift_level & nightshift_level), TRUE) + if(MC_TICK_CHECK && !forced) // subsystem will be in state SS_IDLE if forced by an admin + return SSlighting.resume_instant() diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index 69230f569620..745aaa67e5db 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -1433,10 +1433,12 @@ CREATE_WALL_MOUNTING_TYPES_SHIFTED(/obj/machinery/power/apc, 22) name = "[area.name] APC" update() -/obj/machinery/power/apc/proc/set_nightshift(on, var/automated) +/obj/machinery/power/apc/proc/set_nightshift(on, automated) set waitfor = FALSE if(automated && istype(area, /area/shuttle)) return + if(nightshift_lights == on) + return //no change nightshift_lights = on update_nightshift()