From c8cfb3abebdbeb08c59273f10d04c1a677a5421a Mon Sep 17 00:00:00 2001 From: nicbn Date: Tue, 10 Oct 2017 14:27:15 -0300 Subject: [PATCH 1/2] Cleans up atmos unary machinery code (#31356) * Cleans up atmos unary machinery code * return 0 and return are different things: cryo.dm * same: oxygen generator * same: vent pump * same: vent scrubber * Reveiw * Update vent_scrubber.dm * Update vent_scrubber.dm --- .../components/unary_devices/cryo.dm | 161 +++++++++--------- .../unary_devices/outlet_injector.dm | 8 +- .../unary_devices/oxygen_generator.dm | 2 + .../components/unary_devices/thermomachine.dm | 5 +- .../components/unary_devices/unary_devices.dm | 4 - .../components/unary_devices/vent_pump.dm | 41 +++-- .../components/unary_devices/vent_scrubber.dm | 11 +- 7 files changed, 116 insertions(+), 116 deletions(-) diff --git a/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm b/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm index efc6a8e899..ee7228fdca 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm @@ -20,7 +20,7 @@ var/sleep_factor = 750 var/unconscious_factor = 1000 var/heat_capacity = 20000 - var/conduction_coefficient = 0.30 + var/conduction_coefficient = 0.3 var/obj/item/reagent_containers/glass/beaker = null var/reagent_transfer = 0 @@ -29,7 +29,7 @@ var/radio_key = /obj/item/device/encryptionkey/headset_med var/radio_channel = "Medical" - var/running_bob_anim = FALSE + var/running_anim = FALSE var/escape_in_progress = FALSE var/message_cooldown @@ -83,46 +83,51 @@ /obj/machinery/atmospherics/components/unary/cryo_cell/update_icon() cut_overlays() + if(panel_open) + add_overlay("pod-panel") + if(state_open) icon_state = "pod-open" - else if(occupant) + return + + if(occupant) var/image/occupant_overlay - if(ismonkey(occupant)) // Monkey - occupant_overlay = mutable_appearance(CRYOMOBS, "monkey") - - else if(isalienadult(occupant)) - - if(isalienroyal(occupant)) // Queen and prae - occupant_overlay = image(CRYOMOBS, "alienq") - - else if(isalienhunter(occupant)) // Hunter - occupant_overlay = image(CRYOMOBS, "alienh") - - else if(isaliensentinel(occupant)) // Sentinel - occupant_overlay = image(CRYOMOBS, "aliens") - - else // Drone (or any other alien that isn't any of the above) - occupant_overlay = image(CRYOMOBS, "aliend") - - else if(ishuman(occupant) || islarva(occupant) || (isanimal(occupant) && !ismegafauna(occupant))) // Mobs that are smaller than cryotube + if(ishuman(occupant) || islarva(occupant) || (isanimal(occupant) && !ismegafauna(occupant))) // Mobs that are smaller than cryotube occupant_overlay = image(occupant.icon, occupant.icon_state) occupant_overlay.copy_overlays(occupant) - else // Anything else + else if(ismonkey(occupant)) // Monkey + occupant_overlay = image(CRYOMOBS, "monkey") + occupant_overlay.copy_overlays(occupant) + + else if(!isalienadult(occupant)) occupant_overlay = image(CRYOMOBS, "generic") + else if(isalienroyal(occupant)) // Queen and prae + occupant_overlay = image(CRYOMOBS, "alienq") + + else if(isalienhunter(occupant)) // Hunter + occupant_overlay = image(CRYOMOBS, "alienh") + + else if(isaliensentinel(occupant)) // Sentinel + occupant_overlay = image(CRYOMOBS, "aliens") + + else // Drone or other + occupant_overlay = image(CRYOMOBS, "aliend") + occupant_overlay.dir = SOUTH occupant_overlay.pixel_y = 22 - if(on && !running_bob_anim && is_operational()) + if(on && !running_anim && is_operational()) icon_state = "pod-on" - running_bob_anim = TRUE - run_bob_anim(TRUE, occupant_overlay) + running_anim = TRUE + run_anim(TRUE, occupant_overlay) else icon_state = "pod-off" add_overlay(occupant_overlay) add_overlay("cover-off") + else if(on && is_operational()) icon_state = "pod-on" add_overlay("cover-on") @@ -130,12 +135,9 @@ icon_state = "pod-off" add_overlay("cover-off") - if(panel_open) - add_overlay("pod-panel") - -/obj/machinery/atmospherics/components/unary/cryo_cell/proc/run_bob_anim(anim_up, image/occupant_overlay) +/obj/machinery/atmospherics/components/unary/cryo_cell/proc/run_anim(anim_up, image/occupant_overlay) if(!on || !occupant || !is_operational()) - running_bob_anim = FALSE + running_anim = FALSE return cut_overlays() if(occupant_overlay.pixel_y != 23) // Same effect as occupant_overlay.pixel_y == 22 || occupant_overlay.pixel_y == 24 @@ -146,7 +148,7 @@ occupant_overlay.pixel_y-- add_overlay(occupant_overlay) add_overlay("cover-on") - addtimer(CALLBACK(src, .proc/run_bob_anim, anim_up, occupant_overlay), 7, TIMER_UNIQUE) + addtimer(CALLBACK(src, .proc/run_anim, anim_up, occupant_overlay), 7, TIMER_UNIQUE) /obj/machinery/atmospherics/components/unary/cryo_cell/process() ..() @@ -157,60 +159,65 @@ on = FALSE update_icon() return - var/datum/gas_mixture/air1 = AIR1 - var/turf/T = get_turf(src) - if(occupant) - var/mob/living/mob_occupant = occupant - if(mob_occupant.health >= mob_occupant.getMaxHealth()) // Don't bother with fully healed people. - on = FALSE - update_icon() - playsound(T, 'sound/machines/cryo_warning.ogg', volume) // Bug the doctors. - radio.talk_into(src, "Patient fully restored", radio_channel, get_spans(), get_default_language()) - if(autoeject) // Eject if configured. - radio.talk_into(src, "Auto ejecting patient now", radio_channel, get_spans(), get_default_language()) - open_machine() - return - else if(mob_occupant.stat == DEAD) // We don't bother with dead people. - return - if(autoeject) // Eject if configured. - open_machine() - return - if(air1.gases.len) - if(mob_occupant.bodytemperature < T0C) // Sleepytime. Why? More cryo magic. - mob_occupant.Sleeping((mob_occupant.bodytemperature / sleep_factor) * 2000) - mob_occupant.Unconscious((mob_occupant.bodytemperature / unconscious_factor) * 2000) + if(!occupant) + return + + var/mob/living/mob_occupant = occupant + + if(mob_occupant.stat == DEAD) // We don't bother with dead people. + return + + if(mob_occupant.health >= mob_occupant.getMaxHealth()) // Don't bother with fully healed people. + on = FALSE + update_icon() + playsound(src, 'sound/machines/cryo_warning.ogg', volume) // Bug the doctors. + radio.talk_into(src, "Patient fully restored", radio_channel, get_spans(), get_default_language()) + if(autoeject) // Eject if configured. + radio.talk_into(src, "Auto ejecting patient now", radio_channel, get_spans(), get_default_language()) + open_machine() + return + + var/datum/gas_mixture/air1 = AIR1 + + if(air1.gases.len) + if(mob_occupant.bodytemperature < T0C) // Sleepytime. Why? More cryo magic. + mob_occupant.Sleeping((mob_occupant.bodytemperature / sleep_factor) * 2000) + mob_occupant.Unconscious((mob_occupant.bodytemperature / unconscious_factor) * 2000) + if(beaker) + if(reagent_transfer == 0) // Magically transfer reagents. Because cryo magic. + beaker.reagents.trans_to(occupant, 1, 10 * efficiency) // Transfer reagents, multiplied because cryo magic. + beaker.reagents.reaction(occupant, VAPOR) + air1.gases["o2"][MOLES] -= 2 / efficiency // Lets use gas for this. + if(++reagent_transfer >= 10 * efficiency) // Throttle reagent transfer (higher efficiency will transfer the same amount but consume less from the beaker). + reagent_transfer = 0 - if(beaker) - if(reagent_transfer == 0) // Magically transfer reagents. Because cryo magic. - beaker.reagents.trans_to(occupant, 1, 10 * efficiency) // Transfer reagents, multiplied because cryo magic. - beaker.reagents.reaction(occupant, VAPOR) - air1.gases["o2"][MOLES] -= 2 / efficiency // Lets use gas for this. - if(++reagent_transfer >= 10 * efficiency) // Throttle reagent transfer (higher efficiency will transfer the same amount but consume less from the beaker). - reagent_transfer = 0 return 1 /obj/machinery/atmospherics/components/unary/cryo_cell/process_atmos() ..() + if(!on) return + var/datum/gas_mixture/air1 = AIR1 + if(!NODE1 || !AIR1 || !air1.gases.len || air1.gases["o2"][MOLES] < 5) // Turn off if the machine won't work. on = FALSE update_icon() return + if(occupant) var/mob/living/mob_occupant = occupant var/cold_protection = 0 - var/mob/living/carbon/human/H = occupant - if(istype(H)) + var/temperature_delta = air1.temperature - mob_occupant.bodytemperature // The only semi-realistic thing here: share temperature between the cell and the occupant. + + if(ishuman(occupant)) + var/mob/living/carbon/human/H = occupant cold_protection = H.get_cold_protection(air1.temperature) - var/temperature_delta = air1.temperature - mob_occupant.bodytemperature // The only semi-realistic thing here: share temperature between the cell and the occupant. if(abs(temperature_delta) > 1) var/air_heat_capacity = air1.heat_capacity() - var/heat = ((1 - cold_protection) / 10 + conduction_coefficient) \ - * temperature_delta * \ - (air_heat_capacity * heat_capacity / (air_heat_capacity + heat_capacity)) + var/heat = ((1 - cold_protection) * 0.1 + conduction_coefficient) * temperature_delta * (1 / air_heat_capacity + 1 / heat_capacity) air1.temperature = max(air1.temperature - heat / air_heat_capacity, TCMB) mob_occupant.bodytemperature = max(mob_occupant.bodytemperature + heat / heat_capacity, TCMB) @@ -248,7 +255,7 @@ user.visible_message("You see [user] kicking against the glass of [src]!", \ "You struggle inside [src], kicking the release with your foot... (this will take about [DisplayTimeText(breakout_time)].)", \ "You hear a thump from [src].") - if(do_after(user,(breakout_time), target = src)) + if(do_after(user, breakout_time, target = src)) if(!user || user.stat != CONSCIOUS || user.loc != src ) return user.visible_message("[user] successfully broke out of [src]!", \ @@ -284,16 +291,10 @@ var/reagentlist = pretty_string_from_reagent_list(I.reagents.reagent_list) log_game("[key_name(user)] added an [I] to cyro containing [reagentlist]") return - if(!on && !occupant && !state_open) - if(default_deconstruction_screwdriver(user, "pod-off", "pod-off", I)) - return - if(exchange_parts(user, I)) - return - if(default_change_direction_wrench(user, I)) - return - if(default_pry_open(I)) - return - if(default_deconstruction_crowbar(I)) + if(!on && !occupant && !state_open && (default_deconstruction_screwdriver(user, "pod-o", "pod-off", I) || exchange_parts(user, I)) \ + || default_change_direction_wrench(user, I) \ + || default_pry_open(I) \ + || default_deconstruction_crowbar(I)) return return ..() @@ -384,16 +385,16 @@ update_icon() /obj/machinery/atmospherics/components/unary/cryo_cell/update_remote_sight(mob/living/user) - return //we don't see the pipe network while inside cryo. + return // we don't see the pipe network while inside cryo. /obj/machinery/atmospherics/components/unary/cryo_cell/get_remote_view_fullscreens(mob/user) user.overlay_fullscreen("remote_view", /obj/screen/fullscreen/impaired, 1) /obj/machinery/atmospherics/components/unary/cryo_cell/can_crawl_through() - return //can't ventcrawl in or out of cryo. + return // can't ventcrawl in or out of cryo. /obj/machinery/atmospherics/components/unary/cryo_cell/can_see_pipes() - return 0 //you can't see the pipe network when inside a cryo cell. + return 0 // you can't see the pipe network when inside a cryo cell. /obj/machinery/atmospherics/components/unary/cryo_cell/return_temperature() var/datum/gas_mixture/G = AIR1 diff --git a/code/modules/atmospherics/machinery/components/unary_devices/outlet_injector.dm b/code/modules/atmospherics/machinery/components/unary_devices/outlet_injector.dm index d46d5b47a0..215ee77572 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/outlet_injector.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/outlet_injector.dm @@ -45,6 +45,7 @@ /obj/machinery/atmospherics/components/unary/outlet_injector/process_atmos() ..() + injecting = 0 if(!on || !is_operational()) @@ -63,6 +64,7 @@ update_parents() /obj/machinery/atmospherics/components/unary/outlet_injector/proc/inject() + if(on || injecting || !is_operational()) return @@ -72,11 +74,8 @@ if(air_contents.temperature > 0) var/transfer_moles = (air_contents.return_pressure())*volume_rate/(air_contents.temperature * R_IDEAL_GAS_EQUATION) - var/datum/gas_mixture/removed = air_contents.remove(transfer_moles) - loc.assume_air(removed) - update_parents() flick("inje_inject", src) @@ -88,6 +87,7 @@ radio_connection = SSradio.add_object(src, frequency) /obj/machinery/atmospherics/components/unary/outlet_injector/proc/broadcast_status() + if(!radio_connection) return @@ -112,6 +112,7 @@ ..() /obj/machinery/atmospherics/components/unary/outlet_injector/receive_signal(datum/signal/signal) + if(!signal.data["tag"] || (signal.data["tag"] != id) || (signal.data["sigtype"]!="command")) return @@ -137,6 +138,7 @@ spawn(2) broadcast_status() + update_icon() diff --git a/code/modules/atmospherics/machinery/components/unary_devices/oxygen_generator.dm b/code/modules/atmospherics/machinery/components/unary_devices/oxygen_generator.dm index 0be10fecf0..c0a887e3aa 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/oxygen_generator.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/oxygen_generator.dm @@ -33,7 +33,9 @@ AIR1 = air_contents /obj/machinery/atmospherics/components/unary/oxygen_generator/process_atmos() + ..() + if(!on) return 0 diff --git a/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm b/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm index 17fa3b2cdf..dc482eda02 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm @@ -128,8 +128,10 @@ return data /obj/machinery/atmospherics/components/unary/thermomachine/ui_act(action, params) + if(..()) return + switch(action) if("power") on = !on @@ -141,7 +143,7 @@ var/adjust = text2num(params["adjust"]) if(target == "input") target = input("Set new target ([min_temperature]-[max_temperature] K):", name, target_temperature) as num|null - if(!isnull(target) && !..()) + if(!isnull(target)) . = TRUE else if(adjust) target = target_temperature + adjust @@ -152,6 +154,7 @@ if(.) target_temperature = Clamp(target, min_temperature, max_temperature) investigate_log("was set to [target_temperature] K by [key_name(usr)]", INVESTIGATE_ATMOS) + update_icon() /obj/machinery/atmospherics/components/unary/thermomachine/freezer diff --git a/code/modules/atmospherics/machinery/components/unary_devices/unary_devices.dm b/code/modules/atmospherics/machinery/components/unary_devices/unary_devices.dm index 32076d82e1..a6ac9760e8 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/unary_devices.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/unary_devices.dm @@ -7,14 +7,10 @@ /obj/machinery/atmospherics/components/unary/SetInitDirections() initialize_directions = dir -/* -Iconnery -*/ /obj/machinery/atmospherics/components/unary/on_construction() ..() update_icon() /obj/machinery/atmospherics/components/unary/hide(intact) update_icon() - ..(intact) diff --git a/code/modules/atmospherics/machinery/components/unary_devices/vent_pump.dm b/code/modules/atmospherics/machinery/components/unary_devices/vent_pump.dm index df44b4ca9e..aa6c12a006 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/vent_pump.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/vent_pump.dm @@ -22,9 +22,9 @@ var/pressure_checks = EXT_BOUND var/external_pressure_bound = ONE_ATMOSPHERE var/internal_pressure_bound = 0 - //EXT_BOUND: Do not pass external_pressure_bound - //INT_BOUND: Do not pass internal_pressure_bound - //NO_BOUND: Do not pass either + // EXT_BOUND: Do not pass external_pressure_bound + // INT_BOUND: Do not pass internal_pressure_bound + // NO_BOUND: Do not pass either var/frequency = 1439 var/datum/radio_frequency/radio_connection @@ -98,7 +98,7 @@ if(pump_direction & RELEASING) icon_state = "vent_out" - else //pump_direction == SIPHONING + else // pump_direction == SIPHONING icon_state = "vent_in" /obj/machinery/atmospherics/components/unary/vent_pump/process_atmos() @@ -114,7 +114,7 @@ var/datum/gas_mixture/environment = loc.return_air() var/environment_pressure = environment.return_pressure() - if(pump_direction & RELEASING) //internal -> external + if(pump_direction & RELEASING) // internal -> external var/pressure_delta = 10000 if(pressure_checks&EXT_BOUND) @@ -131,23 +131,22 @@ loc.assume_air(removed) air_update_turf() - else //external -> internal + else // external -> internal var/pressure_delta = 10000 if(pressure_checks&EXT_BOUND) pressure_delta = min(pressure_delta, (environment_pressure - external_pressure_bound)) if(pressure_checks&INT_BOUND) pressure_delta = min(pressure_delta, (internal_pressure_bound - air_contents.return_pressure())) - if(pressure_delta > 0) - if(environment.temperature > 0) - var/transfer_moles = pressure_delta*air_contents.volume/(environment.temperature * R_IDEAL_GAS_EQUATION) + if(pressure_delta > 0 && environment.temperature > 0) + var/transfer_moles = pressure_delta * air_contents.volume / (environment.temperature * R_IDEAL_GAS_EQUATION) - var/datum/gas_mixture/removed = loc.remove_air(transfer_moles) - if (isnull(removed)) //in space - return + var/datum/gas_mixture/removed = loc.remove_air(transfer_moles) + if (isnull(removed)) // in space + return - air_contents.merge(removed) - air_update_turf() + air_contents.merge(removed) + air_update_turf() update_parents() //Radio remote control @@ -163,7 +162,7 @@ return var/datum/signal/signal = new - signal.transmission_method = 1 //radio signal + signal.transmission_method = 1 // radio signal signal.source = src signal.data = list( @@ -200,7 +199,7 @@ /obj/machinery/atmospherics/components/unary/vent_pump/receive_signal(datum/signal/signal) if(!is_operational()) return - //log_admin("DEBUG \[[world.timeofday]\]: /obj/machinery/atmospherics/components/unary/vent_pump/receive_signal([signal.debug_print()])") + // log_admin("DEBUG \[[world.timeofday]\]: /obj/machinery/atmospherics/components/unary/vent_pump/receive_signal([signal.debug_print()])") if(!signal.data["tag"] || (signal.data["tag"] != id_tag) || (signal.data["sigtype"]!="command")) return @@ -248,20 +247,20 @@ if("status" in signal.data) broadcast_status() - return //do not update_icon + return // do not update_icon - //log_admin("DEBUG \[[world.timeofday]\]: vent_pump/receive_signal: unknown command \"[signal.data["command"]]\"\n[signal.debug_print()]") + // log_admin("DEBUG \[[world.timeofday]\]: vent_pump/receive_signal: unknown command \"[signal.data["command"]]\"\n[signal.debug_print()]") broadcast_status() update_icon() /obj/machinery/atmospherics/components/unary/vent_pump/attackby(obj/item/W, mob/user, params) if(istype(W, /obj/item/weldingtool)) var/obj/item/weldingtool/WT = W - if (WT.remove_fuel(0,user)) + if (WT.remove_fuel(0, user)) playsound(loc, WT.usesound, 40, 1) to_chat(user, "You begin welding the vent...") - if(do_after(user, 20*W.toolspeed, target = src)) - if(!src || !WT.isOn()) + if(do_after(user, W.toolspeed * 20, target = src)) + if(!src || !WT.isOn()) return playsound(src.loc, 'sound/items/welder2.ogg', 50, 1) if(!welded) diff --git a/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm b/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm index 1abf84df10..e1365e5a7e 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm @@ -152,11 +152,10 @@ /obj/machinery/atmospherics/components/unary/vent_scrubber/process_atmos() ..() - if(!is_operational()) + if(welded || !is_operational()) return FALSE - if(!NODE1) + if(!NODE1 || !on) on = FALSE - if(!on || welded) return FALSE scrub(loc) if(widenet) @@ -257,7 +256,7 @@ //There is no easy way for an object to be notified of changes to atmos can pass flags_1 // So we check every machinery process (2 seconds) /obj/machinery/atmospherics/components/unary/vent_scrubber/process() - if (widenet) + if(widenet) check_turfs() //we populate a list of turfs with nonatmos-blocked cardinal turfs AND @@ -270,9 +269,7 @@ /obj/machinery/atmospherics/components/unary/vent_scrubber/receive_signal(datum/signal/signal) - if(!is_operational()) - return - if(!signal.data["tag"] || (signal.data["tag"] != id_tag) || (signal.data["sigtype"]!="command")) + if(!is_operational() || !signal.data["tag"] || (signal.data["tag"] != id_tag) || (signal.data["sigtype"]!="command")) return 0 if("power" in signal.data)