From 2fddc6a832dbfdb34c558df8301cdefcdf1b34f4 Mon Sep 17 00:00:00 2001 From: PsiOmega Date: Wed, 19 Nov 2014 17:15:26 +0100 Subject: [PATCH] Less copy-pastah Reduces copy-pasted code in the atmospheric monitor computer code. --- code/WorkInProgress/Mini/atmos_control.dm | 291 +--------------------- code/game/machinery/alarm.dm | 91 ++++--- code/game/machinery/machinery.dm | 4 +- 3 files changed, 48 insertions(+), 338 deletions(-) diff --git a/code/WorkInProgress/Mini/atmos_control.dm b/code/WorkInProgress/Mini/atmos_control.dm index 38dee770cd6..a7221311028 100644 --- a/code/WorkInProgress/Mini/atmos_control.dm +++ b/code/WorkInProgress/Mini/atmos_control.dm @@ -79,7 +79,7 @@ var/dat = "

[current.name]


" dat += current.return_status() if(current.remote_control || overridden) - dat += "
[return_controls()]" + dat += "
[current.return_controls(src)]" return dat //a bunch of this is copied from atmos alarms @@ -90,289 +90,6 @@ current = null if(href_list["alarm"]) current = locate(href_list["alarm"]) - if(href_list["command"]) - var/device_id = href_list["id_tag"] - switch(href_list["command"]) - if( - "power", - "adjust_external_pressure", - "checks", - "co2_scrub", - "tox_scrub", - "n2o_scrub", - "panic_siphon", - "scrubbing" - ) - current.send_signal(device_id, list (href_list["command"] = text2num(href_list["val"]))) - spawn(3) - src.updateUsrDialog() - //if("adjust_threshold") //was a good idea but required very wide window - if("set_threshold") - var/env = href_list["env"] - var/threshold = text2num(href_list["var"]) - var/list/selected = current.TLV[env] - var/list/thresholds = list("lower bound", "low warning", "high warning", "upper bound") - var/newval = input("Enter [thresholds[threshold]] for [env]", "Alarm triggers", selected[threshold]) as num|null - if (isnull(newval) || ..() || (current.locked && issilicon(usr))) - return - if (newval<0) - selected[threshold] = -1.0 - else if (env=="temperature" && newval>5000) - selected[threshold] = 5000 - else if (env=="pressure" && newval>50*ONE_ATMOSPHERE) - selected[threshold] = 50*ONE_ATMOSPHERE - else if (env!="temperature" && env!="pressure" && newval>200) - selected[threshold] = 200 - else - newval = round(newval,0.01) - selected[threshold] = newval - if(threshold == 1) - if(selected[1] > selected[2]) - selected[2] = selected[1] - if(selected[1] > selected[3]) - selected[3] = selected[1] - if(selected[1] > selected[4]) - selected[4] = selected[1] - if(threshold == 2) - if(selected[1] > selected[2]) - selected[1] = selected[2] - if(selected[2] > selected[3]) - selected[3] = selected[2] - if(selected[2] > selected[4]) - selected[4] = selected[2] - if(threshold == 3) - if(selected[1] > selected[3]) - selected[1] = selected[3] - if(selected[2] > selected[3]) - selected[2] = selected[3] - if(selected[3] > selected[4]) - selected[4] = selected[3] - if(threshold == 4) - if(selected[1] > selected[4]) - selected[1] = selected[4] - if(selected[2] > selected[4]) - selected[2] = selected[4] - if(selected[3] > selected[4]) - selected[3] = selected[4] - - //Sets the temperature the built-in heater/cooler tries to maintain. - if(env == "temperature") - if(current.target_temperature < selected[2]) - current.target_temperature = selected[2] - if(current.target_temperature > selected[3]) - current.target_temperature = selected[3] - - spawn(1) - updateUsrDialog() - return - - if(href_list["screen"]) - current.screen = text2num(href_list["screen"]) - spawn(1) - src.updateUsrDialog() - return - - //commenting this out because it causes compile errors - //I tried fixing it but wasn't sucessful. - //if(href_list["atmos_unlock"]) - // switch(href_list["atmos_unlock"]) - // if("0") - // current.alarm_area.air_doors_close() - // if("1") - // current.alarm_area.air_doors_open() - - if(href_list["atmos_alarm"]) - if (current.alarm_area.atmosalert(2)) - current.apply_danger_level(2) - spawn(1) - src.updateUsrDialog() - current.update_icon() - return - if(href_list["atmos_reset"]) - if (current.alarm_area.atmosalert(0)) - current.apply_danger_level(0) - spawn(1) - src.updateUsrDialog() - current.update_icon() - return - - if(href_list["mode"]) - current.mode = text2num(href_list["mode"]) - current.apply_mode() - spawn(5) - src.updateUsrDialog() - return - updateUsrDialog() - -//copypasta from alarm code, changed to work with this without derping hard -//---START COPYPASTA---- - -/obj/machinery/computer/atmoscontrol/proc/return_controls() - var/output = ""//"[alarm_zone] Air [name]
" - - switch(current.screen) - if (AALARM_SCREEN_MAIN) - if(current.alarm_area.atmosalm) - output += {"Reset - Atmospheric Alarm
"} - else - output += {"Activate - Atmospheric Alarm
"} - - output += {" -Scrubbers Control
-Vents Control
-Set environmental mode
-Sensor Control
-
-"} - if (current.mode==AALARM_MODE_PANIC) - output += "PANIC SYPHON ACTIVE
turn syphoning off" - else - output += "ACTIVATE PANIC SYPHON IN AREA" - - output += "

Atmospheric Lockdown: [current.alarm_area.air_doors_activated ? "ENABLED" : "Disabled"]" - if (AALARM_SCREEN_VENT) - var/sensor_data = "" - if(current.alarm_area.air_vent_names.len) - for(var/id_tag in current.alarm_area.air_vent_names) - var/long_name = current.alarm_area.air_vent_names[id_tag] - var/list/data = current.alarm_area.air_vent_info[id_tag] - var/state = "" - if(!data) - state = " can not be found!" - data = list("external" = 0) //for "0" instead of empty string - else if (data["timestamp"]+AALARM_REPORT_TIMEOUT < world.time) - state = " not responding!" - sensor_data += {" -[long_name][state]
-Operating: -[data["power"]?"on":"off"] -
-Pressure checks: -external -internal -
-External pressure bound: -- -- -- -- -[data["external"]] -+ -+ -+ -+ -
-"} - if (data["direction"] == "siphon") - sensor_data += {" -Direction: -siphoning -
-"} - sensor_data += {"
"} - else - sensor_data = "No vents connected.
" - output = {"Main menu
[sensor_data]"} - if (AALARM_SCREEN_SCRUB) - var/sensor_data = "" - if(current.alarm_area.air_scrub_names.len) - for(var/id_tag in current.alarm_area.air_scrub_names) - var/long_name = current.alarm_area.air_scrub_names[id_tag] - var/list/data = current.alarm_area.air_scrub_info[id_tag] - var/state = "" - if(!data) - state = " can not be found!" - data = list("external" = 0) //for "0" instead of empty string - else if (data["timestamp"]+AALARM_REPORT_TIMEOUT < world.time) - state = " not responding!" - - sensor_data += {" -[long_name][state]
-Operating: -[data["power"]?"on":"off"]
-Type: -[data["scrubbing"]?"scrubbing":"syphoning"]
-"} - - if(data["scrubbing"]) - sensor_data += {" -Filtering: -Carbon Dioxide -[data["filter_co2"]?"on":"off"]; -Toxins -[data["filter_phoron"]?"on":"off"]; -Nitrous Oxide -[data["filter_n2o"]?"on":"off"] -
-"} - sensor_data += {" -Panic syphon: [data["panic"]?"PANIC SYPHON ACTIVATED":""] -Dea":"red'>A")]ctivate
-
-"} - else - sensor_data = "No scrubbers connected.
" - output = {"Main menu
[sensor_data]"} - - if (AALARM_SCREEN_MODE) - output += {" -Main menu
-Air machinery mode for the area:" - if (AALARM_SCREEN_SENSORS) - output += {" -Main menu
-Alarm thresholds:
-Partial pressure for gases - - - -"} - var/list/gases = list( - "oxygen" = "O2", - "carbon dioxide" = "CO2", - "phoron" = "Toxin", - "other" = "Other", - ) - var/list/tlv - for (var/g in gases) - output += "" - tlv = current.TLV[g] - for (var/i = 1, i <= 4, i++) - output += "" - output += "" - - tlv = current.TLV["pressure"] - output += "" - for (var/i = 1, i <= 4, i++) - output += "" - output += "" - - tlv = current.TLV["temperature"] - output += "" - for (var/i = 1, i <= 4, i++) - output += "" - output += "" - output += "
min2min1max1max2
[gases[g]][tlv[i] >= 0?tlv[i]:"OFF"]
Pressure[tlv[i]>= 0?tlv[i]:"OFF"]
Temperature[tlv[i]>= 0?tlv[i]:"OFF"]
" - - return output -//---END COPYPASTA---- + else if(current) + current.Topic(href, href_list, 1, 1) + interact(usr) diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index c74f03db43b..f8074755a8b 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -598,27 +598,27 @@ Toxins: [phoron_percent]%
return dat -/obj/machinery/alarm/proc/return_controls() +/obj/machinery/alarm/proc/return_controls(var/source = src) var/output = ""//"[alarm_zone] Air [name]
" switch(screen) if (AALARM_SCREEN_MAIN) if(alarm_area.atmosalm) - output += "Reset - Area Atmospheric Alarm
" + output += "Reset - Area Atmospheric Alarm
" else - output += "Activate - Area Atmospheric Alarm
" + output += "Activate - Area Atmospheric Alarm
" output += {" -Scrubbers Control
-Vents Control
-Set environmentals mode
-Sensor Settings
+Scrubbers Control
+Vents Control
+Set environmentals mode
+Sensor Settings

"} if (mode==AALARM_MODE_PANIC) - output += "PANIC SYPHON ACTIVE
Turn syphoning off" + output += "PANIC SYPHON ACTIVE
Turn syphoning off" else - output += "ACTIVATE PANIC SYPHON IN AREA" + output += "ACTIVATE PANIC SYPHON IN AREA" if (AALARM_SCREEN_VENT) @@ -634,23 +634,23 @@ Toxins: [phoron_percent]%
sensor_data += {" [long_name][state]
Operating: -[data["power"]?"on":"off"] +[data["power"]?"on":"off"]
Pressure checks: -external -internal +external +internal
External pressure bound: -- -- -- -- +- +- +- +- [data["external"]] -+ -+ -+ -+ - (reset) ++ ++ ++ ++ + (reset)
"} if (data["direction"] == "siphon") @@ -662,7 +662,7 @@ siphoning sensor_data += {"
"} else sensor_data = "No vents connected.
" - output = {"Main menu
[sensor_data]"} + output = {"Main menu
[sensor_data]"} if (AALARM_SCREEN_SCRUB) var/sensor_data = "" if(alarm_area.air_scrub_names.len) @@ -676,33 +676,33 @@ siphoning sensor_data += {" [long_name][state]
Operating: -[data["power"]?"on":"off"]
+[data["power"]?"on":"off"]
Type: -[data["scrubbing"]?"scrubbing":"syphoning"]
+[data["scrubbing"]?"scrubbing":"syphoning"]
"} if(data["scrubbing"]) sensor_data += {" Filtering: Carbon Dioxide -[data["filter_co2"]?"on":"off"]; +[data["filter_co2"]?"on":"off"]; Toxins -[data["filter_phoron"]?"on":"off"]; +[data["filter_phoron"]?"on":"off"]; Nitrous Oxide -[data["filter_n2o"]?"on":"off"] +[data["filter_n2o"]?"on":"off"]
"} sensor_data += {" Panic syphon: [data["panic"]?"PANIC SYPHON ACTIVATED":""] -Dea":"red'>A")]ctivate
+Dea":"red'>A")]ctivate

"} else sensor_data = "No scrubbers connected.
" - output = {"Main menu
[sensor_data]"} + output = {"Main menu
[sensor_data]"} if (AALARM_SCREEN_MODE) - output += "Main menu
Air machinery mode for the area: