Skip to content

Commit

Permalink
Documentation and cleanup of bodytemp stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoes01 committed Feb 27, 2013
1 parent 18e44e2 commit 5977e19
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 48 deletions.
4 changes: 2 additions & 2 deletions bodypart.h
Expand Up @@ -4,10 +4,10 @@
#include <string>

enum body_part {
bp_head = 0,
bp_torso = 0,
bp_head,
bp_eyes,
bp_mouth,
bp_torso,
bp_arms,
bp_hands,
bp_legs,
Expand Down
44 changes: 22 additions & 22 deletions disease.cpp
Expand Up @@ -96,19 +96,19 @@ void dis_effect(game *g, player &p, disease &dis)

case DI_COLD_HEAD:
switch (dis.intensity) {
case 3 : p.int_cur -= 3; if (one_in(200)) g->add_msg("Your thoughts are unclear.");
case 3 : p.int_cur -= 3; if (!p.has_disease(DI_SLEEP) && one_in(200)) g->add_msg("Your thoughts are unclear.");
case 2 : p.int_cur--;
case 1 : if (one_in(600)) g->add_msg("Brr.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Brr.\"");
}
break;

case DI_COLD_TORSO:
switch (dis.intensity) {
case 3 : p.dex_cur -= 2; if (one_in(200)) g->add_msg("Your torso is burning up. You should remove some layers.");
case 3 : p.dex_cur -= 2; if (!p.has_disease(DI_SLEEP) && one_in(200)) g->add_msg("Your torso is burning up. You should remove some layers.");
// Speed -20
case 2 : p.dex_cur -= 1;
// Speed -5
case 1 : p.dex_cur -= 1; if (one_in(600)) g->add_msg("Brr.");
case 1 : p.dex_cur -= 1; if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Brr.\"");
// Speed -2
}
break;
Expand All @@ -117,25 +117,25 @@ void dis_effect(game *g, player &p, disease &dis)
switch (dis.intensity) {
case 3 : p.dex_cur -= 2;
case 2 : p.dex_cur--;
case 1 : if (one_in(600)) g->add_msg("Your arms are shivering.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("Your arms are shivering.");
}
break;

case DI_COLD_HANDS:
switch (dis.intensity) {
case 3 : p.dex_cur -= 2;
case 2 : p.dex_cur -= 2;
case 1 : if (one_in(600)) g->add_msg("Brr.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Brr.\"");
}
break;

case DI_COLD_LEGS:
switch (dis.intensity) {
case 3 : p.str_cur--; if (one_in(200)) g->add_msg("Your legs are seizing from the incredible cold.");
case 3 : p.str_cur--; if (!p.has_disease(DI_SLEEP) && one_in(200)) g->add_msg("Your legs are seizing from the incredible cold.");
// Speed -20
case 2 : p.str_cur--;
// Speed -5
case 1 : if (one_in(600)) g->add_msg("Your legs feel sluggish from the cold.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("Your legs feel sluggish from the cold.");
// Speed -2
}
break;
Expand All @@ -144,7 +144,7 @@ void dis_effect(game *g, player &p, disease &dis)
switch (dis.intensity) {
case 3 : p.str_cur--;
case 2 : p.str_cur--;
case 1 : if (one_in(600)) g->add_msg("Brr.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Brr.\"");
}
break;

Expand All @@ -153,7 +153,7 @@ void dis_effect(game *g, player &p, disease &dis)
case 2 : p.dex_cur -= 3;
case 1 :
if (p.temp_cur[bp_mouth] > BODYTEMP_COLD && p.pain < 40) p.pain++;
if (one_in(600)) g->add_msg("Your hands feel numb.");
if (!p.has_disease(DI_SLEEP) && one_in(200)) g->add_msg("Your hands feel numb.");
}
break;

Expand All @@ -162,7 +162,7 @@ void dis_effect(game *g, player &p, disease &dis)
case 2 : // -4 speed
case 1 :
if (p.temp_cur[bp_mouth] > BODYTEMP_COLD && p.pain < 40) p.pain++;
if (one_in(600)) g->add_msg("Your feet feel numb.");
if (!p.has_disease(DI_SLEEP) && one_in(200)) g->add_msg("Your feet feel numb.");
}
break;

Expand All @@ -171,7 +171,7 @@ void dis_effect(game *g, player &p, disease &dis)
case 2 : p.per_cur -= 3;
case 1 :
if (p.temp_cur[bp_mouth] > BODYTEMP_COLD && p.pain < 40) p.pain++;
if (one_in(600)) g->add_msg("Your face feels numb.");
if (!p.has_disease(DI_SLEEP) && one_in(200)) g->add_msg("Your face feels numb.");
}
break;

Expand Down Expand Up @@ -200,16 +200,16 @@ void dis_effect(game *g, player &p, disease &dis)
case 3 :
p.thirst--;
if (p.pain < 50) p.pain++;
if (one_in(400)) g->add_msg("Your head is pounding from the heat.");
if (!p.has_disease(DI_SLEEP) && one_in(400)) g->add_msg("Your head is pounding from the heat.");
// Speed -20
case 2 :
p.thirst--;
if (one_in(1500 - p.temp_cur[bp_head])) p.vomit(g); // Hallucinations handled in game.cpp
if (p.pain < 20) p.pain++;
if (one_in(400)) g->add_msg("The heat is making you see things.");
if (!p.has_disease(DI_SLEEP) && one_in(400)) g->add_msg("The heat is making you see things.");
// Speed -5
case 1 :
if (one_in(600)) g->add_msg("Phew, it's hot out.");
if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Phew, it's hot warm.\"");
// Speed -2
}
break;
Expand All @@ -219,14 +219,14 @@ void dis_effect(game *g, player &p, disease &dis)
case 3 :
p.thirst--;
p.str_cur--;
if (one_in(200)) g->add_msg("You are sweating profusely.");
if (!p.has_disease(DI_SLEEP) && one_in(200)) g->add_msg("You are sweating profusely.");
// Speed -20
case 2 :
p.thirst--;
p.str_cur--;
// Speed -5
case 1 :
if (one_in(600)) g->add_msg("Phew, it's hot out.");
if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Phew, it's hot warm.\"");
// Speed -2
}
break;
Expand All @@ -236,15 +236,15 @@ void dis_effect(game *g, player &p, disease &dis)
case 3 : p.thirst--;
if (p.pain < 50) p.pain++;
case 2 : p.thirst--;
case 1 : if (one_in(600)) g->add_msg("Phew, it's hot out.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Phew, it's hot warm.\"");
}
break;

case DI_HOT_HANDS:
switch (dis.intensity) {
case 3 : p.dex_cur--;
case 2 : p.dex_cur--;
case 1 : if (one_in(600)) g->add_msg("Phew, it's hot out.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Phew, it's hot warm.\"");
}
break;

Expand All @@ -254,7 +254,7 @@ void dis_effect(game *g, player &p, disease &dis)
if (p.pain < 50) p.pain++;
if (one_in(200)) g->add_msg("Your legs are cramping up.");
case 2 : p.thirst--;
case 1 : if (one_in(600)) g->add_msg("Phew, it's hot out.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Phew, it's hot warm.\"");
}
break;

Expand All @@ -263,8 +263,8 @@ void dis_effect(game *g, player &p, disease &dis)
case 3 : if (p.pain < 50) p.pain++;
case 2 :
if (p.pain < 30) p.pain++;
if (one_in(200)) g->add_msg("Your feet are swelling in the heat.");
case 1 : if (one_in(600)) g->add_msg("Phew, it's hot out.");
if (!p.has_disease(DI_SLEEP) && one_in(200)) g->add_msg("Your feet are swelling in the heat.");
case 1 : if (!p.has_disease(DI_SLEEP) && one_in(600)) g->add_msg("\"Phew, it's hot warm.\"");
}
break;

Expand Down
50 changes: 29 additions & 21 deletions game.cpp
Expand Up @@ -723,6 +723,8 @@ bool game::do_turn()
Assumption 1 : a naked person is comfortable at 31C/87.8F.
Assumption 2 : a "lightly clothed" person is comfortable at 25C/77F.
Assumption 3 : frostbite cannot happen above 0C temperature.*
* In the current model, a naked person can get frostbite at 1C. This isn't true, but it's a compromise with using nice whole numbers.
Here is a list of warmth values and the corresponding temperatures in which the player is comfortable, and in which the player is very cold.
Expand All @@ -743,15 +745,15 @@ Warmth Temperature (Comfortable) Temperature (Very cold) Notes

void game::update_bodytemp() // TODO bionics, diseases and humidity (not in yet) can affect body temp.
{
// NOTE : Bodytemp is measured on a scale of 0u to 1000u, where 1u = 0.02C and 500u is 37C
// Converts temperature to Celsius/10!(Wito plans on using degrees Kelvin later)
// NOTE : visit weather.h for some details on the numbers used
// Converts temperature to Celsius/10(Wito plans on using degrees Kelvin later)
int Ctemperature = 10*(temperature - 32) * 5/9;
// Temperature norms
const int ambient_norm = 310;
// This adjusts the temperature scale to match the bodytemp scale
int adjusted_temp = (Ctemperature - ambient_norm);
// Creative thinking for clean morale penalties: this gets incremented in the for loop and applied after the loop
int morale_pen = 0;
// This adjusts the temperature scale to match the bodytemp scale
int adjusted_temp = 1*(Ctemperature - ambient_norm);
// Fetch the morale value of wetness for bodywetness
int bodywetness = 0;
for (int i = 0; bodywetness == 0 && i < u.morale.size(); i++)
Expand All @@ -768,7 +770,8 @@ void game::update_bodytemp() // TODO bionics, diseases and humidity (not in yet)
// Disease name shorthand
int blister_pen = dis_type(DI_BLISTERS) + 1 + i, hot_pen = dis_type(DI_HOT) + 1 + i;
int cold_pen = dis_type(DI_COLD)+ 1 + i, frost_pen = dis_type(DI_FROSTBITE) + 1 + i;
signed int temp_conv = BODYTEMP_NORM + adjusted_temp + clothing_warmth_adjustement; // Convergeant temperature is affected by ambient temperature, clothing warmth, and body wetness.
// Convergeant temperature is affected by ambient temperature, clothing warmth, and body wetness.
signed int temp_conv = BODYTEMP_NORM + adjusted_temp + clothing_warmth_adjustement;
// Fatigue also affects convergeant temperature
if (!u.has_disease(DI_SLEEP)) temp_conv -= u.fatigue/6;
else {
Expand All @@ -778,46 +781,50 @@ void game::update_bodytemp() // TODO bionics, diseases and humidity (not in yet)
else if (m.ter(u.posx, u.posy) == t_makeshift_bed) temp_conv += 50;
else if (m.tr_at(u.posx, u.posy) == tr_cot) temp_conv -= 50;
else if (m.tr_at(u.posx, u.posy) == tr_rollmat) temp_conv -= 100;
else if (veh && veh->part_with_feature (vpart, vpf_seat) >= 0) temp_conv += 30;
else if (veh && veh->part_with_feature (vpart, vpf_seat) >= 0) temp_conv += 20;
else if (veh && veh->part_with_feature (vpart, vpf_bed) >= 0) temp_conv += 30;
else temp_conv -= 200;
}
// Fire : generates body heat, helps fight frostbite TODO : add lava checks. TODO : cleanup like I did with temp_conv calculation
// Convection heat sources : generates body heat, helps fight frostbite
int blister_count = 0; // If the counter is high, your skin starts to burn
for (int j = -6 ; j <= 6 ; j++){
for (int k = -6 ; k <= 6 ; k++){
// Bizarre workaround for u_see() and friends not taking const arguments.
// Bizarre workaround for u_see() and friends not taking const arguments.
int l = std::max(j, k);
int heat_intensity = 0;
if(m.field_at(u.posx + j, u.posy + k).type == fd_fire)
heat_intensity = m.field_at(u.posx + j, u.posy + k).density;
else if (m.tr_at(u.posx + j, u.posy + k) == tr_lava )
heat_intensity = 3;
if (heat_intensity > 0 && u_see(u.posx + j, u.posy + k, l)) {
// Ensure fire_dist >=1 to avoid divide-by-zero errors.
// Ensure fire_dist >=1 to avoid divide-by-zero errors.
int fire_dist = std::max(1, std::max(j, k));
if (u.frostbite_timer[i] > 0) u.frostbite_timer[i] -= heat_intensity - fire_dist / 2;
temp_conv += 50 * heat_intensity / (fire_dist * fire_dist); // How do I square things
temp_conv += 50 * heat_intensity / (fire_dist * fire_dist);
blister_count += heat_intensity / (fire_dist * fire_dist);
}
}
}
// bionic says it is effective from 0F to 140F, these are the corresponding bodytemp values
if( u.has_bionic(bio_climate) && temp_conv > -461 && temp_conv < 1150) {
// Might want something slightly more nuanced than this
temp_conv = BODYTEMP_NORM;
blister_count = 0;
}
// Skin gets blisters from intense heat exposure. TODO : add penalties in disease.cpp
if (blister_count - u.resist(body_part(i)) > 20) u.add_disease(dis_type(blister_pen), 1, this, i, num_bp);
// Bionic "Internal Climate Control" says it is effective from 0F to 140F, these are the corresponding bodytemp values
if (u.has_bionic(bio_climate) && temp_conv > -461 && temp_conv < 1150)
temp_conv = (9*BODYTEMP_NORM + temp_conv)/10; // Bionic "eases" the effects
else if (u.has_bionic(bio_climate) && temp_conv <= -461 || temp_conv >= 1150)
add_msg("Your Internal Climate Control cannot withstand these temperatures!!");
// Bionic "Thermal Dissapation" prevents fire damage up to 2000F. 100 is picked at random :x
if (u.has_bionic(bio_heatsink) && blister_count < 100)
blister_count = 0;
else if (u.has_bionic(bio_heatsink) && blister_count >= 100)
add_msg("Your Thermal Dissapation cannot withstand these temperatures!!");
// Skin gets blisters from intense heat exposure.
if (blister_count - u.resist(body_part(i)) > 20) u.add_disease(dis_type(blister_pen), 1, this);
// Increments current body temperature towards convergant.
int temp_difference = u.temp_cur[i] - temp_conv;
int temp_before = u.temp_cur[i];
// Bodytemp equalization code start
// Bodytemp equalization code
if (i == bp_torso){u.temp_equalizer(bp_torso, bp_arms); u.temp_equalizer(bp_torso, bp_legs); u.temp_equalizer(bp_torso, bp_head);}
else if (i == bp_head) {u.temp_equalizer(bp_head, bp_eyes); u.temp_equalizer(bp_head, bp_mouth);}
else if (i == bp_arms) u.temp_equalizer(bp_arms, bp_hands);
else if (i == bp_legs) u.temp_equalizer(bp_legs, bp_feet);
// Bodytemp equalization code end
if (u.temp_cur[i] != temp_conv) u.temp_cur[i] = temp_difference*exp(-0.1) + temp_conv;
int temp_after = u.temp_cur[i];
// Penalties
Expand All @@ -844,7 +851,8 @@ void game::update_bodytemp() // TODO bionics, diseases and humidity (not in yet)
// Frostbite (level 1 after 2 hours, level 2 after 4 hours)
if (u.frostbite_timer[i] > 0) u.frostbite_timer[i]--;
if (u.frostbite_timer[i] >= 24) {
if (u.disease_intensity(dis_type(frost_pen)) < 2) add_msg("Your %s hardens from the frostbite!", body_part_name(body_part(i), -1).c_str()); // TODO doesn't make sense for hands/feet. Find code that would fix this...
if (u.disease_intensity(dis_type(frost_pen)) < 2 && i == bp_mouth) add_msg("Your %s hardens from the frostbite!", body_part_name(body_part(i), -1).c_str());
else if (u.disease_intensity(dis_type(frost_pen)) < 2 && (i == bp_hands || i == bp_feet)) add_msg("Your %s harden from the frostbite!", body_part_name(body_part(i), -1).c_str());
u.add_disease(dis_type(frost_pen), 10, this, 2, 2);}
else if (u.frostbite_timer[i] >= 12) {
if (!u.has_disease(dis_type(frost_pen))) add_msg("You lose sensation in your %s.", body_part_name(body_part(i), -1).c_str());
Expand Down
7 changes: 6 additions & 1 deletion help.cpp
Expand Up @@ -430,7 +430,12 @@ unwanted attention. Save the guns for emergencies, and melee when you can.\n\
\n\
Try to keep your inventory as full as possible without being overloaded. You\n\
never know when you might need an item, most are good to sell, and you can\n\
easily drop unwanted items on the floor.");
easily drop unwanted items on the floor.\n\
\n\
Keep an eye on the weather. At night, sleeping might be difficult if you\n\
don't have a warm place to rest your head. Be sure to protect your extremities\n\
from frostbite and to keep your distance from large fires.");

getch();
break;

Expand Down
6 changes: 4 additions & 2 deletions weather.h
Expand Up @@ -2,15 +2,17 @@
#define _WEATHER_H_

#define BODYTEMP_FREEZING 50
#define BODYTEMP_VERY_COLD 200
#define BODYTEMP_VERY_COLD 200 // This value means frostbite occurs at the warmest temperature of 1C. If changed, the temp_conv calculation should be reexamined.
#define BODYTEMP_COLD 350
#define BODYTEMP_NORM 500
#define BODYTEMP_NORM 500 // Do not change this value, it is an arbitrary anchor on which other calculations are made.
#define BODYTEMP_HOT 650
#define BODYTEMP_VERY_HOT 800
#define BODYTEMP_SCORCHING 950
/*
Bodytemp is measured on a scale of 0u to 1000u, where 1u = 0.02C and 500u is 37C
Outdoor temperature uses simliar numbers, but on a different scale: 220u = 22C, where 1u = 0.1C.
Most values can be changed with no impact on calculations. Because of caluclations done in disease.cpp,
maximum heat cannot pass 1500u, otherwise the player will vomit to death.
*/

#include "color.h"
Expand Down

0 comments on commit 5977e19

Please sign in to comment.