Fixed Temperature Reagents (#5674)

This commit is contained in:
BurgerLUA
2018-12-01 14:48:43 -08:00
committed by Werner
parent c3fb8d8cb5
commit c2eeeddb54
4 changed files with 74 additions and 29 deletions
+21 -18
View File
@@ -124,8 +124,7 @@
for(var/datum/chemical_reaction/C in effect_reactions)
C.post_reaction(src)
equalize_temperature()
update_holder(FALSE)
update_holder(equalize_temperature()) //If the thermal energy of the reagents is different after a reaction, then run process_reactions again.
return reaction_occured
/* Holder-to-chemical */
@@ -135,19 +134,20 @@
return 0
update_total() //Does this need to be here? It's called in update_holder.
var/old_amount = amount
amount = min(amount, get_free_space())
for(var/datum/reagent/current in reagent_list)
if(current.id == id) //Existing reagent
current.volume += amount
if(thermal_energy > 0)
current.add_thermal_energy(thermal_energy)
for(var/datum/reagent/R in reagent_list)
if(R.id == id) //Existing reagent
R.volume += amount
if(thermal_energy > 0 && old_amount > 0)
R.add_thermal_energy(thermal_energy * (amount/old_amount) )
else
if(temperature <= 0)
temperature = current.default_temperature
current.add_thermal_energy(temperature * current.specific_heat * amount)
temperature = R.default_temperature
R.set_temperature(temperature)
if(!isnull(data)) // For all we know, it could be zero or empty string and meaningful
current.mix_data(data, amount)
R.mix_data(data, amount)
update_holder(!safety)
return 1
@@ -158,8 +158,9 @@
R.holder = src
R.volume = amount
R.specific_heat = SSchemistry.check_specific_heat(R)
if(thermal_energy > 0)
R.thermal_energy = thermal_energy
R.thermal_energy = 0
if(thermal_energy > 0 && old_amount > 0)
R.add_thermal_energy(thermal_energy * (amount/old_amount) )
else
if(temperature <= 0)
temperature = R.default_temperature
@@ -174,10 +175,12 @@
/datum/reagents/proc/remove_reagent(var/id, var/amount, var/safety = 0)
if(!isnum(amount))
return 0
for(var/datum/reagent/current in reagent_list)
if(current.id == id)
amount = min(amount,current.volume)
var/old_volume = current.volume
current.volume -= amount // It can go negative, but it doesn't matter
current.volume -= amount
current.add_thermal_energy( -(current.thermal_energy * (amount/old_volume)) )
update_holder(!safety)
return 1
@@ -277,15 +280,15 @@
for(var/datum/reagent/current in reagent_list)
var/amount_to_transfer = current.volume * part
var/energy_to_transfer = amount_to_transfer * current.get_thermal_energy_per_unit()
target.add_reagent(current.id, amount_to_transfer * multiplier, current.get_data(), 1, thermal_energy = energy_to_transfer * multiplier) // We don't react until everything is in place
var/energy_to_transfer = current.get_thermal_energy() * (amount_to_transfer / current.volume)
target.add_reagent(current.id, amount_to_transfer * multiplier, current.get_data(), TRUE, thermal_energy = energy_to_transfer * multiplier) // We don't react until everything is in place
if(!copy)
remove_reagent(current.id, amount_to_transfer, 1)
remove_reagent(current.id, amount_to_transfer, TRUE)
if(!copy)
handle_reactions()
update_holder()
target.handle_reactions()
target.update_holder()
return amount
+5 -6
View File
@@ -2922,9 +2922,9 @@
id = "water_to_ice"
result = "ice"
required_reagents = list("water" = 1)
required_temperatures_max = list("water" = T0C - 1)
result_amount = 0.5
mix_message = ""
required_temperatures_max = list("water" = T0C)
result_amount = 1
mix_message = "The water freezes."
reaction_sound = ""
/datum/chemical_reaction/ice_to_water
@@ -2933,9 +2933,8 @@
result = "water"
required_reagents = list("ice" = 1)
required_temperatures_min = list("ice" = T0C + 1)
result_amount = 2
reaction_rate = HALF_LIFE(4) //CONFIRMED?
mix_message = ""
result_amount = 1
mix_message = "The ice melts."
reaction_sound = ""
/datum/chemical_reaction/phoron_salt //Safe temperatures for phoron salt is between 0 degress celcius and 200 celcius.
+11 -5
View File
@@ -46,9 +46,6 @@
/datum/reagent/proc/get_thermal_energy_change(var/old_temperature, var/new_temperature)
return get_heat_capacity()*(max(new_temperature, TCMB) - old_temperature)
/datum/reagent/proc/get_thermal_energy_per_unit()
return get_thermal_energy() / volume
/datum/reagent/proc/add_thermal_energy(var/added_energy)
thermal_energy = max(0,thermal_energy + added_energy)
return added_energy
@@ -69,13 +66,22 @@
var/total_thermal_energy = 0
var/total_heat_capacity = 0
var/was_changed = FALSE
for(var/datum/reagent/R in reagent_list)
total_thermal_energy += R.get_thermal_energy()
total_heat_capacity += R.get_heat_capacity()
for(var/datum/reagent/R in reagent_list)
R.set_thermal_energy( total_thermal_energy * (R.get_heat_capacity()/total_heat_capacity) )
var/old_thermal_energy = R.get_thermal_energy()
var/new_thermal_energy = total_thermal_energy * (R.get_heat_capacity()/total_heat_capacity)
if(old_thermal_energy != new_thermal_energy)
R.set_thermal_energy( new_thermal_energy )
was_changed = TRUE
return was_changed
/datum/reagents/proc/add_thermal_energy(var/thermal_energy_to_add)