#define AIRLOCK_WIRE_IDSCAN 1
#define AIRLOCK_WIRE_MAIN_POWER1 2
#define AIRLOCK_WIRE_MAIN_POWER2 3
#define AIRLOCK_WIRE_DOOR_BOLTS 4
#define AIRLOCK_WIRE_BACKUP_POWER1 5
#define AIRLOCK_WIRE_BACKUP_POWER2 6
#define AIRLOCK_WIRE_POWER_ASSIST 7
#define AIRLOCK_WIRE_AI_CONTROL 8
#define AIRLOCK_WIRE_ELECTRIFY 9
/*
* Airlock -- an airlock door.
*
*/
/*
New methods:
pulse - sends a pulse into a wire for hacking purposes
cut - cuts a wire and makes any necessary state changes
mend - mends a wire and makes any necessary state changes
isWireColorCut - returns 1 if that color wire is cut, or 0 if not
isWireCut - returns 1 if that wire (e.g. AIRLOCK_WIRE_DOOR_BOLTS) is cut, or 0 if not
canAIControl - 1 if the AI can control the airlock, 0 if not (then check canAIHack to see if it can hack in)
canAIHack - 1 if the AI can hack into the airlock to recover control, 0 if not. Also returns 0 if the AI does not *need* to hack it.
arePowerSystemsOn - 1 if the main or backup power are functioning, 0 if not. Does not check whether the power grid is charged or an APC has equipment on or anything like that. (Check (stat & NOPOWER) for that)
acceptsIDs - 1 if the airlock is accepting IDs, 0 if not
isAllPowerCut - 1 if the main and backup power both have cut wires.
regainMainPower - handles the effects of main power coming back on.
loseMainPower - handles the effects of main power going offline. Usually (if one isn't already running) spawn a thread to count down how long it will be offline - counting down won't happen if main power was completely cut along with backup power, though, the thread will just sleep.
loseBackupPower - handles the effects of backup power going offline.
regainBackupPower - handles the effects of main power coming back on.
canBoltsBeRaisedManually - 1 if bolts can be raised with a wrench.
shock - has a chance of electrocuting its target.
*/
//This generates the randomized airlock wire assignments for the game.
/proc/RandomAirlockWires()
//to make this not randomize the wires, just set index to 1 and increment it in the flag for loop (after doing everything else).
var/list/wires = list(0, 0, 0, 0, 0, 0, 0, 0, 0)
airlockIndexToFlag = list(0, 0, 0, 0, 0, 0, 0, 0, 0)
airlockIndexToWireColor = list(0, 0, 0, 0, 0, 0, 0, 0, 0)
airlockWireColorToIndex = list(0, 0, 0, 0, 0, 0, 0, 0, 0)
var/flagIndex = 1
for (var/flag=1, flag<512, flag+=flag)
var/valid = 0
while (!valid)
var/colorIndex = rand(1, 9)
if (wires[colorIndex]==0)
valid = 1
wires[colorIndex] = flag
airlockIndexToFlag[flagIndex] = flag
airlockIndexToWireColor[flagIndex] = colorIndex
airlockWireColorToIndex[colorIndex] = flagIndex
flagIndex+=1
return wires
/* Example:
Airlock wires color -> flag are { 64, 128, 256, 2, 16, 4, 8, 32, 1 }.
Airlock wires color -> index are { 7, 8, 9, 2, 5, 3, 4, 6, 1 }.
Airlock index -> flag are { 1, 2, 4, 8, 16, 32, 64, 128, 256 }.
Airlock index -> wire color are { 9, 4, 6, 7, 5, 8, 1, 2, 3 }.
*/
obj/machinery/door/airlock
name = "airlock"
icon = 'Door1.dmi'
var
blocked = null // true if door is welded shut
powered = 1.0 // true if the test light is on
locked = 0.0 // true if the door bolts are down (locked)
wires = 511 // bitmask representing the 9 internal wires. Defaults to all connected
// The wire conditions effect the "powered" and "locked" variables.
aiControlDisabled = 0 //If 1, AI control is disabled until the AI hacks back in and disables the lock. If 2, the AI has bypassed the lock. If -1, the control is enabled but the AI had bypassed it earlier, so if it is disabled again the AI would have no trouble getting back in.
secondsMainPowerLost = 0 //The number of seconds until power is restored.
secondsBackupPowerLost = 0 //The number of seconds until power is restored.
spawnPowerRestoreRunning = 0 //tells us if the power-restore thread is already running, so we don't start more than one.
aiDisabledIdScanner = 0 //Did the AI disable the ID scanner?
aiDisabledPowerAssist = 0 //Did the AI disable power assist?
aiHacking = 0 //Is the AI hacking back into the airlock after having its access blocked?
secondsElectrified = 0 //How many seconds remain until the door is no longer electrified. -1 if it is permanently electrified until someone fixes it.
/*
About the new airlock wires panel:
* An airlock wire dialog can be accessed by the normal way or by using wirecutters or a multitool on the door while the wire-panel is open. This would show the following wires, which you can either wirecut/mend or send a multitool pulse through. There are 9 wires.
* one wire from the ID scanner. Sending a pulse through this flashes the red light on the door (if the door has power). If you cut this wire, the door will stop recognizing valid IDs. (If the door has 0000 access, it still opens and closes, though)
* two wires for power. Sending a pulse through either one causes a breaker to trip, disabling the door for 10 seconds if backup power is connected, or 1 minute if not (or until backup power comes back on, whichever is shorter). Cutting either one disables the main door power, but unless backup power is also cut, the backup power re-powers the door in 10 seconds. While unpowered, the door may be crowbarred open, but bolts-raising will not work. Cutting these wires may electrocute the user.
* one wire for door bolts. Sending a pulse through this drops door bolts (whether the door is powered or not). Cutting this wire also drops the door bolts, and mending it does not raise them. If the wire is cut, trying to raise the door bolts will not work.
* two wires for backup power. Sending a pulse through either one causes a breaker to trip, but this does not disable it unless main power is down too (in which case it is disabled for 1 minute or however long it takes main power to come back, whichever is shorter). Cutting either one disables the backup door power (allowing it to be crowbarred open, but disabling bolts-raising), but may electocute the user.
* one wire for power assist. Sending a pulse through this while the door has power makes it raise the door bolts. Cutting this prevents manual bolts-raising with a wrench from working.
* one wire for AI control. Sending a pulse through this blocks AI control for a second or so (which is enough to see the AI control light on the panel dialog go off and back on again). Cutting this prevents the AI from controlling the door unless it has hacked the door through the power connection (which takes about a minute). If both main and backup power are cut, as well as this wire, then the AI cannot operate or hack the door at all.
* one wire for electrifying the door. Sending a pulse through this electrifies the door for 30 seconds. Cutting this wire electrifies the door, so that the next person to touch the door without insulated gloves gets electrocuted. (Currently it is also STAYING electrified until someone mends the wire)
*/
proc/pulse(var/wireColor)
//var/wireFlag = airlockWireColorToFlag[wireColor] //not used in this function
var/wireIndex = airlockWireColorToIndex[wireColor]
switch(wireIndex)
if(AIRLOCK_WIRE_IDSCAN)
//Sending a pulse through this flashes the red light on the door (if the door has power).
if ((src.arePowerSystemsOn()) && (!(stat & NOPOWER)))
flick("door_deny", src)
if (AIRLOCK_WIRE_MAIN_POWER1 || AIRLOCK_WIRE_MAIN_POWER2)
//Sending a pulse through either one causes a breaker to trip, disabling the door for 10 seconds if backup power is connected, or 1 minute if not (or until backup power comes back on, whichever is shorter).
src.loseMainPower()
if (AIRLOCK_WIRE_DOOR_BOLTS)
//one wire for door bolts. Sending a pulse through this drops door bolts (whether the door is powered or not).
if (src.locked!=1)
src.locked = 1
else
usr.client_mob() << "You hear a click from the bottom of the door."
if (AIRLOCK_WIRE_BACKUP_POWER1 || AIRLOCK_WIRE_BACKUP_POWER2)
//two wires for backup power. Sending a pulse through either one causes a breaker to trip, but this does not disable it unless main power is down too (in which case it is disabled for 1 minute or however long it takes main power to come back, whichever is shorter).
src.loseBackupPower()
if (AIRLOCK_WIRE_AI_CONTROL)
if (src.aiControlDisabled == 0)
src.aiControlDisabled = 1
else if (src.aiControlDisabled == -1)
src.aiControlDisabled = 2
src.updateDialog()
spawn(10)
if (src.aiControlDisabled == 1)
src.aiControlDisabled = 0
else if (src.aiControlDisabled == 2)
src.aiControlDisabled = -1
src.updateDialog()
if (AIRLOCK_WIRE_POWER_ASSIST)
//one wire for power assist. Sending a pulse through this while the door has power makes it raise the door bolts. Cutting this prevents manual bolts-raising with a wrench from working.
if (arePowerSystemsOn())
if (src.locked==1)
src.locked=0
src.updateDialog()
else
usr.client_mob() << "You hear a click or thump sound from inside the door."
if (AIRLOCK_WIRE_ELECTRIFY)
//one wire for electrifying the door. Sending a pulse through this electrifies the door for 30 seconds.
if (src.secondsElectrified!=-1)
if (src.secondsElectrified==0)
src.secondsElectrified = 30
spawn(10)
while (src.secondsElectrified>0)
src.secondsElectrified-=1
if (src.secondsElectrified<0)
src.secondsElectrified = 0
src.updateDialog()
sleep(10)
proc/cut(var/wireColor)
var/wireFlag = airlockWireColorToFlag[wireColor]
var/wireIndex = airlockWireColorToIndex[wireColor]
wires &= ~wireFlag
switch(wireIndex)
if(AIRLOCK_WIRE_MAIN_POWER1 || AIRLOCK_WIRE_MAIN_POWER2)
//Cutting either one disables the main door power, but unless backup power is also cut, the backup power re-powers the door in 10 seconds. While unpowered, the door may be crowbarred open, but bolts-raising will not work. Cutting these wires may electocute the user.
src.loseMainPower()
src.shock(usr, 50)
src.updateDialog()
if (AIRLOCK_WIRE_DOOR_BOLTS)
//Cutting this wire also drops the door bolts, and mending it does not raise them. (This is what happens now, except there are a lot more wires going to door bolts at present)
if (src.locked!=1)
src.locked = 1
src.updateDialog()
if (AIRLOCK_WIRE_BACKUP_POWER1 || AIRLOCK_WIRE_BACKUP_POWER2)
//Cutting either one disables the backup door power (allowing it to be crowbarred open, but disabling bolts-raising), but may electocute the user.
src.loseBackupPower()
src.shock(usr, 50)
src.updateDialog()
if (AIRLOCK_WIRE_AI_CONTROL)
//one wire for AI control. Cutting this prevents the AI from controlling the door unless it has hacked the door through the power connection (which takes about a minute). If both main and backup power are cut, as well as this wire, then the AI cannot operate or hack the door at all.
//aiControlDisabled: If 1, AI control is disabled until the AI hacks back in and disables the lock. If 2, the AI has bypassed the lock. If -1, the control is enabled but the AI had bypassed it earlier, so if it is disabled again the AI would have no trouble getting back in.
if (src.aiControlDisabled == 0)
src.aiControlDisabled = 1
else if (src.aiControlDisabled == -1)
src.aiControlDisabled = 2
src.updateDialog()
if (AIRLOCK_WIRE_ELECTRIFY)
//Cutting this wire electrifies the door, so that the next person to touch the door without insulated gloves gets electrocuted.
if (src.secondsElectrified != -1)
src.secondsElectrified = -1
proc/mend(var/wireColor)
var/wireFlag = airlockWireColorToFlag[wireColor]
var/wireIndex = airlockWireColorToIndex[wireColor] //not used in this function
wires |= wireFlag
switch(wireIndex)
if(AIRLOCK_WIRE_MAIN_POWER1 || AIRLOCK_WIRE_MAIN_POWER2)
if ((!src.isWireCut(AIRLOCK_WIRE_MAIN_POWER1)) && (!src.isWireCut(AIRLOCK_WIRE_MAIN_POWER2)))
src.regainMainPower()
src.shock(usr, 50)
src.updateDialog()
if (AIRLOCK_WIRE_BACKUP_POWER1 || AIRLOCK_WIRE_BACKUP_POWER2)
if ((!src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER1)) && (!src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER2)))
src.regainBackupPower()
src.shock(usr, 50)
src.updateDialog()
if (AIRLOCK_WIRE_AI_CONTROL)
//one wire for AI control. Cutting this prevents the AI from controlling the door unless it has hacked the door through the power connection (which takes about a minute). If both main and backup power are cut, as well as this wire, then the AI cannot operate or hack the door at all.
//aiControlDisabled: If 1, AI control is disabled until the AI hacks back in and disables the lock. If 2, the AI has bypassed the lock. If -1, the control is enabled but the AI had bypassed it earlier, so if it is disabled again the AI would have no trouble getting back in.
if (src.aiControlDisabled == 1)
src.aiControlDisabled = 0
else if (src.aiControlDisabled == 2)
src.aiControlDisabled = -1
src.updateDialog()
if (AIRLOCK_WIRE_ELECTRIFY)
if (src.secondsElectrified == -1)
src.secondsElectrified = 0
proc/isElectrified()
return src.secondsElectrified!=0
proc/isWireColorCut(var/wireColor)
var/wireFlag = airlockWireColorToFlag[wireColor]
return ((src.wires & wireFlag) == 0)
proc/isWireCut(var/wireIndex)
var/wireFlag = airlockIndexToFlag[wireIndex]
return ((src.wires & wireFlag) == 0)
proc/canAIControl()
return ((src.aiControlDisabled!=1) && (!src.isAllPowerCut()));
proc/canAIHack()
return ((src.aiControlDisabled==1) && (!src.isAllPowerCut()));
proc/arePowerSystemsOn()
return (src.secondsMainPowerLost==0 || src.secondsBackupPowerLost==0)
acceptsIDs()
return !(src.isWireCut(AIRLOCK_WIRE_IDSCAN) || aiDisabledIdScanner)
proc/isAllPowerCut()
var/retval=0
if (src.isWireCut(AIRLOCK_WIRE_MAIN_POWER1) || src.isWireCut(AIRLOCK_WIRE_MAIN_POWER2))
if (src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER1) || src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER2))
retval=1
return retval
proc/regainMainPower()
if (src.secondsMainPowerLost > 0)
src.secondsMainPowerLost = 0
proc/loseMainPower()
if (src.secondsMainPowerLost <= 0)
src.secondsMainPowerLost = 60
if (src.secondsBackupPowerLost < 10)
src.secondsBackupPowerLost = 10
if (!src.spawnPowerRestoreRunning)
src.spawnPowerRestoreRunning = 1
spawn(0)
var/cont = 1
while (cont)
sleep(10)
cont = 0
if (src.secondsMainPowerLost>0)
if ((!src.isWireCut(AIRLOCK_WIRE_MAIN_POWER1)) && (!src.isWireCut(AIRLOCK_WIRE_MAIN_POWER2)))
src.secondsMainPowerLost -= 1
src.updateDialog()
cont = 1
if (src.secondsBackupPowerLost>0)
if ((!src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER1)) && (!src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER2)))
src.secondsBackupPowerLost -= 1
src.updateDialog()
cont = 1
src.spawnPowerRestoreRunning = 0
src.updateDialog()
proc/loseBackupPower()
if (src.secondsBackupPowerLost < 60)
src.secondsBackupPowerLost = 60
proc/regainBackupPower()
if (src.secondsBackupPowerLost > 0)
src.secondsBackupPowerLost = 0
proc/canBoltsBeRaisedManually()
return (!src.isWireCut(AIRLOCK_WIRE_POWER_ASSIST)) && arePowerSystemsOn() && (!isWireCut(AIRLOCK_WIRE_DOOR_BOLTS))
//borrowed from the grille's get_connection
proc/get_connection()
var/turf/T = src.loc
if(!istype(T, /turf/station/floor))
return
for(var/obj/cable/C in T)
if(C.d1 == 0)
return C.netnum
return 0
// shock user with probability prb (if all connections & power are working)
// returns 1 if shocked, 0 otherwise
// The preceding comment was borrowed from the grille's shock script
proc/shock(mob/user, prb, bypassPowerCheck)
if(!prob(prb))
return 0
var/net = null
if (!bypassPowerCheck)
net = get_connection() // find the powernet of the connected cable
if(!net) // cable is unpowered
return 0
return src.electrocute(user, prb, net)
proc/updateIconState()
var/d = src.density
if (src.blocked) // true if welded shut
d = "l"
src.icon_state = text("[]door[]", (src.p_open ? "o_" : null), d)
return
attack_ai(mob/user as mob)
if (!src.canAIControl())
if (src.canAIHack())
src.hack(user)
return
//Separate interface for the AI.
user.machine = src
var/t1 = text("Airlock Control
\n")
if (src.secondsMainPowerLost > 0)
if ((!src.isWireCut(AIRLOCK_WIRE_MAIN_POWER1)) && (!src.isWireCut(AIRLOCK_WIRE_MAIN_POWER2)))
t1 += text("Main power is offline for [] seconds.
\n", src.secondsMainPowerLost)
else
t1 += text("Main power is offline indefinitely.
\n")
else
t1 += text("Main power is online.")
if (src.secondsBackupPowerLost > 0)
if ((!src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER1)) && (!src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER2)))
t1 += text("Backup power is offline for [] seconds.
\n", src.secondsBackupPowerLost)
else
t1 += text("Backup power is offline indefinitely.
\n")
else if (src.secondsMainPowerLost > 0)
t1 += text("Backup power is online.")
else
t1 += text("Backup power is offline, but will turn on if main power fails.")
t1 += "
\n"
if (src.isWireCut(AIRLOCK_WIRE_IDSCAN))
t1 += text("IdScan wire is cut.
\n")
else if (src.arePowerSystemsOn() && (!(stat & NOPOWER)))
if (src.aiDisabledIdScanner)
t1 += text("IdScan disabled. Enable?
\n", src)
else
t1 += text("IdScan enabled. Disable?
\n", src)
else
if (src.aiDisabledIdScanner)
t1 += text("IdScan disabled. Cannot enable - power is off.
\n")
else
t1 += text("IdScan enabled. Cannot disable - power is off.
\n")
if (src.isWireCut(AIRLOCK_WIRE_MAIN_POWER1))
t1 += text("Main Power Input wire is cut.
\n")
if (src.isWireCut(AIRLOCK_WIRE_MAIN_POWER2))
t1 += text("Main Power Output wire is cut.
\n")
if (src.secondsMainPowerLost == 0)
t1 += text("Temporarily disrupt main power?.
\n", src)
if (src.secondsBackupPowerLost == 0)
t1 += text("Temporarily disrupt backup power?.
\n", src)
if (src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER1))
t1 += text("Backup Power Input wire is cut.
\n")
if (src.isWireCut(AIRLOCK_WIRE_BACKUP_POWER2))
t1 += text("Backup Power Output wire is cut.
\n")
if (src.isWireCut(AIRLOCK_WIRE_DOOR_BOLTS))
t1 += text("Door bolt drop wire is cut.
\n")
else if (!src.locked)
t1 += text("Door bolts are up. Drop them?
\n", src)
else if (src.isWireCut(AIRLOCK_WIRE_POWER_ASSIST))
t1 += text("Power assist wire is cut.
\n")
else
t1 += text("Door bolts are down.")
if (src.arePowerSystemsOn() && (!(stat & NOPOWER)))
t1 += text(" Raise?
\n", src)
else
t1 += text(" Cannot raise door bolts due to power failure.
\n")
if (src.isWireCut(AIRLOCK_WIRE_ELECTRIFY))
t1 += text("Electrification wire is cut.
\n")
if (src.secondsElectrified==-1)
t1 += text("Door is electrified indefinitely. Un-electrify it?
\n", src)
else if (src.secondsElectrified>0)
t1 += text("Door is electrified temporarily ([] seconds). Un-electrify it?
\n", src.secondsElectrified, src)
else
t1 += text("Door is not electrified. Electrify it for 30 seconds? Or, Electrify it indefinitely until someone cancels the electrification?
\n", src, src)
if (src.blocked)
t1 += text("Door appears to have been welded shut.
\n")
else if (!src.locked)
if (src.density)
if (src.arePowerSystemsOn() && (!(stat & NOPOWER)))
t1 += text("Open door
\n", src)
else
t1 += text("Cannot open door due to power failure.
\n")
else
if (src.arePowerSystemsOn() && (!(stat & NOPOWER)))
t1 += text("Close door
\n", src)
else
t1 += text("Cannot close door due to power failure.
\n")
t1 += text("