diff --git a/code/ZAS/_gas_mixture.dm b/code/ZAS/_gas_mixture.dm index 2a072e8ef9c..749fc4d9a81 100644 --- a/code/ZAS/_gas_mixture.dm +++ b/code/ZAS/_gas_mixture.dm @@ -141,6 +141,30 @@ What are the archived variables for? return max(MINIMUM_HEAT_CAPACITY,heat_capacity_archived) +//this seems like such a common thing to do I can't believe this hasn't been made into it's own proc yet. +/datum/gas_mixture/proc/add_thermal_energy(var/thermal_energy) + //Purpose: Adjusting temperature based on thermal energy transfer + //Called by: Anyone who wants to add or remove energy from the gas mix + //Inputs: An amount of energy in J to be added. Negative values remove energy. + //Outputs: The actual thermal energy change. + + var/old_temperature = temperature + var/heat_capacity = heat_capacity() + + temperature += thermal_energy/heat_capacity + if (temperature < 0) + temperature = 0 + + return (temperature - old_temperature)*heat_capacity + +/datum/gas_mixture/proc/get_thermal_energy_change(var/new_temperature) + //Purpose: Determining how much thermal energy is required + //Called by: Anyone. Machines that want to adjust the temperature of a gas mix. + //Inputs: None + //Outputs: The amount of energy required to get to the new temperature in J. A negative value means that energy needs to be removed. + + return heat_capacity()*(new_temperature - temperature) + /datum/gas_mixture/proc/total_moles() return total_moles /*var/moles = oxygen + carbon_dioxide + nitrogen + phoron diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index ad70d7ca010..aee79735556 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -198,18 +198,25 @@ var/datum/gas_mixture/gas gas = location.remove_air(0.25*environment.total_moles) if(gas) - var/heat_capacity = gas.heat_capacity() - var/energy_used = min( abs( heat_capacity*(gas.temperature - target_temperature) ), MAX_ENERGY_CHANGE) - - //Use power. Assuming that each power unit represents 1 watts.... - use_power(energy_used, ENVIRON) - - //We need to cool ourselves. - if(environment.temperature > target_temperature) - gas.temperature -= energy_used/heat_capacity - else - gas.temperature += energy_used/heat_capacity - + + if (gas.temperature <= target_temperature) //gas heating + var/energy_used = min( gas.get_thermal_energy_change(target_temperature) , MAX_ENERGY_CHANGE) + + gas.add_thermal_energy(energy_used) + use_power(energy_used, ENVIRON) + else //gas cooling + var/heat_transfer = min(abs(gas.get_thermal_energy_change(target_temperature)), MAX_ENERGY_CHANGE) + + //Assume the heat is being pumped into the hull which is fixed at 20 C + //none of this is really proper thermodynamics but whatever + + //heat transfer is limited by the max amount of power the heat pump can put out, which lets say is also MAX_ENERGY_CHANGE + heat_transfer = min(heat_transfer, gas.temperature/T20C*MAX_ENERGY_CHANGE) + var/energy_used = heat_transfer * T20C/gas.temperature + + gas.add_thermal_energy(-heat_transfer) + use_power(energy_used * 1.1, ENVIRON) //heat pump inefficiencies + environment.merge(gas) if(abs(environment.temperature - target_temperature) <= 0.5)