Skip to content

Commit

Permalink
Player is informed he is using floor items for warmth during sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoes01 committed Aug 20, 2013
1 parent 75d1583 commit 929531f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
5 changes: 5 additions & 0 deletions disease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@ void dis_effect(game *g, player &p, disease &dis)
if (p.can_sleep(g)) {
dis.duration = 1;
g->add_msg_if_player(&p,_("You fall asleep."));
// Communicate to the player that he is using items on the floor
if ( p.is_snuggling(g) != "nothing") {
std::string item_name = p.is_snuggling(g);
g->add_msg(_("You snuggle your %s to keep warm"), item_name.c_str());
}
p.add_disease("sleep", 6000);
}
if (dis.duration == 1 && !p.has_disease("sleep"))
Expand Down
41 changes: 29 additions & 12 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,18 +902,20 @@ void player::update_bodytemp(game *g)
// Chemical Imbalance
// Added linse in player::suffer()
// FINAL CALCULATION : Increments current body temperature towards convergant.
int sleep_bonus = floor_bedding_warmth + floor_item_warmth;
// Too warm, don't need items on the floor
if ( temp_conv[i] > BODYTEMP_NORM ) {
// Do nothing
}
// Intelligently use items on the floor; just enough to be comfortable
else if ( (temp_conv[i] + sleep_bonus) > BODYTEMP_NORM ) {
temp_conv[i] = BODYTEMP_NORM;
}
// Use all items on the floor -- there are not enough to keep comfortable
else {
temp_conv[i] += sleep_bonus;
if ( has_disease("sleep") ) {
int sleep_bonus = floor_bedding_warmth + floor_item_warmth;
// Too warm, don't need items on the floor
if ( temp_conv[i] > BODYTEMP_NORM ) {
// Do nothing
}
// Intelligently use items on the floor; just enough to be comfortable
else if ( (temp_conv[i] + sleep_bonus) > BODYTEMP_NORM ) {
temp_conv[i] = BODYTEMP_NORM;
}
// Use all items on the floor -- there are not enough to keep comfortable
else {
temp_conv[i] += sleep_bonus;
}
}
int temp_before = temp_cur[i];
int temp_difference = temp_cur[i] - temp_conv[i]; // Negative if the player is warming up.
Expand Down Expand Up @@ -7602,6 +7604,21 @@ bool player::can_sleep(game *g)
return false;
}

std::string player::is_snuggling(game *g)
{
std::vector<item>& floor_item = g->m.i_at(posx, posy);
bool is_not_armor = true;

while( is_not_armor ) {
int random_index = rand() % floor_item.size();
if ( dynamic_cast<it_armor*>(floor_item[random_index].type)->is_armor() ) {
is_not_armor = false;
std::string floor_item_name = dynamic_cast<it_armor*>(floor_item[random_index].type)->name.c_str();
return floor_item_name;
}
}
return "nothing";
}
// Returned values range from 1.0 (unimpeded vision) to 5.0 (totally blind).
// 2.5 is enough light for detail work.
float player::fine_detail_vision_mod(game *g)
Expand Down
1 change: 1 addition & 0 deletions player.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class player {
void read(game *g, char let); // Read a book
void try_to_sleep(game *g); // '$' command; adds DIS_LYING_DOWN
bool can_sleep(game *g); // Checked each turn during DIS_LYING_DOWN
std::string is_snuggling(game *g); // Check to see if the player is using floor items to keep warm. If so, return one such item
float fine_detail_vision_mod(game *g); // Used for things like reading and sewing, checks light level

// helper functions meant to tell inventory display code what kind of visual feedback to give to the user
Expand Down

0 comments on commit 929531f

Please sign in to comment.