Skip to content

Commit

Permalink
Extends the new Satiety row to more information menus (#44565)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarfakis19 authored Oct 7, 2020
1 parent 0692265 commit 71a3d2f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,8 @@ class Character : public Creature, public visitable<Character>
/** Used to compute how filling a food is.*/
double compute_effective_food_volume_ratio( const item &food ) const;
/** Used to to display how filling a food is. */
int compute_calories_per_effective_volume( const item &food ) const;
int compute_calories_per_effective_volume( const item &food,
const nutrients *nutrient = nullptr ) const;
/** Handles the effects of consuming an item */
bool consume_effects( item &food );
/** Check character's capability of consumption overall */
Expand Down
12 changes: 9 additions & 3 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,12 +1275,18 @@ double Character::compute_effective_food_volume_ratio( const item &food ) const
}

// Used when displaying effective food satiation values.
int Character::compute_calories_per_effective_volume( const item &food ) const
int Character::compute_calories_per_effective_volume( const item &food,
const nutrients *nutrient /* = nullptr */ )const
{
/* Understanding how Calories Per Effective Volume are calculated requires a dive into the
stomach fullness source code. Look at issue #44365*/
const nutrients nutr = compute_effective_nutrients( food );
const int kcalories = nutr.kcal;
int kcalories;
if( nutrient ) {
// if given the optional nutrient argument, we will compute kcal based on that. ( Crafting menu ).
kcalories = nutrient->kcal;
} else {
kcalories = compute_effective_nutrients( food ).kcal;
}
units::volume water_vol = ( food.type->comestible->quench > 0 ) ? food.type->comestible->quench *
5_ml : 0_ml;
// Water volume is ignored.
Expand Down
14 changes: 14 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,20 @@ void item::food_info( const item *food_item, std::vector<iteminfo> &info,
info.push_back( iteminfo( "FOOD", space + _( "Quench: " ),
food_item->get_comestible()->quench ) );
}
if( parts->test( iteminfo_parts::FOOD_SATIATION ) ) {

if( max_nutr.kcal == min_nutr.kcal ) {
info.push_back( iteminfo( "FOOD", _( "<bold>Satiety: </bold>" ),
satiety_bar( player_character.compute_calories_per_effective_volume( *food_item ) ) ) );
} else {
info.push_back( iteminfo( "FOOD", _( "<bold>Satiety: </bold>" ),
satiety_bar( player_character.compute_calories_per_effective_volume( *food_item, &min_nutr ) ),
iteminfo::no_newline
) );
info.push_back( iteminfo( "FOOD", _( " - " ),
satiety_bar( player_character.compute_calories_per_effective_volume( *food_item, &max_nutr ) ) ) );
}
}
}

const std::pair<int, int> fun_for_food_item = player_character.fun_for( *food_item );
Expand Down
1 change: 1 addition & 0 deletions src/iteminfo_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum class iteminfo_parts : size_t {
MED_CONSUME_TIME,

FOOD_NUTRITION,
FOOD_SATIATION,
FOOD_QUENCH,
FOOD_JOY,
FOOD_PORTIONS,
Expand Down

0 comments on commit 71a3d2f

Please sign in to comment.