Skip to content

Commit

Permalink
Merge pull request #39590 from ZhilkinSerg/enum-classes-2020-04-14
Browse files Browse the repository at this point in the history
Enum classes
  • Loading branch information
kevingranade authored Apr 16, 2020
2 parents 34a3b36 + fdad1f1 commit 93c4a41
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 174 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum butcher_type : int {
DISSECT // dissect a corpse for CBMs
};

enum do_activity_reason : int {
enum class do_activity_reason : int {
CAN_DO_CONSTRUCTION, // Can do construction.
CAN_DO_FETCH, // Can do fetch - this is usually the default result for fetch task
CAN_DO_PREREQ, // for constructions - can't build the main construction, but can build the pre-req
Expand Down
230 changes: 129 additions & 101 deletions src/activity_item_handling.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,11 @@ bool avatar::has_identified( const std::string &item_id ) const
hint_rating avatar::rate_action_read( const item &it ) const
{
if( !it.is_book() ) {
return HINT_CANT;
return hint_rating::cant;
}

std::vector<std::string> dummy;
return get_book_reader( it, dummy ) == nullptr ? HINT_IFFY : HINT_GOOD;
return get_book_reader( it, dummy ) == nullptr ? hint_rating::iffy : hint_rating::good;
}

void avatar::wake_up()
Expand Down
2 changes: 1 addition & 1 deletion src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ void avatar_action::use_item( avatar &you, item_location &loc )
void avatar_action::unload( avatar &you )
{
item_location loc = g->inv_map_splice( [&you]( const item & it ) {
return you.rate_action_unload( it ) == HINT_GOOD;
return you.rate_action_unload( it ) == hint_rating::good;
}, _( "Unload item" ), 1, _( "You have nothing to unload." ) );

if( !loc ) {
Expand Down
6 changes: 3 additions & 3 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ formatted_text::formatted_text( const std::string &text, const int color,
case direction::NORTHWEST:
case direction::WEST:
case direction::SOUTHWEST:
alignment = TEXT_ALIGNMENT_RIGHT;
alignment = text_alignment::right;
break;
case direction::NORTH:
case direction::CENTER:
case direction::SOUTH:
alignment = TEXT_ALIGNMENT_CENTER;
alignment = text_alignment::center;
break;
default:
alignment = TEXT_ALIGNMENT_LEFT;
alignment = text_alignment::left;
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ class tileset_loader
void load( const std::string &tileset_id, bool precheck );
};

enum text_alignment {
TEXT_ALIGNMENT_LEFT,
TEXT_ALIGNMENT_CENTER,
TEXT_ALIGNMENT_RIGHT,
enum class text_alignment : int {
left,
center,
right,
};

struct formatted_text {
Expand Down
6 changes: 3 additions & 3 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3436,14 +3436,14 @@ int Character::extraEncumbrance( const layer_level level, const int bp ) const
hint_rating Character::rate_action_change_side( const item &it ) const
{
if( !is_worn( it ) ) {
return HINT_IFFY;
return hint_rating::iffy;
}

if( !it.is_sided() ) {
return HINT_CANT;
return hint_rating::cant;
}

return HINT_GOOD;
return hint_rating::good;
}

bool Character::change_side( item &it, bool interactive )
Expand Down
8 changes: 4 additions & 4 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,17 +1356,17 @@ bool Character::consume_effects( item &food )
hint_rating Character::rate_action_eat( const item &it ) const
{
if( !can_consume( it ) ) {
return HINT_CANT;
return hint_rating::cant;
}

const auto rating = will_eat( it );
if( rating.success() ) {
return HINT_GOOD;
return hint_rating::good;
} else if( rating.value() == INEDIBLE || rating.value() == INEDIBLE_MUTATION ) {
return HINT_CANT;
return hint_rating::cant;
}

return HINT_IFFY;
return hint_rating::iffy;
}

bool Character::can_feed_reactor_with( const item &it ) const
Expand Down
31 changes: 16 additions & 15 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,8 @@ int game::inventory_item_menu( item_location locThisItem, int iStartX, int iWidt
std::vector<iteminfo> vDummy;

const bool bHPR = get_auto_pickup().has_rule( &oThisItem );
const hint_rating rate_drop_item = u.weapon.has_flag( "NO_UNWIELD" ) ? HINT_CANT : HINT_GOOD;
const hint_rating rate_drop_item = u.weapon.has_flag( "NO_UNWIELD" ) ? hint_rating::cant :
hint_rating::good;

int max_text_length = 0;
uilist action_menu;
Expand All @@ -2074,13 +2075,13 @@ int game::inventory_item_menu( item_location locThisItem, int iStartX, int iWidt
action_menu.addentry( key, true, key, text );
auto &entry = action_menu.entries.back();
switch( hint ) {
case HINT_CANT:
case hint_rating::cant:
entry.text_color = c_light_gray;
break;
case HINT_IFFY:
case hint_rating::iffy:
entry.text_color = c_light_red;
break;
case HINT_GOOD:
case hint_rating::good:
entry.text_color = c_light_green;
break;
}
Expand All @@ -2090,8 +2091,8 @@ int game::inventory_item_menu( item_location locThisItem, int iStartX, int iWidt
addentry( 'R', pgettext( "action", "read" ), u.rate_action_read( oThisItem ) );
addentry( 'E', pgettext( "action", "eat" ), u.rate_action_eat( oThisItem ) );
addentry( 'W', pgettext( "action", "wear" ), u.rate_action_wear( oThisItem ) );
addentry( 'w', pgettext( "action", "wield" ), HINT_GOOD );
addentry( 't', pgettext( "action", "throw" ), HINT_GOOD );
addentry( 'w', pgettext( "action", "wield" ), hint_rating::good );
addentry( 't', pgettext( "action", "throw" ), hint_rating::good );
addentry( 'c', pgettext( "action", "change side" ), u.rate_action_change_side( oThisItem ) );
addentry( 'T', pgettext( "action", "take off" ), u.rate_action_takeoff( oThisItem ) );
addentry( 'd', pgettext( "action", "drop" ), rate_drop_item );
Expand All @@ -2102,17 +2103,17 @@ int game::inventory_item_menu( item_location locThisItem, int iStartX, int iWidt
addentry( 'D', pgettext( "action", "disassemble" ), u.rate_action_disassemble( oThisItem ) );

if( oThisItem.is_favorite ) {
addentry( 'f', pgettext( "action", "unfavorite" ), HINT_GOOD );
addentry( 'f', pgettext( "action", "unfavorite" ), hint_rating::good );
} else {
addentry( 'f', pgettext( "action", "favorite" ), HINT_GOOD );
addentry( 'f', pgettext( "action", "favorite" ), hint_rating::good );
}

addentry( '=', pgettext( "action", "reassign" ), HINT_GOOD );
addentry( '=', pgettext( "action", "reassign" ), hint_rating::good );

if( bHPR ) {
addentry( '-', _( "Autopickup" ), HINT_IFFY );
addentry( '-', _( "Autopickup" ), hint_rating::iffy );
} else {
addentry( '+', _( "Autopickup" ), HINT_GOOD );
addentry( '+', _( "Autopickup" ), hint_rating::good );
}

int iScrollPos = 0;
Expand Down Expand Up @@ -8406,7 +8407,7 @@ void game::reload( item_location &loc, bool prompt, bool empty )
}

switch( u.rate_action_reload( *it ) ) {
case HINT_IFFY:
case hint_rating::iffy:
if( ( it->is_ammo_container() || it->is_magazine() ) && it->ammo_remaining() > 0 &&
it->ammo_remaining() == it->ammo_capacity() ) {
add_msg( m_info, _( "The %s is already fully loaded!" ), it->tname() );
Expand All @@ -8427,11 +8428,11 @@ void game::reload( item_location &loc, bool prompt, bool empty )

// intentional fall-through

case HINT_CANT:
case hint_rating::cant:
add_msg( m_info, _( "You can't reload a %s!" ), it->tname() );
return;

case HINT_GOOD:
case hint_rating::good:
break;
}

Expand Down Expand Up @@ -8486,7 +8487,7 @@ void game::reload( item_location &loc, bool prompt, bool empty )
void game::reload_item()
{
item_location item_loc = inv_map_splice( [&]( const item & it ) {
return u.rate_action_reload( it ) == HINT_GOOD;
return u.rate_action_reload( it ) == hint_rating::good;
}, _( "Reload item" ), 1, _( "You have nothing to reload." ) );

if( !item_loc ) {
Expand Down
8 changes: 4 additions & 4 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2234,13 +2234,13 @@ bool item_ptr_compare_by_charges( const item *left, const item *right );
* This is assigned as a result of some legacy logic in @ref draw_item_info(). This
* will eventually be rewritten to eliminate the need for this hack.
*/
enum hint_rating {
enum class hint_rating : int {
/** Item should display as gray */
HINT_CANT = 0,
cant = 0,
/** Item should display as red */
HINT_IFFY = 1,
iffy = 1,
/** Item should display as green */
HINT_GOOD = -999
good = -999
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ bool salvage_actor::try_to_cut_up( player &p, item &it ) const
// There must be some historical significance to these items.
if( !it.is_salvageable() ) {
add_msg( m_info, _( "Can't salvage anything from %s." ), it.tname() );
if( p.rate_action_disassemble( it ) != HINT_CANT ) {
if( p.rate_action_disassemble( it ) != hint_rating::cant ) {
add_msg( m_info, _( "Try disassembling the %s instead." ), it.tname() );
}
return false;
Expand Down Expand Up @@ -2944,7 +2944,7 @@ int ammobelt_actor::use( player &p, item &, bool, const tripoint & ) const
item mag( belt );
mag.ammo_unset();

if( p.rate_action_reload( mag ) != HINT_GOOD ) {
if( p.rate_action_reload( mag ) != hint_rating::good ) {
p.add_msg_if_player( _( "Insufficient ammunition to assemble %s" ), mag.tname() );
return 0;
}
Expand Down
Loading

0 comments on commit 93c4a41

Please sign in to comment.