From ee29b0d5ac31e4bf3dbf6805f0a27bb949359edd Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Fri, 2 Oct 2020 16:48:18 +0100 Subject: [PATCH 01/13] Init --- src/item.cpp | 4 ++++ src/iteminfo_query.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/item.cpp b/src/item.cpp index 9fd6b7a0e7566..9532f1323765e 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1830,6 +1830,10 @@ void item::food_info( const item *food_item, std::vector &info, info.push_back( iteminfo( "FOOD", space + _( "Quench: " ), food_item->get_comestible()->quench ) ); } + if( parts->test( iteminfo_parts::FOOD_SATIATION ) ) { + info.push_back( iteminfo( "FOOD", _( "Satiety: " ), + satiety_bar( player_character.compute_calories_per_effective_volume( *food_item ) ) ) ); + } } const std::pair fun_for_food_item = player_character.fun_for( *food_item ); diff --git a/src/iteminfo_query.h b/src/iteminfo_query.h index 14f135779a1da..275ff4bd94646 100644 --- a/src/iteminfo_query.h +++ b/src/iteminfo_query.h @@ -33,6 +33,7 @@ enum class iteminfo_parts : size_t { MED_CONSUME_TIME, FOOD_NUTRITION, + FOOD_SATIATION, FOOD_QUENCH, FOOD_JOY, FOOD_PORTIONS, From 9f4bcf969c0adbf2e331cc8ff5704a2aea3f80fa Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Fri, 2 Oct 2020 16:57:38 +0100 Subject: [PATCH 02/13] minor spacing --- src/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index 9532f1323765e..0dda1985b2326 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1831,7 +1831,7 @@ void item::food_info( const item *food_item, std::vector &info, food_item->get_comestible()->quench ) ); } if( parts->test( iteminfo_parts::FOOD_SATIATION ) ) { - info.push_back( iteminfo( "FOOD", _( "Satiety: " ), + info.push_back( iteminfo( "FOOD", _( "Satiety: " ), satiety_bar( player_character.compute_calories_per_effective_volume( *food_item ) ) ) ); } } From 644b12c800f48b2daf9cf2191b19896dbd7b7f9c Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Fri, 2 Oct 2020 17:06:02 +0100 Subject: [PATCH 03/13] astyle --- src/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index 0dda1985b2326..24b2b574acd46 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1832,7 +1832,7 @@ void item::food_info( const item *food_item, std::vector &info, } if( parts->test( iteminfo_parts::FOOD_SATIATION ) ) { info.push_back( iteminfo( "FOOD", _( "Satiety: " ), - satiety_bar( player_character.compute_calories_per_effective_volume( *food_item ) ) ) ); + satiety_bar( player_character.compute_calories_per_effective_volume( *food_item ) ) ) ); } } From 1cc8a3aa53a71f5f6c954c185d9c7d44c20dd661 Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Fri, 2 Oct 2020 17:52:00 +0100 Subject: [PATCH 04/13] Initial attempt at making it work for the crafting window as well. The old compute_calories_per_effective volume now gets an optional parameter that lets it accept an external nutrient (kcal) value, and as such, it works with the crafting menus calorie ranges min_cal - max_cal. --- src/character.h | 2 +- src/consumption.cpp | 12 +++++++++--- src/item.cpp | 12 ++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/character.h b/src/character.h index defe11d07bf14..aac26369b47dc 100644 --- a/src/character.h +++ b/src/character.h @@ -2258,7 +2258,7 @@ class Character : public Creature, public visitable /** 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* nutr = nullptr) const; /** Handles the effects of consuming an item */ bool consume_effects( item &food ); /** Check character's capability of consumption overall */ diff --git a/src/consumption.cpp b/src/consumption.cpp index ee64295e168ef..33e285b998ea1 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -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; + const nutrients* nutr; + if( !nutrient ) { + nutr = &compute_effective_nutrients( food ); + } + else { + nutr = nutrient; + } + const int kcalories = nutr->kcal; units::volume water_vol = ( food.type->comestible->quench > 0 ) ? food.type->comestible->quench * 5_ml : 0_ml; // Water volume is ignored. diff --git a/src/item.cpp b/src/item.cpp index 24b2b574acd46..71ae7a2a69a33 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1831,8 +1831,16 @@ void item::food_info( const item *food_item, std::vector &info, food_item->get_comestible()->quench ) ); } if( parts->test( iteminfo_parts::FOOD_SATIATION ) ) { - info.push_back( iteminfo( "FOOD", _( "Satiety: " ), - satiety_bar( player_character.compute_calories_per_effective_volume( *food_item ) ) ) ); + + if( max_nutr.kcal == min_nutr.kcal ) { + info.push_back( iteminfo( "FOOD", _( "Satiety: " ), + satiety_bar( player_character.compute_calories_per_effective_volume( *food_item ) ) ) ); + } else { + info.push_back( iteminfo( "FOOD", _( "Satiety: " ), "", iteminfo::no_newline, + satiety_bar( player_character.compute_calories_per_effective_volume( *food_item, &min_nutr ) ) ) ); + info.push_back( iteminfo( "FOOD", _( "-" ), + satiety_bar( player_character.compute_calories_per_effective_volume( *food_item, &max_nutr ) ) ) ); + } } } From becc5b91847ad001a9d0e27cb6beeb149b5f85ae Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Fri, 2 Oct 2020 18:05:17 +0100 Subject: [PATCH 05/13] Update item.cpp --- src/item.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 71ae7a2a69a33..a3ac413a83846 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1836,8 +1836,10 @@ void item::food_info( const item *food_item, std::vector &info, info.push_back( iteminfo( "FOOD", _( "Satiety: " ), satiety_bar( player_character.compute_calories_per_effective_volume( *food_item ) ) ) ); } else { - info.push_back( iteminfo( "FOOD", _( "Satiety: " ), "", iteminfo::no_newline, - satiety_bar( player_character.compute_calories_per_effective_volume( *food_item, &min_nutr ) ) ) ); + info.push_back( iteminfo( "FOOD", _( "Satiety: " ), + 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 ) ) ) ); } From e6f65b1ef07334accdcb030e77abf0fbd654cd57 Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Fri, 2 Oct 2020 18:06:27 +0100 Subject: [PATCH 06/13] Update character.h --- src/character.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/character.h b/src/character.h index aac26369b47dc..8c32d5fb3992a 100644 --- a/src/character.h +++ b/src/character.h @@ -2258,7 +2258,7 @@ class Character : public Creature, public visitable /** 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 nutrients* nutr = nullptr) 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 */ From 5b2acbce5b7e6b8d0781fad3246a09b5a66737a4 Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Fri, 2 Oct 2020 18:38:26 +0100 Subject: [PATCH 07/13] Function def fix --- src/character.h | 2 +- src/consumption.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/character.h b/src/character.h index 8c32d5fb3992a..94ae9e25f8087 100644 --- a/src/character.h +++ b/src/character.h @@ -2258,7 +2258,7 @@ class Character : public Creature, public visitable /** 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 nutrients* nutrient = nullptr) 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 */ diff --git a/src/consumption.cpp b/src/consumption.cpp index 33e285b998ea1..4c7533db16e46 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1271,7 +1271,7 @@ 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 nutrients *nutrient = nullptr )const +int Character::compute_calories_per_effective_volume( const item &food, const nutrients *nutrient )const { /* Understanding how Calories Per Effective Volume are calculated requires a dive into the stomach fullness source code. Look at issue #44365*/ From ac027a33e5d664d525351028653060a87c49994b Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Fri, 2 Oct 2020 18:56:09 +0100 Subject: [PATCH 08/13] Update consumption.cpp --- src/consumption.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/consumption.cpp b/src/consumption.cpp index 4c7533db16e46..7d8ae9d5fd740 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1273,6 +1273,7 @@ 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 nutrients *nutrient )const { + // ^^ nutrient is nullptr by default. /* Understanding how Calories Per Effective Volume are calculated requires a dive into the stomach fullness source code. Look at issue #44365*/ const nutrients* nutr; From 018445135731f932a8502d358ce2ef34785f4409 Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Sat, 3 Oct 2020 11:40:27 +0100 Subject: [PATCH 09/13] comments --- src/consumption.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/consumption.cpp b/src/consumption.cpp index 7d8ae9d5fd740..292fa12a33aa3 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1271,17 +1271,17 @@ 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 nutrients *nutrient )const +int Character::compute_calories_per_effective_volume( const item &food, const nutrients *nutrient /* = nullptr */ )const { - // ^^ nutrient is nullptr by default. /* Understanding how Calories Per Effective Volume are calculated requires a dive into the stomach fullness source code. Look at issue #44365*/ const nutrients* nutr; - if( !nutrient ) { - nutr = &compute_effective_nutrients( food ); + if( nutrient ) { + // if given the optional nutrient argument, we will compute kcal based on that. ( Crafting menu ). + nutr = nutrient; } else { - nutr = nutrient; + nutr = &compute_effective_nutrients(food); } const int kcalories = nutr->kcal; units::volume water_vol = ( food.type->comestible->quench > 0 ) ? food.type->comestible->quench * From 690e5b5bba4cf2043bb6b537b5bee0d338e373ac Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Sat, 3 Oct 2020 21:24:16 +0100 Subject: [PATCH 10/13] misc function change --- src/consumption.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/consumption.cpp b/src/consumption.cpp index 292fa12a33aa3..6044346c65211 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1275,15 +1275,14 @@ int Character::compute_calories_per_effective_volume( const item &food, const nu { /* Understanding how Calories Per Effective Volume are calculated requires a dive into the stomach fullness source code. Look at issue #44365*/ - const nutrients* nutr; + int kcalories; if( nutrient ) { // if given the optional nutrient argument, we will compute kcal based on that. ( Crafting menu ). - nutr = nutrient; + kcalories = nutrient->kcal; } else { - nutr = &compute_effective_nutrients(food); + kcalories = compute_effective_nutrients(food).kcal; } - const int kcalories = nutr->kcal; units::volume water_vol = ( food.type->comestible->quench > 0 ) ? food.type->comestible->quench * 5_ml : 0_ml; // Water volume is ignored. From 027891d8d0f80f75cb7900afcb0681fe42554513 Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Sun, 4 Oct 2020 12:33:52 +0100 Subject: [PATCH 11/13] spacing change --- src/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index a3ac413a83846..729b092f05e74 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -1840,7 +1840,7 @@ void item::food_info( const item *food_item, std::vector &info, satiety_bar( player_character.compute_calories_per_effective_volume( *food_item, &min_nutr ) ), iteminfo::no_newline ) ); - info.push_back( iteminfo( "FOOD", _( "-" ), + info.push_back( iteminfo( "FOOD", _( " - " ), satiety_bar( player_character.compute_calories_per_effective_volume( *food_item, &max_nutr ) ) ) ); } } From 42e127739dbff6d1b0e9266ecec73225e06c157f Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Sun, 4 Oct 2020 12:35:46 +0100 Subject: [PATCH 12/13] astyle --- src/consumption.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/consumption.cpp b/src/consumption.cpp index 6044346c65211..24ba9f129dc06 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1271,7 +1271,8 @@ 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 nutrients *nutrient /* = nullptr */ )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*/ @@ -1279,9 +1280,8 @@ int Character::compute_calories_per_effective_volume( const item &food, const nu 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; + } else { + kcalories = compute_effective_nutrients( food ).kcal; } units::volume water_vol = ( food.type->comestible->quench > 0 ) ? food.type->comestible->quench * 5_ml : 0_ml; From b4074283408f71f642290ecac080d1759b23993a Mon Sep 17 00:00:00 2001 From: George Karfakis Date: Wed, 7 Oct 2020 11:13:24 +0100 Subject: [PATCH 13/13] astyle 2 Ready to merge. --- src/character.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/character.h b/src/character.h index 94ae9e25f8087..23d718e47f1e1 100644 --- a/src/character.h +++ b/src/character.h @@ -2258,7 +2258,8 @@ class Character : public Creature, public visitable /** 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 nutrients *nutrient = nullptr ) 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 */