Underground temperature and food rot calculation overhaul. #24073
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does it do?
This PR introduces:
1. Inert underground temperatures, based on RL thermodynamics, independent from weather patterns.
2. Food decay calculation now includes actual underground temperatures.
Racionale:
Part 1: General idea
Discussion under PR #23986 has led to new ideas, one of which is need for more options to preserve food.
It led to an obvious conclusion, that most common food preservation method, nowadays and in the past, is temperature control. Having no electric fridges however, people in the past ages used various methods to keep food cool, of which most common one was using actual ground's temperature in form of dugout shelters, root cellars, etc. Nowadays this form of food preservation still live in form of household basement food storages and wine cellars. This however was not represented in game as underground levels were affected by aboveground temperatures and climate calculations.
This PR not only reflects actual RL temperature of underground places, but allows food storage in reduced temperatures. Combined with #23986 it offsets the introduction of wide-range of perishable comestibles, alowing long-term storage at reduced decay rates.
Part 2: Underground temperature
Diurnal and annual temperatures changes at the surface only affect few meters into the ground. This means that below this depth of influence, the only source of heat is the background heat flux coming from the decay of radioactive elements and some heat left over from Earth's formation. Secondly since earth's mass is a huge heatsink, it's residual temperature near surface lags few months behind seasonal temperatures, as presented below.
Studies show that cave (and also basement/cellars etc.) temperatures over the world are roughly equal to average outdoor annual temperature of the location of the entrance of the cave.
As average New England annual temperature is estimated at 43F / 6C (rounded to integer) this was set as new value for the underground. This is also the base temperature already defined in-game for weather calculations (rounded to 6.5 C for that purpose).
Temperature raises about 1C per 40 meters toward the earth's center, but since temperatures are rounded to integers, and underground max depth of zlevels is limited, i have thrown this part of idea to the bin.
Part 3: Food decay
Not much to explain here, as existing code calculates temperature's influence on food in a correct, RL-based manner. Only major change here was introducing actual use of underground temperatures, explained below.
Implementation:
It was quite tricky, as
get_temperature
function were not woven into rot calculators functions (mostly controlled by weather daemon), and both were semi-dumb of where the measurement takes place -get_temperature
function was player-oriented, not location-oriented. Also ice labs were a hardcoded exception in all this.1. Function
get_temperature
was changed to accept location coordinates as input argument, and was changed to switch between returning underground temperature (independent of weather patterns) or weather-based temperature for above-ground locations. In both cases it allows map locations override viaset_temperature
, that is used for example inice_lab
. This override however will be forced upon new underground temp. and not weather-based temperature (of course when underground). All in allget_temperature
is now more universal, and not always oriented on player's location.2. Food decay calculators use sophisticated method to calc cumulative rot from starting point in time to end point in time, including temperature's change in overmap grid, which is designed this way for game efficiency. This method however was solely based on weather patterns, and used item's location only to determine it's overmap for quering weather patterns. After implementing [1.] I changed this function to determine if item is underground, and then push results of new get_temperature to its calculating methods. When food item is above ground it will use previous method based on weather.
3. This allowed me to throw out the door overrides for ice lab from decay calculators. Ice labs remain their temperature 'overrides' in map generator, which is checked by
get_temperature
, which is then used in decay calcualtion. It is a proper approach, rather then hard-coding it.Future ideas: someone could move base annual temperature to game constans or game balance jsons, for further use as quick-access options or mods (global-warming in your hands today).