Alarm centralization completion

Fire alarms now handled centrally.
This commit is contained in:
PsiOmega
2015-02-23 13:19:23 +01:00
parent 93b049e7a6
commit a2cd104cc9
10 changed files with 96 additions and 78 deletions

View File

@@ -110,7 +110,10 @@ var/list/ghostteleportlocs = list()
power_environ = 0 power_environ = 0
ambience = list('sound/ambience/ambispace.ogg','sound/music/title2.ogg','sound/music/space.ogg','sound/music/main.ogg','sound/music/traitor.ogg') ambience = list('sound/ambience/ambispace.ogg','sound/music/title2.ogg','sound/music/space.ogg','sound/music/main.ogg','sound/music/traitor.ogg')
/area/space/firealert() /area/space/fire_alert()
return
/area/space/fire_reset()
return return
/area/space/readyalert() /area/space/readyalert()

View File

@@ -87,9 +87,9 @@
if(!src.master.air_doors_activated) if(!src.master.air_doors_activated)
src.master.air_doors_activated = 1 src.master.air_doors_activated = 1
for(var/obj/machinery/door/firedoor/E in src.master.all_doors) for(var/obj/machinery/door/firedoor/E in src.master.all_doors)
if(!E:blocked) if(!E.blocked)
if(E.operating) if(E.operating)
E:nextstate = CLOSED E.nextstate = CLOSED
else if(!E.density) else if(!E.density)
spawn(0) spawn(0)
E.close() E.close()
@@ -98,21 +98,21 @@
if(src.master.air_doors_activated) if(src.master.air_doors_activated)
src.master.air_doors_activated = 0 src.master.air_doors_activated = 0
for(var/obj/machinery/door/firedoor/E in src.master.all_doors) for(var/obj/machinery/door/firedoor/E in src.master.all_doors)
if(!E:blocked) if(!E.blocked)
if(E.operating) if(E.operating)
E:nextstate = OPEN E.nextstate = OPEN
else if(E.density) else if(E.density)
spawn(0) spawn(0)
E.open() E.open()
/area/proc/firealert() /area/proc/fire_alert()
if(name == "Space") //no fire alarms in space if(!fire)
return
if( !fire )
fire = 1
master.fire = 1 //used for firedoor checks master.fire = 1 //used for firedoor checks
updateicon() master.updateicon()
for(var/area/A in related)
A.fire = 1
A.updateicon()
mouse_opacity = 0 mouse_opacity = 0
for(var/obj/machinery/door/firedoor/D in all_doors) for(var/obj/machinery/door/firedoor/D in all_doors)
if(!D.blocked) if(!D.blocked)
@@ -122,12 +122,14 @@
spawn() spawn()
D.close() D.close()
/area/proc/firereset() /area/proc/fire_reset()
if (fire) if (fire)
fire = 0
master.fire = 0 //used for firedoor checks master.fire = 0 //used for firedoor checks
master.updateicon()
for(var/area/A in related)
A.fire = 0
A.updateicon()
mouse_opacity = 0 mouse_opacity = 0
updateicon()
for(var/obj/machinery/door/firedoor/D in all_doors) for(var/obj/machinery/door/firedoor/D in all_doors)
if(!D.blocked) if(!D.blocked)
if(D.operating) if(D.operating)
@@ -135,13 +137,6 @@
else if(D.density) else if(D.density)
spawn(0) spawn(0)
D.open() D.open()
/*for(var/area/RA in related)
for (var/obj/machinery/camera/C in RA)
C.network.Remove("Fire Alarms")
for (var/mob/living/silicon/ai/aiPlayer in player_list)
aiPlayer.cancelAlarm("Fire", src, src)
for (var/obj/machinery/computer/station_alert/a in machines)
a.cancelAlarm("Fire", src, src)*/
/area/proc/readyalert() /area/proc/readyalert()
if(!eject) if(!eject)

View File

@@ -117,11 +117,6 @@
first_run() first_run()
/obj/machinery/alarm/Del()
//If there's an active alarm, clear it after minute so that alarms don't keep going forver
delayed_reset()
..()
//needed to cancel the alarm after it is deleted //needed to cancel the alarm after it is deleted
/obj/machinery/alarm/proc/delayed_reset() /obj/machinery/alarm/proc/delayed_reset()
var/area/A = alarm_area var/area/A = alarm_area
@@ -949,7 +944,6 @@ FIRE ALARM
var/buildstage = 2 // 2 = complete, 1 = no wires, 0 = circuit gone var/buildstage = 2 // 2 = complete, 1 = no wires, 0 = circuit gone
/obj/machinery/firealarm/update_icon() /obj/machinery/firealarm/update_icon()
if(wiresexposed) if(wiresexposed)
switch(buildstage) switch(buildstage)
if(2) if(2)
@@ -983,7 +977,8 @@ FIRE ALARM
return src.alarm() return src.alarm()
/obj/machinery/firealarm/emp_act(severity) /obj/machinery/firealarm/emp_act(severity)
if(prob(50/severity)) alarm() if(prob(50/severity))
alarm(rand(30/severity, 60/severity))
..() ..()
/obj/machinery/firealarm/attackby(obj/item/W as obj, mob/user as mob) /obj/machinery/firealarm/attackby(obj/item/W as obj, mob/user as mob)
@@ -1082,6 +1077,7 @@ FIRE ALARM
var/d2 var/d2
if (istype(user, /mob/living/carbon/human) || istype(user, /mob/living/silicon)) if (istype(user, /mob/living/carbon/human) || istype(user, /mob/living/silicon))
A = A.loc A = A.loc
A = A.master
if (A.fire) if (A.fire)
d1 = text("<A href='?src=\ref[];reset=1'>Reset - Lockdown</A>", src) d1 = text("<A href='?src=\ref[];reset=1'>Reset - Lockdown</A>", src)
@@ -1147,26 +1143,26 @@ FIRE ALARM
/obj/machinery/firealarm/proc/reset() /obj/machinery/firealarm/proc/reset()
if (!( src.working )) if (!( src.working ))
return return
var/area/A = src.loc var/area/area = get_area(src)
A = A.loc for(var/area/A in area.related)
if (!( istype(A, /area) )) for(var/obj/machinery/firealarm/FA in A)
return fire_alarm.clearAlarm(loc, FA)
A.firereset()
update_icon() update_icon()
return return
/obj/machinery/firealarm/proc/alarm() /obj/machinery/firealarm/proc/alarm(var/duration = 0)
if (!( src.working )) if (!( src.working))
return return
var/area/A = src.loc var/area/area = get_area(src)
A = A.loc for(var/area/A in area.related)
if (!( istype(A, /area) )) for(var/obj/machinery/firealarm/FA in A)
return fire_alarm.triggerAlarm(loc, FA, duration)
A.firealert()
update_icon() update_icon()
//playsound(src.loc, 'sound/ambience/signal.ogg', 75, 0) //playsound(src.loc, 'sound/ambience/signal.ogg', 75, 0)
return return
/obj/machinery/firealarm/New(loc, dir, building) /obj/machinery/firealarm/New(loc, dir, building)
..() ..()
@@ -1182,20 +1178,6 @@ FIRE ALARM
pixel_x = (dir & 3)? 0 : (dir == 4 ? -24 : 24) pixel_x = (dir & 3)? 0 : (dir == 4 ? -24 : 24)
pixel_y = (dir & 3)? (dir ==1 ? -24 : 24) : 0 pixel_y = (dir & 3)? (dir ==1 ? -24 : 24) : 0
/obj/machinery/firealarm/Del()
//so fire alarms don't keep going forever
delayed_reset()
..()
//needed to cancel the alarm after it is deleted
/obj/machinery/firealarm/proc/delayed_reset()
var/area/A = get_area(src)
if (!A) return
src = null
spawn(600)
A.firereset()
/obj/machinery/firealarm/initialize() /obj/machinery/firealarm/initialize()
if(z in config.contact_levels) if(z in config.contact_levels)
if(security_level) if(security_level)

View File

@@ -4,6 +4,7 @@
var/source = null // The source trigger var/source = null // The source trigger
var/source_name = "" // The name of the source should it be lost (for example a destroyed camera) var/source_name = "" // The name of the source should it be lost (for example a destroyed camera)
var/duration = 0 // How long this source will be alarming, 0 for indefinetely. var/duration = 0 // How long this source will be alarming, 0 for indefinetely.
var/severity = 1 // How severe the alarm from this source is.
var/start_time = 0 // When this source began alarming. var/start_time = 0 // When this source began alarming.
var/end_time = 0 // Use to set when this trigger should clear, in case the source is lost. var/end_time = 0 // Use to set when this trigger should clear, in case the source is lost.
@@ -22,11 +23,11 @@
var/area/last_camera_area //The last area in which cameras where fetched, used to see if the camera list should be updated. var/area/last_camera_area //The last area in which cameras where fetched, used to see if the camera list should be updated.
var/end_time //Used to set when this alarm should clear, in case the origin is lost. var/end_time //Used to set when this alarm should clear, in case the origin is lost.
/datum/alarm/New(var/atom/origin, var/atom/source, var/duration) /datum/alarm/New(var/atom/origin, var/atom/source, var/duration, var/severity)
src.origin = origin src.origin = origin
cameras() // Sets up both cameras and last alarm area. cameras() // Sets up both cameras and last alarm area.
set_duration(source, duration) set_source_data(source, duration, severity)
/datum/alarm/proc/process() /datum/alarm/proc/process()
// Has origin gone missing? // Has origin gone missing?
@@ -41,7 +42,7 @@
AS.duration = 0 AS.duration = 0
AS.end_time = world.time + ALARM_RESET_DELAY AS.end_time = world.time + ALARM_RESET_DELAY
/datum/alarm/proc/set_duration(var/atom/source, var/duration) /datum/alarm/proc/set_source_data(var/atom/source, var/duration, var/severity)
var/datum/alarm_source/AS = sources_assoc[source] var/datum/alarm_source/AS = sources_assoc[source]
if(!AS) if(!AS)
AS = new/datum/alarm_source(source) AS = new/datum/alarm_source(source)
@@ -51,6 +52,7 @@
if(AS.duration) if(AS.duration)
duration = SecondsToTicks(duration) duration = SecondsToTicks(duration)
AS.duration = duration AS.duration = duration
AS.severity = severity
/datum/alarm/proc/clear(var/source) /datum/alarm/proc/clear(var/source)
var/datum/alarm_source/AS = sources_assoc[source] var/datum/alarm_source/AS = sources_assoc[source]
@@ -83,22 +85,29 @@
last_camera_area = last_area last_camera_area = last_area
return cameras return cameras
/datum/alarm/proc/max_severity()
var/max_severity = 0
for(var/datum/alarm_source/AS in sources)
max_severity = max(AS.severity, max_severity)
return max_severity
/****************** /******************
* Assisting procs * * Assisting procs *
******************/ ******************/
/atom/proc/get_alarm_area() /atom/proc/get_alarm_area()
return get_area(src) var/area/A = get_area(src)
return A.master
/area/get_alarm_area() /area/get_alarm_area()
return src return src.master
/atom/proc/get_alarm_name() /atom/proc/get_alarm_name()
var/area/A = get_area(src) var/area/A = get_area(src)
return A.master.name return A.master.name
/area/get_alarm_name() /area/get_alarm_name()
return name return master.name
/mob/get_alarm_name() /mob/get_alarm_name()
return name return name

View File

@@ -12,7 +12,7 @@
A.process() A.process()
check_alarm_cleared(A) check_alarm_cleared(A)
/datum/alarm_handler/proc/triggerAlarm(var/atom/origin, var/atom/source, var/duration = 0) /datum/alarm_handler/proc/triggerAlarm(var/atom/origin, var/atom/source, var/duration = 0, var/severity = 1)
var/new_alarm var/new_alarm
//Proper origin and source mandatory //Proper origin and source mandatory
if(!(origin && source)) if(!(origin && source))
@@ -23,16 +23,16 @@
//see if there is already an alarm of this origin //see if there is already an alarm of this origin
var/datum/alarm/existing = alarms_assoc[origin] var/datum/alarm/existing = alarms_assoc[origin]
if(existing) if(existing)
existing.set_duration(source, duration) existing.set_source_data(source, duration, severity)
else else
existing = new/datum/alarm(origin, source, duration) existing = new/datum/alarm(origin, source, duration, severity)
new_alarm = 1 new_alarm = 1
alarms |= existing alarms |= existing
alarms_assoc[origin] = existing alarms_assoc[origin] = existing
if(new_alarm) if(new_alarm)
alarms = dd_sortedObjectList(alarms) alarms = dd_sortedObjectList(alarms)
notify_listeners(existing, ALARM_RAISED) on_alarm_change(existing, ALARM_RAISED)
return new_alarm return new_alarm
@@ -51,10 +51,30 @@
if ((alarm.end_time && world.time > alarm.end_time) || !alarm.sources.len) if ((alarm.end_time && world.time > alarm.end_time) || !alarm.sources.len)
alarms -= alarm alarms -= alarm
alarms_assoc -= alarm.origin alarms_assoc -= alarm.origin
notify_listeners(alarm, ALARM_CLEARED) on_alarm_change(alarm, ALARM_CLEARED)
return 1 return 1
return 0 return 0
/datum/alarm_handler/proc/on_alarm_change(var/datum/alarm/alarm, var/was_raised)
for(var/obj/machinery/camera/C in alarm.cameras())
if(was_raised)
C.network.Add(category)
invalidateCameraCache()
else
C.network.Remove(category)
notify_listeners(alarm, was_raised)
/datum/alarm_handler/proc/get_alarm_severity_for_origin(var/atom/origin)
if(!origin)
return
origin = origin.get_alarm_origin()
var/datum/alarm/existing = alarms_assoc[origin]
if(!existing)
return
return existing.max_severity()
/atom/proc/get_alarm_origin() /atom/proc/get_alarm_origin()
return src return src

View File

@@ -1,2 +1,2 @@
/datum/alarm_handler/atmosphere /datum/alarm_handler/atmosphere
category = "Atmosphere" category = "Atmosphere Alarms"

View File

@@ -1,2 +1,2 @@
/datum/alarm_handler/camera /datum/alarm_handler/camera
category = "Camera" category = "Camera Alarms"

View File

@@ -1,2 +1,11 @@
/datum/alarm_handler/fire /datum/alarm_handler/fire
category = "Fire" category = "Fire Alarms"
/datum/alarm_handler/fire/on_alarm_change(var/datum/alarm/alarm, var/was_raised)
var/area/A = alarm.origin
if(istype(A))
if(was_raised)
A.fire_alert()
else
A.fire_reset()
..()

View File

@@ -1,2 +1,2 @@
/datum/alarm_handler/motion /datum/alarm_handler/motion
category = "Motion" category = "Motion Alarms"

View File

@@ -1,10 +1,10 @@
/datum/alarm_handler/power /datum/alarm_handler/power
category = "Power" category = "Power Alarms"
/datum/alarm_handler/power/notify_listeners(var/datum/alarm/alarm, var/was_raised) /datum/alarm_handler/power/on_alarm_change(var/datum/alarm/alarm, var/was_raised)
..()
var/area/A = alarm.origin var/area/A = alarm.origin
if(istype(A)) if(istype(A))
A.power_alert(was_raised) A.power_alert(was_raised)
..()
/area/proc/power_alert(var/alarming) /area/proc/power_alert(var/alarming)