Skip to content

Commit

Permalink
Merge pull request #39510 from ZhilkinSerg/enum-classes-2020-04-11
Browse files Browse the repository at this point in the history
Enum classes
  • Loading branch information
kevingranade authored Apr 15, 2020
2 parents ac64d81 + 97e34b7 commit 14415de
Show file tree
Hide file tree
Showing 46 changed files with 717 additions and 654 deletions.
203 changes: 102 additions & 101 deletions src/addiction.cpp

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/addiction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

#include <string>

#include "pldata.h"
#include "type_id.h"

class addiction;
class Character;

enum add_type : int;

// Minimum intensity before effects are seen
constexpr int MIN_ADDICTION_LEVEL = 3;
constexpr int MAX_ADDICTION_LEVEL = 20;
Expand Down
2 changes: 0 additions & 2 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

class faction;

enum character_type : int;

class JsonIn;
class JsonObject;
class JsonOut;
Expand Down
45 changes: 23 additions & 22 deletions src/bonuses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@

static bool needs_damage_type( affected_stat as )
{
return as == AFFECTED_DAMAGE || as == AFFECTED_ARMOR ||
as == AFFECTED_ARMOR_PENETRATION;
return as == affected_stat::DAMAGE ||
as == affected_stat::ARMOR ||
as == affected_stat::ARMOR_PENETRATION;
}

static const std::map<std::string, affected_stat> affected_stat_map = {{
std::make_pair( "hit", AFFECTED_HIT ),
std::make_pair( "dodge", AFFECTED_DODGE ),
std::make_pair( "block", AFFECTED_BLOCK ),
std::make_pair( "speed", AFFECTED_SPEED ),
std::make_pair( "movecost", AFFECTED_MOVE_COST ),
std::make_pair( "damage", AFFECTED_DAMAGE ),
std::make_pair( "armor", AFFECTED_ARMOR ),
std::make_pair( "arpen", AFFECTED_ARMOR_PENETRATION ),
std::make_pair( "target_armor_multiplier", AFFECTED_TARGET_ARMOR_MULTIPLIER )
std::make_pair( "hit", affected_stat::HIT ),
std::make_pair( "dodge", affected_stat::DODGE ),
std::make_pair( "block", affected_stat::BLOCK ),
std::make_pair( "speed", affected_stat::SPEED ),
std::make_pair( "movecost", affected_stat::MOVE_COST ),
std::make_pair( "damage", affected_stat::DAMAGE ),
std::make_pair( "armor", affected_stat::ARMOR ),
std::make_pair( "arpen", affected_stat::ARMOR_PENETRATION ),
std::make_pair( "target_armor_multiplier", affected_stat::TARGET_ARMOR_MULTIPLIER )
}
};

Expand Down Expand Up @@ -54,19 +55,19 @@ static affected_stat affected_stat_from_string( const std::string &s )
return iter->second;
}

return AFFECTED_NULL;
return affected_stat::NONE;
}

static const std::map<affected_stat, std::string> affected_stat_map_translation = {{
std::make_pair( AFFECTED_HIT, translate_marker( "Accuracy" ) ),
std::make_pair( AFFECTED_DODGE, translate_marker( "Dodge" ) ),
std::make_pair( AFFECTED_BLOCK, translate_marker( "Block" ) ),
std::make_pair( AFFECTED_SPEED, translate_marker( "Speed" ) ),
std::make_pair( AFFECTED_MOVE_COST, translate_marker( "Move cost" ) ),
std::make_pair( AFFECTED_DAMAGE, translate_marker( "damage" ) ),
std::make_pair( AFFECTED_ARMOR, translate_marker( "Armor" ) ),
std::make_pair( AFFECTED_ARMOR_PENETRATION, translate_marker( "Armor penetration" ) ),
std::make_pair( AFFECTED_TARGET_ARMOR_MULTIPLIER, translate_marker( "Target armor multiplier" ) ),
std::make_pair( affected_stat::HIT, translate_marker( "Accuracy" ) ),
std::make_pair( affected_stat::DODGE, translate_marker( "Dodge" ) ),
std::make_pair( affected_stat::BLOCK, translate_marker( "Block" ) ),
std::make_pair( affected_stat::SPEED, translate_marker( "Speed" ) ),
std::make_pair( affected_stat::MOVE_COST, translate_marker( "Move cost" ) ),
std::make_pair( affected_stat::DAMAGE, translate_marker( "damage" ) ),
std::make_pair( affected_stat::ARMOR, translate_marker( "Armor" ) ),
std::make_pair( affected_stat::ARMOR_PENETRATION, translate_marker( "Armor penetration" ) ),
std::make_pair( affected_stat::TARGET_ARMOR_MULTIPLIER, translate_marker( "Target armor multiplier" ) ),
}
};

Expand Down Expand Up @@ -113,7 +114,7 @@ void bonus_container::load( const JsonArray &jarr, const bool mult )
{
for( const JsonObject &qualifiers : jarr ) {
const affected_stat as = affected_stat_from_string( qualifiers.get_string( "stat" ) );
if( as == AFFECTED_NULL ) {
if( as == affected_stat::NONE ) {
qualifiers.throw_error( "Invalid affected stat", "stat" );
}

Expand Down
24 changes: 12 additions & 12 deletions src/bonuses.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ enum scaling_stat : int {
NUM_STATS
};

enum affected_stat : int {
AFFECTED_NULL = 0,
AFFECTED_HIT,
AFFECTED_DODGE,
AFFECTED_BLOCK,
AFFECTED_SPEED,
AFFECTED_MOVE_COST,
AFFECTED_DAMAGE,
AFFECTED_ARMOR,
AFFECTED_ARMOR_PENETRATION,
AFFECTED_TARGET_ARMOR_MULTIPLIER,
enum class affected_stat : int {
NONE = 0,
HIT,
DODGE,
BLOCK,
SPEED,
MOVE_COST,
DAMAGE,
ARMOR,
ARMOR_PENETRATION,
TARGET_ARMOR_MULTIPLIER,
NUM_AFFECTED
};

Expand All @@ -52,7 +52,7 @@ struct affected_type {
}

private:
affected_stat stat = affected_stat::AFFECTED_NULL;
affected_stat stat = affected_stat::NONE;
damage_type type;
};

Expand Down
34 changes: 17 additions & 17 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ static int msgtype_to_tilecolor( const game_message_type type, const bool bOldMs
}

formatted_text::formatted_text( const std::string &text, const int color,
const direction direction )
const direction text_direction )
: text( text ), color( color )
{
switch( direction ) {
case NORTHWEST:
case WEST:
case SOUTHWEST:
switch( text_direction ) {
case direction::NORTHWEST:
case direction::WEST:
case direction::SOUTHWEST:
alignment = TEXT_ALIGNMENT_RIGHT;
break;
case NORTH:
case CENTER:
case SOUTH:
case direction::NORTH:
case direction::CENTER:
case direction::SOUTH:
alignment = TEXT_ALIGNMENT_CENTER;
break;
default:
Expand Down Expand Up @@ -1085,12 +1085,12 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
for( const point &pt_elem : collision_checkpoints ) {
overlay_strings.emplace( player_to_screen( pt_elem ) + point( tile_width / 2, 0 ),
formatted_text( "CHECK", catacurses::yellow,
NORTH ) );
direction::NORTH ) );
}
for( const point &pt_elem : target_points ) {
overlay_strings.emplace( player_to_screen( pt_elem ) + point( tile_width / 2, 0 ),
formatted_text( "TARGET", catacurses::red,
NORTH ) );
direction::NORTH ) );
}
}
for( int row = min_row; row < max_row; row ++ ) {
Expand Down Expand Up @@ -1141,7 +1141,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
if( scent_value > 0 ) {
overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 2, 0 ),
formatted_text( std::to_string( scent_value ), 8 + catacurses::yellow,
NORTH ) );
direction::NORTH ) );
}
}

Expand All @@ -1151,7 +1151,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
if( !scent_type.is_empty() ) {
overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 2, 0 ),
formatted_text( scent_type.c_str(), 8 + catacurses::yellow,
NORTH ) );
direction::NORTH ) );
}
}

Expand All @@ -1167,7 +1167,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
col = catacurses::cyan;
}
overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 2, 0 ),
formatted_text( std::to_string( rad_value ), 8 + col, NORTH ) );
formatted_text( std::to_string( rad_value ), 8 + col, direction::NORTH ) );
}
}

Expand Down Expand Up @@ -1198,7 +1198,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
}
overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 2, 0 ),
formatted_text( std::to_string( temp_value ), color,
NORTH ) );
direction::NORTH ) );
}

if( g->display_overlay_state( ACTION_DISPLAY_VISIBILITY ) &&
Expand All @@ -1215,7 +1215,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
std::string visibility_str = visibility ? "+" : "-";
overlay_strings.emplace(
player_to_screen( point( x, y ) ) + point( tile_width / 4, tile_height / 4 ),
formatted_text( visibility_str, catacurses::black, NORTH ) );
formatted_text( visibility_str, catacurses::black, direction::NORTH ) );
}

if( g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) {
Expand All @@ -1241,7 +1241,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int

// string overlay
overlay_strings.emplace( tile_pos + point( tile_width / 4, tile_height / 4 ),
formatted_text( string_format( "%.1f", ambient ), catacurses::black, NORTH ) );
formatted_text( string_format( "%.1f", ambient ), catacurses::black, direction::NORTH ) );
}
}

Expand Down Expand Up @@ -1297,7 +1297,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
text += "+";
}
overlay_strings.emplace( player_to_screen( p.pos.xy() ) + point( tile_width / 2, 0 ),
formatted_text( text, catacurses::red, NORTH ) );
formatted_text( text, catacurses::red, direction::NORTH ) );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ struct formatted_text {
: text( text ), color( color ), alignment( alignment ) {
}

formatted_text( const std::string &text, int color, direction direction );
formatted_text( const std::string &text, int color, direction text_direction );
};

/** type used for color blocks overlays.
Expand Down
2 changes: 1 addition & 1 deletion src/cata_variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "debug.h"
#include "enum_conversions.h"
#include "hash_utils.h"
#include "pldata.h"
#include "type_id.h"

class JsonIn;
class JsonOut;
template <typename E> struct enum_traits;

enum add_type : int;
enum body_part : int;
enum class mutagen_technique : int;
enum hp_part : int;
Expand Down
6 changes: 3 additions & 3 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8124,7 +8124,7 @@ void Character::absorb_hit( body_part bp, damage_instance &dam )

if( destroy ) {
if( g->u.sees( *this ) ) {
SCT.add( point( posx(), posy() ), NORTH, remove_color_tags( pre_damage_name ),
SCT.add( point( posx(), posy() ), direction::NORTH, remove_color_tags( pre_damage_name ),
m_neutral, _( "destroyed" ), m_info );
}
destroyed_armor_msg( *this, pre_damage_name );
Expand Down Expand Up @@ -8218,7 +8218,7 @@ bool Character::armor_absorb( damage_unit &du, item &armor )
add_msg_if_player( m_bad, format_string, pre_damage_name, damage_verb );
//item is damaged
if( is_player() ) {
SCT.add( point( posx(), posy() ), NORTH, remove_color_tags( pre_damage_name ), m_neutral,
SCT.add( point( posx(), posy() ), direction::NORTH, remove_color_tags( pre_damage_name ), m_neutral,
damage_verb,
m_info );
}
Expand Down Expand Up @@ -9493,7 +9493,7 @@ int Character::heartrate_bpm() const
heartbeat += average_heartbeat * stim_modifer;
if( get_effect_dur( effect_cig ) > 0_turns ) {
//Nicotine-induced tachycardia
if( get_effect_dur( effect_cig ) > 10_minutes * ( addiction_level( ADD_CIG ) + 1 ) ) {
if( get_effect_dur( effect_cig ) > 10_minutes * ( addiction_level( add_type::CIG ) + 1 ) ) {
heartbeat += average_heartbeat * 0.4;
} else {
heartbeat += average_heartbeat * 0.1;
Expand Down
4 changes: 2 additions & 2 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,8 @@ void Character::modify_stimulation( const islot_comestible &comest )
}
}
if( has_trait( trait_STIMBOOST ) && ( current_stim > 30 ) &&
( ( comest.add == ADD_CAFFEINE ) || ( comest.add == ADD_SPEED ) || ( comest.add == ADD_COKE ) ||
( comest.add == ADD_CRACK ) ) ) {
( ( comest.add == add_type::CAFFEINE ) || ( comest.add == add_type::SPEED ) ||
( comest.add == add_type::COKE ) || ( comest.add == add_type::CRACK ) ) ) {
int hallu_duration = ( current_stim - comest.stim < 30 ) ? current_stim - 30 : comest.stim;
add_effect( effect_visuals, hallu_duration * 30_minutes );
std::vector<std::string> stimboost_msg{ _( "The shadows are getting ever closer." ),
Expand Down
56 changes: 28 additions & 28 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4008,49 +4008,49 @@ void game::mon_info_update( )
// for compatibility with old code, see diagram below, it explains the values for index,
// also might need revisiting one z-levels are in.
switch( dir_to_mon ) {
case ABOVENORTHWEST:
case NORTHWEST:
case BELOWNORTHWEST:
case direction::ABOVENORTHWEST:
case direction::NORTHWEST:
case direction::BELOWNORTHWEST:
index = 7;
break;
case ABOVENORTH:
case NORTH:
case BELOWNORTH:
case direction::ABOVENORTH:
case direction::NORTH:
case direction::BELOWNORTH:
index = 0;
break;
case ABOVENORTHEAST:
case NORTHEAST:
case BELOWNORTHEAST:
case direction::ABOVENORTHEAST:
case direction::NORTHEAST:
case direction::BELOWNORTHEAST:
index = 1;
break;
case ABOVEWEST:
case WEST:
case BELOWWEST:
case direction::ABOVEWEST:
case direction::WEST:
case direction::BELOWWEST:
index = 6;
break;
case ABOVECENTER:
case CENTER:
case BELOWCENTER:
case direction::ABOVECENTER:
case direction::CENTER:
case direction::BELOWCENTER:
index = 8;
break;
case ABOVEEAST:
case EAST:
case BELOWEAST:
case direction::ABOVEEAST:
case direction::EAST:
case direction::BELOWEAST:
index = 2;
break;
case ABOVESOUTHWEST:
case SOUTHWEST:
case BELOWSOUTHWEST:
case direction::ABOVESOUTHWEST:
case direction::SOUTHWEST:
case direction::BELOWSOUTHWEST:
index = 5;
break;
case ABOVESOUTH:
case SOUTH:
case BELOWSOUTH:
case direction::ABOVESOUTH:
case direction::SOUTH:
case direction::BELOWSOUTH:
index = 4;
break;
case ABOVESOUTHEAST:
case SOUTHEAST:
case BELOWSOUTHEAST:
case direction::ABOVESOUTHEAST:
case direction::SOUTHEAST:
case direction::BELOWSOUTHEAST:
index = 3;
break;
}
Expand Down Expand Up @@ -9337,7 +9337,7 @@ point game::place_player( const tripoint &dest_loc )

//Auto pulp or butcher and Auto foraging
if( get_option<bool>( "AUTO_FEATURES" ) && mostseen == 0 && !u.is_mounted() ) {
static const direction adjacentDir[8] = { NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST };
static const direction adjacentDir[8] = { direction::NORTH, direction::NORTHEAST, direction::EAST, direction::SOUTHEAST, direction::SOUTH, direction::SOUTHWEST, direction::WEST, direction::NORTHWEST };

const std::string forage_type = get_option<std::string>( "AUTO_FORAGING" );
if( forage_type != "off" ) {
Expand Down
2 changes: 1 addition & 1 deletion src/gamemode_defense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool defense_game::init()
{
calendar::turn = calendar::turn_zero + 12_hours; // Start at noon
g->weather.temperature = 65;
if( !g->u.create( PLTYPE_CUSTOM ) ) {
if( !g->u.create( character_type::CUSTOM ) ) {
return false;
}
g->u.str_cur = g->u.str_max;
Expand Down
Loading

0 comments on commit 14415de

Please sign in to comment.