Rewrite heaters/freezers; port to tgui

They are now one type, thermomachine.
This commit is contained in:
Bjorn Neergaard
2016-01-22 19:25:35 -06:00
parent 442d286417
commit 4c192d705a
21 changed files with 274 additions and 433 deletions
@@ -3,7 +3,7 @@ So much of atmospherics.dm was used solely by components, so separating this mak
On top of that, now people can add component-speciic procs/vars if they want!
*/
/obj/machinery/atmospherics/components/
/obj/machinery/atmospherics/components
var/welded = 0 //Used on pumps and scrubbers
var/showpipe = 0
@@ -1,252 +0,0 @@
/obj/machinery/atmospherics/components/unary/cold_sink/freezer
name = "freezer"
icon = 'icons/obj/Cryogenic2.dmi'
icon_state = "freezer"
density = 1
var/min_temperature = 0
anchored = 1
use_power = 1
current_heat_capacity = 1000
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/New()
..()
initialize_directions = dir
component_parts = list()
component_parts += new /obj/item/weapon/circuitboard/thermomachine(null)
component_parts += new /obj/item/weapon/stock_parts/matter_bin(null)
component_parts += new /obj/item/weapon/stock_parts/matter_bin(null)
component_parts += new /obj/item/weapon/stock_parts/micro_laser(null)
component_parts += new /obj/item/weapon/stock_parts/micro_laser(null)
component_parts += new /obj/item/weapon/stock_parts/console_screen(null)
component_parts += new /obj/item/stack/cable_coil(null, 1)
RefreshParts()
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/construction()
..(dir,dir)
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/RefreshParts()
var/H
var/T
for(var/obj/item/weapon/stock_parts/matter_bin/M in component_parts)
H += M.rating
for(var/obj/item/weapon/stock_parts/micro_laser/M in component_parts)
T += M.rating
min_temperature = max(T0C - (170 + T*15), TCMB)
current_heat_capacity = 1000 * ((H - 1) ** 2)
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/attackby(obj/item/I, mob/user, params)
if(default_deconstruction_screwdriver(user, "freezer-o", "freezer", I))
on = 0
update_icon()
return
if(exchange_parts(user, I))
return
default_deconstruction_crowbar(I)
if(default_change_direction_wrench(user, I))
return
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/update_icon()
if(panel_open)
icon_state = "freezer-o"
else if(src.on)
icon_state = "freezer_1"
else
icon_state = "freezer"
return
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/attack_ai(mob/user)
return interact(user)
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/attack_paw(mob/user)
return interact(user)
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/attack_hand(mob/user)
return interact(user)
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/interact(mob/user)
if(stat & (NOPOWER|BROKEN))
return
var/datum/gas_mixture/air_contents = AIR1
user.set_machine(src)
var/temp_text = ""
if(air_contents.temperature > (T0C - 20))
temp_text = "<span class='bad'>[air_contents.temperature]</span>"
else if(air_contents.temperature < (T0C - 20) && air_contents.temperature > (T0C - 100))
temp_text = "<span class='average'>[air_contents.temperature]</span>"
else
temp_text = "<span class='good'>[air_contents.temperature]</span>"
var/dat = {"
Current Status: [ on ? "<A href='?src=\ref[src];start=1'>Off</A> <span class='linkOn'>On</span>" : "<span class='linkOn'>Off</span> <A href='?src=\ref[src];start=1'>On</A>"]<BR>
Current Gas Temperature: [temp_text]<BR>
Current Air Pressure: [air_contents.return_pressure()]<BR>
Target Gas Temperature: <A href='?src=\ref[src];temp=-100'>-</A> <A href='?src=\ref[src];temp=-10'>-</A> <A href='?src=\ref[src];temp=-1'>-</A> [current_temperature] <A href='?src=\ref[src];temp=1'>+</A> <A href='?src=\ref[src];temp=10'>+</A> <A href='?src=\ref[src];temp=100'>+</A><BR>
"}
//user << browse(dat, "window=freezer;size=400x500")
//onclose(user, "freezer")
var/datum/browser/popup = new(user, "freezer", "Cryo Gas Cooling System", 400, 240) // Set up the popup browser window
popup.set_title_image(user.browse_rsc_icon(src.icon, src.icon_state))
popup.set_content(dat)
popup.open()
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/Topic(href, href_list)
if(..())
return
usr.set_machine(src)
if (href_list["start"])
src.on = !src.on
use_power = 1 + src.on
update_icon()
if(href_list["temp"])
var/amount = text2num(href_list["temp"])
if(amount > 0)
src.current_temperature = min(T20C, src.current_temperature+amount)
else
src.current_temperature = max(min_temperature, src.current_temperature+amount)
src.updateUsrDialog()
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/process()
..()
src.updateUsrDialog()
/obj/machinery/atmospherics/components/unary/cold_sink/freezer/power_change()
..()
if(stat & NOPOWER)
on = 0
update_icon()
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/
name = "heater"
icon = 'icons/obj/Cryogenic2.dmi'
icon_state = "heater"
density = 1
var/max_temperature = 0
anchored = 1
current_heat_capacity = 1000
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/New()
..()
initialize_directions = dir
var/obj/item/weapon/circuitboard/thermomachine/H = new /obj/item/weapon/circuitboard/thermomachine(null)
H.build_path = /obj/machinery/atmospherics/components/unary/heat_reservoir/heater
H.name = "circuit board (Heater)"
component_parts = list()
component_parts += H
component_parts += new /obj/item/weapon/stock_parts/matter_bin(null)
component_parts += new /obj/item/weapon/stock_parts/matter_bin(null)
component_parts += new /obj/item/weapon/stock_parts/micro_laser(null)
component_parts += new /obj/item/weapon/stock_parts/micro_laser(null)
component_parts += new /obj/item/weapon/stock_parts/console_screen(null)
component_parts += new /obj/item/stack/cable_coil(null, 1)
RefreshParts()
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/construction()
..(dir,dir)
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/RefreshParts()
var/H
var/T
for(var/obj/item/weapon/stock_parts/matter_bin/M in component_parts)
H += M.rating
for(var/obj/item/weapon/stock_parts/micro_laser/M in component_parts)
T += M.rating
max_temperature = T20C + (140 * T)
current_heat_capacity = 1000 * ((H - 1) ** 2)
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/attackby(obj/item/I, mob/user, params)
if(default_deconstruction_screwdriver(user, "heater-o", "heater", I))
on = 0
update_icon()
return
if(exchange_parts(user, I))
return
default_deconstruction_crowbar(I)
if(default_change_direction_wrench(user, I))
return
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/update_icon()
if(panel_open)
icon_state = "heater-o"
else if(src.on)
icon_state = "heater_1"
else
icon_state = "heater"
return
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/attack_ai(mob/user)
return src.attack_hand(user)
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/attack_paw(mob/user)
return src.attack_hand(user)
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/attack_hand(mob/user)
return interact(user)
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/interact(mob/user)
var/datum/gas_mixture/air_contents = AIR1
if(stat & (NOPOWER|BROKEN))
return
user.set_machine(src)
var/temp_text = ""
if(air_contents.temperature < (T20C + 80))
temp_text = "<span class='good'>[air_contents.temperature]</span>"
else if(air_contents.temperature > (T20C + 80) && air_contents.temperature < (T20C + 180))
temp_text = "<span class='average'>[air_contents.temperature]</span>"
else
temp_text = "<span class='bad'>[air_contents.temperature]</span>"
var/dat = {"
Current Status: [ on ? "<A href='?src=\ref[src];start=1'>Off</A> <span class='linkOn'>On</span>" : "<span class='linkOn'>Off</span> <A href='?src=\ref[src];start=1'>On</A>"]<BR>
Current Gas Temperature: [temp_text]<BR>
Current Air Pressure: [air_contents.return_pressure()]<BR>
Target Gas Temperature: <A href='?src=\ref[src];temp=-100'>-</A> <A href='?src=\ref[src];temp=-10'>-</A> <A href='?src=\ref[src];temp=-1'>-</A> [current_temperature] <A href='?src=\ref[src];temp=1'>+</A> <A href='?src=\ref[src];temp=10'>+</A> <A href='?src=\ref[src];temp=100'>+</A><BR>
"}
//user << browse(dat, "window=freezer;size=400x500")
//onclose(user, "freezer")
var/datum/browser/popup = new(user, "freezer", "Pyro Gas Heating System", 400, 240) // Set up the popup browser window
popup.set_title_image(user.browse_rsc_icon(src.icon, src.icon_state))
popup.set_content(dat)
popup.open()
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/Topic(href, href_list)
if(..())
return
usr.set_machine(src)
if (href_list["start"])
src.on = !src.on
use_power = 1 + src.on
update_icon()
if(href_list["temp"])
var/amount = text2num(href_list["temp"])
if(amount > 0)
src.current_temperature = min((max_temperature), src.current_temperature+amount)
else
src.current_temperature = max(T20C, src.current_temperature+amount)
src.updateUsrDialog()
src.add_fingerprint(usr)
return
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/process()
..()
src.updateUsrDialog()
/obj/machinery/atmospherics/components/unary/heat_reservoir/heater/power_change()
..()
if(stat & NOPOWER)
on = 0
update_icon()
@@ -1,54 +0,0 @@
/obj/machinery/atmospherics/components/unary/cold_sink
icon_state = "cold_map"
use_power = 1
name = "cold sink"
desc = "Cools gas when connected to pipe network"
var/on = 0
var/current_temperature = T20C
var/current_heat_capacity = 50000 //totally random
/obj/machinery/atmospherics/components/unary/cold_sink/update_icon_nopipes()
overlays.Cut()
if(showpipe)
overlays += getpipeimage('icons/obj/atmospherics/components/unary_devices.dmi', "scrub_cap", initialize_directions) //scrub_cap works for now
if(!NODE1 || !on || stat & (NOPOWER|BROKEN))
icon_state = "cold_off"
return
else
icon_state = "cold_on"
//Nearly Identical Proc: /obj/machinery/atmospherics/components/unary/heat_reservoir/process_atmos()
/obj/machinery/atmospherics/components/unary/cold_sink/process_atmos()
..()
if(!on)
return 0
var/datum/gas_mixture/air_contents = AIR1
var/air_heat_capacity = air_contents.heat_capacity()
var/combined_heat_capacity = current_heat_capacity + air_heat_capacity
var/old_temperature = air_contents.temperature
if(combined_heat_capacity > 0)
//current_tempature is target tempature
var/combined_energy = current_heat_capacity*current_temperature + air_heat_capacity*air_contents.temperature
air_contents.temperature = combined_energy/combined_heat_capacity
var/temperatureChange=abs(old_temperature-air_contents.temperature)
if(temperatureChange > 1)
//The new formula is based on change from current temp, instead of change from T20C
// The 10 const is not scaled yet.
active_power_usage = (current_heat_capacity * temperatureChange ) / 10 + idle_power_usage
//Note: Powerusage won't be subtracted off till next tick but one tick of not being accurate before machine turns off is fine
update_parents()
else
//No change in temp, use idle power
active_power_usage= idle_power_usage
return 1
@@ -69,10 +69,6 @@
if(!on)
return
var/datum/gas_mixture/air1 = AIR1
if(!is_operational())
on = FALSE
update_icon()
return
if(occupant)
if(occupant.health >= 100) // Don't bother with fully healed people.
on = FALSE
@@ -102,7 +98,7 @@
if(!on)
return
var/datum/gas_mixture/air1 = AIR1
if(!NODE1 || !air1 || air1.gases["o2"][MOLES] < 5) // Turn off if the machine won't work.
if(!NODE1 || !AIR1 || air1.gases["o2"][MOLES] < 5) // Turn off if the machine won't work.
on = FALSE
update_icon()
return
@@ -130,7 +126,6 @@
/obj/machinery/atmospherics/components/unary/cryo_cell/relaymove(mob/user) // Prevent ventcrawl in this machine.
return
/obj/machinery/atmospherics/components/unary/cryo_cell/open_machine()
if(!state_open && !panel_open)
on = FALSE
@@ -1,54 +0,0 @@
/obj/machinery/atmospherics/components/unary/heat_reservoir
//currently the same code as cold_sink but anticipating process() changes
icon_state = "cold_map"
use_power = 1
name = "heat reservoir"
desc = "Heats gas when connected to pipe network"
var/on = 0
var/current_temperature = T20C
var/current_heat_capacity = 50000 //totally random
/obj/machinery/atmospherics/components/unary/heat_reservoir/update_icon_nopipes()
overlays.Cut()
if(showpipe)
overlays += getpipeimage('icons/obj/atmospherics/components/unary_devices.dmi', "scrub_cap", initialize_directions) //scrub_cap works for now
if(!NODE1 || !on || stat & (NOPOWER|BROKEN))
icon_state = "cold_off"
return
else
icon_state = "cold_on"
//Nearly Identical Proc: /obj/machinery/atmospherics/components/unary/cold_sink/process_atmos()
/obj/machinery/atmospherics/components/unary/heat_reservoir/process_atmos()
..()
if(!on)
return 0
var/datum/gas_mixture/air_contents = AIR1
var/air_heat_capacity = air_contents.heat_capacity()
var/combined_heat_capacity = current_heat_capacity + air_heat_capacity
var/old_temperature = air_contents.temperature
if(combined_heat_capacity > 0)
var/combined_energy = current_temperature*current_heat_capacity + air_heat_capacity*air_contents.temperature
air_contents.temperature = combined_energy/combined_heat_capacity
var/temperatureChange=abs(old_temperature-air_contents.temperature)
if(temperatureChange > 1)
active_power_usage = (current_heat_capacity * temperatureChange ) / 10 + idle_power_usage
update_parents()
else
//No change in temp, use idle power
active_power_usage= idle_power_usage
return 1
@@ -0,0 +1,161 @@
/obj/machinery/atmospherics/components/unary/thermomachine
name = "thermomachine"
desc = "Heats or cools gas in connected pipes."
icon_state = "cold_map"
var/icon_state_on = "cold_on"
var/icon_state_open = "cold_off"
density = TRUE
anchored = TRUE
var/on = FALSE
var/min_temperature = 0
var/max_temperature = 0
var/target_temperature = T20C
var/heat_capacity = 0
var/interactive = TRUE // So mapmakers can disable interaction.
/obj/machinery/atmospherics/components/unary/thermomachine/New()
..()
initialize_directions = dir
component_parts = list()
component_parts += new /obj/item/weapon/stock_parts/matter_bin(null)
component_parts += new /obj/item/weapon/stock_parts/matter_bin(null)
component_parts += new /obj/item/weapon/stock_parts/micro_laser(null)
component_parts += new /obj/item/weapon/stock_parts/micro_laser(null)
component_parts += new /obj/item/weapon/stock_parts/console_screen(null)
component_parts += new /obj/item/stack/cable_coil(null, 1)
RefreshParts()
/obj/machinery/atmospherics/components/unary/thermomachine/construction()
..(dir,dir)
/obj/machinery/atmospherics/components/unary/thermomachine/RefreshParts()
var/B
for(var/obj/item/weapon/stock_parts/matter_bin/M in component_parts)
B += M.rating
heat_capacity = 1000 * ((B - 1) ** 2)
/obj/machinery/atmospherics/components/unary/thermomachine/update_icon()
if(panel_open)
icon_state = icon_state_open
else if(on && is_operational())
icon_state = icon_state_on
else
icon_state = initial(icon_state)
return
/obj/machinery/atmospherics/components/unary/thermomachine/update_icon_nopipes()
overlays.Cut()
if(showpipe)
overlays += getpipeimage(icon, "scrub_cap", initialize_directions)
/obj/machinery/atmospherics/components/unary/thermomachine/process_atmos()
..()
if(!on)
return 0
var/datum/gas_mixture/air_contents = AIR1
var/air_heat_capacity = air_contents.heat_capacity()
var/combined_heat_capacity = heat_capacity + air_heat_capacity
var/old_temperature = air_contents.temperature
if(combined_heat_capacity > 0)
var/combined_energy = heat_capacity * target_temperature + air_heat_capacity * air_contents.temperature
air_contents.temperature = combined_energy/combined_heat_capacity
var/temperature_delta= abs(old_temperature - air_contents.temperature)
if(temperature_delta > 1)
active_power_usage = (heat_capacity * temperature_delta) / 10 + idle_power_usage
update_parents()
else
active_power_usage = idle_power_usage
return 1
/obj/machinery/atmospherics/components/unary/thermomachine/power_change()
..()
update_icon()
/obj/machinery/atmospherics/components/unary/thermomachine/attackby(obj/item/I, mob/user, params)
if(!(on || state_open))
if(default_deconstruction_screwdriver(user, icon_state_open, initial(icon_state), I))
return
if(exchange_parts(user, I))
return
if(default_change_direction_wrench(user, I))
return
if(default_deconstruction_crowbar(I))
return
/obj/machinery/atmospherics/components/unary/thermomachine/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = 0, \
datum/tgui/master_ui = null, datum/ui_state/state = default_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "thermomachine", name, 400, 240, master_ui, state)
ui.open()
/obj/machinery/atmospherics/components/unary/thermomachine/get_ui_data(mob/user)
var/list/data = list()
data["on"] = on
data["min"] = min_temperature
data["max"] = max_temperature
data["target"] = target_temperature
data["initial"] = T20C
var/datum/gas_mixture/air1 = AIR1
data["temperature"] = air1.temperature
data["pressure"] = air1.return_pressure()
return data
/obj/machinery/atmospherics/components/unary/thermomachine/ui_act(action, params)
if(..() || !interactive)
return
switch(action)
if("power")
on = !on
use_power = 1 + on
update_icon()
return 1
if("target")
target_temperature += text2num(params["adjust"])
if(min_temperature)
target_temperature = Clamp(target_temperature, min_temperature, T20C)
else if(max_temperature)
target_temperature = Clamp(target_temperature, T20C, max_temperature)
return 1
/obj/machinery/atmospherics/components/unary/thermomachine/freezer
name = "freezer"
icon = 'icons/obj/Cryogenic2.dmi'
icon_state = "freezer"
icon_state_on = "freezer_1"
icon_state_open = "freezer-o"
/obj/machinery/atmospherics/components/unary/thermomachine/freezer/New()
..()
component_parts += new /obj/item/weapon/circuitboard/thermomachine/freezer(null)
/obj/machinery/atmospherics/components/unary/thermomachine/freezer/RefreshParts()
..()
var/L
for(var/obj/item/weapon/stock_parts/micro_laser/M in component_parts)
L += M.rating
min_temperature = max(T0C - (170 + L * 15), TCMB)
/obj/machinery/atmospherics/components/unary/thermomachine/heater
name = "heater"
icon = 'icons/obj/Cryogenic2.dmi'
icon_state = "heater"
icon_state_on = "heater_1"
icon_state_open = "heater-o"
/obj/machinery/atmospherics/components/unary/thermomachine/heater/New()
..()
component_parts += new /obj/item/weapon/circuitboard/thermomachine/heater(null)
/obj/machinery/atmospherics/components/unary/thermomachine/heater/RefreshParts()
..()
var/L
for(var/obj/item/weapon/stock_parts/micro_laser/M in component_parts)
L += M.rating
max_temperature = T20C + (140 * L)