Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underground temperature and food rot calculation overhaul. #24073

Merged
merged 3 commits into from Jun 24, 2018
Merged

Underground temperature and food rot calculation overhaul. #24073

merged 3 commits into from Jun 24, 2018

Conversation

nexusmrsep
Copy link
Contributor

@nexusmrsep nexusmrsep commented Jun 23, 2018

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.

image

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 via set_temperature, that is used for example in ice_lab. This override however will be forced upon new underground temp. and not weather-based temperature (of course when underground). All in all get_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).

@ZhilkinSerg ZhilkinSerg added <Enhancement / Feature> New features, or enhancements on existing Game: Balance Balancing of (existing) in-game features. [C++] Changes (can be) made in C++. Previously named `Code` labels Jun 23, 2018
@DracoGriffin
Copy link
Contributor

Impressive work! A very good template for future PRs as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` <Enhancement / Feature> New features, or enhancements on existing Game: Balance Balancing of (existing) in-game features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants