From 96983fe8b836d5765693e4e5232040c7f9ada57d Mon Sep 17 00:00:00 2001 From: mwerezak Date: Fri, 11 Jul 2014 14:51:57 -0400 Subject: [PATCH] Thermodynamics for spaceheaters --- code/game/machinery/spaceheater.dm | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/code/game/machinery/spaceheater.dm b/code/game/machinery/spaceheater.dm index 9a6849dcdf4..ad3ef327092 100644 --- a/code/game/machinery/spaceheater.dm +++ b/code/game/machinery/spaceheater.dm @@ -178,16 +178,25 @@ if(removed) - var/heat_capacity = removed.heat_capacity() - //world << "heating ([heat_capacity])" - if(heat_capacity) // Added check to avoid divide by zero (oshi-) runtime errors -- TLE - if(removed.temperature < set_temperature + T0C) - removed.temperature = min(removed.temperature + heating_power/heat_capacity, 1000) // Added min() check to try and avoid wacky superheating issues in low gas scenarios -- TLE - else - removed.temperature = max(removed.temperature - heating_power/heat_capacity, TCMB) - cell.use(heating_power/20000) - - //world << "now at [removed.temperature]" + if(removed.temperature < set_temperature + T0C) //heating air + // Added min(set_temperature + T0C, 1000) check to try and avoid wacky superheating issues in low gas scenarios + var/energy_used = min( removed.get_thermal_energy_change(min(set_temperature + T0C, 1000)) , heating_power ) + + removed.add_thermal_energy(energy_used) + cell.use(energy_used*CELLRATE) + else //cooling air + var/heat_transfer = min(abs(removed.get_thermal_energy_change(target_temperature)), heating_power) + + //Assume the heat is being pumped into the hull which is fixed at 20 C + //none of this is really proper thermodynamics but whatever + + var/cop = removed.temperature/T20C //coefficient of performance -> power used = heat_transfer/cop + + heat_transfer = min(heat_transfer, cop * heating_power) //this ensures that we don't use more than MAX_ENERGY_CHANGE amount of power - the machine can only do so much cooling + + heat_transfer = -removed.add_thermal_energy(-heat_transfer) //get the actual heat transfer + + cell.use(heat_transfer/cop*CELLRATE) env.merge(removed)