Skip to content

Commit

Permalink
change some nutrition_for to kcal_for
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Mar 6, 2019
1 parent e70d891 commit 1fcdba4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
25 changes: 15 additions & 10 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int player::stomach_capacity() const
// TODO: Move pizza scraping here.
// Same for other kinds of nutrition alterations
// This is used by item display, making actual nutrition available to player.
int player::nutrition_for( const item &comest ) const
int player::kcal_for( const item &comest ) const
{
static const trait_id trait_CARNIVORE( "CARNIVORE" );
static const trait_id trait_GIZZARD( "GIZZARD" );
Expand All @@ -98,28 +98,28 @@ int player::nutrition_for( const item &comest ) const
}

// As float to avoid rounding too many times
float nutr = 0;
float kcal = 0;

// if item has components, will derive calories from that instead.
if( comest.components.size() > 0 && !comest.has_flag( "NUTRIENT_OVERRIDE" ) ) {
int byproduct_multiplier;
for( item component : comest.components ) {
component.has_flag( "BYPRODUCT" ) ? byproduct_multiplier = -1 : byproduct_multiplier = 1;
nutr += this->nutrition_for( component ) * component.charges * byproduct_multiplier;
kcal += this->kcal_for( component ) * component.charges * byproduct_multiplier;
}
nutr /= comest.recipe_charges;
kcal /= comest.recipe_charges;
} else {
nutr = comest.type->comestible->get_nutr();
kcal = comest.type->comestible->get_calories();
}

if( has_trait( trait_GIZZARD ) ) {
nutr *= 0.6f;
kcal *= 0.6f;
}

if( has_trait( trait_CARNIVORE ) && comest.has_flag( flag_CARNIVORE_OK ) &&
comest.has_any_flag( carnivore_blacklist ) ) {
// TODO: Comment pizza scrapping
nutr *= 0.5f;
kcal *= 0.5f;
}

const float relative_rot = comest.get_relative_rot();
Expand All @@ -128,15 +128,20 @@ int player::nutrition_for( const item &comest ) const
// everyone else only gets a portion of the nutrition
// Scaling linearly from 100% at just-rotten to 0 at halfway-rotten-away
const float rottedness = clamp( 2 * relative_rot - 2.0f, 0.1f, 1.0f );
nutr *= ( 1.0f - rottedness );
kcal *= ( 1.0f - rottedness );
}

// Bionic digestion gives extra nutrition
if( has_bionic( bio_digestion ) ) {
nutr *= 1.5f;
kcal *= 1.5f;
}

return static_cast<int>( nutr );
return static_cast<int>( kcal );
}

int player::nutrition_for( const item &comest ) const
{
return kcal_for( comest ) / islot_comestible::kcal_per_nutr;
}

std::pair<int, int> player::fun_for( const item &comest ) const
Expand Down
3 changes: 1 addition & 2 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ class comestible_inventory_preset : public inventory_selector_preset
comestible_inventory_preset( const player &p ) : inventory_selector_preset(), p( p ) {

append_cell( [ &p, this ]( const item_location & loc ) {
return good_bad_none( p.nutrition_for( get_comestible_item( loc ) ) *
islot_comestible::kcal_per_nutr );
return good_bad_none( p.kcal_for( get_comestible_item( loc ) ) );
}, _( "CALORIES" ) );

append_cell( [ this ]( const item_location & loc ) {
Expand Down
4 changes: 2 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,9 @@ std::string item::info( std::vector<iteminfo> &info, const iteminfo_query *parts
food_item = &contents.front();
}
if( food_item != nullptr ) {
if( g->u.nutrition_for( *food_item ) != 0 || food_item->type->comestible->quench != 0 ) {
if( g->u.kcal_for( *food_item ) != 0 || food_item->type->comestible->quench != 0 ) {
if( parts->test( iteminfo_parts::FOOD_NUTRITION ) ) {
auto value = g->u.nutrition_for( *food_item ) * islot_comestible::kcal_per_nutr;
auto value = g->u.kcal_for( *food_item );
info.push_back( iteminfo( "FOOD", _( "<bold>Calories (kcal)</bold>: " ),
"", iteminfo::no_newline, value ) );
}
Expand Down
2 changes: 2 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ class player : public Character
/** Gets player's minimum hunger and thirst */
int stomach_capacity() const;

/** Handles the kcal value for a comestible **/
int kcal_for( const item &comest ) const;
/** Handles the nutrition value for a comestible **/
int nutrition_for( const item &comest ) const;
/** Handles the enjoyability value for a comestible. First value is enjoyability, second is cap. **/
Expand Down

0 comments on commit 1fcdba4

Please sign in to comment.