-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
temperature_pump.dm
97 lines (82 loc) · 3.54 KB
/
temperature_pump.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/obj/machinery/atmospherics/components/binary/temperature_pump
icon_state = "tpump_map-3"
name = "temperature pump"
desc = "A pump that moves heat from one pipeline to another. The input will get cooler, and the output will get hotter."
can_unwrench = TRUE
shift_underlay_only = FALSE
construction_type = /obj/item/pipe/directional
pipe_state = "tpump"
vent_movement = NONE
///Percent of the heat delta to transfer
var/heat_transfer_rate = 0
///Maximum allowed transfer percentage
var/max_heat_transfer_rate = 100
/obj/machinery/atmospherics/components/binary/temperature_pump/CtrlClick(mob/user)
if(can_interact(user))
on = !on
investigate_log("was turned [on ? "on" : "off"] by [key_name(user)]", INVESTIGATE_ATMOS)
update_appearance()
return ..()
/obj/machinery/atmospherics/components/binary/temperature_pump/AltClick(mob/user)
if(can_interact(user) && !(heat_transfer_rate == max_heat_transfer_rate))
heat_transfer_rate = max_heat_transfer_rate
investigate_log("was set to [heat_transfer_rate]% by [key_name(user)]", INVESTIGATE_ATMOS)
balloon_alert(user, "transfer rate set to [heat_transfer_rate]%")
update_appearance()
return ..()
/obj/machinery/atmospherics/components/binary/temperature_pump/update_icon_nopipes()
icon_state = "tpump_[on && is_operational ? "on" : "off"]-[set_overlay_offset(piping_layer)]"
/obj/machinery/atmospherics/components/binary/temperature_pump/process_atmos()
if(!on || !is_operational)
return
var/datum/gas_mixture/air_input = airs[1]
var/datum/gas_mixture/air_output = airs[2]
if(!QUANTIZE(air_input.total_moles()) || !QUANTIZE(air_output.total_moles())) //Don't transfer if there's no gas
return
var/datum/gas_mixture/remove_input = air_input.remove_ratio(0.9)
var/datum/gas_mixture/remove_output = air_output.remove_ratio(0.9)
var/coolant_temperature_delta = remove_input.temperature - remove_output.temperature
if(coolant_temperature_delta > 0)
var/input_capacity = remove_input.heat_capacity()
var/output_capacity = remove_output.heat_capacity()
var/cooling_heat_amount = (heat_transfer_rate * 0.01) * CALCULATE_CONDUCTION_ENERGY(coolant_temperature_delta, output_capacity, input_capacity)
remove_output.temperature = max(remove_output.temperature + (cooling_heat_amount / output_capacity), TCMB)
remove_input.temperature = max(remove_input.temperature - (cooling_heat_amount / input_capacity), TCMB)
update_parents()
var/power_usage = 200
air_input.merge(remove_input)
air_output.merge(remove_output)
if(power_usage)
use_power(power_usage)
/obj/machinery/atmospherics/components/binary/temperature_pump/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "AtmosTempPump", name)
ui.open()
/obj/machinery/atmospherics/components/binary/temperature_pump/ui_data()
var/data = list()
data["on"] = on
data["rate"] = round(heat_transfer_rate)
data["max_heat_transfer_rate"] = round(max_heat_transfer_rate)
return data
/obj/machinery/atmospherics/components/binary/temperature_pump/ui_act(action, params)
. = ..()
if(.)
return
switch(action)
if("power")
on = !on
investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", INVESTIGATE_ATMOS)
. = TRUE
if("rate")
var/rate = params["rate"]
if(rate == "max")
rate = max_heat_transfer_rate
. = TRUE
else if(text2num(rate) != null)
rate = text2num(rate)
. = TRUE
if(.)
heat_transfer_rate = clamp(rate, 0, max_heat_transfer_rate)
investigate_log("was set to [heat_transfer_rate]% by [key_name(usr)]", INVESTIGATE_ATMOS)
update_appearance()