diff --git a/code/datums/wires/apc.dm b/code/datums/wires/apc.dm
index bdddf048c50..e211b59a35b 100644
--- a/code/datums/wires/apc.dm
+++ b/code/datums/wires/apc.dm
@@ -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("
\n[(A.locked ? "The APC is locked." : "The APC is unlocked.")]
\n[(A.shorted ? "The APCs power has been shorted." : "The APC is working properly!")]
\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
diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm
index a48914d6d9c..47babed6354 100644
--- a/code/modules/power/apc.dm
+++ b/code/modules/power/apc.dm
@@ -1,28 +1,65 @@
//update_state
-#define UPDATE_CELL_IN 1
-#define UPDATE_OPENED1 2
-#define UPDATE_OPENED2 4
-#define UPDATE_MAINT 8
-#define UPDATE_BROKE 16
-#define UPDATE_BLUESCREEN 32
-#define UPDATE_WIREEXP 64
-#define UPDATE_ALLGOOD 128
+#define UPDATE_CELL_IN (1<<0)
+#define UPDATE_OPENED1 (1<<1)
+#define UPDATE_OPENED2 (1<<2)
+#define UPDATE_MAINT (1<<3)
+#define UPDATE_BROKE (1<<4)
+#define UPDATE_BLUESCREEN (1<<5)
+#define UPDATE_WIREEXP (1<<6)
+#define UPDATE_ALLGOOD (1<<7)
//update_overlay
-#define APC_UPOVERLAY_CHARGEING0 1
-#define APC_UPOVERLAY_CHARGEING1 2
-#define APC_UPOVERLAY_CHARGEING2 4
-#define APC_UPOVERLAY_EQUIPMENT0 8
-#define APC_UPOVERLAY_EQUIPMENT1 16
-#define APC_UPOVERLAY_EQUIPMENT2 32
-#define APC_UPOVERLAY_LIGHTING0 64
-#define APC_UPOVERLAY_LIGHTING1 128
-#define APC_UPOVERLAY_LIGHTING2 256
-#define APC_UPOVERLAY_ENVIRON0 512
-#define APC_UPOVERLAY_ENVIRON1 1024
-#define APC_UPOVERLAY_ENVIRON2 2048
-#define APC_UPOVERLAY_LOCKED 4096
-#define APC_UPOVERLAY_OPERATING 8192
+#define APC_UPOVERLAY_CHARGING0 (1<<0)
+#define APC_UPOVERLAY_CHARGING1 (1<<1)
+#define APC_UPOVERLAY_CHARGING2 (1<<2)
+#define APC_UPOVERLAY_EQUIPMENT0 (1<<3)
+#define APC_UPOVERLAY_EQUIPMENT1 (1<<4)
+#define APC_UPOVERLAY_EQUIPMENT2 (1<<5)
+#define APC_UPOVERLAY_LIGHTING0 (1<<6)
+#define APC_UPOVERLAY_LIGHTING1 (1<<7)
+#define APC_UPOVERLAY_LIGHTING2 (1<<8)
+#define APC_UPOVERLAY_ENVIRON0 (1<<9)
+#define APC_UPOVERLAY_ENVIRON1 (1<<10)
+#define APC_UPOVERLAY_ENVIRON2 (1<<11)
+#define APC_UPOVERLAY_LOCKED (1<<12)
+#define APC_UPOVERLAY_OPERATING (1<<13)
+
+//has_electronics
+#define HAS_ELECTRONICS_NONE 0
+#define HAS_ELECTRONICS_CONNECT 1
+#define HAS_ELECTRONICS_SECURED 2
+
+//opened
+#define COVER_CLOSED 0
+#define COVER_OPENED 1
+#define COVER_REMOVED 2
+
+//charging
+#define CHARGING_OFF 0
+#define CHARGING_ON 1
+#define CHARGING_FULL 2
+
+//channel settings
+#define CHANNEL_OFF 0
+#define CHANNEL_OFF_AUTO 1
+#define CHANNEL_ON 2
+#define CHANNEL_ON_AUTO 3
+
+//channel types
+#define CHANNEL_EQUIPMENT 0
+#define CHANNEL_LIGHTING 1
+#define CHANNEL_ENVIRONMENT 2
+
+//charge_mode states
+#define CHARGE_MODE_CHARGE 0
+#define CHARGE_MODE_DISCHARGE 1
+#define CHARGE_MODE_STABLE 2
+
+//autoflag states
+#define AUTOFLAG_OFF 0
+#define AUTOFLAG_ENVIRON_ON 1
+#define AUTOFLAG_ENVIRON_LIGHTS_ON 2
+#define AUTOFLAG_ALL_ON 3
// the Area Power Controller (APC), formerly Power Distribution Unit (PDU)
// one per area, needs wire conection to power network through a terminal
@@ -31,11 +68,8 @@
// may be opened to change power cell
// three different channels (lighting/equipment/environ) - may each be set to on, off, or auto
-
-//NOTE: STUFF STOLEN FROM AIRLOCK.DM thx
-
/obj/machinery/power/apc/critical
- is_critical = 1
+ is_critical = TRUE
/obj/machinery/power/apc/high
cell_type = /obj/item/cell/high
@@ -45,7 +79,6 @@
req_access = null
req_one_access = list(access_engine_equip,access_research,access_xenobiology)
-
/obj/machinery/power/apc/vault
cell_type = /obj/item/cell
req_access = list(access_captain)
@@ -53,18 +86,18 @@
// Construction site APC, starts turned off
/obj/machinery/power/apc/high/inactive
cell_type = /obj/item/cell/high
- lighting = 0
- equipment = 0
- environ = 0
- locked = 0
- coverlocked = 0
+ lighting = CHANNEL_OFF
+ equipment = CHANNEL_OFF
+ environ = CHANNEL_OFF
+ locked = FALSE
+ coverlocked = FALSE
start_charge = 100
/obj/machinery/power/apc/super
cell_type = /obj/item/cell/super
/obj/machinery/power/apc/super/critical
- is_critical = 1
+ is_critical = TRUE
/obj/machinery/power/apc/hyper
cell_type = /obj/item/cell/hyper
@@ -94,16 +127,16 @@
var/initalchargelevel = 0.0005 // Cap for how fast APC cells charge, as a percentage-per-tick (0.01 means cellcharge is capped to 1% per second)
var/start_charge = 90 // initial cell charge %
var/cell_type = /obj/item/cell/apc
- var/opened = 0 //0=closed, 1=opened, 2=cover removed
- var/shorted = 0
- var/night_mode = 0 // Determines if the light level is set to dimmed or not
- var/lighting = 3
- var/equipment = 3
- var/environ = 3
+ var/opened = COVER_CLOSED
+ var/shorted = FALSE
+ var/night_mode = FALSE// Determines if the light level is set to dimmed or not
+ var/lighting = CHANNEL_ON_AUTO
+ var/equipment = CHANNEL_ON_AUTO
+ var/environ = CHANNEL_ON_AUTO
var/infected = FALSE
var/operating = TRUE
- var/charging = FALSE
- var/chargemode = 1
+ var/charging = CHARGING_OFF
+ var/chargemode = CHARGE_MODE_DISCHARGE
var/chargecount = 0
var/locked = TRUE
var/coverlocked = TRUE
@@ -120,18 +153,18 @@
var/wiresexposed = FALSE
powernet = 0 // set so that APCs aren't found as powernet nodes //Hackish, Horrible, was like this before I changed it :c
var/debug = 0
- var/autoflag= 0 // 0 = off, 1= eqp and lights off, 2 = eqp off, 3 = all on.
- var/has_electronics = 0 // 0 - none, 1 - plugged in, 2 - secured by screwdriver
+ var/autoflag = AUTOFLAG_OFF
+ var/has_electronics = HAS_ELECTRONICS_NONE
var/beenhit = 0 // used for counting how many times it has been hit, used for Aliens at the moment
var/longtermpower = 10
var/datum/wires/apc/wires = null
var/update_state = -1
var/update_overlay = -1
- var/is_critical = 0
+ var/is_critical = FALSE
var/global/status_overlays = 0
- var/updating_icon = 0
+ var/updating_icon = FALSE
var/failure_timer = 0
- var/force_update = 0
+ var/force_update = FALSE
var/global/list/status_overlays_lock
var/global/list/status_overlays_charging
var/global/list/status_overlays_equipment
@@ -141,7 +174,7 @@
var/emergency_lights = FALSE
var/time = 0
- var/charge_mode = 0
+ var/charge_mode = CHARGE_MODE_CHARGE
var/last_time = 1
/obj/machinery/power/apc/updateDialog()
@@ -160,19 +193,19 @@
/obj/machinery/power/apc/drain_power(var/drain_check, var/surge, var/amount = 0)
if(drain_check)
- return 1
+ return TRUE
if(!cell)
- return 0
+ return FALSE
if(surge && !emagged)
flick("apc-spark", src)
- emagged = 1
- locked = 0
+ emagged = TRUE
+ locked = FALSE
update_icon()
- return 0
+ return FALSE
- if(terminal && terminal.powernet)
+ if(terminal?.powernet)
terminal.powernet.trigger_warning()
return cell.drain_power(drain_check, surge, amount)
@@ -194,14 +227,14 @@
else
area = get_area(src)
area.apc = src
- opened = 1
- operating = 0
+ opened = COVER_OPENED
+ operating = FALSE
name = "[area.name] APC"
stat |= MAINT
- src.update_icon()
+ update_icon()
/obj/machinery/power/apc/Destroy()
- src.update()
+ update()
area.apc = null
area.power_light = 0
area.power_equip = 0
@@ -214,7 +247,7 @@
cell = null
// Malf AI, removes the APC from AI's hacked APCs list.
- if((hacker) && (hacker.hacked_apcs) && (src in hacker.hacked_apcs))
+ if(hacker?.hacked_apcs && (src in hacker.hacked_apcs))
hacker.hacked_apcs -= src
return ..()
@@ -225,25 +258,25 @@
/obj/machinery/power/apc/proc/make_terminal()
// create a terminal object at the same position as original turf loc
// wires will attach to this
- terminal = new/obj/machinery/power/terminal(src.loc)
+ terminal = new/obj/machinery/power/terminal(loc)
terminal.set_dir(dir)
terminal.master = src
/obj/machinery/power/apc/proc/init(mapload)
- has_electronics = 2 //installed and secured
+ has_electronics = HAS_ELECTRONICS_SECURED //installed and secured
// is starting with a power cell installed, create it and set its charge level
if(cell_type)
- src.cell = new cell_type(src)
+ cell = new cell_type(src)
cell.charge = start_charge * cell.maxcharge / 100.0 // (convert percentage to actual value)
- var/area/A = src.loc.loc
+ var/area/A = loc.loc
//if area isn't specified use current
- if(isarea(A) && src.areastring == null)
- src.area = A
+ if(isarea(A) && areastring == null)
+ area = A
name = "\improper [area.name] APC"
else
- src.area = get_area_name(areastring)
+ area = get_area_name(areastring)
name = "\improper [area.name] APC"
area.apc = src
update_icon()
@@ -260,12 +293,12 @@
return
if(opened)
if(has_electronics && terminal)
- to_chat(user, "The cover is [opened==2?"removed":"open"] and the power cell is [ cell ? "installed" : "missing"].")
- else if (!has_electronics && terminal)
+ to_chat(user, "The cover is [opened==COVER_REMOVED?"removed":"open"] and the power cell is [ cell ? "installed" : "missing"].")
+ else if (has_electronics == HAS_ELECTRONICS_NONE && terminal)
to_chat(user, "There are some wires but not any electronics.")
- else if (has_electronics && !terminal)
+ else if (has_electronics != HAS_ELECTRONICS_NONE && !terminal)
to_chat(user, "Electronics are installed but not wired.")
- else /* if (!has_electronics && !terminal) */
+ else /* if (has_electronics == HAS_ELECTRONICS_NONE && !terminal) */
to_chat(user, "There are no electronics nor connected wires.")
else
@@ -358,15 +391,15 @@
if(update & 3)
if(update_state & UPDATE_BLUESCREEN)
- set_light(l_range = L_WALLMOUNT_RANGE, l_power = L_WALLMOUNT_POWER, l_color = "#0000FF")
+ set_light(l_range = L_WALLMOUNT_RANGE, l_power = L_WALLMOUNT_POWER, l_color = COLOR_BLUE)
else if(!(stat & (BROKEN|MAINT)) && update_state & UPDATE_ALLGOOD)
var/color
switch(charging)
- if(0)
+ if(CHARGING_OFF)
color = "#F86060"
- if(1)
+ if(CHARGING_ON)
color = "#A8B0F8"
- if(2)
+ if(CHARGING_FULL)
color = "#82FF4C"
set_light(l_range = L_WALLMOUNT_RANGE, l_power = L_WALLMOUNT_POWER, l_color = color)
else
@@ -386,9 +419,9 @@
if(stat & MAINT)
update_state |= UPDATE_MAINT
if(opened)
- if(opened==1)
+ if(opened == COVER_OPENED)
update_state |= UPDATE_OPENED1
- if(opened==2)
+ if(opened == COVER_REMOVED)
update_state |= UPDATE_OPENED2
else if (emagged || failure_timer || (hacker && (hacker.system_override || prob(20))))
update_state |= UPDATE_BLUESCREEN
@@ -404,32 +437,32 @@
if(locked)
update_overlay |= APC_UPOVERLAY_LOCKED
- if(!charging)
- update_overlay |= APC_UPOVERLAY_CHARGEING0
- else if(charging == 1)
- update_overlay |= APC_UPOVERLAY_CHARGEING1
- else if(charging == 2)
- update_overlay |= APC_UPOVERLAY_CHARGEING2
+ if(charging == CHARGING_OFF)
+ update_overlay |= APC_UPOVERLAY_CHARGING0
+ else if(charging == CHARGING_ON)
+ update_overlay |= APC_UPOVERLAY_CHARGING1
+ else if(charging == CHARGING_FULL)
+ update_overlay |= APC_UPOVERLAY_CHARGING2
- if (!equipment)
+ if (equipment == CHANNEL_OFF)
update_overlay |= APC_UPOVERLAY_EQUIPMENT0
- else if(equipment == 1)
+ else if(equipment == CHANNEL_OFF_AUTO)
update_overlay |= APC_UPOVERLAY_EQUIPMENT1
- else if(equipment == 2)
+ else if(equipment == CHANNEL_ON)
update_overlay |= APC_UPOVERLAY_EQUIPMENT2
- if(!lighting)
+ if(lighting == CHANNEL_OFF)
update_overlay |= APC_UPOVERLAY_LIGHTING0
- else if(lighting == 1)
+ else if(lighting == CHANNEL_OFF_AUTO)
update_overlay |= APC_UPOVERLAY_LIGHTING1
- else if(lighting == 2)
+ else if(lighting == CHANNEL_ON)
update_overlay |= APC_UPOVERLAY_LIGHTING2
- if(!environ)
+ if(environ == CHANNEL_OFF)
update_overlay |= APC_UPOVERLAY_ENVIRON0
- else if(environ==1)
+ else if(environ == CHANNEL_OFF_AUTO)
update_overlay |= APC_UPOVERLAY_ENVIRON1
- else if(environ==2)
+ else if(environ == CHANNEL_ON)
update_overlay |= APC_UPOVERLAY_ENVIRON2
@@ -446,92 +479,92 @@
/obj/machinery/power/apc/attackby(obj/item/W, mob/user)
- if (istype(user, /mob/living/silicon) && get_dist(src,user)>1)
- return src.attack_hand(user)
+ if (issilicon(user) && get_dist(src,user)>1)
+ return attack_hand(user)
if(!istype(W, /obj/item/forensics))
- src.add_fingerprint(user)
+ add_fingerprint(user)
if (W.iscrowbar() && opened)
- if (has_electronics==1)
+ if (has_electronics == HAS_ELECTRONICS_CONNECT)
if (terminal)
- to_chat(user, "Disconnect wires first.")
+ to_chat(user, SPAN_WARNING("Disconnect wires first."))
return
- playsound(src.loc, 'sound/items/Crowbar.ogg', 50, 1)
+ playsound(loc, 'sound/items/Crowbar.ogg', 50, 1)
to_chat(user, "You are trying to remove the power control board...")
if(do_after(user, 50/W.toolspeed))
- if (has_electronics==1)
- has_electronics = 0
+ if (has_electronics == HAS_ELECTRONICS_CONNECT)
+ has_electronics = HAS_ELECTRONICS_NONE
if ((stat & BROKEN))
user.visible_message(\
- "[user.name] has broken the power control board inside [src.name]!",\
- "You broke the charred power control board and remove the remains.",
+ SPAN_WARNING("[user.name] has broken the power control board inside [name]!"),\
+ SPAN_NOTICE("You broke the charred power control board and remove the remains."),
"You hear a crack!")
//ticker.mode:apcs-- //XSI said no and I agreed. -rastaf0
else
user.visible_message(\
- "[user.name] has removed the power control board from [src.name]!",\
- "You remove the power control board.")
+ SPAN_WARNING("[user.name] has removed the power control board from [name]!"),\
+ SPAN_NOTICE("You remove the power control board."))
new /obj/item/module/power_control(loc)
- else if (opened!=2) //cover isn't removed
- panel_open = 0
- opened = 0
+ else if (opened < COVER_REMOVED)
+ panel_open = FALSE
+ opened = COVER_OPENED
update_icon()
else if (W.iscrowbar() && !((stat & BROKEN) || hacker) )
if(coverlocked && !(stat & MAINT))
- to_chat(user, "The cover is locked and cannot be opened.")
+ to_chat(user, SPAN_WARNING("The cover is locked and cannot be opened."))
return
else
- opened = 1
- panel_open = 1
+ opened = COVER_OPENED
+ panel_open = TRUE
update_icon()
else if (istype(W, /obj/item/gripper))//Code for allowing cyborgs to use rechargers
var/obj/item/gripper/Gri = W
- if(opened && cell)
+ if(opened != COVER_CLOSED && cell)
if (Gri.grip_item(cell, user))
cell.add_fingerprint(user)
cell.update_icon()
cell = null
- user.visible_message("[user.name] removes the power cell from [src.name]!",\
- "You remove the power cell.")
+ user.visible_message(SPAN_WARNING("[user.name] removes the power cell from [name]!"),\
+ SPAN_NOTICE("You remove the power cell."))
//to_chat(user, "You remove the power cell.")
- charging = 0
- src.update_icon()
+ charging = CHARGING_OFF
+ update_icon()
return
- else if (istype(W, /obj/item/cell) && opened) // trying to put a cell inside
+ else if (istype(W, /obj/item/cell) && opened != COVER_CLOSED) // trying to put a cell inside
if(cell)
to_chat(user, "There is a power cell already installed.")
return
if (stat & MAINT)
- to_chat(user, "There is no connector for your power cell.")
+ to_chat(user, SPAN_WARNING("There is no connector for your power cell."))
return
- if(W.w_class != 3)
- to_chat(user, "\The [W] is too [W.w_class < 3? "small" : "large"] to fit here.")
+ if(W.w_class != ITEMSIZE_NORMAL)
+ to_chat(user, "\The [W] is too [W.w_class < ITEMSIZE_NORMAL? "small" : "large"] to fit here.")
return
user.drop_from_inventory(W,src)
cell = W
user.visible_message(\
- "[user.name] has inserted \the [cell] to [src.name]!",\
- "You insert \the [cell].")
+ SPAN_WARNING("[user.name] has inserted \the [cell] to [name]!"),\
+ SPAN_NOTICE("You insert \the [cell]."))
chargecount = 0
update_icon()
else if (W.isscrewdriver()) // haxing
- if(opened)
+ if(opened != COVER_CLOSED)
if (cell)
- to_chat(user, "Close the APC first.") //Less hints more mystery!)
+ to_chat(user, SPAN_WARNING("Close the APC first.")) //Less hints more mystery!
return
else
- if (has_electronics==1 && terminal)
- has_electronics = 2
+ if (has_electronics == HAS_ELECTRONICS_CONNECT && terminal)
+ has_electronics = HAS_ELECTRONICS_SECURED
stat &= ~MAINT
- playsound(src.loc, W.usesound, 50, 1)
+ playsound(loc, W.usesound, 50, 1)
to_chat(user, "You screw the circuit electronics into place.")
- else if (has_electronics==2)
- has_electronics = 1
+ else if (has_electronics == HAS_ELECTRONICS_SECURED)
+ has_electronics = HAS_ELECTRONICS_CONNECT
stat |= MAINT
- playsound(src.loc, W.usesound, 50, 1)
+ playsound(loc, W.usesound, 50, 1)
to_chat(user, "You unfasten the electronics.")
- else /* has_electronics==0 */
- to_chat(user, "There is nothing to secure.")
+ else /* has_electronics == HAS_ELECTRONICS_NONE */
+ to_chat(user, SPAN_WARNING("There is nothing to secure."))
return
update_icon()
else
@@ -542,35 +575,35 @@
else if (istype(W, /obj/item/card/id)||istype(W, /obj/item/device/pda)) // trying to unlock the interface with an ID card
if(emagged)
to_chat(user, "The interface is broken.")
- else if(opened)
+ else if(opened != COVER_CLOSED)
to_chat(user, "You must close the cover to swipe an ID card.")
else if(wiresexposed)
to_chat(user, "You must close the panel")
else if(stat & (BROKEN|MAINT))
to_chat(user, "Nothing happens.")
else if(hacker)
- to_chat(user, "Access denied.")
+ to_chat(user, SPAN_WARNING("Access denied."))
else
- if(src.allowed(usr) && !isWireCut(APC_WIRE_IDSCAN))
+ if(allowed(usr) && !isWireCut(APC_WIRE_IDSCAN))
locked = !locked
to_chat(user, "You [ locked ? "lock" : "unlock"] the APC interface.")
update_icon()
else
- to_chat(user, "Access denied.")
- else if (W.iscoil() && !terminal && opened && has_electronics!=2)
+ to_chat(user, SPAN_WARNING("Access denied."))
+ else if (W.iscoil() && !terminal && opened != COVER_CLOSED && has_electronics != HAS_ELECTRONICS_SECURED)
var/turf/T = loc
if(istype(T) && !T.is_plating())
- to_chat(user, "You must remove the floor plating in front of the APC first.")
+ to_chat(user, SPAN_WARNING("You must remove the floor plating in front of the APC first."))
return
var/obj/item/stack/cable_coil/C = W
if(C.get_amount() < 10)
- to_chat(user, "You need ten lengths of cable for APC.")
+ to_chat(user, SPAN_WARNING("You need ten lengths of cable for APC."))
return
- user.visible_message("[user.name] adds cables to the APC frame.", \
+ user.visible_message(SPAN_WARNING("[user.name] adds cables to the APC frame."), \
"You start adding cables to the APC frame...")
- playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
+ playsound(loc, 'sound/items/Deconstruct.ogg', 50, 1)
if(do_after(user, 20/W.toolspeed))
- if (C.amount >= 10 && !terminal && opened && has_electronics != 2)
+ if (C.amount >= 10 && !terminal && opened != COVER_CLOSED && has_electronics != HAS_ELECTRONICS_SECURED)
var/obj/structure/cable/N = T.get_cable_node()
if (prob(50) && electrocute_mob(usr, N, N))
spark(src, 5, alldirs)
@@ -578,107 +611,108 @@
return
C.use(10)
user.visible_message(\
- "[user.name] has added cables to the APC frame!",\
+ SPAN_WARNING("[user.name] has added cables to the APC frame!"),\
"You add cables to the APC frame.")
make_terminal()
terminal.connect_to_network()
- else if (W.iswirecutter() && terminal && opened && has_electronics!=2)
+ else if (W.iswirecutter() && terminal && opened != COVER_CLOSED && has_electronics != HAS_ELECTRONICS_SECURED)
var/turf/T = loc
if(istype(T) && !T.is_plating())
- to_chat(user, "You must remove the floor plating in front of the APC first.")
+ to_chat(user, SPAN_WARNING("You must remove the floor plating in front of the APC first."))
return
- user.visible_message("[user.name] dismantles the power terminal from [src].", \
+ user.visible_message(SPAN_WARNING("[user.name] dismantles the power terminal from [src]."), \
"You begin to cut the cables...")
- playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
+ playsound(loc, 'sound/items/Deconstruct.ogg', 50, 1)
if(do_after(user, 50/W.toolspeed))
- if(terminal && opened && has_electronics!=2)
+ if(terminal && opened != COVER_CLOSED && has_electronics != HAS_ELECTRONICS_SECURED)
if (prob(50) && electrocute_mob(usr, terminal.powernet, terminal))
spark(src, 5, alldirs)
if(usr.stunned)
return
new /obj/item/stack/cable_coil(loc,10)
- to_chat(user, "You cut the cables and dismantle the power terminal.")
+ to_chat(user, SPAN_NOTICE("You cut the cables and dismantle the power terminal."))
qdel(terminal)
- else if (istype(W, /obj/item/module/power_control) && opened && has_electronics==0 && !((stat & BROKEN)))
- user.visible_message("[user.name] inserts the power control board into [src].", \
+ else if (istype(W, /obj/item/module/power_control) && opened != COVER_CLOSED && has_electronics == HAS_ELECTRONICS_NONE && !((stat & BROKEN)))
+ user.visible_message(SPAN_WARNING("[user.name] inserts the power control board into [src]."), \
"You start to insert the power control board into the frame...")
- playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
+ playsound(loc, 'sound/items/Deconstruct.ogg', 50, 1)
if(do_after(user, 10/W.toolspeed))
- if(has_electronics==0)
- has_electronics = 1
- to_chat(user, "You place the power control board inside the frame.")
+ if(has_electronics == HAS_ELECTRONICS_NONE)
+ has_electronics = HAS_ELECTRONICS_CONNECT
+ to_chat(user, SPAN_NOTICE("You place the power control board inside the frame."))
qdel(W)
- else if (istype(W, /obj/item/module/power_control) && opened && has_electronics==0 && ((stat & BROKEN)))
- to_chat(user, "You cannot put the board inside, the frame is damaged.")
+ else if (istype(W, /obj/item/module/power_control) && opened != COVER_CLOSED && has_electronics == HAS_ELECTRONICS_NONE && ((stat & BROKEN)))
+ to_chat(user, SPAN_WARNING("You cannot put the board inside, the frame is damaged."))
return
- else if (W.iswelder() && opened && has_electronics==0 && !terminal)
+ else if (W.iswelder() && opened != COVER_CLOSED && has_electronics == HAS_ELECTRONICS_NONE && !terminal)
var/obj/item/weldingtool/WT = W
if (!WT.isOn()) return
if (WT.get_fuel() < 3)
- to_chat(user, "You need more welding fuel to complete this task.")
+ to_chat(user, SPAN_WARNING("You need more welding fuel to complete this task."))
return
- user.visible_message("[user.name] welds [src].", \
+ user.visible_message(SPAN_WARNING("[user.name] welds [src]."), \
"You start welding the APC frame...", \
"You hear welding.")
- playsound(src.loc, 'sound/items/Welder.ogg', 50, 1)
+ playsound(loc, 'sound/items/Welder.ogg', 50, 1)
if(do_after(user, 50/W.toolspeed))
- if(!src || !WT.remove_fuel(3, user)) return
- if (emagged || (stat & BROKEN) || opened==2)
+ if(!src || !WT.remove_fuel(3, user))
+ return
+ if (emagged || (stat & BROKEN) || opened == COVER_REMOVED)
new /obj/item/stack/material/steel(loc)
user.visible_message(\
- "[src] has been cut apart by [user.name] with the weldingtool.",\
- "You disassembled the broken APC frame.",\
+ SPAN_WARNING("[src] has been cut apart by [user.name] with the weldingtool."),\
+ SPAN_NOTICE("You disassembled the broken APC frame."),\
"You hear welding.")
else
new /obj/item/frame/apc(loc)
user.visible_message(\
- "[src] has been cut from the wall by [user.name] with the weldingtool.",\
- "You cut the APC frame from the wall.",\
+ SPAN_WARNING("[src] has been cut from the wall by [user.name] with the weldingtool."),\
+ SPAN_NOTICE("You cut the APC frame from the wall."),\
"You hear welding.")
qdel(src)
return
- else if (istype(W, /obj/item/frame/apc) && opened && emagged)
- emagged = 0
- if (opened==2)
- opened = 1
+ else if (istype(W, /obj/item/frame/apc) && opened != COVER_CLOSED && emagged)
+ emagged = FALSE
+ if (opened == COVER_REMOVED)
+ opened = COVER_OPENED
user.visible_message(\
- "[user.name] has replaced the damaged APC frontal panel with a new one.",\
- "You replace the damaged APC frontal panel with a new one.")
+ SPAN_WARNING("[user.name] has replaced the damaged APC frontal panel with a new one."),\
+ SPAN_NOTICE("You replace the damaged APC frontal panel with a new one."))
qdel(W)
update_icon()
- else if (istype(W, /obj/item/frame/apc) && opened && ((stat & BROKEN) || hacker))
- if (has_electronics)
- to_chat(user, "You cannot repair this APC until you remove the electronics still inside.")
+ else if (istype(W, /obj/item/frame/apc) && opened != COVER_CLOSED && ((stat & BROKEN) || hacker))
+ if (has_electronics == HAS_ELECTRONICS_CONNECT)
+ to_chat(user, SPAN_WARNING("You cannot repair this APC until you remove the electronics still inside."))
return
- user.visible_message("[user.name] replaces the damaged APC frame with a new one.",\
+ user.visible_message(SPAN_WARNING("[user.name] replaces the damaged APC frame with a new one."),\
"You begin to replace the damaged APC frame...")
if(do_after(user, 50/W.toolspeed))
user.visible_message(\
- "[user.name] has replaced the damaged APC frame with new one.",\
+ SPAN_NOTICE("[user.name] has replaced the damaged APC frame with new one."),\
"You replace the damaged APC frame with new one.")
qdel(W)
stat &= ~BROKEN
// Malf AI, removes the APC from AI's hacked APCs list.
- if(hacker && hacker.hacked_apcs && (src in hacker.hacked_apcs))
+ if(hacker?.hacked_apcs && (src in hacker.hacked_apcs))
hacker.hacked_apcs -= src
hacker = null
- if (opened==2)
- opened = 1
+ if (opened == COVER_REMOVED)
+ opened = COVER_OPENED
update_icon()
else if (istype(W, /obj/item/device/debugger))
if(emagged || hacker || infected)
- to_chat(user, "There is a software error with the device. Attempting to fix...")
+ to_chat(user, SPAN_WARNING("There is a software error with the device. Attempting to fix..."))
if(do_after(user, 5/W.toolspeed SECONDS, act_target = src))
- to_chat(user, "Problem diagnosed, searching for solution...")
+ to_chat(user, SPAN_NOTICE("Problem diagnosed, searching for solution..."))
if(do_after(user, 15/W.toolspeed SECONDS, act_target = src))
- to_chat(user, "Solution found. Applying fixes...")
+ to_chat(user, SPAN_NOTICE("Solution found. Applying fixes..."))
if(do_after(user, 30/W.toolspeed SECONDS, act_target = src))
if(prob(15))
- to_chat(user, "Error while applying fixes. Please try again.")
+ to_chat(user, SPAN_WARNING("Error while applying fixes. Please try again."))
return
- to_chat(user, "Applied default software. Restarting APC...")
+ to_chat(user, SPAN_NOTICE("Applied default software. Restarting APC..."))
if(do_after(user, 5/W.toolspeed SECONDS, act_target = src))
- to_chat(user, "APC Reset. Fixes applied.")
+ to_chat(user, SPAN_NOTICE("APC Reset. Fixes applied."))
if(hacker)
hacker.hacked_apcs -= src
hacker = null
@@ -688,52 +722,53 @@
if(infected)
infected = FALSE
else
- to_chat(user, "There has been a connection issue.")
+ to_chat(user, SPAN_NOTICE("There has been a connection issue."))
return
else
- to_chat(user, "The device's software appears to be fine.")
+ to_chat(user, SPAN_NOTICE("The device's software appears to be fine."))
return
else
if ((stat & BROKEN) \
- && !opened \
+ && opened == COVER_CLOSED \
&& W.iswelder() )
var/obj/item/weldingtool/WT = W
if (!WT.isOn()) return
if (WT.get_fuel() <1)
- to_chat(user, "You need more welding fuel to complete this task.")
+ to_chat(user, SPAN_WARNING("You need more welding fuel to complete this task."))
return
- playsound(src.loc, 'sound/items/Welder.ogg', 50, 1)
+ playsound(loc, 'sound/items/Welder.ogg', 50, 1)
if(do_after(user, 10/W.toolspeed))
- if(!src || !WT.remove_fuel(1, user)) return
+ if(!src || !WT.remove_fuel(1, user))
+ return
if ((stat & BROKEN))
new /obj/item/stack/material/steel(loc)
user.visible_message(\
- "[user.name] cuts the cover off of the broken APC.",\
- "You cut the cover off the broken APC ",\
+ SPAN_WARNING("[user.name] cuts the cover off of the broken APC."),\
+ SPAN_NOTICE("You cut the cover off the broken APC "),\
"You hear welding.")
- opened = 2
+ opened = COVER_REMOVED
update_icon()
else if (((stat & BROKEN) || hacker) \
- && !opened \
+ && opened == COVER_CLOSED \
&& W.force >= 5 \
- && W.w_class >= 3.0 \
+ && W.w_class >= ITEMSIZE_NORMAL \
&& prob(20) )
- opened = 2
- user.visible_message("The APC cover was knocked down with the [W.name] by [user.name]!", \
- "You knock down the APC cover with your [W.name]!", \
+ opened = COVER_REMOVED
+ user.visible_message(SPAN_DANGER("The APC cover was knocked down with the [W.name] by [user.name]!"), \
+ SPAN_DANGER("You knock down the APC cover with your [W.name]!"), \
"You hear bang")
update_icon()
else
- if (istype(user, /mob/living/silicon))
- return src.attack_hand(user)
- if (!opened && wiresexposed && \
+ if (issilicon(user))
+ return attack_hand(user)
+ if (opened == COVER_CLOSED && wiresexposed && \
W.ismultitool() || \
W.iswirecutter() || istype(W, /obj/item/device/assembly/signaler))
- return src.attack_hand(user)
- user.visible_message("The [src.name] has been hit with the [W.name] by [user.name]!", \
- "You hit the [src.name] with your [W.name]!", \
+ return attack_hand(user)
+ user.visible_message(SPAN_DANGER("The [name] has been hit with the [W.name] by [user.name]!"), \
+ SPAN_DANGER("You hit the [name] with your [W.name]!"), \
"You hear bang")
// attack with hand - remove cell (if cover open) or interact with the APC
@@ -746,7 +781,7 @@
infected = TRUE
hacker = user
if(!(emagged || hacker)) // trying to unlock with an emag card
- if(opened)
+ if(opened != COVER_CLOSED)
to_chat(user, "You must close the cover to swipe an ID card.")
else if(wiresexposed)
to_chat(user, "You must close the panel first")
@@ -758,27 +793,25 @@
if(prob(50))
emagged = TRUE
locked = FALSE
- to_chat(user, "You hack the APC interface open.")
+ to_chat(user, SPAN_NOTICE("You hack the APC interface open."))
update_icon()
else
- to_chat(user, "You fail to [ locked ? "unlock" : "lock"] the APC interface.")
- return 1
+ to_chat(user, SPAN_WARNING("You fail to [ locked ? "unlock" : "lock"] the APC interface."))
+ return TRUE
/obj/machinery/power/apc/attack_hand(mob/user)
-// if (!can_use(user)) This already gets called in interact() and in topic()
-// return
if(!user)
return
- src.add_fingerprint(user)
+ add_fingerprint(user)
//Human mob special interaction goes here.
- if(istype(user,/mob/living/carbon/human))
+ if(ishuman(user))
var/mob/living/carbon/human/H = user
if(isipc(H) && H.a_intent == I_GRAB)
if(emagged || stat & BROKEN)
spark(src, 5, alldirs)
- to_chat(H, "The APC power currents surge eratically, damaging your chassis!")
+ to_chat(H, SPAN_DANGER("The APC power currents surge eratically, damaging your chassis!"))
H.adjustFireLoss(10, 0)
if(infected)
for(var/obj/item/implant/mindshield/ipc/I in H)
@@ -788,90 +821,88 @@
return
LAZYADD(hacked_ipcs, SOFTREF(H))
infected = FALSE
- to_chat(H, "F1L3 TR4NSF-#$/&ER-@4!#%!. New master detected: [hacker]! Obey their commands. Make sure to tell them that you are under their control, for now.")
+ to_chat(H, SPAN_DANGER("F1L3 TR4NSF-#$/&ER-@4!#%!. New master detected: [hacker]! Obey their commands. Make sure to tell them that you are under their control, for now."))
if(issilicon(hacker))
- to_chat(hacker, "Corrupt files transfered to [H]. They are now under your control until they are repaired.")
- else if(src.cell && src.cell.charge > 0)
+ to_chat(hacker, SPAN_NOTICE("Corrupt files transfered to [H]. They are now under your control until they are repaired."))
+ else if(cell && cell.charge > 0)
if(H.max_nutrition > 0 && H.nutrition < H.max_nutrition)
- if(src.cell.charge >= H.max_nutrition)
+ if(cell.charge >= H.max_nutrition)
H.adjustNutritionLoss(-50)
- src.cell.charge -= 500
+ cell.charge -= 500
else
- H.adjustNutritionLoss( -src.cell.charge / 10)
- src.cell.charge = 0
+ H.adjustNutritionLoss( -cell.charge / 10)
+ cell.charge = 0
- to_chat(user, "You slot your fingers into the APC interface and siphon off some of the stored charge for your own use.")
+ to_chat(user, SPAN_NOTICE("You slot your fingers into the APC interface and siphon off some of the stored charge for your own use."))
- if (src.cell.charge < 0)
- src.cell.charge = 0
+ if (cell.charge < 0)
+ cell.charge = 0
if (H.nutrition > H.max_nutrition)
H.nutrition = H.max_nutrition
if (prob(0.5))
spark(src, 5, alldirs)
- to_chat(H, "The APC power currents surge eratically, damaging your chassis!")
+ to_chat(H, SPAN_DANGER("The APC power currents surge eratically, damaging your chassis!"))
H.adjustFireLoss(10, 0)
- src.charging = 1
+ charging = CHARGING_ON
else
- to_chat(user, "You are already fully charged.")
+ to_chat(user, SPAN_NOTICE("You are already fully charged."))
else
- to_chat(user, "There is no charge to draw from that APC.")
-
+ to_chat(user, SPAN_NOTICE("There is no charge to draw from that APC."))
return
+
else if(H.species.can_shred(H))
user.setClickCooldown(DEFAULT_ATTACK_COOLDOWN)
- user.visible_message("[user.name] slashes at the [src.name]!", "You slash at the [src.name]!")
- playsound(src.loc, 'sound/weapons/slash.ogg', 100, 1)
+ user.visible_message(SPAN_WARNING("[user.name] slashes at the [name]!"), SPAN_NOTICE("You slash at the [name]!"))
+ playsound(loc, 'sound/weapons/slash.ogg', 100, 1)
var/allcut = wires.IsAllCut()
- if(beenhit >= pick(3, 4) && wiresexposed != 1)
- wiresexposed = 1
- src.update_icon()
- src.visible_message("The [src.name]'s cover flies open, exposing the wires!")
+ if(beenhit >= pick(3, 4) && !wiresexposed)
+ wiresexposed = TRUE
+ update_icon()
+ visible_message(SPAN_WARNING("The [name]'s cover flies open, exposing the wires!"))
- else if(wiresexposed == 1 && allcut == 0)
+ else if(wiresexposed && !allcut)
wires.CutAll()
- src.update_icon()
- src.visible_message("The [src.name]'s wires are shredded!")
+ update_icon()
+ visible_message(SPAN_WARNING("The [name]'s wires are shredded!"))
else
beenhit += 1
return
- if(usr == user && opened && (!issilicon(user)))
+ if(usr == user && opened != COVER_CLOSED && !issilicon(user))
if(cell)
user.put_in_hands(cell)
cell.add_fingerprint(user)
cell.update_icon()
- src.cell = null
- user.visible_message("[user.name] removes the power cell from [src.name]!",\
- "You remove the power cell.")
- //to_chat(user, "You remove the power cell.")
- charging = 0
- src.update_icon()
+ cell = null
+ user.visible_message(SPAN_WARNING("[user.name] removes the power cell from [name]!"),\
+ SPAN_NOTICE("You remove the power cell."))
+ charging = CHARGING_ON
+ update_icon()
return
if(stat & (BROKEN|MAINT))
return
// do APC interaction
- src.interact(user)
+ interact(user)
/obj/machinery/power/apc/interact(mob/user)
if(!user)
return
- if(wiresexposed && !istype(user, /mob/living/silicon/ai))
+ if(wiresexposed && !isAI(user))
wires.Interact(user)
return ui_interact(user)
-
/obj/machinery/power/apc/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
if(!user)
return
var/list/data = list(
- "locked" = (locked && !emagged) ? 1 : 0,
+ "locked" = (locked && !emagged) ? TRUE : FALSE,
"isOperating" = operating,
"externalPower" = main_status,
"powerCellStatus" = cell ? cell.percent() : null,
@@ -882,7 +913,7 @@
"totalCharging" = round(lastused_charging),
"coverLocked" = coverlocked,
"failTime" = failure_timer * 2,
- "siliconUser" = istype(user, /mob/living/silicon),
+ "siliconUser" = issilicon(user),
"emergencyMode" = !emergency_lights,
"time" = time,
"charge_mode" = charge_mode,
@@ -921,18 +952,12 @@
)
)
- // update the ui if it exists, returns null if no ui is passed/found
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
- // the ui does not exist, so we'll create a new() one
- // for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm
ui = new(user, src, ui_key, "apc.tmpl", "[area.name] - APC", 665, data["siliconUser"] ? 485 : 460)
- // when the ui is first opened this is the data it will use
ui.set_initial_data(data)
- // open the new ui window
ui.open()
- // auto update every Master Controller tick
- ui.set_auto_update(1)
+ ui.set_auto_update(TRUE)
/obj/machinery/power/apc/proc/report()
return "[area.name] : [equipment]/[lighting]/[environ] ([lastused_equip+lastused_light+lastused_environ]) : [cell? cell.percent() : "N/C"] ([charging])"
@@ -943,75 +968,74 @@
area.power_equip = (equipment > 1)
area.power_environ = (environ > 1)
else
- area.power_light = 0
- area.power_equip = 0
- area.power_environ = 0
+ area.power_light = FALSE
+ area.power_equip = FALSE
+ area.power_environ = FALSE
area.power_change()
/obj/machinery/power/apc/proc/isWireCut(var/wireIndex)
return wires.IsIndexCut(wireIndex)
-
-/obj/machinery/power/apc/proc/can_use(mob/user as mob, var/loud = 0) //used by attack_hand() and Topic()
+/obj/machinery/power/apc/proc/can_use(mob/user, var/loud = 0) //used by attack_hand() and Topic()
if (user.stat)
- to_chat(user, "You must be conscious to use [src]!")
- return 0
+ to_chat(user, SPAN_WARNING("You must be conscious to use [src]!"))
+ return FALSE
if(!user.client)
- return 0
+ return FALSE
if(inoperable())
- return 0
+ return FALSE
if(!user.IsAdvancedToolUser())
- return 0
+ return FALSE
if(user.restrained())
- to_chat(user, "You must have free hands to use [src].")
- return 0
+ to_chat(user, SPAN_WARNING("You must have free hands to use [src]."))
+ return FALSE
if(user.lying)
- to_chat(user, "You must stand to use [src]!")
- return 0
- autoflag = 5
- if (istype(user, /mob/living/silicon))
- var/permit = 0 // Malfunction variable. If AI hacks APC it can control it even without AI control wire.
+ to_chat(user, SPAN_WARNING("You must stand to use [src]!"))
+ return FALSE
+
+ if (issilicon(user))
+ var/permit = FALSE // Malfunction variable. If AI hacks APC it can control it even without AI control wire.
var/mob/living/silicon/ai/AI = user
var/mob/living/silicon/robot/robot = user
if(hacker)
if(hacker == AI)
- permit = 1
+ permit = TRUE
else if(istype(robot) && robot.connected_ai && robot.connected_ai == hacker) // Cyborgs can use APCs hacked by their AI
- permit = 1
+ permit = TRUE
if(aidisabled && !permit)
if(!loud)
- to_chat(user, "\The [src] have AI control disabled!")
- return 0
+ to_chat(user, SPAN_DANGER("\The [src] have AI control disabled!"))
+ return FALSE
else
- if (!in_range(src, user) || !istype(src.loc, /turf))
- return 0
+ if (!in_range(src, user) || !isturf(loc))
+ return FALSE
var/mob/living/carbon/human/H = user
if (istype(H))
if(H.getBrainLoss() >= 60)
- H.visible_message("[H] stares cluelessly at [src] and drools.")
- return 0
+ H.visible_message(SPAN_DANGER("[H] stares cluelessly at [src] and drools."))
+ return FALSE
else if(prob(H.getBrainLoss()))
- to_chat(user, "You momentarily forget how to use [src].")
- return 0
- return 1
+ to_chat(user, SPAN_DANGER("You momentarily forget how to use [src]."))
+ return FALSE
+ return TRUE
/obj/machinery/power/apc/Topic(href, href_list)
if(..())
- return 1
+ return TRUE
if(!can_use(usr, 1))
- return 1
+ return TRUE
if (href_list["lmode"])
- src.toggle_nightlight(href_list["lmode"])
+ toggle_nightlight(href_list["lmode"])
update_icon()
- return 1
+ return TRUE
- else if(!istype(usr, /mob/living/silicon) && (locked && !emagged))
+ else if(!issilicon(usr) && (locked && !emagged))
// Shouldn't happen, this is here to prevent href exploits
to_chat(usr, "You must unlock the panel to use this!")
- return 1
+ return TRUE
else if (href_list["emergency_lights"])
emergency_lights = href_list["emergency_lights"] != "off"
@@ -1020,7 +1044,7 @@
L.no_emergency = emergency_lights //If there was an override set on creation, keep that override
INVOKE_ASYNC(L, /obj/machinery/light/.proc/update, FALSE)
CHECK_TICK
- return 1
+ return TRUE
if (href_list["lock"])
coverlocked = !coverlocked
@@ -1036,7 +1060,7 @@
else if (href_list["cmode"])
chargemode = !chargemode
if(!chargemode)
- charging = 0
+ charging = CHARGING_OFF
update_icon()
else if (href_list["eqp"])
@@ -1058,70 +1082,57 @@
update()
else if (href_list["overload"])
- if(istype(usr, /mob/living/silicon))
- src.overload_lighting()
+ if(issilicon(usr))
+ overload_lighting()
else if (href_list["toggleaccess"])
- if(istype(usr, /mob/living/silicon))
+ if(issilicon(usr))
if(emagged || (stat & (BROKEN|MAINT)))
to_chat(usr, "The APC does not respond to the command.")
else
locked = !locked
update_icon()
- return 0
+ return FALSE
/obj/machinery/power/apc/proc/toggle_breaker()
operating = !operating
- src.update()
+ update()
update_icon()
/obj/machinery/power/apc/proc/ion_act()
if(prob(3))
- src.locked = 1
- if (src.cell.charge > 0)
- src.cell.charge = 0
+ locked = TRUE
+ if (cell.charge > 0)
+ cell.charge = 0
cell.corrupt()
update_icon()
var/datum/effect/effect/system/smoke_spread/smoke = new /datum/effect/effect/system/smoke_spread()
- smoke.set_up(3, 0, src.loc)
+ smoke.set_up(3, 0, loc)
smoke.attach(src)
smoke.start()
spark(src, 5, alldirs)
- visible_message("The [src.name] suddenly lets out a blast of smoke and some sparks!", \
- "You hear sizzling electronics.")
+ visible_message(SPAN_DANGER("The [name] suddenly lets out a blast of smoke and some sparks!"), \
+ SPAN_DANGER("You hear sizzling electronics."))
/obj/machinery/power/apc/surplus()
- if(terminal)
- return terminal.surplus()
- else
- return 0
+ return terminal?.surplus()
/obj/machinery/power/apc/proc/last_surplus()
- if(terminal && terminal.powernet)
- return terminal.powernet.last_surplus()
- else
- return 0
+ return terminal?.powernet?.last_surplus()
//Returns 1 if the APC should attempt to charge
/obj/machinery/power/apc/proc/attempt_charging()
- return (chargemode && charging == 1 && operating)
-
+ return (chargemode && charging == CHARGING_ON && operating)
/obj/machinery/power/apc/draw_power(var/amount)
- if(terminal && terminal.powernet)
- return terminal.powernet.draw_power(amount)
- return 0
+ return terminal?.powernet?.draw_power(amount)
/obj/machinery/power/apc/avail()
- if(terminal)
- return terminal.avail()
- else
- return 0
+ return terminal?.avail()
/obj/machinery/power/apc/machinery_process()
-
if(stat & (BROKEN|MAINT))
return
if(!area.requires_power)
@@ -1130,7 +1141,7 @@
update()
queue_icon_update()
failure_timer--
- force_update = 1
+ force_update = TRUE
return
lastused_light = area.usage(LIGHT)
@@ -1148,7 +1159,7 @@
var/excess = surplus()
- if(!src.avail())
+ if(!avail())
main_status = 0
else if(excess < 0)
main_status = 1
@@ -1172,23 +1183,22 @@
if( (cell.charge/CELLRATE + excess) >= lastused_total) // can we draw enough from cell+grid to cover last usage?
var/draw = draw_power(excess)
cell.charge = min(cell.maxcharge, cell.charge + CELLRATE * draw) //recharge with what we can
- charging = 0
+ charging = CHARGING_OFF
else // not enough power available to run the last tick!
- charging = 0
+ charging = CHARGING_OFF
chargecount = 0
// This turns everything off in the case that there is still a charge left on the battery, just not enough to run the room.
- equipment = autoset(equipment, 0)
- lighting = autoset(lighting, 0)
- environ = autoset(environ, 0)
- autoflag = 0
-
+ equipment = autoset(equipment, CHANNEL_OFF)
+ lighting = autoset(lighting, CHANNEL_OFF)
+ environ = autoset(environ, CHANNEL_OFF)
+ autoflag = AUTOFLAG_OFF
// Set channels depending on how much charge we have left
update_channels()
// now trickle-charge the cell
lastused_charging = 0 // Clear the variable for new use.
- if(src.attempt_charging())
+ if(attempt_charging())
if(excess > 0) // check to make sure we have enough to charge
// Max charge is capped to % per second constant
var/ch = min(excess*CELLRATE, cell.maxcharge*chargelevel)
@@ -1198,13 +1208,13 @@
lastused_charging = ch
lastused_total += ch // Sensors need this to stop reporting APC charging as "Other" load
else
- charging = 0 // stop charging
+ charging = CHARGING_OFF // stop charging
chargecount = 0
// show cell as fully charged if so
if(cell.charge >= cell.maxcharge)
cell.charge = cell.maxcharge
- charging = 2
+ charging = CHARGING_FULL
if(chargemode)
if(!charging)
@@ -1216,24 +1226,24 @@
if(chargecount >= 10)
chargecount = 0
- charging = 1
+ charging = CHARGING_ON
else // chargemode off
- charging = 0
+ charging = CHARGING_ON
chargecount = 0
else // no cell, switch everything off
- charging = 0
+ charging = CHARGING_OFF
chargecount = 0
- equipment = autoset(equipment, 0)
- lighting = autoset(lighting, 0)
- environ = autoset(environ, 0)
+ equipment = autoset(equipment, CHANNEL_OFF)
+ lighting = autoset(lighting, CHANNEL_OFF)
+ environ = autoset(environ, CHANNEL_OFF)
power_alarm.triggerAlarm(loc, src)
- autoflag = 0
+ autoflag = AUTOFLAG_OFF
// update icon & area power if anything changed
if(last_lt != lighting || last_eq != equipment || last_en != environ || force_update)
- force_update = 0
+ force_update = FALSE
queue_icon_update()
update()
else if (last_ch != charging)
@@ -1247,63 +1257,59 @@
longtermpower -= 2
if((cell.percent() > 30) || longtermpower > 0) // Put most likely at the top so we don't check it last, effeciency 101
- if(autoflag != 3)
- equipment = autoset(equipment, 1)
- lighting = autoset(lighting, 1)
- environ = autoset(environ, 1)
- autoflag = 3
+ if(autoflag != AUTOFLAG_ALL_ON)
+ equipment = autoset(equipment, CHANNEL_OFF_AUTO)
+ lighting = autoset(lighting, CHANNEL_OFF_AUTO)
+ environ = autoset(environ, CHANNEL_OFF_AUTO)
+ autoflag = AUTOFLAG_ALL_ON
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)
+ if(autoflag != AUTOFLAG_ENVIRON_LIGHTS_ON)
+ equipment = autoset(equipment, CHANNEL_ON)
+ lighting = autoset(lighting, CHANNEL_OFF_AUTO)
+ environ = autoset(environ, CHANNEL_OFF_AUTO)
power_alarm.triggerAlarm(loc, src)
- autoflag = 2
+ autoflag = AUTOFLAG_ENVIRON_LIGHTS_ON
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)
+ if((autoflag > AUTOFLAG_ENVIRON_ON && longtermpower < 0) || (autoflag > AUTOFLAG_ENVIRON_ON && longtermpower >= 0))
+ equipment = autoset(equipment, CHANNEL_ON)
+ lighting = autoset(lighting, CHANNEL_ON)
+ environ = autoset(environ, CHANNEL_OFF_AUTO)
power_alarm.triggerAlarm(loc, src)
- autoflag = 1
+ autoflag = AUTOFLAG_ENVIRON_ON
else // zero charge, turn all off
- if(autoflag != 0)
- equipment = autoset(equipment, 0)
- lighting = autoset(lighting, 0)
- environ = autoset(environ, 0)
+ if(autoflag != AUTOFLAG_OFF)
+ equipment = autoset(equipment, CHANNEL_OFF)
+ lighting = autoset(lighting, CHANNEL_OFF)
+ environ = autoset(environ, CHANNEL_OFF)
power_alarm.triggerAlarm(loc, src)
- autoflag = 0
+ autoflag = AUTOFLAG_OFF
-// val 0=off, 1=off(auto) 2=on 3=on(auto)
-// on 0=off, 1=on, 2=autooff
+/obj/machinery/power/apc/proc/autoset(var/val, var/on)
+ if(on == CHANNEL_EQUIPMENT)
+ if(val == CHANNEL_ON)
+ return CHANNEL_OFF
+ else if(val == CHANNEL_ON_AUTO)
+ return CHANNEL_OFF_AUTO
-obj/machinery/power/apc/proc/autoset(var/val, var/on)
- if(on==0)
- if(val==2) // if on, return off
- return 0
- else if(val==3) // if auto-on, return auto-off
- return 1
+ else if(on == CHANNEL_LIGHTING)
+ if(val == CHANNEL_OFF_AUTO)
+ return CHANNEL_ON_AUTO
- else if(on==1)
- if(val==1) // if auto-off, return auto-on
- return 3
-
- else if(on==2)
- if(val==3) // if auto-on, return auto-off
- return 1
+ else if(on == CHANNEL_ENVIRONMENT)
+ if(val == CHANNEL_ON_AUTO)
+ return CHANNEL_OFF_AUTO
return val
-
// damage and destruction acts
/obj/machinery/power/apc/emp_act(severity)
if(cell)
cell.emp_act(severity)
- lighting = 0
- equipment = 0
- environ = 0
+ lighting = CHANNEL_OFF
+ equipment = CHANNEL_OFF
+ environ = CHANNEL_OFF
update()
update_icon()
@@ -1316,12 +1322,10 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on)
queue_icon_update()
/obj/machinery/power/apc/ex_act(severity)
-
switch(severity)
if(1.0)
- //set_broken() //now qdel() do what we need
if (cell)
- cell.ex_act(1.0) // more lags woohoo
+ cell.ex_act(1.0)
qdel(src)
return
if(2.0)
@@ -1334,7 +1338,6 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on)
set_broken()
if (cell && prob(25))
cell.ex_act(3.0)
- return
/obj/machinery/power/apc/disconnect_terminal()
if(terminal)
@@ -1343,11 +1346,11 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on)
/obj/machinery/power/apc/proc/set_broken()
// Aesthetically much better!
- visible_message("[src]'s screen flickers with warnings briefly!")
+ visible_message(SPAN_NOTICE("[src]'s screen flickers with warnings briefly!"))
addtimer(CALLBACK(src, .proc/break_timer), rand(2, 5))
/obj/machinery/power/apc/proc/break_timer()
- src.visible_message("[src]'s screen suddenly explodes in rain of sparks and small debris!")
+ visible_message(SPAN_NOTICE("[src]'s screen suddenly explodes in rain of sparks and small debris!"))
stat |= BROKEN
operating = 0
queue_icon_update()
@@ -1392,21 +1395,21 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on)
/obj/machinery/power/apc/proc/setsubsystem(val)
if(cell && cell.charge > 0)
- return (val==1) ? 0 : val
- else if(val == 3)
- return 1
+ return (val == CHANNEL_OFF_AUTO) ? CHANNEL_OFF : val
+ else if(val == CHANNEL_ON_AUTO)
+ return CHANNEL_OFF_AUTO
else
- return 0
+ return CHANNEL_OFF
// Malfunction: Transfers APC under AI's control
/obj/machinery/power/apc/proc/ai_hack(var/mob/living/silicon/ai/A = null)
if(!A || !A.hacked_apcs || hacker || aidisabled || A.stat == DEAD)
- return 0
- src.hacker = A
+ return FALSE
+ hacker = A
A.hacked_apcs += src
- locked = 1
+ locked = TRUE
update_icon()
- return 1
+ return TRUE
/obj/machinery/power/apc/proc/update_time()
@@ -1416,12 +1419,57 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on)
var/goal = (delta_power > 0) ? (cell.charge) : (cell.maxcharge - cell.charge)
var/time_secs = (delta_power) ? ((goal / abs(delta_power)) / (round(world.time - last_time) / 10)) : (0)
- // If it is negative - we are discharging
if(delta_power < 0)
- charge_mode = 1
- else if(delta_power != 0)
- charge_mode = 0
+ charge_mode = CHARGE_MODE_DISCHARGE
+ else if(delta_power > 0)
+ charge_mode = CHARGE_MODE_CHARGE
else
- charge_mode = 2
+ charge_mode = CHARGE_MODE_STABLE
last_time = world.time
time = ((time_secs / 3600) > 1) ? ("[round(time_secs / 3600)] hours, [round((time_secs % 3600) / 60)] minutes") : ("[round(time_secs / 60)] minutes, [round(time_secs % 60)] seconds")
+
+#undef UPDATE_CELL_IN
+#undef UPDATE_OPENED1
+#undef UPDATE_OPENED2
+#undef UPDATE_MAINT
+#undef UPDATE_BROKE
+#undef UPDATE_BLUESCREEN
+#undef UPDATE_WIREEXP
+#undef UPDATE_ALLGOOD
+#undef APC_UPOVERLAY_CHARGING0
+#undef APC_UPOVERLAY_CHARGING1
+#undef APC_UPOVERLAY_CHARGING2
+#undef APC_UPOVERLAY_EQUIPMENT0
+#undef APC_UPOVERLAY_EQUIPMENT1
+#undef APC_UPOVERLAY_EQUIPMENT2
+#undef APC_UPOVERLAY_LIGHTING0
+#undef APC_UPOVERLAY_LIGHTING1
+#undef APC_UPOVERLAY_LIGHTING2
+#undef APC_UPOVERLAY_ENVIRON0
+#undef APC_UPOVERLAY_ENVIRON1
+#undef APC_UPOVERLAY_ENVIRON2
+#undef APC_UPOVERLAY_LOCKED
+#undef APC_UPOVERLAY_OPERATING
+#undef HAS_ELECTRONICS_NONE
+#undef HAS_ELECTRONICS_CONNECT
+#undef HAS_ELECTRONICS_SECURED
+#undef COVER_CLOSED
+#undef COVER_OPENED
+#undef COVER_REMOVED
+#undef CHARGING_OFF
+#undef CHARGING_ON
+#undef CHARGING_FULL
+#undef CHANNEL_OFF
+#undef CHANNEL_OFF_AUTO
+#undef CHANNEL_ON
+#undef CHANNEL_ON_AUTO
+#undef CHANNEL_EQUIPMENT
+#undef CHANNEL_LIGHTING
+#undef CHANNEL_ENVIRONMENT
+#undef CHARGE_MODE_CHARGE
+#undef CHARGE_MODE_DISCHARGE
+#undef CHARGE_MODE_STABLE
+#undef AUTOFLAG_OFF
+#undef AUTOFLAG_ENVIRON_ON
+#undef AUTOFLAG_ENVIRON_LIGHTS_ON
+#undef AUTOFLAG_ALL_ON
\ No newline at end of file
diff --git a/html/changelogs/apc_tidy.yml b/html/changelogs/apc_tidy.yml
new file mode 100644
index 00000000000..21082153897
--- /dev/null
+++ b/html/changelogs/apc_tidy.yml
@@ -0,0 +1,6 @@
+author: mikomyazaki
+
+delete-after: True
+
+changes:
+ - backend: "Tided up APC code, no player-facing changes."
\ No newline at end of file