Refactor: refactor security levels (#21899)

* refactor: datumize security levels

* refactor: implement `SSsecurity_level` for handling security level related stuff

* feat: returns back old `delta_alarm` sound

* refactor: adjust existing code to use `SSsecurity_level`

* fix: remove redundunt new init order

* fix: fix type in var

* refactor: apply reviewer changes

* fix: replace `can_fire=FALSE` with `ss_flags = SS_NO_FIRE`, as subsystem will never fire

* fix: use `flags` instead of `ss_flags` for subsystem

Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com>

* fix: replace old security level interactions

* feat: implement `Recover` proc for `SSsecurity_level`

* refactor: add clearer doc for `security_level_set_timer_id`  propery of `SSsecurirt_level`

* refactor: swap `security_level` datum properties to make it clearer to read

* refactor: move initialization code from `New` to `Initialize` for `/obj/machinery/firealarm`

* fix: revert back `delta_alarm` annoing sound, use `delta_claxon` on change to delta security level

---------

Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com>
This commit is contained in:
Gaxeer
2023-10-14 22:46:49 +03:00
committed by GitHub
parent 6a2704a3ad
commit eda2102bdc
29 changed files with 450 additions and 321 deletions

View File

@@ -95,7 +95,7 @@
/obj/machinery/keycard_auth/ui_data()
var/list/data = list()
data["redAvailable"] = GLOB.security_level == SEC_LEVEL_RED ? FALSE : TRUE
data["redAvailable"] = SSsecurity_level.get_current_level_as_number() != SEC_LEVEL_RED
data["swiping"] = swiping
data["busy"] = busy
data["event"] = active && event_source && event_source.event ? event_source.event : event
@@ -172,7 +172,7 @@
SHOULD_NOT_SLEEP(TRUE) // trigger_armed_response_team sleeps, which can cause issues for procs that call trigger_event(). We want to avoid that
switch(event)
if("Red Alert")
INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(set_security_level), SEC_LEVEL_RED)
INVOKE_ASYNC(SSsecurity_level, TYPE_PROC_REF(/datum/controller/subsystem/security_level, set_level), SEC_LEVEL_RED)
if("Grant Emergency Maintenance Access")
make_maint_all_access()
if("Revoke Emergency Maintenance Access")

View File

@@ -0,0 +1,145 @@
/**
* Security levels
*
* These are used by the security level subsystem. Each one of these represents a security level that a player can set.
*
* Base type is abstract
*/
/datum/security_level
/// The name of this security level.
var/name = "Not set."
/// The numerical level of this security level, see defines for more information.
var/number_level = -1
/// The delay, after which the security level will be set
var/set_delay = 0
/// The sound that we will play when elevated to this security level
var/elevating_to_sound
/// The sound that we will play when lowered to this security level
var/lowering_to_sound
/// The AI announcement sound about code change, that will be played after main sound
var/ai_announcement_sound
/// Color of security level
var/color
/// The status display that will be posted to all status displays on security level set
var/status_display_mode = STATUS_DISPLAY_TRANSFER_SHUTTLE_TIME
/// The status display data that will be posted to all status displays on security level set
var/status_display_data = ""
/// Our announcement title when lowering to this level
var/lowering_to_announcement_title = "Not set."
/// Our announcement when lowering to this level
var/lowering_to_announcement_text = "Not set."
/// Our announcement title when elevating to this level
var/elevating_to_announcement_title = "Not set."
/// Our announcement when elevating to this level
var/elevating_to_announcement_text = "Not set."
/**
* Should contain actions that must be completed before actual security level set
*/
/datum/security_level/proc/pre_change()
return
/**
* GREEN
*
* No threats
*/
/datum/security_level/green
name = "green"
number_level = SEC_LEVEL_GREEN
ai_announcement_sound = 'sound/AI/green.ogg'
color = "limegreen"
lowering_to_announcement_title = "Attention! Security level lowered to Green."
lowering_to_announcement_text = "All threats to the station have passed. All weapons need to be holstered and privacy laws are once again fully enforced."
/**
* BLUE
*
* Caution advised
*/
/datum/security_level/blue
name = "blue"
number_level = SEC_LEVEL_BLUE
elevating_to_sound = 'sound/misc/notice1.ogg'
ai_announcement_sound = 'sound/AI/blue.ogg'
color = "dodgerblue"
lowering_to_announcement_title = "Attention! Security level lowered to Blue."
lowering_to_announcement_text = "The immediate threat has passed. Security may no longer have weapons drawn at all times, but may continue to have them visible. Random searches are still allowed."
elevating_to_announcement_title = "Attention! Security level elevated to Blue."
elevating_to_announcement_text = "The station has received reliable information about possible hostile activity on the station. Security staff may have weapons visible and random searches are permitted."
/**
* RED
*
* Hostile threats
*/
/datum/security_level/red
name = "red"
number_level = SEC_LEVEL_RED
elevating_to_sound = 'sound/misc/notice1.ogg'
ai_announcement_sound = 'sound/AI/red.ogg'
color = "red"
status_display_mode = STATUS_DISPLAY_ALERT
status_display_data = "redalert"
lowering_to_announcement_title = "Attention! Code Red!"
lowering_to_announcement_text = "The station's self-destruct mechanism has been deactivated, but there is still an immediate and serious threat to the station. Security may have weapons unholstered at all times. Random searches are allowed and advised."
elevating_to_announcement_title = "Attention! Code Red!"
elevating_to_announcement_text = "There is an immediate and serious threat to the station. Security may have weapons unholstered at all times. Random searches are allowed and advised."
/**
* Gamma
*
* Station major hostile threats
*/
/datum/security_level/gamma
name = "gamma"
number_level = SEC_LEVEL_GAMMA
lowering_to_sound = 'sound/effects/new_siren.ogg'
elevating_to_sound = 'sound/effects/new_siren.ogg'
ai_announcement_sound = 'sound/AI/gamma.ogg'
color = "gold"
status_display_mode = STATUS_DISPLAY_ALERT
status_display_data = "gammaalert"
lowering_to_announcement_title = "Attention! Gamma security level activated!"
lowering_to_announcement_text = "Central Command has ordered the Gamma security level on the station. Security is to have weapons equipped at all times, and all civilians are to immediately seek their nearest head for transportation to a secure location."
elevating_to_announcement_text = "Central Command has ordered the Gamma security level on the station. Security is to have weapons equipped at all times, and all civilians are to immediately seek their nearest head for transportation to a secure location."
elevating_to_announcement_title = "Attention! Gamma security level activated!"
/**
* Epsilon
*
* Station is not longer under the Central Command and to be destroyed by Death Squad (Or maybe not)
*/
/datum/security_level/epsilon
name = "epsilon"
number_level = SEC_LEVEL_EPSILON
set_delay = 15 SECONDS
lowering_to_sound = 'sound/effects/purge_siren.ogg'
elevating_to_sound = 'sound/effects/purge_siren.ogg'
ai_announcement_sound = 'sound/AI/epsilon.ogg'
color = "blueviolet"
status_display_mode = STATUS_DISPLAY_ALERT
status_display_data = "epsilonalert"
lowering_to_announcement_title = "Attention! Epsilon security level activated!"
lowering_to_announcement_text = "Central Command has ordered the Epsilon security level on the station. Consider all contracts terminated."
elevating_to_announcement_title = "Attention! Epsilon security level activated!"
elevating_to_announcement_text = "Central Command has ordered the Epsilon security level on the station. Consider all contracts terminated."
/datum/security_level/epsilon/pre_change()
sound_to_playing_players_on_station_level(S = sound('sound/effects/powerloss.ogg'))
/**
* DELTA
*
* Station self-destruiction mechanism has been engaged
*/
/datum/security_level/delta
name = "delta"
number_level = SEC_LEVEL_DELTA
elevating_to_sound = 'sound/effects/delta_klaxon.ogg'
ai_announcement_sound = 'sound/AI/delta.ogg'
color = "orangered"
status_display_mode = STATUS_DISPLAY_ALERT
status_display_data = "deltaalert"
elevating_to_announcement_title = "Attention! Delta security level reached!"
elevating_to_announcement_text = "The station's self-destruct mechanism has been engaged. All crew are instructed to obey all instructions given by heads of staff. Any violations of these orders can be punished by death. This is not a drill."

View File

@@ -1,225 +0,0 @@
GLOBAL_VAR_INIT(security_level, 0)
//0 = code green
//1 = code blue
//2 = code red
//3 = gamma
//4 = epsilon
//5 = code delta
//config.alert_desc_blue_downto
GLOBAL_DATUM_INIT(security_announcement, /datum/announcer, new(config_type = /datum/announcement_configuration/security))
/proc/set_security_level(level)
switch(level)
if("green")
level = SEC_LEVEL_GREEN
if("blue")
level = SEC_LEVEL_BLUE
if("red")
level = SEC_LEVEL_RED
if("gamma")
level = SEC_LEVEL_GAMMA
if("epsilon")
level = SEC_LEVEL_EPSILON
if("delta")
level = SEC_LEVEL_DELTA
//Will not be announced if you try to set to the same level as it already is
if(level >= SEC_LEVEL_GREEN && level <= SEC_LEVEL_DELTA && level != GLOB.security_level)
if(level >= SEC_LEVEL_RED && GLOB.security_level < SEC_LEVEL_RED)
// Mark down this time to prevent shuttle cheese
SSshuttle.emergency_sec_level_time = world.time
switch(level)
if(SEC_LEVEL_GREEN)
GLOB.security_announcement.Announce("All threats to the station have passed. All weapons need to be holstered and privacy laws are once again fully enforced.","Attention! Security level lowered to green.", new_sound2 = 'sound/AI/green.ogg')
GLOB.security_level = SEC_LEVEL_GREEN
unset_stationwide_emergency_lighting()
post_status(STATUS_DISPLAY_TRANSFER_SHUTTLE_TIME)
update_firealarms()
if(SEC_LEVEL_BLUE)
if(GLOB.security_level < SEC_LEVEL_BLUE)
GLOB.security_announcement.Announce("The station has received reliable information about possible hostile activity on the station. Security staff may have weapons visible and random searches are permitted.", "Attention! Security level elevated to blue.",
new_sound = 'sound/misc/notice1.ogg',
new_sound2 = 'sound/AI/blue.ogg')
else
GLOB.security_announcement.Announce("The immediate threat has passed. Security may no longer have weapons drawn at all times, but may continue to have them visible. Random searches are still allowed.", "Attention! Security level lowered to blue.", new_sound2 = 'sound/AI/blue.ogg')
GLOB.security_level = SEC_LEVEL_BLUE
post_status(STATUS_DISPLAY_TRANSFER_SHUTTLE_TIME)
unset_stationwide_emergency_lighting()
update_firealarms()
if(SEC_LEVEL_RED)
if(GLOB.security_level < SEC_LEVEL_RED)
GLOB.security_announcement.Announce("There is an immediate and serious threat to the station. Security may have weapons unholstered at all times. Random searches are allowed and advised.", "Attention! Code Red!",
new_sound = 'sound/misc/notice1.ogg',
new_sound2 = 'sound/AI/red.ogg')
else
GLOB.security_announcement.Announce("The station's self-destruct mechanism has been deactivated, but there is still an immediate and serious threat to the station. Security may have weapons unholstered at all times. Random searches are allowed and advised.", "Attention! Code Red!", new_sound2 = 'sound/AI/red.ogg')
unset_stationwide_emergency_lighting()
GLOB.security_level = SEC_LEVEL_RED
var/obj/machinery/door/airlock/highsecurity/red/R = locate(/obj/machinery/door/airlock/highsecurity/red) in GLOB.airlocks
if(R && is_station_level(R.z))
R.unlock(TRUE)
post_status(STATUS_DISPLAY_ALERT, "redalert")
update_firealarms()
if(SEC_LEVEL_GAMMA)
GLOB.security_announcement.Announce("Central Command has ordered the Gamma security level on the station. Security is to have weapons equipped at all times, and all civilians are to immediately seek their nearest head for transportation to a secure location.", "Attention! Gamma security level activated!", 'sound/effects/new_siren.ogg', new_sound2 = 'sound/AI/gamma.ogg')
GLOB.security_level = SEC_LEVEL_GAMMA
if(GLOB.security_level < SEC_LEVEL_RED)
for(var/obj/machinery/door/airlock/highsecurity/red/R in GLOB.airlocks)
if(is_station_level(R.z))
R.unlock(TRUE)
post_status(STATUS_DISPLAY_ALERT, "gammaalert")
update_firealarms()
if(SEC_LEVEL_EPSILON)
for(var/mob/M in GLOB.player_list)
var/turf/T = get_turf(M)
if(!M.client || !is_station_level(T.z))
continue
SEND_SOUND(M, sound('sound/effects/powerloss.ogg'))
set_stationwide_emergency_lighting()
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(epsilon_process)), 15 SECONDS)
SSblackbox.record_feedback("tally", "security_level_changes", 1, level)
return
if(SEC_LEVEL_DELTA)
var/temp_sound = GLOB.security_announcement.config.sound
GLOB.security_announcement.config.sound = null
GLOB.security_announcement.Announce("The station's self-destruct mechanism has been engaged. All crew are instructed to obey all instructions given by heads of staff. Any violations of these orders can be punished by death. This is not a drill.","Attention! Delta security level reached!",
new_sound = 'sound/effects/delta_klaxon.ogg',
new_sound2 = 'sound/AI/delta.ogg')
GLOB.security_announcement.config.sound = temp_sound
GLOB.security_level = SEC_LEVEL_DELTA
post_status(STATUS_DISPLAY_ALERT, "deltaalert")
update_firealarms()
set_stationwide_emergency_lighting()
SSblackbox.record_feedback("tally", "security_level_changes", 1, level)
return
SSnightshift.check_nightshift(TRUE)
SSblackbox.record_feedback("tally", "security_level_changes", 1, level)
else
return
/proc/get_security_level()
switch(GLOB.security_level)
if(SEC_LEVEL_GREEN)
return "green"
if(SEC_LEVEL_BLUE)
return "blue"
if(SEC_LEVEL_RED)
return "red"
if(SEC_LEVEL_GAMMA)
return "gamma"
if(SEC_LEVEL_EPSILON)
return "epsilon"
if(SEC_LEVEL_DELTA)
return "delta"
/proc/update_firealarms()
for(var/obj/machinery/firealarm/FA in GLOB.machines)
if(is_station_contact(FA.z))
FA.update_icon()
FA.update_fire_light()
/proc/num2seclevel(num)
switch(num)
if(SEC_LEVEL_GREEN)
return "green"
if(SEC_LEVEL_BLUE)
return "blue"
if(SEC_LEVEL_RED)
return "red"
if(SEC_LEVEL_GAMMA)
return "gamma"
if(SEC_LEVEL_EPSILON)
return "epsilon"
if(SEC_LEVEL_DELTA)
return "delta"
/proc/seclevel2num(seclevel)
switch( lowertext(seclevel) )
if("green")
return SEC_LEVEL_GREEN
if("blue")
return SEC_LEVEL_BLUE
if("red")
return SEC_LEVEL_RED
if("gamma")
return SEC_LEVEL_GAMMA
if("epsilon")
return SEC_LEVEL_EPSILON
if("delta")
return SEC_LEVEL_DELTA
/proc/get_security_level_colors()
switch(GLOB.security_level)
if(SEC_LEVEL_GREEN)
return "<font color='limegreen'>Green</font>"
if(SEC_LEVEL_BLUE)
return "<font color='dodgerblue'>Blue</font>"
if(SEC_LEVEL_RED)
return "<font color='red'>Red</font>"
if(SEC_LEVEL_GAMMA)
return "<font color='gold'>Gamma</font>"
if(SEC_LEVEL_EPSILON)
return "<font color='blueviolet'>Epsilon</font>"
if(SEC_LEVEL_DELTA)
return "<font color='orangered'>Delta</font>"
/proc/set_stationwide_emergency_lighting()
for(var/obj/machinery/power/apc/A in GLOB.apcs)
var/area/AR = get_area(A)
if(!is_station_level(A.z))
continue
A.emergency_lights = FALSE
AR.area_emergency_mode = TRUE
for(var/obj/machinery/light/L in A.apc_area)
if(L.status)
continue
if(GLOB.security_level == SEC_LEVEL_DELTA)
L.fire_mode = TRUE
L.on = FALSE
L.emergency_mode = TRUE
INVOKE_ASYNC(L, TYPE_PROC_REF(/obj/machinery/light, update), FALSE)
/proc/unset_stationwide_emergency_lighting()
for(var/area/A as anything in GLOB.all_areas)
if(!is_station_level(A.z))
continue
if(!A.area_emergency_mode)
continue
A.area_emergency_mode = FALSE
for(var/obj/machinery/light/L in A)
if(A.fire)
continue
if(L.status)
continue
L.fire_mode = FALSE
L.emergency_mode = FALSE
L.on = TRUE
INVOKE_ASYNC(L, TYPE_PROC_REF(/obj/machinery/light, update), FALSE)
/proc/epsilon_process()
GLOB.security_announcement.Announce("Central Command has ordered the Epsilon security level on the station. Consider all contracts terminated.", "Attention! Epsilon security level activated!", 'sound/effects/purge_siren.ogg')
GLOB.security_level = SEC_LEVEL_EPSILON
post_status(STATUS_DISPLAY_ALERT, "epsilonalert")
for(var/area/A as anything in GLOB.all_areas)
if(!is_station_level(A.z))
continue
for(var/obj/machinery/light/L in A)
if(L.status)
continue
L.fire_mode = TRUE
L.update()
update_firealarms()