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

Extends the new Satiety row to more information menus #44565

Merged
merged 13 commits into from
Oct 7, 2020
3 changes: 2 additions & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,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 @@ -1271,12 +1271,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