Skip to content

Commit

Permalink
More complex satiety calculations (#40402)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramza13 authored May 11, 2020
1 parent a0cc190 commit ffc02de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,12 +1315,19 @@ bool Character::consume_effects( item &food )
set_hunger( capacity );
}

nutrients food_nutrients = compute_effective_nutrients( food );
// TODO: Move quench values to mL and remove the magic number here
units::volume water = food.type->comestible->quench * 5_ml;
units::volume water_vol = food.type->comestible->quench * 5_ml;
units::volume food_vol = food.base_volume() - std::max( water_vol, 0_ml );
units::mass food_weight = ( food.weight() / food.count() ) - units::from_gram( units::to_milliliter(
water_vol ) ); //water is 1 gram per milliliter
double ratio = std::max( static_cast<double>( food_nutrients.kcal ) / units::to_gram( food_weight ),
1.0 );

food_summary ingested{
water,
food.base_volume() - std::max( water, 0_ml ),
compute_effective_nutrients( food )
water_vol,
food_vol * ratio,
food_nutrients
};
// Maybe move tapeworm to digestion
if( has_effect( effect_tapeworm ) ) {
Expand Down
4 changes: 2 additions & 2 deletions tests/stomach_contents_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ TEST_CASE( "hunger" )
if( print_tests ) {
printf( "%d minutes til hunger sets in\n", hunger_time );
}
CHECK( hunger_time <= 240 );
CHECK( hunger_time >= 210 );
CHECK( hunger_time <= 435 );
CHECK( hunger_time >= 405 );
if( print_tests ) {
print_stomach_contents( dummy, print_tests );
printf( "eat 16 veggy\n" );
Expand Down

0 comments on commit ffc02de

Please sign in to comment.