Skip to content

Commit

Permalink
Fixed segfault for sleeping on top of clothes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoes01 committed Aug 20, 2013
1 parent 8e0552d commit b6e679d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions disease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,8 @@ void dis_effect(game *g, player &p, disease &dis)
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);
std::string item_name = p.is_snuggling(g);
if ( item_name != "nothing") {
if ( one_in(15) ) {
g->add_msg(_("You snuggle your %s to keep warm."), item_name.c_str());
}
Expand Down
15 changes: 9 additions & 6 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ void player::update_bodytemp(game *g)
it_armor* floor_armor = NULL;

for ( std::vector<item>::iterator afloor_item = floor_item.begin() ; afloor_item != floor_item.end() ; ++afloor_item) {
if (!dynamic_cast<it_armor*>(afloor_item->type)->is_armor()) {
if ( !afloor_item->is_armor() ) {
continue;
}
floor_armor = dynamic_cast<it_armor*>(afloor_item->type);
Expand Down Expand Up @@ -7608,6 +7608,7 @@ std::string player::is_snuggling(game *g)
{
std::vector<item>& floor_item = g->m.i_at(posx, posy);
int attempts = 0;
it_armor* floor_armor = NULL;

// If there are no items on the floor, return nothing
if ( floor_item.size() == 0 ) {
Expand All @@ -7617,11 +7618,13 @@ std::string player::is_snuggling(game *g)
while (attempts < 5) {
// Pick a random item
int random_index = rand() % floor_item.size();
it_armor* afloor_item = dynamic_cast<it_armor*>(floor_item[random_index].type);

// Check to see if the item is armor and that it covers the torso
if ( afloor_item->is_armor() && ((afloor_item->covers & mfb(bp_torso)) || (afloor_item->covers & mfb(bp_legs))) ) {
return afloor_item->name.c_str();
if ( floor_item[random_index].is_armor() ) {
floor_armor = dynamic_cast<it_armor*>(floor_item[random_index].type);

// Check to see if the item covers the torso or legs
if ( (floor_armor->covers & mfb(bp_torso)) || (floor_armor->covers & mfb(bp_legs)) ) {
return floor_armor->name.c_str();
}
}

attempts++;
Expand Down

0 comments on commit b6e679d

Please sign in to comment.