Tidies up APC code (#9391)

This commit is contained in:
mikomyazaki
2020-07-22 17:49:54 +01:00
committed by GitHub
parent 8c14469018
commit 7d9492f500
3 changed files with 483 additions and 432 deletions
+30 -33
View File
@@ -2,22 +2,19 @@
holder_type = /obj/machinery/power/apc
wire_count = 4
#define APC_WIRE_IDSCAN 1
#define APC_WIRE_MAIN_POWER1 2
#define APC_WIRE_MAIN_POWER2 4
#define APC_WIRE_AI_CONTROL 8
#define APC_WIRE_IDSCAN (1<<0)
#define APC_WIRE_MAIN_POWER1 (1<<1)
#define APC_WIRE_MAIN_POWER2 (1<<2)
#define APC_WIRE_AI_CONTROL (1<<3)
/datum/wires/apc/GetInteractWindow()
var/obj/machinery/power/apc/A = holder
. += ..()
. += text("<br>\n[(A.locked ? "The APC is locked." : "The APC is unlocked.")]<br>\n[(A.shorted ? "The APCs power has been shorted." : "The APC is working properly!")]<br>\n[(A.aidisabled ? "The 'AI control allowed' light is off." : "The 'AI control allowed' light is on.")]")
/datum/wires/apc/CanUse(var/mob/living/L)
var/obj/machinery/power/apc/A = holder
if(A.wiresexposed)
return 1
return 0
return A?.wiresexposed
/datum/wires/apc/UpdatePulsed(var/index)
@@ -26,27 +23,33 @@
switch(index)
if(APC_WIRE_IDSCAN)
A.locked = 0
spawn(300)
if(A)
A.locked = 1
set_locked(A, FALSE)
addtimer(CALLBACK(src, .proc/set_locked, A, TRUE), 30 SECONDS)
if (APC_WIRE_MAIN_POWER1, APC_WIRE_MAIN_POWER2)
if(A.shorted == 0)
A.shorted = 1
spawn(1200)
if(A && !IsIndexCut(APC_WIRE_MAIN_POWER1) && !IsIndexCut(APC_WIRE_MAIN_POWER2))
A.shorted = 0
set_short_out(A, TRUE)
addtimer(CALLBACK(src, .proc/set_short_out, A, FALSE), 120 SECONDS)
if (APC_WIRE_AI_CONTROL)
if (A.aidisabled == 0)
A.aidisabled = 1
set_ai_control(A, TRUE)
addtimer(CALLBACK(src, .proc/set_ai_control, A, FALSE), 1 SECONDS)
spawn(10)
if(A && !IsIndexCut(APC_WIRE_AI_CONTROL))
A.aidisabled = 0
/datum/wires/apc/proc/set_locked(var/obj/machinery/power/apc/A, var/setting)
if(A)
A.locked = setting
/datum/wires/apc/proc/set_short_out(var/obj/machinery/power/apc/A, var/setting)
if(setting)
A.shorted = TRUE
else if(A && !IsIndexCut(APC_WIRE_MAIN_POWER1) && !IsIndexCut(APC_WIRE_MAIN_POWER2))
A.shorted = FALSE
/datum/wires/apc/proc/set_ai_control(var/obj/machinery/power/apc/A, var/setting)
if(setting)
A.aidisabled = TRUE
else if(A && !IsIndexCut(APC_WIRE_AI_CONTROL))
A.aidisabled = FALSE
/datum/wires/apc/UpdateCut(var/index, var/mended)
var/obj/machinery/power/apc/A = holder
@@ -56,17 +59,11 @@
if(!mended)
A.shock(usr, 50)
A.shorted = 1
A.shorted = TRUE
else if(!IsIndexCut(APC_WIRE_MAIN_POWER1) && !IsIndexCut(APC_WIRE_MAIN_POWER2))
A.shorted = 0
A.shorted = FALSE
A.shock(usr, 50)
if(APC_WIRE_AI_CONTROL)
if(!mended)
if (A.aidisabled == 0)
A.aidisabled = 1
else
if (A.aidisabled == 1)
A.aidisabled = 0
A.aidisabled = !mended