Security level datums (#21051)

* Initial conversion

* Fixed cryopods

* It compiles, yay

* Removes cowbot's bad variables

* Small fixes

* Tweaked epsilon

* Fix build

* Switches to using defines

* Nuke old file, fix typo

* Add proper comment to epsilon
This commit is contained in:
adamsong
2024-02-26 20:13:25 -05:00
committed by GitHub
parent b36407fe44
commit cf3be5cb15
47 changed files with 295 additions and 304 deletions

View File

@@ -24,7 +24,7 @@ SUBSYSTEM_DEF(nightshift)
priority_announce(message, sound='sound/misc/notice2.ogg', sender_override="Automated Lighting System Announcement")
/datum/controller/subsystem/nightshift/proc/check_nightshift()
var/emergency = GLOB.security_level >= SEC_LEVEL_RED
var/emergency = SSsecurity_level.current_security_level.disable_night_mode
var/announcing = TRUE
var/time = station_time()
var/night_time = (time < nightshift_end_time) || (time > nightshift_start_time)

View File

@@ -0,0 +1,94 @@
SUBSYSTEM_DEF(security_level)
name = "Security Level"
can_fire = FALSE // We will control when we fire in this subsystem
init_order = INIT_ORDER_SECURITY_LEVEL
/// Currently set security level
var/datum/security_level/current_security_level
/// A list of initialised security level datums.
var/list/available_levels = list()
/datum/controller/subsystem/security_level/Initialize()
for(var/iterating_security_level_type in subtypesof(/datum/security_level))
var/datum/security_level/new_security_level = new iterating_security_level_type
available_levels[new_security_level.name] = new_security_level
current_security_level = available_levels[number_level_to_text(SEC_LEVEL_GREEN)]
return SS_INIT_SUCCESS
/datum/controller/subsystem/security_level/fire(resumed)
if(!current_security_level.looping_sound) // No sound? No play.
can_fire = FALSE
return
sound_to_playing_players(current_security_level.looping_sound)
/**
* Sets a new security level as our current level
*
* This is how everything should change the security level.
*
* Arguments:
* * new_level - The new security level that will become our current level
*/
/datum/controller/subsystem/security_level/proc/set_level(new_level)
new_level = istext(new_level) ? new_level : number_level_to_text(new_level)
if(new_level == current_security_level.name) // If we are already at the desired level, do nothing
return
var/datum/security_level/selected_level = available_levels[new_level]
if(!selected_level)
CRASH("set_level was called with an invalid security level([new_level])")
if(SSnightshift.can_fire && (selected_level.disable_night_mode || current_security_level.disable_night_mode))
SSnightshift.next_fire = world.time + 7 SECONDS // Fire nightshift after the security level announcement is complete
level_announce(selected_level, current_security_level.number_level) // We want to announce BEFORE updating to the new level
selected_level.on_activate(current_security_level)
SSsecurity_level.current_security_level = selected_level
if(selected_level.looping_sound)
wait = selected_level.looping_sound_interval
can_fire = TRUE
else
can_fire = FALSE
if(SSshuttle.emergency.mode == SHUTTLE_CALL || SSshuttle.emergency.mode == SHUTTLE_RECALL) // By god this is absolutely shit
SSshuttle.emergency.alert_coeff_change(selected_level.shuttle_call_time_mod)
SEND_SIGNAL(src, COMSIG_SECURITY_LEVEL_CHANGED, selected_level)
SSblackbox.record_feedback("tally", "security_level_changes", 1, selected_level.name)
/**
* Returns the current security level as a number
*/
/datum/controller/subsystem/security_level/proc/get_current_level_as_number()
return ((!initialized || !current_security_level) ? SEC_LEVEL_GREEN : current_security_level.number_level) //Send the default security level in case the subsystem hasn't finished initializing yet
/**
* Returns the current security level as text
*/
/datum/controller/subsystem/security_level/proc/get_current_level_as_text()
return ((!initialized || !current_security_level) ? "green" : current_security_level.name)
/**
* Converts a text security level to a number
*
* Arguments:
* * level - The text security level to convert
*/
/datum/controller/subsystem/security_level/proc/text_level_to_number(text_level)
var/datum/security_level/selected_level = available_levels[text_level]
return selected_level?.number_level
/**
* Converts a number security level to a text
*
* Arguments:
* * level - The number security level to convert
*/
/datum/controller/subsystem/security_level/proc/number_level_to_text(number_level)
for(var/iterating_level_text in available_levels)
var/datum/security_level/iterating_security_level = available_levels[iterating_level_text]
if(iterating_security_level.number_level == number_level)
return iterating_security_level.name

View File

@@ -334,7 +334,7 @@ SUBSYSTEM_DEF(shuttle)
call_reason = trim(html_encode(call_reason))
if(length(call_reason) < CALL_SHUTTLE_REASON_LENGTH && seclevel2num(get_security_level()) > SEC_LEVEL_GREEN)
if(length(call_reason) < CALL_SHUTTLE_REASON_LENGTH && SSsecurity_level.current_security_level.require_call_reason)
to_chat(user, "You must provide a reason.")
return
@@ -396,7 +396,7 @@ SUBSYSTEM_DEF(shuttle)
/datum/controller/subsystem/shuttle/proc/canRecall()
if(!emergency || emergency.mode != SHUTTLE_CALL || admin_emergency_no_recall || emergency_no_recall)
return
var/security_num = seclevel2num(get_security_level())
var/security_num = SSsecurity_level.get_current_level_as_number()
switch(security_num)
if(SEC_LEVEL_GREEN)
if(emergency.timeLeft(1) < emergency_call_time)

View File

@@ -145,15 +145,6 @@ SUBSYSTEM_DEF(ticker)
return SS_INIT_SUCCESS
/datum/controller/subsystem/ticker/fire()
if(seclevel2num(get_security_level()) < SEC_LEVEL_GAMMA && !GLOB.cryopods_enabled)
GLOB.cryopods_enabled = TRUE
for(var/obj/machinery/cryopod/pod as anything in GLOB.cryopods)
pod.PowerOn()
else if(seclevel2num(get_security_level()) >= SEC_LEVEL_GAMMA && GLOB.cryopods_enabled)
GLOB.cryopods_enabled = FALSE
for(var/obj/machinery/cryopod/pod as anything in GLOB.cryopods)
pod.PowerOff()
switch(current_state)
if(GAME_STATE_STARTUP)
if(Master.initializations_finished_with_no_players_logged_in)