Skip to content

Commit e3f2579

Browse files
authored
Thermostat Fixes (#37000)
* thermostat fixes * handles map presets and vv * clamps input instead of erroring
1 parent 5e12a53 commit e3f2579

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

code/game/machinery/alarm.dm

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ var/global/list/air_alarms = list()
330330
var/buildstage = 2 //2 is built, 1 is building, 0 is frame.
331331
var/cycle_after_preset = 1 // Whether we automatically cycle when presets are changed
332332

333-
var/target_temperature = T0C+20
333+
var/target_temperature //Manual override for target temperature changing, usable for maps/admin vv edits
334334
var/regulating_temperature = 0
335335

336336
var/datum/radio_frequency/radio_connection
@@ -439,32 +439,45 @@ var/global/list/air_alarms = list()
439439
if(!istype(location))
440440
return//returns if loc is not simulated
441441

442+
if(!isnull(target_temperature))
443+
set_temperature(target_temperature, FALSE)
444+
target_temperature = null
445+
442446
var/datum/gas_mixture/environment = location.return_air()
443447

444448
// Handle temperature adjustment here.
445449
if(environment.temperature < config.target_temperature - 2 || environment.temperature > config.target_temperature + 2 || regulating_temperature)
446450
//If it goes too far, we should adjust ourselves back before stopping.
447-
var/actual_target_temperature = target_temperature
451+
var/actual_target_temperature = config.target_temperature
448452
if(config.temperature_threshold.assess_danger(actual_target_temperature))
449453
//use the max or min safe temperature
450454
actual_target_temperature = clamp(actual_target_temperature, config.temperature_threshold.min_1(), config.temperature_threshold.max_1())
451-
455+
var/thermo_changed = FALSE
452456
if(!regulating_temperature)
453-
regulating_temperature = 1
454-
visible_message("\The [src] clicks as it starts [environment.temperature > config.target_temperature ? "cooling" : "heating"] the room.",\
457+
if(environment.temperature > config.target_temperature)
458+
regulating_temperature = "cooling"
459+
else
460+
regulating_temperature = "heating"
461+
thermo_changed = TRUE
462+
else if(regulating_temperature == "heating" && environment.temperature > config.target_temperature)
463+
regulating_temperature = "cooling"
464+
thermo_changed = TRUE
465+
else if(regulating_temperature == "cooling" && environment.temperature < config.target_temperature)
466+
regulating_temperature = "heating"
467+
thermo_changed = TRUE
468+
if(thermo_changed)
469+
visible_message("\The [src] clicks as it starts [regulating_temperature] the room.",\
455470
"You hear a click and a faint electronic hum.")
456471

457472
var/datum/gas_mixture/gas = environment.remove_volume(0.25 * CELL_VOLUME)
458473
if(gas)
459474
var/heat_capacity = gas.heat_capacity()
460475
var/energy_used = min(abs(heat_capacity * (gas.temperature - actual_target_temperature)), MAX_ENERGY_CHANGE)
461-
var/cooled = 0 //1 means we cooled this tick, 0 means we warmed. Used for the message below.
462476

463477
// We need to cool ourselves, but only if the gas isn't already colder than what we can do.
464478
if (environment.temperature > actual_target_temperature && gas.temperature >= MIN_TEMPERATURE)
465479
gas.temperature -= energy_used / heat_capacity
466480
use_power(energy_used/3) //these are heat pumps, so they can have a >100% efficiency, typically about 300%
467-
cooled = 1
468481
// We need to warm ourselves, but only if the gas isn't already hotter than what we can do.
469482
else if (environment.temperature < actual_target_temperature && gas.temperature <= MAX_TEMPERATURE)
470483
gas.temperature += energy_used / heat_capacity
@@ -473,9 +486,9 @@ var/global/list/air_alarms = list()
473486
environment.merge(gas)
474487

475488
if (abs(environment.temperature - actual_target_temperature) <= 0.5)
476-
regulating_temperature = 0
477-
visible_message("\The [src] clicks quietly as it stops [cooled ? "cooling" : "heating"] the room.",\
489+
visible_message("\The [src] clicks quietly as it stops [regulating_temperature] the room.",\
478490
"You hear a click as a faint electronic humming stops.")
491+
regulating_temperature = 0
479492

480493
var/old_level = local_danger_level
481494
var/new_danger = calculate_local_danger_level(environment)
@@ -976,14 +989,11 @@ var/global/list/air_alarms = list()
976989
else
977990
max_temperature = temperature_threshold.max_1() - T0C
978991
min_temperature = temperature_threshold.min_1() - T0C
979-
var/input_temperature = input("What temperature (in C) would you like the system to target? (Capped between [min_temperature]C and [max_temperature]C).\n\nNote that the cooling unit in this air alarm can not go below [MIN_TEMPERATURE]C or above [MAX_TEMPERATURE]C by itself. ", "Thermostat Controls") as num|null
992+
var/input_temperature = input("What temperature (in C) would you like the system to target? (Capped between [min_temperature]C and [max_temperature]C).\n\nNote that the cooling unit in this air alarm can not go below [MIN_TEMPERATURE - T0C]C or above [MAX_TEMPERATURE - T0C]C by itself. ", "Thermostat Controls") as num|null
980993
if(input_temperature==null)
981994
return 1
982-
if(!input_temperature || input_temperature >= max_temperature || input_temperature <= min_temperature)
983-
to_chat(usr, "<span class='warning'>Temperature must be between [min_temperature]C and [max_temperature]C.</span>")
984-
else
985-
input_temperature = input_temperature + T0C
986-
set_temperature(input_temperature)
995+
input_temperature = round(clamp(input_temperature, min_temperature, max_temperature) + T0C, 0.01)
996+
set_temperature(input_temperature)
987997
return 1
988998

989999
if(!buttonCheck(usr))

code/game/machinery/computer/atmos_control.dm

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,10 @@ var/global/list/atmos_controllers = list()
427427
if(href_list["set_preset_setting"] == "target_temperature")
428428
var/max_temperature = MAX_TARGET_TEMPERATURE - T0C //these defines should come from code\game\machinery\alarm.dm
429429
var/min_temperature = MIN_TARGET_TEMPERATURE - T0C
430-
var/input_temperature = input("What temperature (in C) would you like the system to target? (Capped between [min_temperature]C and [max_temperature]C).\n\nNote that the cooling unit in this air alarm can not go below [MIN_TEMPERATURE]C or above [MAX_TEMPERATURE]C by itself. ", "Thermostat Controls") as num|null
430+
var/input_temperature = input("What temperature (in C) would you like the system to target? (Capped between [min_temperature]C and [max_temperature]C).\n\nNote that the cooling unit in this air alarm can not go below [MIN_TEMPERATURE - T0C]C or above [MAX_TEMPERATURE - T0C]C by itself. ", "Thermostat Controls") as num|null
431431
if(input_temperature==null)
432432
return 1
433-
if(!input_temperature || input_temperature >= max_temperature || input_temperature <= min_temperature)
434-
to_chat(usr, "<span class='warning'>Temperature must be between [min_temperature]C and [max_temperature]C.</span>")
435-
else
436-
input_temperature = input_temperature + T0C
433+
input_temperature = round(clamp(input_temperature, min_temperature, max_temperature) + T0C, 0.01)
437434
selected_preset.target_temperature = input_temperature
438435
return 1
439436
else if(href_list["set_preset_setting"] == "scrubbed_gases")
@@ -613,14 +610,11 @@ var/global/list/atmos_controllers = list()
613610
else
614611
max_temperature = temperature_threshold.max_1() - T0C
615612
min_temperature = temperature_threshold.min_1() - T0C
616-
var/input_temperature = input("What temperature (in C) would you like the system to target? (Capped between [min_temperature]C and [max_temperature]C).\n\nNote that the cooling unit in this air alarm can not go below [MIN_TEMPERATURE]C or above [MAX_TEMPERATURE]C by itself. ", "Thermostat Controls") as num|null
613+
var/input_temperature = input("What temperature (in C) would you like the system to target? (Capped between [min_temperature]C and [max_temperature]C).\n\nNote that the cooling unit in this air alarm can not go below [MIN_TEMPERATURE - T0C]C or above [MAX_TEMPERATURE - T0C]C by itself. ", "Thermostat Controls") as num|null
617614
if(input_temperature==null)
618615
return 1
619-
if(!input_temperature || input_temperature >= max_temperature || input_temperature <= min_temperature)
620-
to_chat(usr, "<span class='warning'>Temperature must be between [min_temperature]C and [max_temperature]C.</span>")
621-
else
622-
input_temperature = input_temperature + T0C
623-
current.set_temperature(input_temperature)
616+
input_temperature = round(clamp(input_temperature, min_temperature, max_temperature) + T0C, 0.01)
617+
current.set_temperature(input_temperature)
624618
return 1
625619

626620
#undef ACA_SCREEN_DETAILSVIEW

0 commit comments

Comments
 (0)