From 28d58598f6809d5c4ebbc03e834ccfd1cffb525b Mon Sep 17 00:00:00 2001 From: Giacomand Date: Wed, 10 Jul 2013 12:50:04 +0100 Subject: [PATCH] Converted the old air alarm wires to use the more structured datum wires. --- code/datums/wires/alarm.dm | 94 ++++++++++++++ code/game/machinery/alarm.dm | 240 +++-------------------------------- code/global.dm | 9 -- tgstation.dme | 1 + 4 files changed, 115 insertions(+), 229 deletions(-) create mode 100644 code/datums/wires/alarm.dm diff --git a/code/datums/wires/alarm.dm b/code/datums/wires/alarm.dm new file mode 100644 index 00000000000..2c826e6d527 --- /dev/null +++ b/code/datums/wires/alarm.dm @@ -0,0 +1,94 @@ + +/datum/wires/alarm + holder_type = /obj/machinery/alarm + wire_count = 5 + +var/const/AALARM_WIRE_IDSCAN = 1 +var/const/AALARM_WIRE_POWER = 2 +var/const/AALARM_WIRE_SYPHON = 4 +var/const/AALARM_WIRE_AI_CONTROL = 8 +var/const/AALARM_WIRE_AALARM = 16 + + +/datum/wires/alarm/CanUse(var/mob/living/L) + var/obj/machinery/alarm/A = holder + if(A.wiresexposed) + return 1 + return 0 + +/datum/wires/alarm/GetInteractWindow() + var/obj/machinery/alarm/A = holder + . += ..() + . += text("
\n[(A.locked ? "The Air Alarm is locked." : "The Air Alarm is unlocked.")]
\n[((A.shorted || (A.stat & (NOPOWER|BROKEN))) ? "The Air Alarm is offline." : "The Air Alarm is working properly!")]
\n[(A.aidisabled ? "The 'AI control allowed' light is off." : "The 'AI control allowed' light is on.")]") + +/datum/wires/alarm/UpdateCut(var/index, var/mended) + var/obj/machinery/alarm/A = holder + switch(index) + if(AALARM_WIRE_IDSCAN) + if(!mended) + A.locked = 1 + //world << "Idscan wire cut" + + if(AALARM_WIRE_POWER) + A.shock(usr, 50) + A.shorted = !mended + A.update_icon() + //world << "Power wire cut" + + if (AALARM_WIRE_AI_CONTROL) + if (A.aidisabled == !mended) + A.aidisabled = mended + //world << "AI Control Wire Cut" + + if(AALARM_WIRE_SYPHON) + if(!mended) + A.mode = 3 // AALARM_MODE_PANIC + A.apply_mode() + //world << "Syphon Wire Cut" + + if(AALARM_WIRE_AALARM) + if (A.alarm_area.atmosalert(2)) + A.post_alert(2) + A.update_icon() + +/datum/wires/alarm/UpdatePulsed(var/index) + var/obj/machinery/alarm/A = holder + switch(index) + if(AALARM_WIRE_IDSCAN) + A.locked = !A.locked + // world << "Idscan wire pulsed" + + if (AALARM_WIRE_POWER) + // world << "Power wire pulsed" + if(A.shorted == 0) + A.shorted = 1 + A.update_icon() + + spawn(12000) + if(A.shorted == 1) + A.shorted = 0 + A.update_icon() + + + if (AALARM_WIRE_AI_CONTROL) + // world << "AI Control wire pulsed" + if (A.aidisabled == 0) + A.aidisabled = 1 + A.updateDialog() + spawn(100) + if (A.aidisabled == 1) + A.aidisabled = 0 + + if(AALARM_WIRE_SYPHON) + // world << "Syphon wire pulsed" + if(A.mode == 1) // AALARM_MODE_SCRUB + A.mode = 3 // AALARM_MODE_PANIC + else + A.mode = 1 // AALARM_MODE_SCRUB + A.apply_mode() + + if(AALARM_WIRE_AALARM) + // world << "Aalarm wire pulsed" + if (A.alarm_area.atmosalert(0)) + A.post_alert(0) + A.update_icon() diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index dccfb930f63..eb25e49cfad 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -1,28 +1,4 @@ //This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:31 - - -/proc/RandomAAlarmWires() - //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/AAlarmwires = list(0, 0, 0, 0, 0) - AAlarmIndexToFlag = list(0, 0, 0, 0, 0) - AAlarmIndexToWireColor = list(0, 0, 0, 0, 0) - AAlarmWireColorToIndex = list(0, 0, 0, 0, 0) - var/flagIndex = 1 - for (var/flag=1, flag<32, flag+=flag) - var/valid = 0 - while (!valid) - var/colorIndex = rand(1, 5) - if (AAlarmwires[colorIndex]==0) - valid = 1 - AAlarmwires[colorIndex] = flag - AAlarmIndexToFlag[flagIndex] = flag - AAlarmIndexToWireColor[flagIndex] = colorIndex - AAlarmWireColorToIndex[colorIndex] = flagIndex - flagIndex+=1 - return AAlarmwires - - - // A datum for dealing with threshold limit values // used in /obj/machinery/alarm /datum/tlv @@ -51,6 +27,20 @@ max1 = other.max1 max2 = other.max2 +#define AALARM_MODE_SCRUBBING 1 +#define AALARM_MODE_VENTING 2 //makes draught +#define AALARM_MODE_PANIC 3 //constantly sucks all air +#define AALARM_MODE_REPLACEMENT 4 //sucks off all air, then refill and swithes to scrubbing +#define AALARM_MODE_OFF 5 + +#define AALARM_SCREEN_MAIN 1 +#define AALARM_SCREEN_VENT 2 +#define AALARM_SCREEN_SCRUB 3 +#define AALARM_SCREEN_MODE 4 +#define AALARM_SCREEN_SENSORS 5 + +#define AALARM_REPORT_TIMEOUT 100 + /obj/machinery/alarm name = "alarm" icon = 'icons/obj/monitors.dmi' @@ -64,36 +54,19 @@ var/frequency = 1439 //var/skipprocess = 0 //Experimenting var/alarm_frequency = 1437 -#define AALARM_REPORT_TIMEOUT 100 + var/datum/radio_frequency/radio_connection var/locked = 1 + var/datum/wires/alarm/wires = null var/wiresexposed = 0 // If it's been screwdrivered open. var/aidisabled = 0 var/AAlarmwires = 31 var/shorted = 0 var/buildstage = 2 // 2 = complete, 1 = no wires, 0 = circuit gone - // Uses code from apc.dm -#define AALARM_WIRE_IDSCAN 1 //Added wires -#define AALARM_WIRE_POWER 2 -#define AALARM_WIRE_SYPHON 3 -#define AALARM_WIRE_AI_CONTROL 4 -#define AALARM_WIRE_AALARM 5 - - -#define AALARM_MODE_SCRUBBING 1 -#define AALARM_MODE_VENTING 2 //makes draught -#define AALARM_MODE_PANIC 3 //constantly sucks all air -#define AALARM_MODE_REPLACEMENT 4 //sucks off all air, then refill and swithes to scrubbing -#define AALARM_MODE_OFF 5 var/mode = AALARM_MODE_SCRUBBING -#define AALARM_SCREEN_MAIN 1 -#define AALARM_SCREEN_VENT 2 -#define AALARM_SCREEN_SCRUB 3 -#define AALARM_SCREEN_MODE 4 -#define AALARM_SCREEN_SENSORS 5 var/screen = AALARM_SCREEN_MAIN var/area_uid var/area/alarm_area @@ -145,6 +118,7 @@ /obj/machinery/alarm/New(nloc, ndir, nbuild) ..() + wires = new(src) if(nloc) loc = nloc @@ -201,31 +175,6 @@ user << browse(null, "window=air_alarm") return - if(wiresexposed && (!istype(user, /mob/living/silicon))) - var/t1 = text("Access Panel
\n") - var/list/AAlarmwires = list( - "Orange" = 1, - "Dark red" = 2, - "White" = 3, - "Yellow" = 4, - "Black" = 5, - ) - for(var/wiredesc in AAlarmwires) - var/is_uncut = src.AAlarmwires & AAlarmWireColorToFlag[AAlarmwires[wiredesc]] - t1 += "[wiredesc] wire: " - if(!is_uncut) - t1 += "Mend" - - else - t1 += "Cut " - t1 += "Pulse " - - t1 += "
" - t1 += text("
\n[(src.locked ? "The Air Alarm is locked." : "The Air Alarm is unlocked.")]
\n[((src.shorted || (stat & (NOPOWER|BROKEN))) ? "The Air Alarm is offline." : "The Air Alarm is working properly!")]
\n[(src.aidisabled ? "The 'AI control allowed' light is off." : "The 'AI control allowed' light is on.")]") - t1 += text("

Close

") - user << browse(t1, "window=AAlarmwires") - onclose(user, "AAlarmwires") - if(!shorted) //user << browse(return_text(),"window=air_alarm") //onclose(user, "air_alarm") @@ -235,135 +184,11 @@ popup.open() refresh_all() - return - - -/obj/machinery/alarm/proc/isWireColorCut(var/wireColor) - var/wireFlag = AAlarmWireColorToFlag[wireColor] - return ((src.AAlarmwires & wireFlag) == 0) - -/obj/machinery/alarm/proc/isWireCut(var/wireIndex) - var/wireFlag = AAlarmIndexToFlag[wireIndex] - return ((src.AAlarmwires & wireFlag) == 0) - -/obj/machinery/alarm/proc/cut(var/wireColor) - var/wireFlag = AAlarmWireColorToFlag[wireColor] - var/wireIndex = AAlarmWireColorToIndex[wireColor] - AAlarmwires &= ~wireFlag - switch(wireIndex) - if(AALARM_WIRE_IDSCAN) - src.locked = 1 - //world << "Idscan wire cut" - - if(AALARM_WIRE_POWER) - src.shock(usr, 50) - src.shorted = 1 - update_icon() - //world << "Power wire cut" - - if (AALARM_WIRE_AI_CONTROL) - if (src.aidisabled == 0) - src.aidisabled = 1 - //world << "AI Control Wire Cut" - - if(AALARM_WIRE_SYPHON) - mode = AALARM_MODE_PANIC - apply_mode() - //world << "Syphon Wire Cut" - - if(AALARM_WIRE_AALARM) - - if (alarm_area.atmosalert(2)) - post_alert(2) - spawn(1) - src.updateUsrDialog() - update_icon() - - //world << "AAlarm Wire Cut" - - src.updateDialog() - update_icon() + if(wiresexposed && (!istype(user, /mob/living/silicon))) + wires.Interact(user) return -/obj/machinery/alarm/proc/mend(var/wireColor) - var/wireFlag = AAlarmWireColorToFlag[wireColor] - var/wireIndex = AAlarmWireColorToIndex[wireColor] //not used in this function - AAlarmwires |= wireFlag - switch(wireIndex) - if(AALARM_WIRE_IDSCAN) - //world << "Idscan wire mended" - - if(AALARM_WIRE_POWER) - src.shorted = 0 - src.shock(usr, 50) - update_icon() - //world << "Power wire mended" - - if(AALARM_WIRE_AI_CONTROL) - if (src.aidisabled == 1) - src.aidisabled = 0 - //world << "AI Cont. wire mended" - - - // if(AALARM_WIRE_SYPHON) - // world << "Syphon Wire mended" - - - // if(AALARM_WIRE_AALARM) - //world << "AAlarm Wire mended" - - update_icon() - src.updateDialog() - return - -/obj/machinery/alarm/proc/pulse(var/wireColor) - //var/wireFlag = AAlarmWireColorToFlag[wireColor] //not used in this function - var/wireIndex = AAlarmWireColorToIndex[wireColor] - switch(wireIndex) - if(AALARM_WIRE_IDSCAN) //unlocks for 30 seconds, if you have a better way to hack I'm all ears - src.locked = 0 - spawn(300) - src.locked = 1 - //world << "Idscan wire pulsed" - - if (AALARM_WIRE_POWER) - // world << "Power wire pulsed" - if(shorted == 0) - shorted = 1 - update_icon() - - spawn(1200) - if(shorted == 1) - shorted = 0 - update_icon() - - - if (AALARM_WIRE_AI_CONTROL) - // world << "AI Control wire pulsed" - if (src.aidisabled == 0) - src.aidisabled = 1 - src.updateDialog() - spawn(10) - if (src.aidisabled == 1) - src.aidisabled = 0 - src.updateDialog() - - if(AALARM_WIRE_SYPHON) - // world << "Syphon wire pulsed" - mode = AALARM_MODE_REPLACEMENT - apply_mode() - - if(AALARM_WIRE_AALARM) - // world << "Aalarm wire pulsed" - if (alarm_area.atmosalert(0)) - post_alert(0) - spawn(1) - src.updateUsrDialog() - update_icon() - - src.updateDialog() - return /obj/machinery/alarm/proc/shock(mob/user, prb) if((stat & (NOPOWER))) // unpowered, no shock @@ -702,33 +527,8 @@ table tr:first-child th:first-child { border: none;} if (!istype(usr, /mob/living/silicon)) usr.unset_machine() usr << browse(null, "window=air_alarm") - usr << browse(null, "window=AAlarmwires") return - if (href_list["AAlarmwires"]) - var/t1 = text2num(href_list["AAlarmwires"]) - if (!( istype(usr.get_active_hand(), /obj/item/weapon/wirecutters) )) - usr << "You need wirecutters!" - return - if (src.isWireColorCut(t1)) - src.mend(t1) - else - src.cut(t1) - spawn(1) - src.updateUsrDialog() - else if (href_list["pulse"]) - var/t1 = text2num(href_list["pulse"]) - if (!istype(usr.get_active_hand(), /obj/item/device/multitool)) - usr << "You need a multitool!" - return - if (src.isWireColorCut(t1)) - usr << "You can't pulse a cut wire." - return - else - src.pulse(t1) - spawn(1) - src.updateUsrDialog() - if(href_list["command"]) @@ -988,7 +788,7 @@ table tr:first-child th:first-child { border: none;} if(stat & (NOPOWER|BROKEN)) user << "It does nothing" else - if(src.allowed(usr) && !isWireCut(AALARM_WIRE_IDSCAN)) + if(src.allowed(usr) && !wires.IsIndexCut(AALARM_WIRE_IDSCAN)) locked = !locked user << "\blue You [ locked ? "lock" : "unlock"] the Air Alarm interface." src.updateUsrDialog() diff --git a/code/global.dm b/code/global.dm index 0b5af7d9149..e75a8d4e468 100644 --- a/code/global.dm +++ b/code/global.dm @@ -134,15 +134,6 @@ var/shuttlecoming = 0 var/join_motd = null var/forceblob = 0 - //airlockWireColorToIndex takes a number representing the wire color, e.g. the orange wire is always 1, the dark red wire is always 2, etc. It returns the index for whatever that wire does. - //airlockIndexToWireColor does the opposite thing - it takes the index for what the wire does, for example AIRLOCK_WIRE_IDSCAN is 1, AIRLOCK_WIRE_POWER1 is 2, etc. It returns the wire color number. - //airlockWireColorToFlag takes the wire color number and returns the flag for it (1, 2, 4, 8, 16, etc) - -var/list/AAlarmWireColorToFlag = RandomAAlarmWires() -var/list/AAlarmIndexToFlag -var/list/AAlarmIndexToWireColor -var/list/AAlarmWireColorToIndex - //This was a define, but I changed it to a variable so it can be changed in-game.(kept the all-caps definition because... code...) -Errorage var/MAX_EX_DEVESTATION_RANGE = 3 var/MAX_EX_HEAVY_RANGE = 7 diff --git a/tgstation.dme b/tgstation.dme index 826d69ff1fd..d7aa93be9ca 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -152,6 +152,7 @@ #include "code\datums\spells\turf_teleport.dm" #include "code\datums\spells\wizard.dm" #include "code\datums\wires\airlock.dm" +#include "code\datums\wires\alarm.dm" #include "code\datums\wires\apc.dm" #include "code\datums\wires\camera.dm" #include "code\datums\wires\explosive.dm"