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 Newchar functions to avatar from player #30806

Merged
merged 2 commits into from
May 24, 2019
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
5 changes: 5 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class avatar : public player

/** Prints out the player's memorial file */
void memorial( std::ostream &memorial_file, const std::string &epitaph );

// newcharacter.cpp
bool create( character_type type, const std::string &tempname = "" );
void randomize( bool random_scenario, points_left &points, bool play_now = false );
bool load_template( const std::string &template_name, points_left &points );
};

#endif
72 changes: 36 additions & 36 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ tab_direction set_scenario( const catacurses::window &w, player &u, points_left
tab_direction set_profession( const catacurses::window &w, player &u, points_left &points,
const tab_direction direction );
tab_direction set_skills( const catacurses::window &w, player &u, points_left &points );
tab_direction set_description( const catacurses::window &w, player &u, bool allow_reroll,
tab_direction set_description( const catacurses::window &w, avatar &you, bool allow_reroll,
points_left &points );

static cata::optional<std::string> query_for_template_name();
Expand Down Expand Up @@ -230,12 +230,12 @@ static matype_id choose_ma_style( const character_type type, const std::vector<m
}
}

void player::randomize( const bool random_scenario, points_left &points, bool play_now )
void avatar::randomize( const bool random_scenario, points_left &points, bool play_now )
{

const int max_trait_points = get_option<int>( "MAX_TRAIT_POINTS" );
// Reset everything to the defaults to have a clean state.
*this = player();
*this = avatar();

male = ( rng( 1, 100 ) > 50 );
if( !MAP_SHARING::isSharing() ) {
Expand Down Expand Up @@ -424,7 +424,7 @@ void player::randomize( const bool random_scenario, points_left &points, bool pl
}
}

bool player::create( character_type type, const std::string &tempname )
bool avatar::create( character_type type, const std::string &tempname )
{
weapon = item( "null", 0 );

Expand Down Expand Up @@ -2135,7 +2135,7 @@ tab_direction set_scenario( const catacurses::window &w, player &u, points_left
return retval;
}

tab_direction set_description( const catacurses::window &w, player &u, const bool allow_reroll,
tab_direction set_description( const catacurses::window &w, avatar &you, const bool allow_reroll,
points_left &points )
{
draw_tabs( w, _( "DESCRIPTION" ) );
Expand Down Expand Up @@ -2177,17 +2177,17 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
for( const auto &loc : start_location::get_all() ) {
if( g->scen->allowed_start( loc.ident() ) ) {
select_location.entries.emplace_back( loc.name() );
if( loc.ident() == u.start_location ) {
if( loc.ident() == you.start_location ) {
select_location.selected = offset;
}
offset++;
}
}
select_location.setup();
if( MAP_SHARING::isSharing() ) {
u.name = MAP_SHARING::getUsername(); // set the current username as default character name
you.name = MAP_SHARING::getUsername(); // set the current username as default character name
} else if( !get_option<std::string>( "DEF_CHAR_NAME" ).empty() ) {
u.name = get_option<std::string>( "DEF_CHAR_NAME" );
you.name = get_option<std::string>( "DEF_CHAR_NAME" );
}
do {
if( redraw ) {
Expand Down Expand Up @@ -2220,14 +2220,14 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
utf8_width( vStatNames[i] ) : pos );
mvwprintz( w_stats, i + 1, 0, c_light_gray, vStatNames[i] );
}
mvwprintz( w_stats, 1, pos + 1, c_light_gray, "%2d", u.str_max );
mvwprintz( w_stats, 2, pos + 1, c_light_gray, "%2d", u.dex_max );
mvwprintz( w_stats, 3, pos + 1, c_light_gray, "%2d", u.int_max );
mvwprintz( w_stats, 4, pos + 1, c_light_gray, "%2d", u.per_max );
mvwprintz( w_stats, 1, pos + 1, c_light_gray, "%2d", you.str_max );
mvwprintz( w_stats, 2, pos + 1, c_light_gray, "%2d", you.dex_max );
mvwprintz( w_stats, 3, pos + 1, c_light_gray, "%2d", you.int_max );
mvwprintz( w_stats, 4, pos + 1, c_light_gray, "%2d", you.per_max );
wrefresh( w_stats );

mvwprintz( w_traits, 0, 0, COL_HEADER, _( "Traits: " ) );
std::vector<trait_id> current_traits = u.get_base_traits();
std::vector<trait_id> current_traits = you.get_base_traits();
if( current_traits.empty() ) {
wprintz( w_traits, c_light_red, _( "None!" ) );
} else {
Expand All @@ -2241,16 +2241,16 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
mvwprintz( w_skills, 0, 0, COL_HEADER, _( "Skills:" ) );

auto skillslist = Skill::get_skills_sorted_by( [&]( const Skill & a, const Skill & b ) {
const int level_a = u.get_skill_level_object( a.ident() ).exercised_level();
const int level_b = u.get_skill_level_object( b.ident() ).exercised_level();
const int level_a = you.get_skill_level_object( a.ident() ).exercised_level();
const int level_b = you.get_skill_level_object( b.ident() ).exercised_level();
return level_a > level_b || ( level_a == level_b && a.name() < b.name() );
} );

int line = 1;
bool has_skills = false;
profession::StartingSkillList list_skills = u.prof->skills();
profession::StartingSkillList list_skills = you.prof->skills();
for( auto &elem : skillslist ) {
int level = u.get_skill_level( elem->ident() );
int level = you.get_skill_level( elem->ident() );
profession::StartingSkillList::iterator i = list_skills.begin();
while( i != list_skills.end() ) {
if( i->first == ( elem )->ident() ) {
Expand Down Expand Up @@ -2298,7 +2298,7 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
//We draw this stuff every loop because this is user-editable
mvwprintz( w_name, 0, 0, c_light_gray, _( "Name:" ) );
mvwprintz( w_name, 0, namebar_pos, c_light_gray, "_______________________________" );
mvwprintz( w_name, 0, namebar_pos, c_white, u.name );
mvwprintz( w_name, 0, namebar_pos, c_white, you.name );
wprintz( w_name, h_light_gray, "_" );

if( !MAP_SHARING::isSharing() ) { // no random names when sharing maps
Expand All @@ -2308,8 +2308,8 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
wrefresh( w_name );

mvwprintz( w_gender, 0, 0, c_light_gray, _( "Gender:" ) );
mvwprintz( w_gender, 0, male_pos, ( u.male ? c_light_red : c_light_gray ), _( "Male" ) );
mvwprintz( w_gender, 0, female_pos, ( u.male ? c_light_gray : c_light_red ), _( "Female" ) );
mvwprintz( w_gender, 0, male_pos, ( you.male ? c_light_red : c_light_gray ), _( "Male" ) );
mvwprintz( w_gender, 0, female_pos, ( you.male ? c_light_gray : c_light_red ), _( "Female" ) );
mvwprintz( w_gender, 1, 0, c_light_gray, _( "Press %s to switch gender" ),
ctxt.get_desc( "CHANGE_GENDER" ) );
wrefresh( w_gender );
Expand All @@ -2322,17 +2322,17 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
mvwprintz( w_location, 0, prompt_offset + 1, c_light_gray, _( "Starting location:" ) );
// ::find will return empty location if id was not found. Debug msg will be printed too.
mvwprintz( w_location, 0, prompt_offset + utf8_width( _( "Starting location:" ) ) + 2,
c_light_gray, u.start_location.obj().name() );
c_light_gray, you.start_location.obj().name() );
wrefresh( w_location );

werase( w_scenario );
mvwprintz( w_scenario, 0, 0, COL_HEADER, _( "Scenario: " ) );
wprintz( w_scenario, c_light_gray, g->scen->gender_appropriate_name( u.male ) );
wprintz( w_scenario, c_light_gray, g->scen->gender_appropriate_name( you.male ) );
wrefresh( w_scenario );

werase( w_profession );
mvwprintz( w_profession, 0, 0, COL_HEADER, _( "Profession: " ) );
wprintz( w_profession, c_light_gray, u.prof->gender_appropriate_name( u.male ) );
wprintz( w_profession, c_light_gray, you.prof->gender_appropriate_name( you.male ) );
wrefresh( w_profession );

const std::string action = ctxt.handle_input();
Expand All @@ -2354,14 +2354,14 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
!query_yn( _( "Remaining points will be discarded, are you sure you want to proceed?" ) ) ) {
redraw = true;
continue;
} else if( u.name.empty() ) {
} else if( you.name.empty() ) {
mvwprintz( w_name, 0, namebar_pos, h_light_gray, _( "_______NO NAME ENTERED!_______" ) );
wrefresh( w_name );
if( !query_yn( _( "Are you SURE you're finished? Your name will be randomly generated." ) ) ) {
redraw = true;
continue;
} else {
u.pick_name();
you.pick_name();
return tab_direction::FORWARD;
}
} else if( query_yn( _( "Are you SURE you're finished?" ) ) ) {
Expand All @@ -2374,32 +2374,32 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
return tab_direction::BACKWARD;
} else if( action == "REROLL_CHARACTER" && allow_reroll ) {
points.init_from_options();
u.randomize( false, points );
you.randomize( false, points );
// Return tab_direction::NONE so we re-enter this tab again, but it forces a complete redrawing of it.
return tab_direction::NONE;
} else if( action == "REROLL_CHARACTER_WITH_SCENARIO" && allow_reroll ) {
points.init_from_options();
u.randomize( true, points );
you.randomize( true, points );
// Return tab_direction::NONE so we re-enter this tab again, but it forces a complete redrawing of it.
return tab_direction::NONE;
} else if( action == "SAVE_TEMPLATE" ) {
if( const auto name = query_for_template_name() ) {
::save_template( u, *name, points );
::save_template( you, *name, points );
}
redraw = true;
} else if( action == "PICK_RANDOM_NAME" ) {
if( !MAP_SHARING::isSharing() ) { // Don't allow random names when sharing maps. We don't need to check at the top as you won't be able to edit the name
u.pick_name();
you.pick_name();
}
} else if( action == "CHANGE_GENDER" ) {
u.male = !u.male;
you.male = !you.male;
} else if( action == "CHOOSE_LOCATION" ) {
select_location.redraw();
select_location.query();
if( select_location.ret >= 0 ) {
for( const auto &loc : start_location::get_all() ) {
if( loc.name() == select_location.entries[ select_location.ret ].txt ) {
u.start_location = loc.ident();
you.start_location = loc.ident();
}
}
}
Expand All @@ -2414,22 +2414,22 @@ tab_direction set_description( const catacurses::window &w, player &u, const boo
} else if( action == "ANY_INPUT" &&
!MAP_SHARING::isSharing() ) { // Don't edit names when sharing maps
const long ch = ctxt.get_raw_input().get_first_input();
utf8_wrapper wrap( u.name );
utf8_wrapper wrap( you.name );
if( ch == KEY_BACKSPACE ) {
if( !wrap.empty() ) {
wrap.erase( wrap.length() - 1, 1 );
u.name = wrap.str();
you.name = wrap.str();
}
} else if( ch == KEY_F( 2 ) ) {
utf8_wrapper tmp( get_input_string_from_file() );
if( !tmp.empty() && tmp.length() + wrap.length() < 30 ) {
u.name.append( tmp.str() );
you.name.append( tmp.str() );
}
} else if( ch == '\n' ) {
// nope, we ignore this newline, don't want it in char names
} else {
wrap.append( ctxt.get_raw_input().text );
u.name = wrap.str();
you.name = wrap.str();
}
} else if( action == "QUIT" && query_yn( _( "Return to main menu?" ) ) ) {
return tab_direction::QUIT;
Expand Down Expand Up @@ -2578,7 +2578,7 @@ void save_template( const player &u, const std::string &name, const points_left
}, _( "player template" ) );
}

bool player::load_template( const std::string &template_name, points_left &points )
bool avatar::load_template( const std::string &template_name, points_left &points )
{
return read_from_file_json( FILENAMES["templatedir"] + utf8_to_native( template_name ) +
".template", [&]( JsonIn & jsin ) {
Expand Down
5 changes: 0 additions & 5 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ class player : public Character
player &operator=( const player & ) = delete;
player &operator=( player && );

// newcharacter.cpp
bool create( character_type type, const std::string &tempname = "" );
void randomize( bool random_scenario, points_left &points, bool play_now = false );
bool load_template( const std::string &template_name, points_left &points );

/** Calls Character::normalize()
* normalizes HP and body temperature
*/
Expand Down