Files
Letter NandGitHub 37c6a7d1fc time, is it really that time (#7482)
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request
update time related procs & glob too (i was originally targeting that
lmao).
also **stop** using byondtime for sql stuff, we have `NOW()`!!
<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

## Why It's Good For The Game

<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->

## Changelog

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Please note that
maintainers freely reserve the right to remove and add tags should they
deem it appropriate. You can attempt to finagle the system all you want,
but it's best to shoot for clear communication right off the bat. -->

<!-- Both 🆑's are required for the changelog to work! You can put
your name to the right of the first 🆑 if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->
2026-01-13 22:06:30 -05:00

92 lines
3.3 KiB
Plaintext

SUBSYSTEM_DEF(nightshift)
name = "Night Shift"
wait = 5 MINUTES
/// Set from configuration - enabled nightshift flags.
var/nightshift_level = NONE
//! legacy below
var/nightshift_active = FALSE
var/nightshift_start_time = 19 HOURS + 30 MINUTES //7:30 PM, station time
var/nightshift_end_time = 7 HOURS + 30 MINUTES //7:30 AM, station time
var/nightshift_first_check = 5 MINUTES // Wait 5 minutes after roundstart to turn on nightshift
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))
can_fire = FALSE
return SS_INIT_SUCCESS
/datum/controller/subsystem/nightshift/fire(resumed = FALSE)
if(resumed)
update_nightshift(resumed = TRUE)
return
if(STATION_TIME_PASSED() < nightshift_first_check)
return
check_nightshift()
/datum/controller/subsystem/nightshift/proc/announce(message)
priority_announcement.Announce(
message,
new_title = "Automated Lighting System Announcement",
new_sound = 'sound/misc/notice2.ogg',
)
/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
//station_time_in_ds = deciseconds after midnight in station time
//nightshift_start_time = 702,000 deciseconds after midnight (7:30 PM)
//nightshift_end_time = 207,000 deciseconds after midnight (7:30 AM)
//if time is greater than start time (between 7:30pm and 11:59pm) OR less than end time (between midnight and 7:29am) it should turn on.
//If time rolls over to midnight, station_time will keep incrementing so there is no need for a special case.
var/time = station_time_in_ds
var/night_time = (time > nightshift_start_time) || (time < nightshift_end_time)
if(high_security_mode != emergency)
high_security_mode = emergency
if(night_time)
announcing = FALSE
if(!emergency)
announce("Restoring night lighting configuration to normal operation.")
else
announce("Disabling night lighting: Station is in a state of emergency.")
if(emergency)
night_time = FALSE
if(nightshift_active != night_time)
update_nightshift(night_time, announcing)
/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 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)
//TODO: redo below logic: as-is, it does not allow the nightshift subsystem to actually finish processing
//if(MC_TICK_CHECK && !forced) // subsystem will be in state SS_IDLE if forced by an admin
//return
SSlighting.resume_instant()