Skip to content

Commit

Permalink
Thermal energy based temperature system (CleverRaven#27387)
Browse files Browse the repository at this point in the history
* set_temperature also sets energy, set product temp
In old system crafted items just reset the temp check without setting the actual temperature.
Not going to try to implement anything fancy for that so crafted items that are not heated up are just set to 20 C which should behave similarly to old system.
Temperature is now calculated with newton's law of cooling. No more using approximation of an approximation.
* Energy and temperature are in 0.00001 J/g and K
  • Loading branch information
Hirmuolio authored and kevingranade committed Mar 14, 2019
1 parent 84c5471 commit a868b99
Show file tree
Hide file tree
Showing 13 changed files with 717 additions and 253 deletions.
60 changes: 60 additions & 0 deletions data/json/materials.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"ident": "bone",
"name": "Bone",
"density": 7,
"specific_heat_liquid": 1.2,
"specific_heat_solid": 1.2,
"latent_heat": 200,
"edible": true,
"bash_resist": 2,
"cut_resist": 3,
Expand Down Expand Up @@ -221,6 +224,9 @@
"ident": "egg",
"name": "Egg",
"density": 3,
"specific_heat_liquid": 3.63,
"specific_heat_solid": 1.95,
"latent_heat": 252,
"edible": true,
"bash_resist": 0,
"cut_resist": 0,
Expand All @@ -239,6 +245,9 @@
"ident": "flesh",
"name": "Flesh",
"density": 5,
"specific_heat_liquid": 3.7,
"specific_heat_solid": 2.15,
"latent_heat": 260,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand Down Expand Up @@ -276,6 +285,9 @@
"ident": "fruit",
"name": "Fruit Matter",
"density": 4,
"specific_heat_liquid": 3.9,
"specific_heat_solid": 1.9,
"latent_heat": 290,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand Down Expand Up @@ -399,6 +411,9 @@
"ident": "hflesh",
"name": "Human Flesh",
"density": 5,
"specific_heat_liquid": 3.7,
"specific_heat_solid": 2.15,
"latent_heat": 260,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand All @@ -421,6 +436,9 @@
"ident": "honey",
"name": "Honey",
"density": 1,
"specific_heat_liquid": 2.03,
"specific_heat_solid": 2.03,
"latent_heat": 57,
"edible": true,
"bash_resist": 0,
"cut_resist": 0,
Expand Down Expand Up @@ -459,6 +477,9 @@
"ident": "iflesh",
"name": "Insect Flesh",
"density": 5,
"specific_heat_liquid": 3.7,
"specific_heat_solid": 2.15,
"latent_heat": 260,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand Down Expand Up @@ -498,6 +519,9 @@
"ident": "junk",
"name": "Junk Food",
"density": 4,
"specific_heat_liquid": 3.3,
"specific_heat_solid": 2.05,
"latent_heat": 220,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand Down Expand Up @@ -572,6 +596,9 @@
"ident": "milk",
"name": "Dairy",
"density": 1,
"specific_heat_liquid": 3.89,
"specific_heat_solid": 1.81,
"latent_heat": 293,
"edible": true,
"bash_resist": 0,
"cut_resist": 0,
Expand Down Expand Up @@ -651,6 +678,9 @@
"ident": "oil",
"name": "Oil",
"density": 1,
"specific_heat_liquid": 2,
"specific_heat_solid": 1.8,
"latent_heat": 200,
"edible": true,
"bash_resist": 0,
"cut_resist": 0,
Expand Down Expand Up @@ -711,6 +741,9 @@
"ident": "powder",
"name": "Powder",
"density": 1,
"specific_heat_liquid": 1.5,
"specific_heat_solid": 1.2,
"latent_heat": 10,
"bash_resist": 1,
"cut_resist": 1,
"acid_resist": 0,
Expand All @@ -731,6 +764,9 @@
"ident": "powder_nonflam",
"name": "Powder",
"density": 1,
"specific_heat_liquid": 1.5,
"specific_heat_solid": 1.2,
"latent_heat": 10,
"bash_resist": 1,
"cut_resist": 1,
"acid_resist": 0,
Expand Down Expand Up @@ -832,6 +868,9 @@
"ident": "veggy",
"name": "Vegetable Matter",
"density": 4,
"specific_heat_liquid": 3.9,
"specific_heat_solid": 1.9,
"latent_heat": 290,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand All @@ -854,6 +893,9 @@
"ident": "tomato",
"name": "Tomato",
"density": 4,
"specific_heat_liquid": 3.9,
"specific_heat_solid": 1.9,
"latent_heat": 290,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand All @@ -876,6 +918,9 @@
"ident": "bean",
"name": "Bean",
"density": 4,
"specific_heat_liquid": 3.9,
"specific_heat_solid": 1.9,
"latent_heat": 290,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand All @@ -898,6 +943,9 @@
"ident": "garlic",
"name": "Garlic",
"density": 4,
"specific_heat_liquid": 3.9,
"specific_heat_solid": 1.9,
"latent_heat": 290,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand All @@ -920,6 +968,9 @@
"ident": "nut",
"name": "Nut",
"density": 5,
"specific_heat_liquid": 2.2,
"specific_heat_solid": 2.2,
"latent_heat": 20,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand All @@ -942,6 +993,9 @@
"ident": "mushroom",
"name": "Mushroom",
"density": 4,
"specific_heat_liquid": 3.9,
"specific_heat_solid": 1.9,
"latent_heat": 290,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand All @@ -964,6 +1018,9 @@
"ident": "water",
"name": "Water",
"density": 1,
"specific_heat_liquid": 4.186,
"specific_heat_solid": 2.108,
"latent_heat": 333,
"edible": true,
"bash_resist": 0,
"cut_resist": 0,
Expand All @@ -985,6 +1042,9 @@
"ident": "wheat",
"name": "Wheat",
"density": 4,
"specific_heat_liquid": 2,
"specific_heat_solid": 2,
"latent_heat": 150,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
Expand Down
39 changes: 28 additions & 11 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,38 @@ The syntax listed here is still valid.
| `acid_resist` | Ability of a material to resist acid.
| `elec_resist` | Ability of a material to resist electricity.
| `fire_resist` | Ability of a material to resist fire.
| `dmg_adj` | Adjectives used to describe damage states of a material.
| `density` | Density of a material.
| `vitamins` | Vitamins in a material. Usually overridden by item specific values.
| `specific_heat_liquid` | Specific heat of a material when not frozen (J/(g K)). Default 4.186.
| `specific_heat_solid` | Specific heat of a material when frozen (J/(g K)). Default 2.108.
| `latent_heat` | Latent heat of a material (J/g). Default 334.

```C++
{
"ident" : "hflesh",
"name" : "Human Flesh",
"bash_resist" : 1,
"cut_resist" : 1,
"bash_dmg_verb" : "bruised",
"cut_dmg_verb" : "sliced",
"dmg_adj" : ["bruised", "mutilated", "badly mutilated", "thoroughly mutilated"],
"acid_resist" : 1,
"elec_resist" : 1,
"fire_resist" : 0,
"density" : 5
"type": "material",
"ident": "hflesh",
"name": "Human Flesh",
"density": 5,
"specific_heat_liquid": 3.7,
"specific_heat_solid": 2.15,
"latent_heat": 260,
"edible": true,
"bash_resist": 1,
"cut_resist": 1,
"acid_resist": 1,
"fire_resist": 1,
"elec_resist": 1,
"chip_resist": 2,
"dmg_adj": [ "bruised", "mutilated", "badly mutilated", "thoroughly mutilated" ],
"bash_dmg_verb": "bruised",
"cut_dmg_verb": "sliced",
"vitamins": [ [ "calcium", 0.1 ], [ "vitB", 1 ], [ "iron", 1.3 ] ],
"burn_data": [
{ "fuel": 1, "smoke": 1, "burn": 1, "volume_per_turn": "2500_ml" },
{ "fuel": 2, "smoke": 3, "burn": 2, "volume_per_turn": "10000_ml" },
{ "fuel": 3, "smoke": 10, "burn": 3 }
]
}
```

Expand Down
14 changes: 7 additions & 7 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,15 @@ void player::complete_craft()

if( should_heat ) {
newit.heat_up();
} else {
} else if( newit.is_food() || newit.is_food_container() ) {
// Really what we should be doing is averaging the temperatures
// between the recipe components if we don't have a heat tool, but
// that's kind of hard. For now just reset the temperature, don't
// that's kind of hard. For now just set the item to 20 C
// and reset the temperature, don't
// forget byproducts below either when you fix this.
//
// Also, this is going to reset the temperature on non-food items
// as well. This isn't a big deal because they don't care about
// temperature (yet?) and it's actually more costly to check for
// is_food() than just reset the timer.
// Temperature is not functional for non-foods
newit.set_item_temperature( 293.15 );
newit.reset_temp_check();
}

Expand All @@ -793,7 +792,8 @@ void player::complete_craft()
}
if( should_heat ) {
bp.heat_up();
} else {
} else if( bp.is_food() || bp.is_food_container() ) {
bp.set_item_temperature( 293.15 );
bp.reset_temp_check();
}
finalize_crafted_item( bp );
Expand Down
4 changes: 2 additions & 2 deletions src/game_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
/** Temperature constants */
namespace temperatures
{
/** temperature at which something starts warming and can become HOT */
/** temperature at which something starts is considered HOT */
constexpr int hot = 100; // ~ 38 Celsius

/** the "normal" temperature midpoint between cold and hot */
Expand All @@ -92,7 +92,7 @@ constexpr int normal = 70; // ~ 21 Celsius
constexpr int fridge = 37; // ~ 2.7 Celsius

/** Temperature at which things are considered "cold" */
constexpr int cold = 40;
constexpr int cold = 40; // ~4.4 C

/** Temperature inside an active freezer in Fahrenheit */
constexpr int freezer = 23; // -5 Celsius
Expand Down
Loading

0 comments on commit a868b99

Please sign in to comment.