From c2eeeddb549aa1fa1353503000a4d9539ed63f6f Mon Sep 17 00:00:00 2001 From: BurgerLUA Date: Sat, 1 Dec 2018 14:48:43 -0800 Subject: [PATCH] Fixed Temperature Reagents (#5674) --- code/modules/reagents/Chemistry-Holder.dm | 39 ++++++++++--------- code/modules/reagents/Chemistry-Recipes.dm | 11 +++--- .../modules/reagents/Chemistry-Temperature.dm | 16 +++++--- html/changelogs/unga bunga.yml | 37 ++++++++++++++++++ 4 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 html/changelogs/unga bunga.yml diff --git a/code/modules/reagents/Chemistry-Holder.dm b/code/modules/reagents/Chemistry-Holder.dm index 15ea02bea61..46ce95805b1 100644 --- a/code/modules/reagents/Chemistry-Holder.dm +++ b/code/modules/reagents/Chemistry-Holder.dm @@ -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 diff --git a/code/modules/reagents/Chemistry-Recipes.dm b/code/modules/reagents/Chemistry-Recipes.dm index 905caace733..6a7f368076d 100644 --- a/code/modules/reagents/Chemistry-Recipes.dm +++ b/code/modules/reagents/Chemistry-Recipes.dm @@ -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. diff --git a/code/modules/reagents/Chemistry-Temperature.dm b/code/modules/reagents/Chemistry-Temperature.dm index 16d158731fd..5bfd0a6679d 100644 --- a/code/modules/reagents/Chemistry-Temperature.dm +++ b/code/modules/reagents/Chemistry-Temperature.dm @@ -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) diff --git a/html/changelogs/unga bunga.yml b/html/changelogs/unga bunga.yml new file mode 100644 index 00000000000..4ed11a92ec2 --- /dev/null +++ b/html/changelogs/unga bunga.yml @@ -0,0 +1,37 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +################################# + +# Your name. +author: BurgerBB + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - bugfix: "Fixes ice having odd interactions with other chemicals. Fixes certain temperature-triggered chems from not triggering."