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 display-related string colorization functions out of Character class #50972

Merged
merged 7 commits into from
Aug 27, 2021
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
194 changes: 0 additions & 194 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ static const efftype_id effect_frostbite_recovery( "frostbite_recovery" );
static const efftype_id effect_fungus( "fungus" );
static const efftype_id effect_glowing( "glowing" );
static const efftype_id effect_glowy_led( "glowy_led" );
static const efftype_id effect_got_checked( "got_checked" );
static const efftype_id effect_grabbed( "grabbed" );
static const efftype_id effect_grabbing( "grabbing" );
static const efftype_id effect_harnessed( "harnessed" );
Expand Down Expand Up @@ -5795,83 +5794,6 @@ int Character::get_thirst() const
return thirst;
}

std::pair<std::string, nc_color> Character::get_thirst_description() const
{
// some delay from water in stomach is desired, but there needs to be some visceral response
int thirst = get_thirst() - ( std::max( units::to_milliliter<int>( stomach.get_water() ) / 10,
0 ) );
std::string hydration_string;
nc_color hydration_color = c_white;
if( thirst > 520 ) {
hydration_color = c_light_red;
hydration_string = translate_marker( "Parched" );
} else if( thirst > 240 ) {
hydration_color = c_light_red;
hydration_string = translate_marker( "Dehydrated" );
} else if( thirst > 80 ) {
hydration_color = c_yellow;
hydration_string = translate_marker( "Very thirsty" );
} else if( thirst > 40 ) {
hydration_color = c_yellow;
hydration_string = translate_marker( "Thirsty" );
} else if( thirst < -60 ) {
hydration_color = c_green;
hydration_string = translate_marker( "Turgid" );
} else if( thirst < -20 ) {
hydration_color = c_green;
hydration_string = translate_marker( "Hydrated" );
} else if( thirst < 0 ) {
hydration_color = c_green;
hydration_string = translate_marker( "Slaked" );
}
return std::make_pair( _( hydration_string ), hydration_color );
}

std::pair<std::string, nc_color> Character::get_hunger_description() const
{
// clang 3.8 has some sort of issue where if the initializer list contains const arguments,
// like all of the effect_* string_id variables which are const string_id, then it fails to
// initialize the array with tuples successfully complaining that
// "chosen constructor is explicit in copy-initialization". Using std::forward_as_tuple
// returns a tuple consisting of correctly implcitly copyable types.
static const std::array<std::tuple<const efftype_id &, const char *, nc_color>, 9> hunger_states{ {
std::forward_as_tuple( effect_hunger_engorged, translate_marker( "Engorged" ), c_red ),
std::forward_as_tuple( effect_hunger_full, translate_marker( "Full" ), c_yellow ),
std::forward_as_tuple( effect_hunger_satisfied, translate_marker( "Satisfied" ), c_green ),
std::forward_as_tuple( effect_hunger_blank, "", c_white ),
std::forward_as_tuple( effect_hunger_hungry, translate_marker( "Hungry" ), c_yellow ),
std::forward_as_tuple( effect_hunger_very_hungry, translate_marker( "Very Hungry" ), c_yellow ),
std::forward_as_tuple( effect_hunger_near_starving, translate_marker( "Near starving" ), c_red ),
std::forward_as_tuple( effect_hunger_starving, translate_marker( "Starving!" ), c_red ),
std::forward_as_tuple( effect_hunger_famished, translate_marker( "Famished" ), c_light_red )
}
};
for( auto &hunger_state : hunger_states ) {
if( has_effect( std::get<0>( hunger_state ) ) ) {
return std::make_pair( _( std::get<1>( hunger_state ) ), std::get<2>( hunger_state ) );
}
}
return std::make_pair( _( "ERROR!" ), c_light_red );
}

std::pair<std::string, nc_color> Character::get_fatigue_description() const
{
int fatigue = get_fatigue();
std::string fatigue_string;
nc_color fatigue_color = c_white;
if( fatigue > fatigue_levels::EXHAUSTED ) {
fatigue_color = c_red;
fatigue_string = translate_marker( "Exhausted" );
} else if( fatigue > fatigue_levels::DEAD_TIRED ) {
fatigue_color = c_light_red;
fatigue_string = translate_marker( "Dead Tired" );
} else if( fatigue > fatigue_levels::TIRED ) {
fatigue_color = c_yellow;
fatigue_string = translate_marker( "Tired" );
}
return std::make_pair( _( fatigue_string ), fatigue_color );
}

void Character::mod_thirst( int nthirst )
{
if( has_flag( json_flag_NO_THIRST ) || ( is_npc() && get_option<bool>( "NO_NPC_FOOD" ) ) ) {
Expand Down Expand Up @@ -5928,27 +5850,6 @@ 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 Expand Up @@ -8872,101 +8773,6 @@ float Character::get_bmi() const
return 12 * get_kcal_percent() + 13;
}

std::string Character::get_weight_string() const
{
std::pair<std::string, nc_color> weight_pair = get_weight_description();
return colorize( weight_pair.first, weight_pair.second );
}

std::pair<std::string, nc_color> Character::get_weight_description() const
{
const float bmi = get_bmi();
std::string weight_string;
nc_color weight_color = c_light_gray;
if( get_option<bool>( "CRAZY" ) ) {
if( bmi > character_weight_category::morbidly_obese + 10.0f ) {
weight_string = translate_marker( "AW HELL NAH" );
weight_color = c_red;
} else if( bmi > character_weight_category::morbidly_obese + 5.0f ) {
weight_string = translate_marker( "DAYUM" );
weight_color = c_red;
} else if( bmi > character_weight_category::morbidly_obese ) {
weight_string = translate_marker( "Fluffy" );
weight_color = c_red;
} else if( bmi > character_weight_category::very_obese ) {
weight_string = translate_marker( "Husky" );
weight_color = c_red;
} else if( bmi > character_weight_category::obese ) {
weight_string = translate_marker( "Healthy" );
weight_color = c_light_red;
} else if( bmi > character_weight_category::overweight ) {
weight_string = translate_marker( "Big" );
weight_color = c_yellow;
} else if( bmi > character_weight_category::normal ) {
weight_string = translate_marker( "Normal" );
weight_color = c_light_gray;
} else if( bmi > character_weight_category::underweight ) {
weight_string = translate_marker( "Bean Pole" );
weight_color = c_yellow;
} else if( bmi > character_weight_category::emaciated ) {
weight_string = translate_marker( "Emaciated" );
weight_color = c_light_red;
} else {
weight_string = translate_marker( "Spooky Scary Skeleton" );
weight_color = c_red;
}
} else {
if( bmi > character_weight_category::morbidly_obese ) {
weight_string = translate_marker( "Morbidly Obese" );
weight_color = c_red;
} else if( bmi > character_weight_category::very_obese ) {
weight_string = translate_marker( "Very Obese" );
weight_color = c_red;
} else if( bmi > character_weight_category::obese ) {
weight_string = translate_marker( "Obese" );
weight_color = c_light_red;
} else if( bmi > character_weight_category::overweight ) {
weight_string = translate_marker( "Overweight" );
weight_color = c_yellow;
} else if( bmi > character_weight_category::normal ) {
weight_string = translate_marker( "Normal" );
weight_color = c_light_gray;
} else if( bmi > character_weight_category::underweight ) {
weight_string = translate_marker( "Underweight" );
weight_color = c_yellow;
} else if( bmi > character_weight_category::emaciated ) {
weight_string = translate_marker( "Emaciated" );
weight_color = c_light_red;
} else {
weight_string = translate_marker( "Skeletal" );
weight_color = c_red;
}
}
return std::make_pair( _( weight_string ), weight_color );
}

std::string Character::get_weight_long_description() const
{
const float bmi = get_bmi();
if( bmi > character_weight_category::morbidly_obese ) {
return _( "You have far more fat than is healthy or useful. It is causing you major problems." );
} else if( bmi > character_weight_category::very_obese ) {
return _( "You have too much fat. It impacts your day-to-day health and wellness." );
} else if( bmi > character_weight_category::obese ) {
return _( "You've definitely put on a lot of extra weight. Although helpful in times of famine, this is too much and is impacting your health." );
} else if( bmi > character_weight_category::overweight ) {
return _( "You've put on some extra pounds. Nothing too excessive, but it's starting to impact your health and waistline a bit." );
} else if( bmi > character_weight_category::normal ) {
return _( "You look to be a pretty healthy weight, with some fat to last you through the winter, but nothing excessive." );
} else if( bmi > character_weight_category::underweight ) {
return _( "You are thin, thinner than is healthy. You are less resilient to going without food." );
} else if( bmi > character_weight_category::emaciated ) {
return _( "You are very unhealthily underweight, nearing starvation." );
} else {
return _( "You have very little meat left on your bones. You appear to be starving." );
}
}

units::mass Character::bodyweight() const
{
return units::from_kilogram( get_bmi() * std::pow( height() / 100.0f, 2 ) );
Expand Down
10 changes: 0 additions & 10 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,9 @@ class Character : public Creature, public visitable
virtual int get_starvation() const;
virtual int get_thirst() 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;
std::pair<std::string, nc_color> get_weight_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, bool ignore_weariness = false );
virtual void mod_stored_nutr( int nnutr );
Expand Down Expand Up @@ -2414,10 +2408,6 @@ class Character : public Creature, public visitable
float metabolic_rate() const;
// gets the max value healthy you can be, related to your weight
int get_max_healthy() const;
// gets the string that describes your weight
std::string get_weight_string() const;
// gets the description, printed in player_display, related to your current bmi
std::string get_weight_long_description() const;
// calculates the BMI
float get_bmi() const;
// returns amount of calories burned in a day given various metabolic factors
Expand Down
2 changes: 1 addition & 1 deletion src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static std::vector<std::string> recipe_info(
recp.batch_savings_string() );

oss << string_format( _( "Activity level: <color_cyan>%s</color>\n" ),
activity_level::activity_level_str( recp.exertion_level() ) );
display::activity_level_str( recp.exertion_level() ) );

const int makes = recp.makes_amount();
if( makes > 1 ) {
Expand Down
28 changes: 0 additions & 28 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,34 +1536,6 @@ int Creature::get_perceived_pain() const
return get_pain();
}

std::pair<std::string, nc_color> Creature::get_pain_description() const
{
float scale = get_perceived_pain() / 10.f;
std::string pain_string;
nc_color pain_color = c_yellow;
if( scale > 7 ) {
pain_string = _( "Severe pain" );
} else if( scale > 6 ) {
pain_string = _( "Intense pain" );
} else if( scale > 5 ) {
pain_string = _( "Unmanageable pain" );
} else if( scale > 4 ) {
pain_string = _( "Distressing pain" );
} else if( scale > 3 ) {
pain_string = _( "Distracting pain" );
} else if( scale > 2 ) {
pain_string = _( "Moderate pain" );
} else if( scale > 1 ) {
pain_string = _( "Mild pain" );
} else if( scale > 0 ) {
pain_string = _( "Minimal pain" );
} else {
pain_string = _( "No pain" );
pain_color = c_white;
}
return std::make_pair( pain_string, pain_color );
}

int Creature::get_moves() const
{
return moves;
Expand Down
1 change: 0 additions & 1 deletion src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ class Creature : public location, public viewer
virtual void set_pain( int npain );
virtual int get_pain() const;
virtual int get_perceived_pain() const;
virtual std::pair<std::string, nc_color> get_pain_description() const;

int get_moves() const;
void mod_moves( int nmoves );
Expand Down
7 changes: 4 additions & 3 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#include "overmap_ui.h"
#include "overmapbuffer.h"
#include "path_info.h" // IWYU pragma: keep
#include "panels.h"
#include "pimpl.h"
#include "point.h"
#include "popup.h"
Expand Down Expand Up @@ -1511,9 +1512,9 @@ void character_edit_menu()
}
break;
case D_NEEDS: {
std::pair<std::string, nc_color> hunger_pair = you.get_hunger_description();
std::pair<std::string, nc_color> thirst_pair = you.get_thirst_description();
std::pair<std::string, nc_color> fatigue_pair = you.get_fatigue_description();
std::pair<std::string, nc_color> hunger_pair = display::hunger_text_color( you );
std::pair<std::string, nc_color> thirst_pair = display::thirst_text_color( you );
std::pair<std::string, nc_color> fatigue_pair = display::fatigue_text_color( you );

std::stringstream data;
data << string_format( _( "Hunger: %d %s" ), you.get_hunger(), colorize( hunger_pair.first,
Expand Down
7 changes: 4 additions & 3 deletions src/faction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "optional.h"
#include "output.h"
#include "overmapbuffer.h"
#include "panels.h"
#include "pimpl.h"
#include "point.h"
#include "skill.h"
Expand Down Expand Up @@ -641,9 +642,9 @@ int npc::faction_display( const catacurses::window &fac_w, const int width ) con

const std::pair <std::string, nc_color> condition = hp_description();
mvwprintz( fac_w, point( width, ++y ), condition.second, _( "Condition: " ) + condition.first );
const std::pair <std::string, nc_color> hunger_pair = get_hunger_description();
const std::pair <std::string, nc_color> thirst_pair = get_thirst_description();
const std::pair <std::string, nc_color> fatigue_pair = get_fatigue_description();
const std::pair <std::string, nc_color> hunger_pair = display::hunger_text_color( *this );
const std::pair <std::string, nc_color> thirst_pair = display::thirst_text_color( *this );
const std::pair <std::string, nc_color> fatigue_pair = display::fatigue_text_color( *this );
const std::string nominal = pgettext( "needs", "Nominal" );
mvwprintz( fac_w, point( width, ++y ), hunger_pair.second,
_( "Hunger: " ) + ( hunger_pair.first.empty() ? nominal : hunger_pair.first ) );
Expand Down
11 changes: 6 additions & 5 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "optional.h"
#include "options.h"
#include "output.h"
#include "panels.h"
#include "pimpl.h"
#include "point.h"
#include "recipe.h"
Expand Down Expand Up @@ -954,19 +955,19 @@ class fuel_inventory_preset : public inventory_selector_preset
static std::string get_consume_needs_hint( Character &you )
{
auto hint = std::string();
auto desc = you.get_hunger_description();
auto desc = display::hunger_text_color( you );
hint.append( string_format( "%s %s", _( "Food:" ), colorize( desc.first, desc.second ) ) );
hint.append( string_format( " %s ", LINE_XOXO_S ) );
desc = you.get_thirst_description();
desc = display::thirst_text_color( you );
hint.append( string_format( "%s %s", _( "Drink:" ), colorize( desc.first, desc.second ) ) );
hint.append( string_format( " %s ", LINE_XOXO_S ) );
desc = you.get_pain_description();
desc = display::pain_text_color( you );
hint.append( string_format( "%s %s", _( "Pain:" ), colorize( desc.first, desc.second ) ) );
hint.append( string_format( " %s ", LINE_XOXO_S ) );
desc = you.get_fatigue_description();
desc = display::fatigue_text_color( you );
hint.append( string_format( "%s %s", _( "Rest:" ), colorize( desc.first, desc.second ) ) );
hint.append( string_format( " %s ", LINE_XOXO_S ) );
hint.append( string_format( "%s %s", _( "Weight:" ), you.get_weight_string() ) );
hint.append( string_format( "%s %s", _( "Weight:" ), display::weight_string( you ) ) );
return hint;
}

Expand Down
Loading