Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors intercom code to not process , adds signals for area power changes and area apc deletion , removes .src from fire alarm code #6097

Merged
merged 7 commits into from
May 7, 2021
2 changes: 2 additions & 0 deletions code/__DEFINES/components.dm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@

//machinery
#define COMSIG_AREA_APC_OPERATING "area_operating" //from apc process()
#define COMSIG_AREA_APC_DELETED "area_apc_gone"
#define COMSIG_AREA_APC_POWER_CHANGE "area_apc_power_change"
#define COMSING_DESTRUCTIVE_ANALIZER "destructive_analizer"
#define COMSIG_TURRENT "create_turrent"

Expand Down
1 change: 1 addition & 0 deletions code/game/area/areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
/area/proc/power_change()
for(var/obj/machinery/M in src) // for each machine in the area
M.power_change() // reverify power status (to update icons etc.)
SEND_SIGNAL(src, COMSIG_AREA_APC_POWER_CHANGE)
if (fire || eject || party)
updateicon()

Expand Down
15 changes: 7 additions & 8 deletions code/game/machinery/alarm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1084,15 +1084,15 @@ FIRE ALARM
if(stat & (NOPOWER|BROKEN))
return

if(src.timing)
if(src.time > 0)
src.time = src.time - ((world.timeofday - last_process)/10)
if(timing)
if(time > 0)
time -= (world.timeofday - last_process)/10
else
src.alarm()
src.time = 0
src.timing = 0
alarm()
time = 0
timing = 0
STOP_PROCESSING(SSmachines, src)
src.updateDialog()
updateDialog()
last_process = world.timeofday

if(locate(/obj/fire) in loc)
Expand Down Expand Up @@ -1304,4 +1304,3 @@ Just a object used in constructing fire alarms
var/tp = text2num(href_list["tp"])
time += tp
time = min(max(round(time), 0), 120)

47 changes: 24 additions & 23 deletions code/game/objects/items/devices/radio/intercom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
canhear_range = 2
flags = CONDUCT | NOBLOODY
var/number = 0
var/last_tick //used to delay the powercheck
var/area/linked_area

/obj/item/device/radio/intercom/custom
name = "station intercom (Custom)"
Expand Down Expand Up @@ -39,7 +39,7 @@

/obj/item/device/radio/intercom/New()
..()
START_PROCESSING(SSobj, src)
loop_area_check()

/obj/item/device/radio/intercom/department/medbay/New()
..()
Expand All @@ -64,10 +64,6 @@
..()
internal_channels[num2text(SYND_FREQ)] = list(access_syndicate)

/obj/item/device/radio/intercom/Destroy()
STOP_PROCESSING(SSobj, src)
. = ..()

/obj/item/device/radio/intercom/attack_ai(mob/user as mob)
src.add_fingerprint(user)
spawn (0)
Expand All @@ -93,23 +89,28 @@

return canhear_range

/obj/item/device/radio/intercom/Process()
if(((world.timeofday - last_tick) > 30) || ((world.timeofday - last_tick) < 0))
last_tick = world.timeofday

if(!src.loc)
on = FALSE
else
var/area/A = get_area(src)
if(!A)
on = FALSE
else
on = A.powered(EQUIP) // set "on" to the power status

if(!on)
icon_state = "intercom-p"
else
icon_state = "intercom"
/obj/item/device/radio/intercom/proc/change_status()
on = linked_area.powered(EQUIP)
icon_state = on ? "intercom" : "intercom-p"

/obj/item/device/radio/intercom/proc/loop_area_check()
var/area/target_area = get_area(src)
if(!target_area)
addtimer(CALLBACK(src, .proc/loop_area_check), 30 SECONDS)
return FALSE
if(!target_area.apc)
addtimer(CALLBACK(src, .proc/loop_area_check), 30 SECONDS) // We don't proces if there is no APC , no point in doing so is there ?
return FALSE
Evankhell561 marked this conversation as resolved.
Show resolved Hide resolved
linked_area = target_area
RegisterSignal(target_area, COMSIG_AREA_APC_DELETED, .proc/on_apc_removal)
RegisterSignal(target_area, COMSIG_AREA_APC_POWER_CHANGE, .proc/change_status)

/obj/item/device/radio/intercom/proc/on_apc_removal()
UnregisterSignal(linked_area , COMSIG_AREA_APC_DELETED)
UnregisterSignal(linked_area, COMSIG_AREA_APC_POWER_CHANGE)
linked_area = null
on = FALSE
addtimer(CALLBACK(src, .proc/loop_area_check), 30 SECONDS)

/obj/item/device/radio/intercom/broadcasting
broadcasting = 1
Expand Down
1 change: 1 addition & 0 deletions code/modules/power/apc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
/obj/machinery/power/apc/Destroy()
update()
area.apc = null
SEND_SIGNAL(area, COMSIG_AREA_APC_DELETED)
area.power_light = 0
area.power_equip = 0
area.power_environ = 0
Expand Down