From 9854050719043bc26660226d81d9822758a2eee3 Mon Sep 17 00:00:00 2001 From: LetterN <24603524+LetterN@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:25:14 +0800 Subject: [PATCH 1/3] update nightshift --- code/__DEFINES/controllers/_subsystems.dm | 2 - code/controllers/subsystem/nightshift.dm | 55 +++++++++++++---------- code/modules/power/apc.dm | 4 +- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/code/__DEFINES/controllers/_subsystems.dm b/code/__DEFINES/controllers/_subsystems.dm index 3a5f1b5360b2..15047ec5df34 100644 --- a/code/__DEFINES/controllers/_subsystems.dm +++ b/code/__DEFINES/controllers/_subsystems.dm @@ -144,7 +144,6 @@ DEFINE_BITFIELD(runlevels, list( #define INIT_ORDER_PERSISTENCE -3 #define INIT_ORDER_AMBIENT_OCCLUSION -5 #define INIT_ORDER_HOLOMAPS -5 -#define INIT_ORDER_NIGHTSHIFT -5 #define INIT_ORDER_ICON_SMOOTHING -6 #define INIT_ORDER_OVERLAY -7 #define INIT_ORDER_EVENTS -10 @@ -184,7 +183,6 @@ DEFINE_BITFIELD(runlevels, list( #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 7321979537bb..65b9bacbfddc 100644 --- a/code/controllers/subsystem/nightshift.dm +++ b/code/controllers/subsystem/nightshift.dm @@ -1,9 +1,6 @@ SUBSYSTEM_DEF(nightshift) name = "Night Shift" - init_order = INIT_ORDER_NIGHTSHIFT - 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 @@ -15,19 +12,22 @@ 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)) + if(!CONFIG_GET(flag/nightshifts_enabled)) can_fire = FALSE - //if(CONFIG_GET(flag/randomized_start_time_enabled)) - //GLOB.gametime_offset = rand(0, 23) HOURS return ..() /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() @@ -35,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 @@ -57,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 lights aboard the station 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 e42290cc3c60..7931e5ad573d 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -1435,10 +1435,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() From 1245ce10a8b70f14438591a418a1faf95a6a9c2f Mon Sep 17 00:00:00 2001 From: LetterN <24603524+LetterN@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:28:03 +0800 Subject: [PATCH 2/3] s --- code/controllers/subsystem/nightshift.dm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/controllers/subsystem/nightshift.dm b/code/controllers/subsystem/nightshift.dm index 65b9bacbfddc..bbf6f21a3a7e 100644 --- a/code/controllers/subsystem/nightshift.dm +++ b/code/controllers/subsystem/nightshift.dm @@ -19,7 +19,7 @@ SUBSYSTEM_DEF(nightshift) var/overridden /datum/controller/subsystem/nightshift/Initialize() - if(!CONFIG_GET(flag/nightshifts_enabled)) + if (!CONFIG_GET(flag/nightshifts_enabled)) can_fire = FALSE return ..() @@ -68,7 +68,7 @@ SUBSYSTEM_DEF(nightshift) 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 lights aboard the station have been dimmed for the night.") + 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.") From 7ad3b391b1d41b5921aaa571af43f6eb8d69b16f Mon Sep 17 00:00:00 2001 From: LetterN <24603524+LetterN@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:33:22 +0800 Subject: [PATCH 3/3] APC --- code/controllers/subsystem/nightshift.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/controllers/subsystem/nightshift.dm b/code/controllers/subsystem/nightshift.dm index bbf6f21a3a7e..7363dab429a3 100644 --- a/code/controllers/subsystem/nightshift.dm +++ b/code/controllers/subsystem/nightshift.dm @@ -77,7 +77,7 @@ SUBSYSTEM_DEF(nightshift) 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) + 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