From f8c79aa4725b1883e8393d87c3f896b16bec5e6a Mon Sep 17 00:00:00 2001 From: Fris0uman <41293484+Fris0uman@users.noreply.github.com> Date: Mon, 24 Feb 2020 07:55:24 +0100 Subject: [PATCH] Move some description function to Character (#38236) --- src/character.cpp | 104 +++++++++++++++++++++++++++++++++++----------- src/character.h | 12 +++--- src/player.cpp | 87 -------------------------------------- src/player.h | 4 -- 4 files changed, 86 insertions(+), 121 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index bd9844298ed85..fb1c6eb1d2377 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -3502,34 +3502,67 @@ std::pair Character::get_thirst_description() const std::pair Character::get_hunger_description() const { - int hunger = get_hunger(); + const bool calorie_deficit = get_bmi() < character_weight_category::normal; + const units::volume contains = stomach.contains(); + const units::volume cap = stomach.capacity( *this ); std::string hunger_string; nc_color hunger_color = c_white; - if( hunger >= 300 && get_starvation() > 2500 ) { - hunger_color = c_red; - hunger_string = _( "Starving!" ); - } else if( hunger >= 300 && get_starvation() > 1100 ) { - hunger_color = c_light_red; - hunger_string = _( "Near starving" ); - } else if( hunger > 250 ) { - hunger_color = c_light_red; - hunger_string = _( "Famished" ); - } else if( hunger > 100 ) { - hunger_color = c_yellow; - hunger_string = _( "Very hungry" ); - } else if( hunger > 40 ) { - hunger_color = c_yellow; - hunger_string = _( "Hungry" ); - } else if( hunger < -60 ) { - hunger_color = c_yellow; - hunger_string = _( "Engorged" ); - } else if( hunger < -20 ) { - hunger_color = c_green; - hunger_string = _( "Sated" ); - } else if( hunger < 0 ) { - hunger_color = c_green; - hunger_string = _( "Full" ); + // i ate just now! + const bool just_ate = stomach.time_since_ate() < 15_minutes; + // i ate a meal recently enough that i shouldn't need another meal + const bool recently_ate = stomach.time_since_ate() < 3_hours; + if( calorie_deficit ) { + if( contains >= cap ) { + hunger_string = _( "Engorged" ); + hunger_color = c_green; + } else if( contains > cap * 3 / 4 ) { + hunger_string = _( "Sated" ); + hunger_color = c_green; + } else if( just_ate && contains > cap / 2 ) { + hunger_string = _( "Full" ); + hunger_color = c_green; + } else if( just_ate ) { + hunger_string = _( "Hungry" ); + hunger_color = c_yellow; + } else if( recently_ate ) { + hunger_string = _( "Very Hungry" ); + hunger_color = c_yellow; + } else if( get_bmi() < character_weight_category::emaciated ) { + hunger_string = _( "Starving!" ); + hunger_color = c_red; + } else if( get_bmi() < character_weight_category::underweight ) { + hunger_string = _( "Near starving" ); + hunger_color = c_red; + } else { + hunger_string = _( "Famished" ); + hunger_color = c_light_red; + } + } else { + if( contains >= cap * 5 / 6 ) { + hunger_string = _( "Engorged" ); + hunger_color = c_green; + } else if( contains > cap * 11 / 20 ) { + hunger_string = _( "Sated" ); + hunger_color = c_green; + } else if( recently_ate && contains >= cap * 3 / 8 ) { + hunger_string = _( "Full" ); + hunger_color = c_green; + } else if( ( stomach.time_since_ate() > 90_minutes && contains < cap / 8 && recently_ate ) || + ( just_ate && contains > 0_ml && contains < cap * 3 / 8 ) ) { + hunger_string = _( "Peckish" ); + hunger_color = c_dark_gray; + } else if( !just_ate && ( recently_ate || contains > 0_ml ) ) { + hunger_string.clear(); + } else { + if( get_bmi() > character_weight_category::overweight ) { + hunger_string = _( "Hungry" ); + } else { + hunger_string = _( "Very Hungry" ); + } + hunger_color = c_yellow; + } } + return std::make_pair( hunger_string, hunger_color ); } @@ -3602,6 +3635,27 @@ int Character::get_sleep_deprivation() const return sleep_deprivation; } +std::pair Character::get_pain_description() const +{ + const std::pair pain = Creature::get_pain_description(); + nc_color pain_color = pain.second; + std::string pain_string; + // get pain color + if( get_perceived_pain() >= 60 ) { + pain_color = c_red; + } else if( get_perceived_pain() >= 40 ) { + pain_color = c_light_red; + } + // get pain string + if( ( has_trait( trait_SELFAWARE ) || has_effect( effect_got_checked ) ) && + get_perceived_pain() > 0 ) { + pain_string = string_format( "%s %d", _( "Pain " ), get_perceived_pain() ); + } else if( get_perceived_pain() > 0 ) { + pain_string = pain.first; + } + return std::make_pair( pain_string, pain_color ); +} + bool Character::is_deaf() const { return get_effect_int( effect_deaf ) > 2 || worn_with_flag( flag_DEAF ) || diff --git a/src/character.h b/src/character.h index ee37495b04842..75e8e37f4bc52 100644 --- a/src/character.h +++ b/src/character.h @@ -352,11 +352,13 @@ class Character : public Creature, public visitable virtual int get_thirst() const; /** Gets character's minimum hunger and thirst */ int stomach_capacity() const; - virtual std::pair get_thirst_description() const; - virtual std::pair get_hunger_description() const; - virtual std::pair get_fatigue_description() const; - virtual int get_fatigue() const; - virtual int get_sleep_deprivation() const; + std::pair get_thirst_description() const; + std::pair get_hunger_description() const; + std::pair get_fatigue_description() const; + int get_fatigue() const; + int get_sleep_deprivation() const; + + std::pair get_pain_description() const override; /** Modifiers for need values exclusive to characters */ virtual void mod_stored_kcal( int nkcal ); diff --git a/src/player.cpp b/src/player.cpp index ba6546e38462f..1baa50b7b0c7f 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -5683,90 +5683,3 @@ std::set player::get_path_avoid() const return ret; } - -std::pair player::get_hunger_description() const -{ - const bool calorie_deficit = get_bmi() < character_weight_category::normal; - const units::volume contains = stomach.contains(); - const units::volume cap = stomach.capacity( *this ); - std::string hunger_string; - nc_color hunger_color = c_white; - // i ate just now! - const bool just_ate = stomach.time_since_ate() < 15_minutes; - // i ate a meal recently enough that i shouldn't need another meal - const bool recently_ate = stomach.time_since_ate() < 3_hours; - if( calorie_deficit ) { - if( contains >= cap ) { - hunger_string = _( "Engorged" ); - hunger_color = c_green; - } else if( contains > cap * 3 / 4 ) { - hunger_string = _( "Sated" ); - hunger_color = c_green; - } else if( just_ate && contains > cap / 2 ) { - hunger_string = _( "Full" ); - hunger_color = c_green; - } else if( just_ate ) { - hunger_string = _( "Hungry" ); - hunger_color = c_yellow; - } else if( recently_ate ) { - hunger_string = _( "Very Hungry" ); - hunger_color = c_yellow; - } else if( get_bmi() < character_weight_category::emaciated ) { - hunger_string = _( "Starving!" ); - hunger_color = c_red; - } else if( get_bmi() < character_weight_category::underweight ) { - hunger_string = _( "Near starving" ); - hunger_color = c_red; - } else { - hunger_string = _( "Famished" ); - hunger_color = c_light_red; - } - } else { - if( contains >= cap * 5 / 6 ) { - hunger_string = _( "Engorged" ); - hunger_color = c_green; - } else if( contains > cap * 11 / 20 ) { - hunger_string = _( "Sated" ); - hunger_color = c_green; - } else if( recently_ate && contains >= cap * 3 / 8 ) { - hunger_string = _( "Full" ); - hunger_color = c_green; - } else if( ( stomach.time_since_ate() > 90_minutes && contains < cap / 8 && recently_ate ) || - ( just_ate && contains > 0_ml && contains < cap * 3 / 8 ) ) { - hunger_string = _( "Peckish" ); - hunger_color = c_dark_gray; - } else if( !just_ate && ( recently_ate || contains > 0_ml ) ) { - hunger_string.clear(); - } else { - if( get_bmi() > character_weight_category::overweight ) { - hunger_string = _( "Hungry" ); - } else { - hunger_string = _( "Very Hungry" ); - } - hunger_color = c_yellow; - } - } - - return std::make_pair( hunger_string, hunger_color ); -} - -std::pair player::get_pain_description() const -{ - auto pain = Creature::get_pain_description(); - nc_color pain_color = pain.second; - std::string pain_string; - // get pain color - if( get_perceived_pain() >= 60 ) { - pain_color = c_red; - } else if( get_perceived_pain() >= 40 ) { - pain_color = c_light_red; - } - // get pain string - if( ( has_trait( trait_SELFAWARE ) || has_effect( effect_got_checked ) ) && - get_perceived_pain() > 0 ) { - pain_string = string_format( "%s %d", _( "Pain " ), get_perceived_pain() ); - } else if( get_perceived_pain() > 0 ) { - pain_string = pain.first; - } - return std::make_pair( pain_string, pain_color ); -} diff --git a/src/player.h b/src/player.h index 27f86ebb3c03c..99be20fa30579 100644 --- a/src/player.h +++ b/src/player.h @@ -509,10 +509,6 @@ class player : public Character /** Handles the enjoyability value for a book. **/ int book_fun_for( const item &book, const player &p ) const; - std::pair get_hunger_description() const override; - - std::pair get_pain_description() const override; - int get_lift_assist() const; bool list_ammo( const item &base, std::vector &ammo_list,