Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update nightshift #6862

Merged
merged 4 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/__DEFINES/controllers/_subsystem-init.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 0 additions & 1 deletion code/__DEFINES/controllers/_subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 31 additions & 21 deletions code/controllers/subsystem/nightshift.dm
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,32 +12,42 @@ 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))
can_fire = FALSE
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()

/datum/controller/subsystem/nightshift/proc/announce(message)
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
Expand All @@ -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()
4 changes: 3 additions & 1 deletion code/modules/power/apc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading