From de4df0c44bcb853a9b5124c2716252baefdec573 Mon Sep 17 00:00:00 2001 From: MistakeNot4892 Date: Thu, 23 Jan 2025 16:42:59 +1100 Subject: [PATCH] Cleaning up HE pipes. --- .../components/unary/heat_exchanger.dm | 2 +- code/modules/atmospherics/datum_pipeline.dm | 66 ++++----- code/modules/atmospherics/he_pipes.dm | 131 +++++++++--------- 3 files changed, 97 insertions(+), 102 deletions(-) diff --git a/code/modules/atmospherics/components/unary/heat_exchanger.dm b/code/modules/atmospherics/components/unary/heat_exchanger.dm index 30849bc53b9..f19c4ecb4f7 100644 --- a/code/modules/atmospherics/components/unary/heat_exchanger.dm +++ b/code/modules/atmospherics/components/unary/heat_exchanger.dm @@ -4,7 +4,7 @@ icon_state = "intact" density = TRUE - name = "Heat Exchanger" + name = "heat exchanger" desc = "Exchanges heat between two input gases. Setup for fast heat transfer." var/obj/machinery/atmospherics/unary/heat_exchanger/partner = null diff --git a/code/modules/atmospherics/datum_pipeline.dm b/code/modules/atmospherics/datum_pipeline.dm index 51634ba2d58..55a58d0138f 100644 --- a/code/modules/atmospherics/datum_pipeline.dm +++ b/code/modules/atmospherics/datum_pipeline.dm @@ -193,13 +193,23 @@ network.update = 1 /datum/pipeline/proc/temperature_interact(turf/target, share_volume, thermal_conductivity) + + if(air.volume <= 0) // Avoid div by zero. + return + var/total_heat_capacity = air.heat_capacity() var/partial_heat_capacity = total_heat_capacity*(share_volume/air.volume) + if(total_heat_capacity <= 0) // Avoid div by zero. + return + if(SHOULD_PARTICIPATE_IN_ZONES(target) && !target.blocks_air) + + if(partial_heat_capacity <= 0) + return + var/delta_temperature = 0 var/sharer_heat_capacity = 0 - if(target.zone) delta_temperature = (air.temperature - target.zone.air.temperature) sharer_heat_capacity = target.zone.air.heat_capacity() @@ -207,18 +217,14 @@ delta_temperature = (air.temperature - target.air.temperature) sharer_heat_capacity = target.air.heat_capacity() + if(sharer_heat_capacity <= 0) + return + var/self_temperature_delta = 0 var/sharer_temperature_delta = 0 - - if((sharer_heat_capacity > 0) && (partial_heat_capacity > 0)) - var/heat = thermal_conductivity*delta_temperature* \ - (partial_heat_capacity*sharer_heat_capacity/(partial_heat_capacity+sharer_heat_capacity)) - - self_temperature_delta = -heat/total_heat_capacity - sharer_temperature_delta = heat/sharer_heat_capacity - else - return 1 - + var/heat = thermal_conductivity * delta_temperature * ( partial_heat_capacity * sharer_heat_capacity / (partial_heat_capacity + sharer_heat_capacity) ) + self_temperature_delta = -heat/total_heat_capacity + sharer_temperature_delta = heat/sharer_heat_capacity air.temperature += self_temperature_delta if(target.zone) @@ -228,33 +234,29 @@ else if(target.external_atmosphere_participation && !target.blocks_air) - var/turf/modeled_location = target - var/datum/gas_mixture/target_air = modeled_location.return_air() + if(partial_heat_capacity <= 0) + return - var/delta_temperature = air.temperature - target_air.temperature - var/sharer_heat_capacity = target_air.heat_capacity() + var/datum/gas_mixture/target_air = target.return_air() + var/sharer_heat_capacity = target_air?.heat_capacity() - if((sharer_heat_capacity > 0) && (partial_heat_capacity > 0)) - var/heat = thermal_conductivity*delta_temperature* \ - (partial_heat_capacity*sharer_heat_capacity/(partial_heat_capacity+sharer_heat_capacity)) - air.temperature += -heat/total_heat_capacity - else - return 1 + if(sharer_heat_capacity <= 0) + return - else - if((target.heat_capacity > 0) && (partial_heat_capacity > 0)) - var/delta_temperature = air.temperature - target.temperature - - var/heat = thermal_conductivity*delta_temperature* \ - (partial_heat_capacity*target.heat_capacity/(partial_heat_capacity+target.heat_capacity)) + var/delta_temperature = air.temperature - target_air.temperature + var/heat = thermal_conductivity * delta_temperature * ( partial_heat_capacity * sharer_heat_capacity / (partial_heat_capacity+sharer_heat_capacity) ) + air.temperature += -heat/total_heat_capacity - air.temperature -= heat/total_heat_capacity - // Only increase the temperature of the target if it's simulated. - if(target.simulated) - target.temperature += heat/target.heat_capacity + else if((target.heat_capacity > 0) && (partial_heat_capacity > 0)) + var/delta_temperature = air.temperature - target.temperature + var/heat = thermal_conductivity * delta_temperature * ( partial_heat_capacity * target.heat_capacity / (partial_heat_capacity + target.heat_capacity) ) + air.temperature -= heat/total_heat_capacity + // Only increase the temperature of the target if it's simulated. + if(target.simulated) + target.temperature += heat/target.heat_capacity if(network) - network.update = 1 + network.update = TRUE //surface must be the surface area in m^2 /datum/pipeline/proc/radiate_heat_to_space(surface, thermal_conductivity) diff --git a/code/modules/atmospherics/he_pipes.dm b/code/modules/atmospherics/he_pipes.dm index 55afc98fd37..380adf9245f 100644 --- a/code/modules/atmospherics/he_pipes.dm +++ b/code/modules/atmospherics/he_pipes.dm @@ -1,28 +1,26 @@ /obj/machinery/atmospherics/pipe/simple/heat_exchanging - icon = 'icons/atmos/heat.dmi' - icon_state = "11" - color = "#404040" - pipe_color = "#404040" - level = LEVEL_ABOVE_PLATING - connect_types = CONNECT_TYPE_HE + icon = 'icons/atmos/heat.dmi' + icon_state = "11" + color = "#404040" + pipe_color = "#404040" + level = LEVEL_ABOVE_PLATING + connect_types = CONNECT_TYPE_HE interact_offline = TRUE //Needs to be set so that pipes don't say they lack power in their description - var/initialize_directions_he - var/surface = 2 //surface area in m^2 - var/icon_temperature = T20C //stop small changes in temperature causing an icon refresh build_icon_state = "he" - atom_flags = 0 // no painting + atom_flags = 0 // no painting + maximum_pressure = 360 ATM + fatigue_pressure = 300 ATM + can_buckle = TRUE + buckle_lying = TRUE appearance_flags = KEEP_TOGETHER + var/initialize_directions_he + var/surface = 2 //surface area in m^2 + var/icon_temperature = T20C //stop small changes in temperature causing an icon refresh var/thermal_conductivity = OPEN_HEAT_TRANSFER_COEFFICIENT var/minimum_temperature_difference = 20 - maximum_pressure = 360 ATM - fatigue_pressure = 300 ATM - - can_buckle = 1 - buckle_lying = 1 - /obj/machinery/atmospherics/pipe/simple/heat_exchanging/Initialize() . = ..() add_filter("glow",1, list(type = "drop_shadow", x = 0, y = 0, offset = 0, size = 4)) @@ -57,62 +55,57 @@ update_icon() /obj/machinery/atmospherics/pipe/simple/heat_exchanging/Process() + if(!parent) ..() - else - var/turf/turf = loc - var/datum/gas_mixture/pipe_air = return_air() - if(istype(loc, /turf/space)) - parent.radiate_heat_to_space(surface, 1) - else if(istype(turf) && turf.simulated) - var/turf/pipe_turf = loc - var/environment_temperature = 0 - if(pipe_turf.blocks_air) - environment_temperature = pipe_turf.temperature - else - var/datum/gas_mixture/environment = pipe_turf.return_air() - environment_temperature = environment.temperature - if(abs(environment_temperature-pipe_air.temperature) > minimum_temperature_difference) - parent.temperature_interact(pipe_turf, volume, thermal_conductivity) - - if(buckled_mob) - var/hc = pipe_air.heat_capacity() - var/avg_temp = (pipe_air.temperature * hc + buckled_mob.bodytemperature * 3500) / (hc + 3500) - pipe_air.temperature = avg_temp - buckled_mob.bodytemperature = avg_temp - - var/heat_limit = 1000 - - var/mob/living/human/H = buckled_mob - if(istype(H) && H.species) - heat_limit = H.get_mob_temperature_threshold(HEAT_LEVEL_3) - - if(pipe_air.temperature > heat_limit + 1) - buckled_mob.apply_damage(4 * log(pipe_air.temperature - heat_limit), BURN, BP_CHEST, used_weapon = "Excessive Heat") - - //fancy radiation glowing - if(pipe_air.temperature && (icon_temperature > 500 || pipe_air.temperature > 500)) //start glowing at 500K - if(abs(pipe_air.temperature - icon_temperature) > 10) - icon_temperature = pipe_air.temperature - var/scale = max((icon_temperature - 500) / 1500, 0) - - var/h_r = heat2color_r(icon_temperature) - var/h_g = heat2color_g(icon_temperature) - var/h_b = heat2color_b(icon_temperature) - - if(icon_temperature < 2000) //scale up overlay until 2000K - h_r = 64 + (h_r - 64)*scale - h_g = 64 + (h_g - 64)*scale - h_b = 64 + (h_b - 64)*scale - var/scale_color = rgb(h_r, h_g, h_b) - var/list/animate_targets = get_above_oo() + src - for (var/thing in animate_targets) - var/atom/movable/AM = thing - animate(AM, color = scale_color, time = 2 SECONDS, easing = SINE_EASING) - animate_filter("glow", list(color = scale_color, time = 2 SECONDS, easing = LINEAR_EASING)) - set_light(min(3, scale*2.5), min(3, scale*2.5), scale_color) + return + + // Handle pipe heat exchange. + var/turf/turf = loc + var/datum/gas_mixture/pipe_air = return_air() + if(istype(loc, /turf/space)) + parent.radiate_heat_to_space(surface, 1) + else if(istype(turf) && turf.simulated) + var/environment_temperature = 0 + if(turf.blocks_air) + environment_temperature = turf.temperature else - set_light(0, 0) + var/datum/gas_mixture/environment = turf.return_air() + environment_temperature = environment?.temperature || 0 + if(abs(environment_temperature-pipe_air.temperature) > minimum_temperature_difference) + parent.temperature_interact(turf, volume, thermal_conductivity) + + // Burn mobs buckled to this pipe. + if(buckled_mob) + var/hc = pipe_air.heat_capacity() + var/avg_temp = (pipe_air.temperature * hc + buckled_mob.bodytemperature * 3500) / (hc + 3500) + pipe_air.temperature = avg_temp + buckled_mob.bodytemperature = avg_temp + var/heat_limit = buckled_mob.get_mob_temperature_threshold(HEAT_LEVEL_3) + if(pipe_air.temperature > heat_limit + 1) + buckled_mob.apply_damage(4 * log(pipe_air.temperature - heat_limit), BURN, BP_CHEST, used_weapon = "Excessive Heat") + + //fancy radiation glowing + if(pipe_air.temperature && (icon_temperature > 500 || pipe_air.temperature > 500)) //start glowing at 500K + if(abs(pipe_air.temperature - icon_temperature) > 10) + icon_temperature = pipe_air.temperature + var/scale = max((icon_temperature - 500) / 1500, 0) + var/h_r = heat2color_r(icon_temperature) + var/h_g = heat2color_g(icon_temperature) + var/h_b = heat2color_b(icon_temperature) + if(icon_temperature < 2000) //scale up overlay until 2000K + h_r = 64 + (h_r - 64)*scale + h_g = 64 + (h_g - 64)*scale + h_b = 64 + (h_b - 64)*scale + var/scale_color = rgb(h_r, h_g, h_b) + var/list/animate_targets = get_above_oo() + src + for (var/thing in animate_targets) + var/atom/movable/AM = thing + animate(AM, color = scale_color, time = 2 SECONDS, easing = SINE_EASING) + animate_filter("glow", list(color = scale_color, time = 2 SECONDS, easing = LINEAR_EASING)) + set_light(min(3, scale*2.5), min(3, scale*2.5), scale_color) + else + set_light(0, 0) /obj/machinery/atmospherics/pipe/simple/heat_exchanging/junction icon = 'icons/atmos/junction.dmi'