mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-05 22:43:46 +00:00
Redoes how alarms are handled, moves their behavior to datums (#60060)
* Adds in a set of datums to support sending, listening and storing alerts In contrast to the old system, we now store a list of send alerts on the listener, rather then the area itself. This makes clearing "our" alerts on destroy not a massive headache. In addition, we now use a direct ref to the area's cameras list and signals to prevent camera hard deletes. This, combined with the aformentioned ability to clear, virtually eliminates hard deletes sourced from alerts caused by strange senarios like the alert source moving its tile. * Converts areas to the system, of note is the fact that areas no longer store a bool that determins if an alert for power or atmos has been sent, that's instead handled by the alert sender datum. This means the sources list on alert listeners actually means something additionally, in order to prevent dumbassery with fire alarms since they're area based, fire alerts are sent by an alert handler on the area itself
This commit is contained in:
@@ -10,7 +10,20 @@
|
||||
tgui_id = "NtosStationAlertConsole"
|
||||
program_icon = "bell"
|
||||
var/has_alert = 0
|
||||
var/alarms = list("Fire" = list(), "Atmosphere" = list(), "Power" = list())
|
||||
///Listens for alarms, manages our listing of alarms
|
||||
var/datum/alarm_listener/listener
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/New()
|
||||
//We want to send an alarm if we're in one of the mining home areas
|
||||
//Or if we're on station. Otherwise, die.
|
||||
var/list/allowed_areas = GLOB.the_station_areas + typesof(/area/mine)
|
||||
listener = new(list(ALARM_ATMOS, ALARM_FIRE, ALARM_POWER), null, allowed_areas)
|
||||
RegisterSignal(listener, list(COMSIG_ALARM_TRIGGERED, COMSIG_ALARM_CLEARED), .proc/update_alarm_display)
|
||||
return ..()
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/Destroy()
|
||||
QDEL_NULL(listener)
|
||||
return ..()
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/process_tick()
|
||||
..()
|
||||
@@ -30,87 +43,19 @@
|
||||
var/list/data = get_header_data()
|
||||
|
||||
data["alarms"] = list()
|
||||
for(var/class in alarms)
|
||||
data["alarms"][class] = list()
|
||||
for(var/area in alarms[class])
|
||||
data["alarms"][class] += area
|
||||
var/list/alarms = listener.alarms
|
||||
for(var/alarm_type in alarms)
|
||||
data["alarms"][alarm_type] = list()
|
||||
for(var/area in alarms[alarm_type])
|
||||
data["alarms"][alarm_type] += area
|
||||
|
||||
return data
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/proc/triggerAlarm(class, area/home, cameras, obj/source)
|
||||
if(is_station_level(source.z))
|
||||
if(!(home.type in GLOB.the_station_areas))
|
||||
return
|
||||
else if(!is_mining_level(source.z) || istype(home, /area/ruin))
|
||||
return
|
||||
|
||||
var/list/our_sort = alarms[class]
|
||||
for(var/areaname in our_sort)
|
||||
if (areaname == home.name)
|
||||
var/list/alarm = our_sort[areaname]
|
||||
var/list/sources = alarm[3]
|
||||
if (!(source in sources))
|
||||
sources += source
|
||||
return TRUE
|
||||
|
||||
var/obj/machinery/camera/cam = null
|
||||
var/list/our_cams = null
|
||||
if(cameras && islist(cameras))
|
||||
our_cams = cameras
|
||||
if (our_cams.len == 1)
|
||||
cam = our_cams[1]
|
||||
else if(cameras && istype(cameras, /obj/machinery/camera))
|
||||
cam = cameras
|
||||
our_sort[home.name] = list(home, (cam ? cam : cameras), list(source))
|
||||
|
||||
update_alarm_display()
|
||||
return TRUE
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/proc/freeCamera(area/home, obj/machinery/camera/cam)
|
||||
for(var/class in alarms)
|
||||
var/our_area = alarms[class][home.name]
|
||||
if(!our_area)
|
||||
continue
|
||||
var/cams = our_area[2] //Get the cameras
|
||||
if(!cams)
|
||||
continue
|
||||
if(islist(cams))
|
||||
cams -= cam
|
||||
if(length(cams) == 1)
|
||||
our_area[2] = cams[1]
|
||||
else
|
||||
our_area[2] = null
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/proc/cancelAlarm(class, area/A, obj/origin)
|
||||
var/list/L = alarms[class]
|
||||
var/cleared = 0
|
||||
var/arealevelalarm = FALSE // set to TRUE for alarms that set/clear whole areas
|
||||
if (class=="Fire")
|
||||
arealevelalarm = TRUE
|
||||
for (var/I in L)
|
||||
if (I == A.name)
|
||||
if (!arealevelalarm) // the traditional behaviour
|
||||
var/list/alarm = L[I]
|
||||
var/list/srcs = alarm[3]
|
||||
if (origin in srcs)
|
||||
srcs -= origin
|
||||
if (srcs.len == 0)
|
||||
cleared = 1
|
||||
L -= I
|
||||
else
|
||||
L -= I // wipe the instances entirely
|
||||
cleared = 1
|
||||
|
||||
|
||||
update_alarm_display()
|
||||
return !cleared
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/proc/update_alarm_display()
|
||||
SIGNAL_HANDLER
|
||||
has_alert = FALSE
|
||||
for(var/cat in alarms)
|
||||
var/list/L = alarms[cat]
|
||||
if(L.len)
|
||||
has_alert = TRUE
|
||||
if(length(listener.alarms))
|
||||
has_alert = TRUE
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/run_program(mob/user)
|
||||
. = ..(user)
|
||||
@@ -118,4 +63,4 @@
|
||||
|
||||
/datum/computer_file/program/alarm_monitor/kill_program(forced = FALSE)
|
||||
GLOB.alarmdisplay -= src
|
||||
..()
|
||||
return ..()
|
||||
|
||||
Reference in New Issue
Block a user