mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2026-08-27 13:46:40 +01:00
update nightshift (#6862)
title it now waits every 10 min and doesnt have any fancy priority/init order (it doesnt need that this is a generic subsystem) fixes `world.time - (world.time - SSticker.round_start_time)` makes it able to sleep() as well
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user