diff options
author | Bardur Arantsson <bardur@scientician.net> | 2019-02-15 19:20:25 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2019-02-15 19:20:25 +0100 |
commit | ca14a8b243f7963e52b2b92d584e25f7d5c21ed6 (patch) | |
tree | 5f8ada931dc9a72968dfe6b081201e0f5eb8b2c9 | |
parent | a0de18fbfeb1f4c746249c3f5508a27b54c05220 (diff) |
Add set_player_base()
This replaces the "set" + "mutate-in-place" approach to player_base
with a saner approach.
-rw-r--r-- | src/birth.cc | 20 | ||||
-rw-r--r-- | src/dungeon.cc | 2 | ||||
-rw-r--r-- | src/files.cc | 15 | ||||
-rw-r--r-- | src/files.hpp | 2 | ||||
-rw-r--r-- | src/main.cc | 3 |
5 files changed, 22 insertions, 20 deletions
diff --git a/src/birth.cc b/src/birth.cc index 7b8717ae..d9e65026 100644 --- a/src/birth.cc +++ b/src/birth.cc @@ -3121,10 +3121,14 @@ savefile_try_again: prt("Enter the name of the savefile that will hold this character: ", 23, 0); /* Ask the user for a string */ - if (!askfor_aux(&game->player_base, 15)) continue; + auto tmp = game->player_base; + if (!askfor_aux(&tmp, 15)) + { + continue; + } /* Process the player name */ - process_player_name(); + set_player_base(tmp); // If the savefile already exists, we do *NOT* want to // create a new game, so we'll need to return FALSE for @@ -3161,10 +3165,14 @@ savefile_try_again: prt("Enter the name of a savefile: ", 23, 0); /* Ask the user for a string */ - if (!askfor_aux(&game->player_base, 15)) continue; + auto tmp = game->player_base; + if (!askfor_aux(&tmp, 15)) + { + continue; + } /* Process the player name */ - process_player_name(); + set_player_base(tmp); return false; } @@ -3177,10 +3185,8 @@ savefile_try_again: if ((x < 2) || (x >= max)) continue; - game->player_base = savefile_names[savefile_idx[x - 2]]; - /* Process the player name */ - process_player_name(); + set_player_base(savefile_names[savefile_idx[x - 2]]); return false; } diff --git a/src/dungeon.cc b/src/dungeon.cc index 6bc58493..5b0e54c4 100644 --- a/src/dungeon.cc +++ b/src/dungeon.cc @@ -4693,7 +4693,7 @@ void play_game() if (!new_game) { /* Process the player name */ - process_player_name(); + set_player_base(game->player_name); } /* Force "complex" RNG */ diff --git a/src/files.cc b/src/files.cc index 9c0b891c..c246bc6e 100644 --- a/src/files.cc +++ b/src/files.cc @@ -3730,9 +3730,9 @@ std::string process_player_name(std::string const &name) -void process_player_name() +void set_player_base(std::string const &name) { - game->player_base = process_player_name(game->player_base); + game->player_base = process_player_name(name); } @@ -3748,8 +3748,6 @@ void process_player_name() */ void get_name() { - char tmp[32]; - /* Clear last line */ clear_from(22); @@ -3763,22 +3761,21 @@ void get_name() move_cursor(2, 9); /* Save the player name */ - strcpy(tmp, game->player_name.c_str()); + auto tmp = game->player_name; /* Get an input, ignore "Escape" */ - if (askfor_aux(tmp, 31)) + if (askfor_aux(&tmp, 31)) { game->player_name = tmp; + set_player_base(tmp); } - /* Process the player name */ - process_player_name(); - /* All done */ break; } /* Pad the name (to clear junk) */ + char tmp[32]; sprintf(tmp, "%-31.31s", game->player_name.c_str()); /* Re-Draw the name (in light blue) */ diff --git a/src/files.hpp b/src/files.hpp index 3a289e7d..7658306a 100644 --- a/src/files.hpp +++ b/src/files.hpp @@ -39,4 +39,4 @@ void race_legends(); void show_highclass(int building); errr get_xtra_line(const char * file_name, monster_type *m_ptr, char * output); std::string process_player_name(std::string const &); -void process_player_name(); +void set_player_base(std::string const &name); diff --git a/src/main.cc b/src/main.cc index 04fb4c56..090809f8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -170,7 +170,6 @@ int main_real(int argc, char *argv[], char const *platform_sys, int (*init_platf { if (!argv[i][2]) goto usage; game->player_name = &argv[i][2]; - game->player_base = &argv[i][2]; no_begin_screen = true; break; } @@ -237,7 +236,7 @@ usage: /* Process the player name */ - process_player_name(); + set_player_base(game->player_name); /* Install "quit" hook */ |