From d186c4f2365e1a8a51fc29695a29bd4f3fce3020 Mon Sep 17 00:00:00 2001 From: Ghilker <42839747+Ghilker@users.noreply.github.com> Date: Sun, 13 Dec 2020 06:16:53 +0100 Subject: [PATCH] Temperature control unit (#55345) This PR changes how freezers/heaters work by adding a button in the GUI that allow the users to switch between cooling and heating without the need to deconstruct the machine. Circuitboards now will build the freezer and can't be changed by screwdriving the board. Mapping isn't touched, all other functionalities are still there. --- .../circuitboards/machine_circuitboards.dm | 48 +------- .../components/unary_devices/thermomachine.dm | 104 ++++++++++-------- .../modules/unit_tests/machine_disassembly.dm | 2 +- .../packages/tgui/interfaces/ThermoMachine.js | 9 +- tgui/public/tgui.bundle.js | 2 +- 5 files changed, 72 insertions(+), 93 deletions(-) diff --git a/code/game/objects/items/circuitboards/machine_circuitboards.dm b/code/game/objects/items/circuitboards/machine_circuitboards.dm index d6661c5e2b2..922598bf3cd 100644 --- a/code/game/objects/items/circuitboards/machine_circuitboards.dm +++ b/code/game/objects/items/circuitboards/machine_circuitboards.dm @@ -274,7 +274,7 @@ /obj/item/circuitboard/machine/thermomachine name = "Thermomachine (Machine Board)" icon_state = "engineering" - desc = "You can use a screwdriver to switch between heater and freezer." + build_path = /obj/machinery/atmospherics/components/unary/thermomachine/freezer var/pipe_layer = PIPING_LAYER_DEFAULT req_components = list( /obj/item/stock_parts/matter_bin = 2, @@ -282,58 +282,16 @@ /obj/item/stack/cable_coil = 1, /obj/item/stack/sheet/glass = 1) -#define PATH_FREEZER /obj/machinery/atmospherics/components/unary/thermomachine/freezer -#define PATH_HEATER /obj/machinery/atmospherics/components/unary/thermomachine/heater - -/obj/item/circuitboard/machine/thermomachine/Initialize() +/obj/item/circuitboard/machine/thermomachine/multitool_act(mob/living/user, obj/item/multitool/I) . = ..() - if(!build_path) - if(prob(50)) - name = "Freezer (Machine Board)" - build_path = PATH_FREEZER - else - name = "Heater (Machine Board)" - build_path = PATH_HEATER - -/obj/item/circuitboard/machine/thermomachine/attackby(obj/item/I, mob/user, params) - if(I.tool_behaviour == TOOL_SCREWDRIVER) - var/obj/item/circuitboard/new_type - var/new_setting - switch(build_path) - if(PATH_FREEZER) - new_type = /obj/item/circuitboard/machine/thermomachine/heater - new_setting = "Heater" - if(PATH_HEATER) - new_type = /obj/item/circuitboard/machine/thermomachine/freezer - new_setting = "Freezer" - name = initial(new_type.name) - build_path = initial(new_type.build_path) - I.play_tool_sound(src) - to_chat(user, "You change the circuitboard setting to \"[new_setting]\".") - return - - if(I.tool_behaviour == TOOL_MULTITOOL) + if (istype(I)) pipe_layer = (pipe_layer >= PIPING_LAYER_MAX) ? PIPING_LAYER_MIN : (pipe_layer + 1) to_chat(user, "You change the circuitboard to layer [pipe_layer].") - return - - . = ..() /obj/item/circuitboard/machine/thermomachine/examine() . = ..() . += "It is set to layer [pipe_layer]." -/obj/item/circuitboard/machine/thermomachine/heater - name = "Heater (Machine Board)" - build_path = PATH_HEATER - -/obj/item/circuitboard/machine/thermomachine/freezer - name = "Freezer (Machine Board)" - build_path = PATH_FREEZER - -#undef PATH_FREEZER -#undef PATH_HEATER - /obj/item/circuitboard/machine/HFR_fuel_input name = "HFR Fuel Input (Machine Board)" icon_state = "engineering" diff --git a/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm b/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm index c2807a55a0a..8b7b5249c66 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm @@ -2,7 +2,7 @@ icon = 'icons/obj/atmospherics/components/thermomachine.dmi' icon_state = "freezer" - name = "thermomachine" + name = "Temperature control unit" desc = "Heats or cools gas in connected pipes." density = TRUE @@ -17,28 +17,59 @@ var/icon_state_on = "freezer_1" var/icon_state_open = "freezer-o" - var/min_temperature = 0 - var/max_temperature = 0 + var/min_temperature = T20C //actual temperature will be defined by RefreshParts() and by the cooling var + var/max_temperature = T20C //actual temperature will be defined by RefreshParts() and by the cooling var var/target_temperature = T20C var/heat_capacity = 0 var/interactive = TRUE // So mapmakers can disable interaction. + var/cooling = TRUE + var/base_heating = 140 + var/base_cooling = 170 /obj/machinery/atmospherics/components/unary/thermomachine/Initialize() . = ..() initialize_directions = dir + RefreshParts() + update_icon() + +/obj/machinery/atmospherics/components/unary/thermomachine/proc/swap_function() + cooling = !cooling + if(cooling) + icon_state_off = "freezer" + icon_state_on = "freezer_1" + icon_state_open = "freezer-o" + else + icon_state_off = "heater" + icon_state_on = "heater_1" + icon_state_open = "heater-o" + target_temperature = T20C + RefreshParts() + update_icon() /obj/machinery/atmospherics/components/unary/thermomachine/on_construction(obj_color, set_layer) var/obj/item/circuitboard/machine/thermomachine/board = circuit if(board) piping_layer = board.pipe_layer set_layer = piping_layer - ..() + return..() /obj/machinery/atmospherics/components/unary/thermomachine/RefreshParts() - var/B - for(var/obj/item/stock_parts/matter_bin/M in component_parts) - B += M.rating - heat_capacity = 5000 * ((B - 1) ** 2) + var/calculated_bin_rating + for(var/obj/item/stock_parts/matter_bin/bin in component_parts) + calculated_bin_rating += bin.rating + heat_capacity = 5000 * ((calculated_bin_rating - 1) ** 2) + min_temperature = T20C + max_temperature = T20C + if(cooling) + var/calculated_laser_rating + for(var/obj/item/stock_parts/micro_laser/laser in component_parts) + calculated_laser_rating += laser.rating + min_temperature = max(T0C - (base_cooling + calculated_laser_rating * 15), TCMB) //73.15K with T1 stock parts + else + var/calculated_laser_rating + for(var/obj/item/stock_parts/micro_laser/laser in component_parts) + calculated_laser_rating += laser.rating + max_temperature = T20C + (base_heating * calculated_laser_rating) //573.15K with T1 stock parts /obj/machinery/atmospherics/components/unary/thermomachine/update_icon() cut_overlays() @@ -64,6 +95,18 @@ . += "The status display reads: Efficiency [(heat_capacity/5000)*100]%." . += "Temperature range [min_temperature]K - [max_temperature]K ([(T0C-min_temperature)*-1]C - [(T0C-max_temperature)*-1]C)." +/obj/machinery/atmospherics/components/unary/thermomachine/AltClick(mob/living/user) + if(!can_interact(user)) + return + if(cooling) + target_temperature = min_temperature + investigate_log("was set to [target_temperature] K by [key_name(user)]", INVESTIGATE_ATMOS) + to_chat(user, "You minimize the target temperature on [src] to [target_temperature] K.") + else + target_temperature = max_temperature + investigate_log("was set to [target_temperature] K by [key_name(user)]", INVESTIGATE_ATMOS) + to_chat(user, "You maximize the target temperature on [src] to [target_temperature] K.") + /obj/machinery/atmospherics/components/unary/thermomachine/process_atmos() ..() if(!on || !nodes[1]) @@ -130,6 +173,7 @@ /obj/machinery/atmospherics/components/unary/thermomachine/ui_data(mob/user) var/list/data = list() data["on"] = on + data["cooling"] = cooling data["min"] = min_temperature data["max"] = max_temperature @@ -152,6 +196,10 @@ use_power = on ? ACTIVE_POWER_USE : IDLE_POWER_USE investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", INVESTIGATE_ATMOS) . = TRUE + if("cooling") + swap_function() + investigate_log("was changed to [cooling ? "cooling" : "heating"] by [key_name(usr)]", INVESTIGATE_ATMOS) + . = TRUE if("target") var/target = params["target"] var/adjust = text2num(params["adjust"]) @@ -179,14 +227,11 @@ update_icon() /obj/machinery/atmospherics/components/unary/thermomachine/freezer - name = "freezer" icon_state = "freezer" icon_state_off = "freezer" icon_state_on = "freezer_1" icon_state_open = "freezer-o" - max_temperature = T20C - min_temperature = 170 //actual minimum temperature is defined by RefreshParts() - circuit = /obj/item/circuitboard/machine/thermomachine/freezer + cooling = TRUE /obj/machinery/atmospherics/components/unary/thermomachine/freezer/on on = TRUE @@ -198,50 +243,19 @@ target_temperature = min_temperature /obj/machinery/atmospherics/components/unary/thermomachine/freezer/on/coldroom - name = "cold room freezer" + name = "Cold room temperature control unit" /obj/machinery/atmospherics/components/unary/thermomachine/freezer/on/coldroom/Initialize() . = ..() target_temperature = COLD_ROOM_TEMP -/obj/machinery/atmospherics/components/unary/thermomachine/freezer/RefreshParts() - ..() - var/L - for(var/obj/item/stock_parts/micro_laser/M in component_parts) - L += M.rating - min_temperature = max(T0C - (initial(min_temperature) + L * 15), TCMB) //73.15K with T1 stock parts - -/obj/machinery/atmospherics/components/unary/thermomachine/freezer/AltClick(mob/living/user) - if(!can_interact(user)) - return - target_temperature = min_temperature - investigate_log("was set to [target_temperature] K by [key_name(user)]", INVESTIGATE_ATMOS) - to_chat(user, "You minimize the target temperature on [src] to [target_temperature] K.") - /obj/machinery/atmospherics/components/unary/thermomachine/heater - name = "heater" icon_state = "heater" icon_state_off = "heater" icon_state_on = "heater_1" icon_state_open = "heater-o" - max_temperature = 140 //actual maximum temperature is defined by RefreshParts() - min_temperature = T20C - circuit = /obj/item/circuitboard/machine/thermomachine/heater + cooling = FALSE /obj/machinery/atmospherics/components/unary/thermomachine/heater/on on = TRUE icon_state = "heater_1" - -/obj/machinery/atmospherics/components/unary/thermomachine/heater/RefreshParts() - ..() - var/L - for(var/obj/item/stock_parts/micro_laser/M in component_parts) - L += M.rating - max_temperature = T20C + (initial(max_temperature) * L) //573.15K with T1 stock parts - -/obj/machinery/atmospherics/components/unary/thermomachine/heater/AltClick(mob/living/user) - if(!can_interact(user)) - return - target_temperature = max_temperature - investigate_log("was set to [target_temperature] K by [key_name(user)]", INVESTIGATE_ATMOS) - to_chat(user, "You maximize the target temperature on [src] to [target_temperature] K.") diff --git a/code/modules/unit_tests/machine_disassembly.dm b/code/modules/unit_tests/machine_disassembly.dm index e0e38214aa6..59edb4ae9db 100644 --- a/code/modules/unit_tests/machine_disassembly.dm +++ b/code/modules/unit_tests/machine_disassembly.dm @@ -9,4 +9,4 @@ TEST_ASSERT(locate(/obj/item/stock_parts/micro_laser) in freezer_location, "Couldn't find micro-laser when disassembling freezer") // Check that the circuit board itself is created - TEST_ASSERT(locate(/obj/item/circuitboard/machine/thermomachine/freezer) in freezer_location, "Couldn't find the circuit board when disassembling freezer") + TEST_ASSERT(locate(/obj/item/circuitboard/machine/thermomachine) in freezer_location, "Couldn't find the circuit board when disassembling freezer") diff --git a/tgui/packages/tgui/interfaces/ThermoMachine.js b/tgui/packages/tgui/interfaces/ThermoMachine.js index 69bd39aaaaf..e7e4c0ecd3c 100644 --- a/tgui/packages/tgui/interfaces/ThermoMachine.js +++ b/tgui/packages/tgui/interfaces/ThermoMachine.js @@ -8,7 +8,7 @@ export const ThermoMachine = (props, context) => { return ( + height={250}>
@@ -36,6 +36,13 @@ export const ThermoMachine = (props, context) => { onClick={() => act('power')} /> )}> + +