Alarm centralization completion

Ensures the master area is always used, to avoid issues caused by dynamic lightning which splits areas into sub-areas.
Power alarms now handled centrally.
This commit is contained in:
PsiOmega
2015-02-23 10:47:47 +01:00
parent 1c763ff2c9
commit 93b049e7a6
8 changed files with 30 additions and 47 deletions

View File

@@ -95,7 +95,7 @@
/atom/proc/get_alarm_name()
var/area/A = get_area(src)
return A.name
return A.master.name
/area/get_alarm_name()
return name

View File

@@ -15,8 +15,9 @@
/datum/alarm_handler/proc/triggerAlarm(var/atom/origin, var/atom/source, var/duration = 0)
var/new_alarm
//Proper origin and source mandatory
if(!origin || !source)
if(!(origin && source))
return
origin = origin.get_alarm_origin()
new_alarm = 0
//see if there is already an alarm of this origin
@@ -37,8 +38,9 @@
/datum/alarm_handler/proc/clearAlarm(var/atom/origin, var/source)
//Proper origin and source mandatory
if(!origin || !source)
if(!(origin && source))
return
origin = origin.get_alarm_origin()
var/datum/alarm/existing = alarms_assoc[origin]
if(existing)
@@ -53,6 +55,13 @@
return 1
return 0
/atom/proc/get_alarm_origin()
return src
/turf/get_alarm_origin()
var/area/area = get_area(src)
return area.master // Very important to get area.master, as dynamic lightning can and will split areas.
/datum/alarm_handler/proc/register(var/object, var/procName)
listeners[object] = procName

View File

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

View File

@@ -1,6 +1,6 @@
/obj/nano_module/alarm_monitor
name = "Alarm monitor"
var/list_cameras = 0 // Whether or not to list camera references. A future goal would be to merge this with the enginering/security camera console.
var/list_cameras = 0 // Whether or not to list camera references. A future goal would be to merge this with the enginering/security camera console. Currently really only for AI-use.
var/list/datum/alarm_handler/alarm_handlers // The particular list of alarm handlers this alarm monitor should present to the user.
/obj/nano_module/alarm_monitor/ai
@@ -38,9 +38,6 @@
return all_alarms
/obj/nano_module/alarm_monitor/Topic(href, href_list)
if(..()) return 1
/obj/nano_module/alarm_monitor/ai/Topic(ref, href_list)
if(..())
return 1

View File

@@ -183,9 +183,6 @@
if(terminal)
disconnect_terminal()
//If there's no more APC then there shouldn't be a cause for alarm I guess
area.poweralert(1, src) //so that alarms don't go on forever
..()
/obj/machinery/power/apc/proc/make_terminal()
@@ -725,7 +722,7 @@
src.interact(user)
/obj/machinery/power/apc/attack_ghost(user as mob)
if(stat & (BROKEN|MAINT))
if(stat & (BROKEN|MAINT))
return
return ui_interact(user)
@@ -1164,29 +1161,27 @@
lighting = autoset(lighting, 1)
environ = autoset(environ, 1)
autoflag = 3
area.poweralert(1, src)
if(cell.charge >= 4000)
area.poweralert(1, src)
power_alarm.clearAlarm(loc, src)
else if((cell.percent() <= 30) && (cell.percent() > 15) && longtermpower < 0) // <30%, turn off equipment
if(autoflag != 2)
equipment = autoset(equipment, 2)
lighting = autoset(lighting, 1)
environ = autoset(environ, 1)
area.poweralert(0, src)
power_alarm.triggerAlarm(loc, src)
autoflag = 2
else if(cell.percent() <= 15) // <15%, turn off lighting & equipment
if((autoflag > 1 && longtermpower < 0) || (autoflag > 1 && longtermpower >= 0))
equipment = autoset(equipment, 2)
lighting = autoset(lighting, 2)
environ = autoset(environ, 1)
area.poweralert(0, src)
power_alarm.triggerAlarm(loc, src)
autoflag = 1
else // zero charge, turn all off
if(autoflag != 0)
equipment = autoset(equipment, 0)
lighting = autoset(lighting, 0)
environ = autoset(environ, 0)
area.poweralert(0, src)
power_alarm.triggerAlarm(loc, src)
autoflag = 0
// now trickle-charge the cell
@@ -1233,7 +1228,7 @@
equipment = autoset(equipment, 0)
lighting = autoset(lighting, 0)
environ = autoset(environ, 0)
area.poweralert(0, src)
power_alarm.triggerAlarm(loc, src)
autoflag = 0
// update icon & area power if anything changed

View File

@@ -1,4 +1,4 @@
/area/engineering/poweralert(var/state, var/source)
if (state != poweralm)
/area/engineering/power_alert(var/alarming)
if (alarming)
investigate_log("has a power alarm!","singulo")
..()