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

Move some description function to Character #38236

Merged
merged 3 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 79 additions & 25 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3502,34 +3502,67 @@ std::pair<std::string, nc_color> Character::get_thirst_description() const

std::pair<std::string, nc_color> 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 );
}

Expand Down Expand Up @@ -3602,6 +3635,27 @@ int Character::get_sleep_deprivation() const
return sleep_deprivation;
}

std::pair<std::string, nc_color> Character::get_pain_description() const
{
const std::pair<std::string, nc_color> 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 ) ||
Expand Down
12 changes: 7 additions & 5 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,13 @@ class Character : public Creature, public visitable<Character>
virtual int get_thirst() const;
/** Gets character's minimum hunger and thirst */
int stomach_capacity() const;
virtual std::pair<std::string, nc_color> get_thirst_description() const;
virtual std::pair<std::string, nc_color> get_hunger_description() const;
virtual std::pair<std::string, nc_color> get_fatigue_description() const;
virtual int get_fatigue() const;
virtual int get_sleep_deprivation() const;
std::pair<std::string, nc_color> get_thirst_description() const;
std::pair<std::string, nc_color> get_hunger_description() const;
std::pair<std::string, nc_color> get_fatigue_description() const;
int get_fatigue() const;
int get_sleep_deprivation() const;

std::pair<std::string, nc_color> get_pain_description() const override;

/** Modifiers for need values exclusive to characters */
virtual void mod_stored_kcal( int nkcal );
Expand Down
87 changes: 0 additions & 87 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5683,90 +5683,3 @@ std::set<tripoint> player::get_path_avoid() const

return ret;
}

std::pair<std::string, nc_color> 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<std::string, nc_color> 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 );
}
4 changes: 0 additions & 4 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, nc_color> get_hunger_description() const override;

std::pair<std::string, nc_color> get_pain_description() const override;

int get_lift_assist() const;

bool list_ammo( const item &base, std::vector<item::reload_option> &ammo_list,
Expand Down