Skip to content

Commit

Permalink
Make character_type a class enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg committed Apr 13, 2020
1 parent e309183 commit 1d484dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
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
12 changes: 6 additions & 6 deletions src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,19 +820,19 @@ bool main_menu::new_character_tab()
debugmsg( "Error: %s", err.what() );
continue;
}
character_type play_type = PLTYPE_CUSTOM;
character_type play_type = character_type::CUSTOM;
switch( sel2 ) {
case 0:
play_type = PLTYPE_CUSTOM;
play_type = character_type::CUSTOM;
break;
case 2:
play_type = PLTYPE_RANDOM;
play_type = character_type::RANDOM;
break;
case 3:
play_type = PLTYPE_NOW;
play_type = character_type::NOW;
break;
case 4:
play_type = PLTYPE_FULL_RANDOM;
play_type = character_type::FULL_RANDOM;
break;
}
if( !g->u.create( play_type ) ) {
Expand Down Expand Up @@ -906,7 +906,7 @@ bool main_menu::new_character_tab()
debugmsg( "Error: %s", err.what() );
continue;
}
if( !g->u.create( PLTYPE_TEMPLATE, templates[sel3] ) ) {
if( !g->u.create( character_type::TEMPLATE, templates[sel3] ) ) {
load_char_templates();
MAPBUFFER.reset();
overmap_buffer.clear();
Expand Down
17 changes: 9 additions & 8 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void Character::pick_name( bool bUseDefault )
static matype_id choose_ma_style( const character_type type, const std::vector<matype_id> &styles,
const avatar &u )
{
if( type == PLTYPE_NOW || type == PLTYPE_FULL_RANDOM ) {
if( type == character_type::NOW || type == character_type::FULL_RANDOM ) {
return random_entry( styles );
}
if( styles.size() == 1 ) {
Expand Down Expand Up @@ -372,28 +372,29 @@ bool avatar::create( character_type type, const std::string &tempname )
prof = profession::generic();
g->scen = scenario::generic();

const bool interactive = type != PLTYPE_NOW && type != PLTYPE_FULL_RANDOM;
const bool interactive = type != character_type::NOW &&
type != character_type::FULL_RANDOM;

int tab = 0;
points_left points = points_left();

switch( type ) {
case PLTYPE_CUSTOM:
case character_type::CUSTOM:
break;
case PLTYPE_RANDOM:
case character_type::RANDOM:
//random scenario, default name if exist
randomize( true, points );
tab = NEWCHAR_TAB_MAX;
break;
case PLTYPE_NOW:
case character_type::NOW:
//default world, fixed scenario, random name
randomize( false, points, true );
break;
case PLTYPE_FULL_RANDOM:
case character_type::FULL_RANDOM:
//default world, random scenario, random name
randomize( true, points, true );
break;
case PLTYPE_TEMPLATE:
case character_type::TEMPLATE:
if( !load_template( tempname, points ) ) {
return false;
}
Expand All @@ -414,7 +415,7 @@ bool avatar::create( character_type type, const std::string &tempname )
"Continue anyways?" ), name );
};

const bool allow_reroll = type == PLTYPE_RANDOM;
const bool allow_reroll = type == character_type::RANDOM;
tab_direction result = tab_direction::QUIT;
do {
if( !interactive ) {
Expand Down
12 changes: 6 additions & 6 deletions src/pldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class JsonIn;
class JsonOut;
template <typename E> struct enum_traits;

enum character_type : int {
PLTYPE_CUSTOM,
PLTYPE_RANDOM,
PLTYPE_TEMPLATE,
PLTYPE_NOW,
PLTYPE_FULL_RANDOM,
enum class character_type : int {
CUSTOM,
RANDOM,
TEMPLATE,
NOW,
FULL_RANDOM,
};

enum add_type : int {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static void init_global_game_state( const std::vector<mod_id> &mods,
g->load_world_modfiles( ui );

g->u = avatar();
g->u.create( PLTYPE_NOW );
g->u.create( character_type::NOW );

g->m = map( get_option<bool>( "ZLEVELS" ) );

Expand Down

0 comments on commit 1d484dd

Please sign in to comment.