Skip to content

Commit

Permalink
Show needs in the comestible inventory windows (CleverRaven#33481)
Browse files Browse the repository at this point in the history
* small refactor to make Creature::get_pain_description returns a label/color pair just like get_hunger_description and get_thirst_description

* show needs in the 4 comestible inventory windows using the inventory_selector's hint line
  • Loading branch information
pierredavidbelanger authored and misterprimus committed Sep 21, 2019
1 parent 32a0679 commit a1b52dd
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 44 deletions.
24 changes: 14 additions & 10 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,28 +1238,32 @@ int Creature::get_perceived_pain() const
return get_pain();
}

std::string Creature::get_pain_description() const
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 ) {
return _( "Severe pain" );
pain_string = _( "Severe pain" );
} else if( scale > 6 ) {
return _( "Intense pain" );
pain_string = _( "Intense pain" );
} else if( scale > 5 ) {
return _( "Unmanageable pain" );
pain_string = _( "Unmanageable pain" );
} else if( scale > 4 ) {
return _( "Distressing pain" );
pain_string = _( "Distressing pain" );
} else if( scale > 3 ) {
return _( "Distracting pain" );
pain_string = _( "Distracting pain" );
} else if( scale > 2 ) {
return _( "Moderate pain" );
pain_string = _( "Moderate pain" );
} else if( scale > 1 ) {
return _( "Mild pain" );
pain_string = _( "Mild pain" );
} else if( scale > 0 ) {
return _( "Minimal pain" );
pain_string = _( "Minimal pain" );
} else {
return _( "No pain" );
pain_string = _( "No pain" );
pain_color = c_white;
}
return std::make_pair( pain_string, pain_color );
}

int Creature::get_moves() const
Expand Down
2 changes: 1 addition & 1 deletion src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class Creature
virtual void set_pain( int npain );
virtual int get_pain() const;
virtual int get_perceived_pain() const;
virtual std::string get_pain_description() const;
virtual std::pair<std::string, nc_color> get_pain_description() const;

int get_moves() const;
void mod_moves( int nmoves );
Expand Down
28 changes: 24 additions & 4 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,22 @@ class comestible_inventory_preset : public inventory_selector_preset
const player &p;
};

static std::string get_consume_needs_hint( player &p )
{
const auto &cmgr = get_all_colors();
auto hint = std::string();
auto desc = p.get_hunger_description();
hint.append( string_format( "[%s <color_%s>%s</color>] ", _( "Food :" ),
cmgr.get_name( desc.second ), desc.first ) );
desc = p.get_thirst_description();
hint.append( string_format( "[%s <color_%s>%s</color>] ", _( "Drink:" ),
cmgr.get_name( desc.second ), desc.first ) );
desc = p.get_pain_description();
hint.append( string_format( "[%s <color_%s>%s</color>] ", _( "Pain :" ),
cmgr.get_name( desc.second ), desc.first ) );
return hint;
}

item_location game_menus::inv::consume( player &p )
{
if( !g->u.has_activity( activity_id( "ACT_EAT_MENU" ) ) ) {
Expand All @@ -673,7 +689,8 @@ item_location game_menus::inv::consume( player &p )

return inv_internal( p, comestible_inventory_preset( p ),
_( "Consume item" ), 1,
_( "You have nothing to consume." ) );
_( "You have nothing to consume." ),
get_consume_needs_hint( p ) );
}

class comestible_filtered_inventory_preset : public comestible_inventory_preset
Expand Down Expand Up @@ -702,7 +719,8 @@ item_location game_menus::inv::consume_food( player &p )
it.has_flag( "USE_EAT_VERB" );
} ),
_( "Consume food" ), 1,
_( "You have no food to consume." ) );
_( "You have no food to consume." ),
get_consume_needs_hint( p ) );
}

item_location game_menus::inv::consume_drink( player &p )
Expand All @@ -716,7 +734,8 @@ item_location game_menus::inv::consume_drink( player &p )
!it.has_flag( "USE_EAT_VERB" );
} ),
_( "Consume drink" ), 1,
_( "You have no drink to consume." ) );
_( "You have no drink to consume." ),
get_consume_needs_hint( p ) );
}

item_location game_menus::inv::consume_meds( player &p )
Expand All @@ -729,7 +748,8 @@ item_location game_menus::inv::consume_meds( player &p )
return it.is_medication();
} ),
_( "Consume medication" ), 1,
_( "You have no medication to consume." ) );
_( "You have no medication to consume." ),
get_consume_needs_hint( p ) );
}

class activatable_inventory_preset : public pickup_inventory_preset
Expand Down
38 changes: 9 additions & 29 deletions src/panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,26 +669,6 @@ static std::pair<nc_color, std::string> temp_stat( const avatar &u )
return std::make_pair( temp_color, temp_string );
}

static std::pair<nc_color, std::string> pain_stat( const avatar &u )
{
nc_color pain_color = c_yellow;
std::string pain_string;
// get pain color
if( u.get_perceived_pain() >= 60 ) {
pain_color = c_red;
} else if( u.get_perceived_pain() >= 40 ) {
pain_color = c_light_red;
}
// get pain string
if( ( u.has_trait( trait_SELFAWARE ) || u.has_effect( effect_got_checked ) ) &&
u.get_perceived_pain() > 0 ) {
pain_string = string_format( "%s %d", _( "Pain " ), u.get_perceived_pain() );
} else if( u.get_perceived_pain() > 0 ) {
pain_string = u.get_pain_description();
}
return std::make_pair( pain_color, pain_string );
}

static std::string get_armor( const avatar &u, body_part bp, unsigned int truncate = 0 )
{
for( std::list<item>::const_iterator it = u.worn.end(); it != u.worn.begin(); ) {
Expand Down Expand Up @@ -1118,12 +1098,12 @@ static void draw_needs_compact( const avatar &u, const catacurses::window &w )
hunger_pair = u.get_fatigue_description();
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w, point( 0, 1 ), hunger_pair.second, hunger_pair.first );
auto pair = pain_stat( u );
mvwprintz( w, point( 0, 2 ), pair.first, pair.second );
auto pain_pair = u.get_pain_description();
mvwprintz( w, point( 0, 2 ), pain_pair.second, pain_pair.first );

hunger_pair = u.get_thirst_description();
mvwprintz( w, point( 17, 0 ), hunger_pair.second, hunger_pair.first );
pair = temp_stat( u );
auto pair = temp_stat( u );
mvwprintz( w, point( 17, 1 ), pair.first, pair.second );
const auto arrow = temp_delta_arrows( u );
mvwprintz( w, point( 17 + utf8_width( pair.second ), 1 ), arrow.first, arrow.second );
Expand Down Expand Up @@ -1431,7 +1411,7 @@ static void draw_needs_narrow( const avatar &u, const catacurses::window &w )
std::pair<std::string, nc_color> thirst_pair = u.get_thirst_description();
std::pair<std::string, nc_color> rest_pair = u.get_fatigue_description();
std::pair<nc_color, std::string> temp_pair = temp_stat( u );
std::pair<nc_color, std::string> pain_pair = pain_stat( u );
std::pair<std::string, nc_color> pain_pair = u.get_pain_description();
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w, point( 1, 0 ), c_light_gray, _( "Food :" ) );
// NOLINTNEXTLINE(cata-use-named-point-constants)
Expand All @@ -1442,7 +1422,7 @@ static void draw_needs_narrow( const avatar &u, const catacurses::window &w )
mvwprintz( w, point( 8, 0 ), hunger_pair.second, hunger_pair.first );
mvwprintz( w, point( 8, 1 ), thirst_pair.second, thirst_pair.first );
mvwprintz( w, point( 8, 2 ), rest_pair.second, rest_pair.first );
mvwprintz( w, point( 8, 3 ), pain_pair.first, pain_pair.second );
mvwprintz( w, point( 8, 3 ), pain_pair.second, pain_pair.first );
mvwprintz( w, point( 8, 4 ), temp_pair.first, temp_pair.second );
wrefresh( w );
}
Expand All @@ -1454,7 +1434,7 @@ static void draw_needs_wide( const avatar &u, const catacurses::window &w )
std::pair<std::string, nc_color> thirst_pair = u.get_thirst_description();
std::pair<std::string, nc_color> rest_pair = u.get_fatigue_description();
std::pair<nc_color, std::string> temp_pair = temp_stat( u );
std::pair<nc_color, std::string> pain_pair = pain_stat( u );
std::pair<std::string, nc_color> pain_pair = u.get_pain_description();
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w, point( 1, 0 ), c_light_gray, _( "Rest :" ) );
mvwprintz( w, point( 16, 0 ), c_light_gray, _( "Pain :" ) );
Expand All @@ -1463,7 +1443,7 @@ static void draw_needs_wide( const avatar &u, const catacurses::window &w )
mvwprintz( w, point( 1, 1 ), c_light_gray, _( "Food :" ) );
mvwprintz( w, point( 23, 1 ), c_light_gray, _( "Drink:" ) );
mvwprintz( w, point( 8, 0 ), rest_pair.second, rest_pair.first );
mvwprintz( w, point( 23, 0 ), pain_pair.first, pain_pair.second );
mvwprintz( w, point( 23, 0 ), pain_pair.second, pain_pair.first );
mvwprintz( w, point( 38, 0 ), temp_pair.first, temp_pair.second );
mvwprintz( w, point( 8, 1 ), hunger_pair.second, hunger_pair.first );
mvwprintz( w, point( 30, 1 ), thirst_pair.second, thirst_pair.first );
Expand Down Expand Up @@ -1564,8 +1544,8 @@ static void draw_health_classic( avatar &u, const catacurses::window &w )
mvwprintz( w, point( 27, 4 ), c_white, to_string( u.focus_pool ) );
needs_pair = u.get_fatigue_description();
mvwprintz( w, point( 21, 3 ), needs_pair.second, needs_pair.first );
auto pain_pair = pain_stat( u );
mvwprintz( w, point( 21, 0 ), pain_pair.first, pain_pair.second );
auto pain_pair = u.get_pain_description();
mvwprintz( w, point( 21, 0 ), pain_pair.second, pain_pair.first );

// print mood
std::pair<nc_color, int> morale_pair = morale_stat( u );
Expand Down
22 changes: 22 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const efftype_id effect_frostbite_recovery( "frostbite_recovery" );
const efftype_id effect_fungus( "fungus" );
const efftype_id effect_glowing( "glowing" );
const efftype_id effect_glowy_led( "glowy_led" );
const efftype_id effect_got_checked( "got_checked" );
const efftype_id effect_grabbed( "grabbed" );
const efftype_id effect_hallu( "hallu" );
const efftype_id effect_happy( "happy" );
Expand Down Expand Up @@ -11895,6 +11896,27 @@ std::pair<std::string, nc_color> player::get_hunger_description() const
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 );
}

void player::enforce_minimum_healing()
{
for( int i = 0; i < num_hp_parts; i++ ) {
Expand Down
2 changes: 2 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ class player : public Character

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

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

/** Get vitamin contents for a comestible */
std::map<vitamin_id, int> vitamins_from( const item &it ) const;
std::map<vitamin_id, int> vitamins_from( const itype_id &id ) const;
Expand Down

0 comments on commit a1b52dd

Please sign in to comment.