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

Fix for freezing bugs - part 2 #24905

Merged
merged 8 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,8 @@ void set_item_food( item &newit )
int bday_tmp = to_turn<int>( newit.birthday() ) % 3600; // fuzzy birthday for stacking reasons
newit.set_birthday( newit.birthday() + 3600_turns - time_duration::from_turns( bday_tmp ) );
if( newit.has_flag( "EATEN_HOT" ) ) { // hot foods generated
if( newit.item_tags.count( "COLD" ) ) {
newit.item_tags.erase( "COLD" );
}
if( newit.item_tags.count( "FROZEN" ) ) {
newit.item_tags.erase( "FROZEN" );
}
newit.item_tags.erase( "COLD" );
newit.item_tags.erase( "FROZEN" );
newit.item_tags.insert( "HOT" );
newit.item_counter = 600;
newit.active = true;
Expand Down
42 changes: 18 additions & 24 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,11 +982,11 @@ std::string item::info(std::vector<iteminfo> &info, const iteminfo_query *parts,
"It's on a brink of becoming inedible." ) );
}
}
if( food_item->has_flag( "NO_FREEZE" ) && !food_item->rotten() ) {
info.emplace_back( "DESCRIPTION", _( "* Quality of this food suffers when it's <neutral>frozen.</neutral>." ) );
if( food_item->has_flag( "NO_FREEZE" ) && !food_item->rotten() && !food_item->has_flag( "MUSHY" ) ) {
info.emplace_back( "DESCRIPTION", _( "* Quality of this food suffers when it's <neutral>frozen, and it becames mushy after defrosting</neutral>." ) );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still an error. Here's a suggestion:
(...), and it will become mushy after thawing out.

}
if( food_item->has_flag( "MUSHY" ) && !food_item->rotten() ) {
info.emplace_back( "DESCRIPTION", _( "* It was frozen once and bacame <bad>mushy and tasteless</bad>." ) );
info.emplace_back( "DESCRIPTION", _( "* It was frozen once and after thawing became <bad>mushy and tasteless</bad>." ) );
}
if( food_item->has_flag( "NO_PARASITES" ) && g->u.get_skill_level( skill_cooking ) >= 3 ) {
info.emplace_back( "DESCRIPTION", _( "* It seems that deep freezing <good>killed all parasites</good>." ) );
Expand Down Expand Up @@ -5730,7 +5730,7 @@ int item::processing_speed() const
// Hot and cold food need turn-by-turn updates.
// If they ever become a performance problem, update process_food to handle them occasionally.
return 600;
} else {
} else if( is_food() ) {
return 100;
}
if( is_corpse() ) {
Expand All @@ -5743,28 +5743,22 @@ int item::processing_speed() const
bool item::process_food( player * /*carrier*/, const tripoint &pos )
{
calc_rot( g->m.getabs( pos ) );
if( item_tags.count( "HOT" ) > 0 ) {
if( item_counter == 0 ) {
item_tags.erase( "HOT" );
}
} else if( item_tags.count( "COLD" ) > 0 ) {
if( item_counter == 0 ) {
if( item_tags.count( "HOT" ) && item_counter == 0 ) {
item_tags.erase( "HOT" );
}
if( item_tags.count( "COLD" ) && item_counter == 0 ) {
item_tags.erase( "COLD" );
}
if( item_tags.count( "FROZEN" ) && item_counter == 0 ) {
item_tags.erase( "FROZEN" );
if( has_flag( "NO_FREEZE" ) && !rotten() ) {
item_tags.insert( "MUSHY" );
} else if( has_flag( "NO_FREEZE" ) && has_flag( "MUSHY" ) &&
rot < type->comestible->spoils ) {
rot = type->comestible->spoils;
}
} else if( item_tags.count( "FROZEN" ) > 0 ) {
if( item_counter == 0 ) {
item_tags.erase( "FROZEN" );
if( has_flag( "NO_FREEZE" ) && !rotten() ) {
item_tags.insert( "MUSHY" );
} else if( has_flag( "NO_FREEZE" ) && has_flag( "MUSHY" ) &&
rot < type->comestible->spoils ) {
rot = type->comestible->spoils;
}
if( has_flag( "EATEN_COLD" ) ) {
item_tags.insert( "COLD" );
item_counter = 600;
}
}
item_tags.insert( "COLD" );
item_counter = 600;
}
// deep freezing kills parasites but not instantly
if( item_tags.count( "FROZEN" ) > 0 && item_counter > 500 && type->comestible->parasites > 0 ) {
Expand Down
21 changes: 7 additions & 14 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4862,7 +4862,8 @@ static bool heat_item( player &p )
auto loc = g->inv_map_splice( []( const item & itm ) {
return ( ( itm.is_food() && ( itm.has_flag( "EATEN_HOT" ) || itm.item_tags.count( "FROZEN" ) ) ) ||
( itm.is_food_container() &&
( itm.contents.front().has_flag( "EATEN_HOT" ) || itm.item_tags.count( "FROZEN" ) ) ) );
( itm.contents.front().has_flag( "EATEN_HOT" ) ||
itm.contents.front().item_tags.count( "FROZEN" ) ) ) );
}, _( "Heat up what?" ), 1, _( "You don't have appropriate food to heat up." ) );

item *heat = loc.get_item();
Expand All @@ -4881,7 +4882,7 @@ static bool heat_item( player &p )
target.item_tags.erase( "FROZEN" );
target.item_tags.insert( "HOT" );
target.active = true;
target.item_counter = 250; // prevents insta-freeze after defrosting
target.item_counter = 300; // prevents insta-freeze after defrosting
if( target.has_flag( "NO_FREEZE" ) && !target.rotten() ) {
target.item_tags.insert( "MUSHY" );
} else if( target.has_flag( "NO_FREEZE" ) && target.has_flag( "MUSHY" ) &&
Expand All @@ -4890,12 +4891,8 @@ static bool heat_item( player &p )
}
} else {
add_msg( _( "You heat up the food." ) );
if( target.item_tags.count( "COLD" ) ) {
target.item_tags.erase( "COLD" );
}
if( target.item_tags.count( "FROZEN" ) ) {
target.item_tags.erase( "FROZEN" );
}
target.item_tags.erase( "COLD" );
target.item_tags.erase( "FROZEN" );
target.item_tags.insert( "HOT" );
p.mod_moves( -to_gram( target.weight() ) ); // simulates heat capacity of food
target.active = true;
Expand Down Expand Up @@ -6948,12 +6945,8 @@ int iuse::multicooker( player *p, item *it, bool t, const tripoint &pos )
item &meal = it->emplace_back( it->get_var( "DISH" ) );
if( meal.has_flag( "EATEN_HOT" ) ) {
meal.active = true;
if( meal.item_tags.count( "COLD" ) ) {
meal.item_tags.erase( "COLD" );
}
if( meal.item_tags.count( "FROZEN" ) ) {
meal.item_tags.erase( "FROZEN" );
}
meal.item_tags.erase( "COLD" );
meal.item_tags.erase( "FROZEN" );
meal.item_tags.insert( "HOT" );
meal.item_counter = 600;
}
Expand Down
23 changes: 11 additions & 12 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4579,12 +4579,12 @@ void map::make_active( item_location &loc )
void map::apply_in_fridge( item &it, int temp )
{
unsigned int diff_freeze = abs(temp - FREEZING_TEMPERATURE);
diff_freeze = diff_freeze < 1 ? 1 : diff_freeze;
diff_freeze = diff_freeze > 10 ? 10 : diff_freeze;
diff_freeze = std::max( 1, diff_freeze );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't put int and unsigned int together.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticed that in a compiler, sorry

diff_freeze = std::min( 5, diff_freeze );

unsigned int diff_cold = abs(temp - FRIDGE_TEMPERATURE);
diff_cold = diff_cold < 1 ? 1 : diff_cold;
diff_cold = diff_cold > 10 ? 10 : diff_cold;
diff_freeze = std::max( 1, diff_cold );
diff_freeze = std::min( 5, diff_cold );

if( it.is_food() ) {
if( temp <= FREEZING_TEMPERATURE ) {
Expand All @@ -4604,8 +4604,8 @@ void map::apply_in_fridge( item &it, int temp )
it.item_counter = 0;
}
// This sets the COLD flag, and doesn't go above 600
if( it.has_flag( "EATEN_COLD" ) && !( it.item_tags.count( "COLD" ) ||
it.item_tags.count( "FROZEN" ) || it.item_tags.count( "HOT" ) ) ) {
if( !( it.item_tags.count( "COLD" ) || it.item_tags.count( "FROZEN" ) ||
it.item_tags.count( "HOT" ) ) ) {

it.item_tags.insert( "COLD" );
it.active = true;
Expand All @@ -4614,16 +4614,15 @@ void map::apply_in_fridge( item &it, int temp )
it.item_counter += diff_cold;
}
// Freezer converts COLD flag at 600 ticks to FROZEN flag with max 600 ticks
if ( temp <= FREEZING_TEMPERATURE && it.item_tags.count( "COLD" ) && it.item_counter >= 600 ) {
if ( temp <= FREEZING_TEMPERATURE && it.item_tags.count( "COLD" ) && it.item_counter >= 600 &&
!( it.item_tags.count( "FROZEN" ) || it.item_tags.count( "HOT" ) ) ) {

it.item_tags.erase( "COLD" );
it.item_tags.insert( "FROZEN" );
it.active = true;
it.item_counter = 0;
}
// items that don't use COLD flag can go FROZEN bypassing COLD state
if( !it.has_flag( "EATEN_COLD" ) && !it.item_tags.count( "FROZEN" ) ) {
it.item_tags.insert( "FROZEN" );
it.active = true;

// items that don't use COLD flag can go FROZEN bypassing COLD state
}
if ( temp <= FREEZING_TEMPERATURE && it.item_tags.count( "FROZEN" ) && it.item_counter <= 600 ) {
it.item_counter += diff_freeze;
Expand Down