Skip to content

Commit

Permalink
Merge pull request #4795 from MistakeNot4892/cleanup/he_pipes
Browse files Browse the repository at this point in the history
Cleaning up HE pipes.
  • Loading branch information
out-of-phaze authored Jan 23, 2025
2 parents 2f4aaac + de4df0c commit e22125b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 34 additions & 32 deletions code/modules/atmospherics/datum_pipeline.dm
Original file line number Diff line number Diff line change
Expand Up @@ -193,32 +193,38 @@
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()
else
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)
Expand All @@ -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)
Expand Down
131 changes: 62 additions & 69 deletions code/modules/atmospherics/he_pipes.dm
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit e22125b

Please sign in to comment.