From 330335e7e25bc144af4eb4799aee27d5295a0096 Mon Sep 17 00:00:00 2001 From: jwhitak Date: Thu, 29 Aug 2024 10:38:33 -0500 Subject: [PATCH 1/3] thermostat fixes --- code/game/machinery/alarm.dm | 32 ++++++++++++------- code/game/machinery/computer/atmos_control.dm | 12 +++---- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index 93c8cd3783d2..576e693e7d29 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -330,7 +330,6 @@ var/global/list/air_alarms = list() var/buildstage = 2 //2 is built, 1 is building, 0 is frame. var/cycle_after_preset = 1 // Whether we automatically cycle when presets are changed - var/target_temperature = T0C+20 var/regulating_temperature = 0 var/datum/radio_frequency/radio_connection @@ -444,27 +443,36 @@ var/global/list/air_alarms = list() // Handle temperature adjustment here. if(environment.temperature < config.target_temperature - 2 || environment.temperature > config.target_temperature + 2 || regulating_temperature) //If it goes too far, we should adjust ourselves back before stopping. - var/actual_target_temperature = target_temperature + var/actual_target_temperature = config.target_temperature if(config.temperature_threshold.assess_danger(actual_target_temperature)) //use the max or min safe temperature actual_target_temperature = clamp(actual_target_temperature, config.temperature_threshold.min_1(), config.temperature_threshold.max_1()) - + var/thermo_changed = FALSE if(!regulating_temperature) - regulating_temperature = 1 - visible_message("\The [src] clicks as it starts [environment.temperature > config.target_temperature ? "cooling" : "heating"] the room.",\ + if(environment.temperature > config.target_temperature) + regulating_temperature = "cooling" + else + regulating_temperature = "heating" + thermo_changed = TRUE + else if(regulating_temperature == "heating" && environment.temperature > config.target_temperature) + regulating_temperature = "cooling" + thermo_changed = TRUE + else if(regulating_temperature == "cooling" && environment.temperature < config.target_temperature) + regulating_temperature = "heating" + thermo_changed = TRUE + if(thermo_changed) + visible_message("\The [src] clicks as it starts [regulating_temperature] the room.",\ "You hear a click and a faint electronic hum.") var/datum/gas_mixture/gas = environment.remove_volume(0.25 * CELL_VOLUME) if(gas) var/heat_capacity = gas.heat_capacity() var/energy_used = min(abs(heat_capacity * (gas.temperature - actual_target_temperature)), MAX_ENERGY_CHANGE) - var/cooled = 0 //1 means we cooled this tick, 0 means we warmed. Used for the message below. // We need to cool ourselves, but only if the gas isn't already colder than what we can do. if (environment.temperature > actual_target_temperature && gas.temperature >= MIN_TEMPERATURE) gas.temperature -= energy_used / heat_capacity use_power(energy_used/3) //these are heat pumps, so they can have a >100% efficiency, typically about 300% - cooled = 1 // We need to warm ourselves, but only if the gas isn't already hotter than what we can do. else if (environment.temperature < actual_target_temperature && gas.temperature <= MAX_TEMPERATURE) gas.temperature += energy_used / heat_capacity @@ -473,9 +481,9 @@ var/global/list/air_alarms = list() environment.merge(gas) if (abs(environment.temperature - actual_target_temperature) <= 0.5) - regulating_temperature = 0 - visible_message("\The [src] clicks quietly as it stops [cooled ? "cooling" : "heating"] the room.",\ + visible_message("\The [src] clicks quietly as it stops [regulating_temperature] the room.",\ "You hear a click as a faint electronic humming stops.") + regulating_temperature = 0 var/old_level = local_danger_level var/new_danger = calculate_local_danger_level(environment) @@ -976,13 +984,13 @@ var/global/list/air_alarms = list() else max_temperature = temperature_threshold.max_1() - T0C min_temperature = temperature_threshold.min_1() - T0C - 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 + 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 if(input_temperature==null) return 1 - if(!input_temperature || input_temperature >= max_temperature || input_temperature <= min_temperature) + if(input_temperature > max_temperature || input_temperature < min_temperature) to_chat(usr, "Temperature must be between [min_temperature]C and [max_temperature]C.") else - input_temperature = input_temperature + T0C + input_temperature = round(input_temperature + T0C,0.01) set_temperature(input_temperature) return 1 diff --git a/code/game/machinery/computer/atmos_control.dm b/code/game/machinery/computer/atmos_control.dm index 0902ed1a8b60..bec645930e0b 100644 --- a/code/game/machinery/computer/atmos_control.dm +++ b/code/game/machinery/computer/atmos_control.dm @@ -427,13 +427,13 @@ var/global/list/atmos_controllers = list() if(href_list["set_preset_setting"] == "target_temperature") var/max_temperature = MAX_TARGET_TEMPERATURE - T0C //these defines should come from code\game\machinery\alarm.dm var/min_temperature = MIN_TARGET_TEMPERATURE - T0C - 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 + 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 if(input_temperature==null) return 1 - if(!input_temperature || input_temperature >= max_temperature || input_temperature <= min_temperature) + if(input_temperature > max_temperature || input_temperature < min_temperature) to_chat(usr, "Temperature must be between [min_temperature]C and [max_temperature]C.") else - input_temperature = input_temperature + T0C + input_temperature = round(input_temperature + T0C,0.01) selected_preset.target_temperature = input_temperature return 1 else if(href_list["set_preset_setting"] == "scrubbed_gases") @@ -613,13 +613,13 @@ var/global/list/atmos_controllers = list() else max_temperature = temperature_threshold.max_1() - T0C min_temperature = temperature_threshold.min_1() - T0C - 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 + 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 if(input_temperature==null) return 1 - if(!input_temperature || input_temperature >= max_temperature || input_temperature <= min_temperature) + if(input_temperature > max_temperature || input_temperature < min_temperature) to_chat(usr, "Temperature must be between [min_temperature]C and [max_temperature]C.") else - input_temperature = input_temperature + T0C + input_temperature = round(input_temperature + T0C,0.01) current.set_temperature(input_temperature) return 1 From e6d6f406efbfd6976503bfa43bcf108ed39ce460 Mon Sep 17 00:00:00 2001 From: jwhitak Date: Thu, 29 Aug 2024 11:14:50 -0500 Subject: [PATCH 2/3] handles map presets and vv --- code/game/machinery/alarm.dm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index 576e693e7d29..0ca8f685a7b9 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -330,6 +330,7 @@ var/global/list/air_alarms = list() var/buildstage = 2 //2 is built, 1 is building, 0 is frame. var/cycle_after_preset = 1 // Whether we automatically cycle when presets are changed + var/target_temperature //Manual override for target temperature changing, usable for maps/admin vv edits var/regulating_temperature = 0 var/datum/radio_frequency/radio_connection @@ -438,6 +439,10 @@ var/global/list/air_alarms = list() if(!istype(location)) return//returns if loc is not simulated + if(!isnull(target_temperature)) + set_temperature(target_temperature, FALSE) + target_temperature = null + var/datum/gas_mixture/environment = location.return_air() // Handle temperature adjustment here. From 9882871159786f522678d1f6277c2fc81f2e6d31 Mon Sep 17 00:00:00 2001 From: jwhitak Date: Wed, 4 Sep 2024 02:32:42 -0500 Subject: [PATCH 3/3] clamps input instead of erroring --- code/game/machinery/alarm.dm | 7 ++----- code/game/machinery/computer/atmos_control.dm | 12 +++--------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index 0ca8f685a7b9..9b1cc11a01e0 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -992,11 +992,8 @@ var/global/list/air_alarms = list() 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 if(input_temperature==null) return 1 - if(input_temperature > max_temperature || input_temperature < min_temperature) - to_chat(usr, "Temperature must be between [min_temperature]C and [max_temperature]C.") - else - input_temperature = round(input_temperature + T0C,0.01) - set_temperature(input_temperature) + input_temperature = round(clamp(input_temperature, min_temperature, max_temperature) + T0C, 0.01) + set_temperature(input_temperature) return 1 if(!buttonCheck(usr)) diff --git a/code/game/machinery/computer/atmos_control.dm b/code/game/machinery/computer/atmos_control.dm index bec645930e0b..6fa6ae4358cb 100644 --- a/code/game/machinery/computer/atmos_control.dm +++ b/code/game/machinery/computer/atmos_control.dm @@ -430,10 +430,7 @@ var/global/list/atmos_controllers = list() 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 if(input_temperature==null) return 1 - if(input_temperature > max_temperature || input_temperature < min_temperature) - to_chat(usr, "Temperature must be between [min_temperature]C and [max_temperature]C.") - else - input_temperature = round(input_temperature + T0C,0.01) + input_temperature = round(clamp(input_temperature, min_temperature, max_temperature) + T0C, 0.01) selected_preset.target_temperature = input_temperature return 1 else if(href_list["set_preset_setting"] == "scrubbed_gases") @@ -616,11 +613,8 @@ var/global/list/atmos_controllers = list() 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 if(input_temperature==null) return 1 - if(input_temperature > max_temperature || input_temperature < min_temperature) - to_chat(usr, "Temperature must be between [min_temperature]C and [max_temperature]C.") - else - input_temperature = round(input_temperature + T0C,0.01) - current.set_temperature(input_temperature) + input_temperature = round(clamp(input_temperature, min_temperature, max_temperature) + T0C, 0.01) + current.set_temperature(input_temperature) return 1 #undef ACA_SCREEN_DETAILSVIEW