diff options
-rw-r--r-- | lib/edit/misc.txt | 6 | ||||
-rw-r--r-- | lib/mods/theme/edit/misc.txt | 6 | ||||
-rw-r--r-- | src/birth.cc | 43 | ||||
-rw-r--r-- | src/cmd5.cc | 16 | ||||
-rw-r--r-- | src/corrupt.cc | 11 | ||||
-rw-r--r-- | src/dungeon.cc | 40 | ||||
-rw-r--r-- | src/files.cc | 29 | ||||
-rw-r--r-- | src/game_edit_data.hpp | 12 | ||||
-rw-r--r-- | src/help.cc | 8 | ||||
-rw-r--r-- | src/help.hpp | 4 | ||||
-rw-r--r-- | src/init1.cc | 51 | ||||
-rw-r--r-- | src/init2.cc | 2 | ||||
-rw-r--r-- | src/loadsave.cc | 4 | ||||
-rw-r--r-- | src/object1.cc | 11 | ||||
-rw-r--r-- | src/player_race.hpp | 5 | ||||
-rw-r--r-- | src/util.cc | 4 | ||||
-rw-r--r-- | src/variable.cc | 20 | ||||
-rw-r--r-- | src/variable.hpp | 8 | ||||
-rw-r--r-- | src/xtra1.cc | 2 | ||||
-rw-r--r-- | src/xtra2.cc | 6 | ||||
-rw-r--r-- | src/xtra2.hpp | 2 |
21 files changed, 148 insertions, 142 deletions
diff --git a/lib/edit/misc.txt b/lib/edit/misc.txt index cec8b4a4..c412340a 100644 --- a/lib/edit/misc.txt +++ b/lib/edit/misc.txt @@ -54,12 +54,6 @@ M:O:1024 # Maximum size for "m_list[]" M:M:768 -# Maximum number of race types in p_info.txt -M:P:R:22 - -# Maximum number of subrace types in p_info.txt -M:P:S:10 - # Maximum number of histories types in p_info.txt M:P:H:266 diff --git a/lib/mods/theme/edit/misc.txt b/lib/mods/theme/edit/misc.txt index 3bf40391..e4857746 100644 --- a/lib/mods/theme/edit/misc.txt +++ b/lib/mods/theme/edit/misc.txt @@ -54,12 +54,6 @@ M:O:1024 # Maximum size for "m_list[]" M:M:768 -# Maximum number of race types in p_info.txt -M:P:R:24 - -# Maximum number of subrace types in p_info.txt -M:P:S:26 - # Maximum number of histories types in p_info.txt M:P:H:294 diff --git a/src/birth.cc b/src/birth.cc index ba0ed9df..889d1cc9 100644 --- a/src/birth.cc +++ b/src/birth.cc @@ -1303,6 +1303,8 @@ static void dump_specs(int sel_) static int dump_races(int sel) { + auto const &race_info = game->edit_data.race_info; + int n = 0; char buf[80]; @@ -1310,7 +1312,7 @@ static int dump_races(int sel) /* Clean up */ clear_from(12); - for (n = 0; n < max_rp_idx; n++) + for (n = 0; n < static_cast<int>(race_info.size()); n++) { char p2 = ')', p1 = ' '; @@ -1325,7 +1327,7 @@ static int dump_races(int sel) } /* Display */ - strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, rp_ptr->title); + strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, rp_ptr->title.c_str()); /* Print some more info */ if (sel == n) @@ -1360,6 +1362,8 @@ static int dump_races(int sel) static int dump_rmods(int sel, int *racem, int max) { + auto const &race_mod_info = game->edit_data.race_mod_info; + int n = 0; char buf[80]; @@ -1482,6 +1486,8 @@ static bool_ do_quick_start = FALSE; static bool_ player_birth_aux_ask() { auto &class_info = game->edit_data.class_info; + auto const &race_info = game->edit_data.race_info; + auto const &race_mod_info = game->edit_data.race_mod_info; int k, n, v, sel; @@ -1564,8 +1570,10 @@ static bool_ player_birth_aux_ask() else { /* Only one choice = instant choice */ - if (max_rp_idx == 1) + if (race_info.size() == 1) + { k = 0; + } else { /* Extra info */ @@ -1580,7 +1588,7 @@ static bool_ player_birth_aux_ask() while (1) { strnfmt(buf, 200, "Choose a race (%c-%c), * for a random choice, = for options, 8/2/4/6 for movement: ", - I2A(0), I2A(max_rp_idx - 1)); + I2A(0), I2A(race_info.size() - 1)); put_str(buf, 17, 2); c = inkey(); @@ -1588,7 +1596,7 @@ static bool_ player_birth_aux_ask() if (c == 'S') return (FALSE); if (c == '*') { - k = rand_int(max_rp_idx); + k = rand_int(race_info.size()); break; } k = (islower(c) ? A2I(c) : -1); @@ -1643,7 +1651,7 @@ static bool_ player_birth_aux_ask() rp_ptr = &race_info[p_ptr->prace]; /* Display */ - c_put_str(TERM_L_BLUE, rp_ptr->title, RACE_ROW, 9); + c_put_str(TERM_L_BLUE, rp_ptr->title.c_str(), RACE_ROW, 9); /* Get a random name */ if (!do_quick_start) create_random_name(p_ptr->prace, player_name); @@ -1665,14 +1673,16 @@ static bool_ player_birth_aux_ask() else { /* Only one choice = instant choice */ - if (max_rmp_idx == 1) + if (race_mod_info.size() == 1) + { k = 0; + } else { for (n = 0; n < 100; n++) racem[n] = 0; max_racem = 0; - for (n = 0; n < max_rmp_idx; n++) + for (n = 0; n < static_cast<int>(race_mod_info.size()); n++) { /* Analyze */ p_ptr->pracem = n; @@ -3002,22 +3012,23 @@ static void validate_bg_aux(int chart, bool_ chart_checked[], char *buf) */ static void validate_bg(void) { - int i, race; + auto const &race_info = game->edit_data.race_info; bool_ chart_checked[512]; - char buf[1024]; - - - for (i = 0; i < 512; i++) chart_checked[i] = FALSE; + for (std::size_t i = 0; i < 512; i++) + { + chart_checked[i] = FALSE; + } /* Check each race */ - for (race = 0; race < max_rp_idx; race++) + for (auto const &race: race_info) { /* Get the first chart for this race */ - int chart = race_info[race].chart; + int chart = race.chart; - (void) strcpy(buf, ""); + /* Buffer */ + char buf[1024] = { '\0' }; /* Validate the chart recursively */ validate_bg_aux(chart, chart_checked, buf); diff --git a/src/cmd5.cc b/src/cmd5.cc index e2c2e1b8..bcf22124 100644 --- a/src/cmd5.cc +++ b/src/cmd5.cc @@ -13,6 +13,7 @@ #include "cave_type.hpp" #include "corrupt.hpp" #include "dungeon_flag.hpp" +#include "game.hpp" #include "lua_bind.hpp" #include "monster2.hpp" #include "monster_race.hpp" @@ -287,6 +288,8 @@ static void do_poly_wounds() void do_poly_self(void) { + auto const &race_info = game->edit_data.race_info; + int power = p_ptr->lev; int poly_power; @@ -357,22 +360,25 @@ void do_poly_self(void) /* Roll until an appropriate selection is made */ while (1) { - new_race = rand_int(max_rp_idx); + new_race = rand_int(race_info.size()); expfact = race_info[new_race].ps.exp; - if ((new_race != p_ptr->prace) && (expfact <= goalexpfact)) break; + if ((new_race != p_ptr->prace) && (expfact <= goalexpfact)) + { + break; + } } if (effect_msg[0]) { msg_format("You turn into a%s %s!", - ((is_a_vowel(*race_info[new_race].title)) ? "n" : ""), - race_info[new_race].title); + (is_a_vowel(race_info[new_race].title[0]) ? "n" : ""), + race_info[new_race].title.c_str()); } else { msg_format("You turn into a %s %s!", effect_msg, - race_info[new_race].title); + race_info[new_race].title.c_str()); } p_ptr->prace = new_race; diff --git a/src/corrupt.cc b/src/corrupt.cc index 18b23ad4..bd3ae5f0 100644 --- a/src/corrupt.cc +++ b/src/corrupt.cc @@ -1,5 +1,6 @@ #include "corrupt.hpp" +#include "game.hpp" #include "init1.hpp" #include "object_flag.hpp" #include "player_race.hpp" @@ -46,6 +47,8 @@ static void subrace_add_power(player_race_mod *rmp_ptr, int power) static void player_gain_vampire_teeth() { + auto &race_mod_info = game->edit_data.race_mod_info; + player_race_mod *rmp_ptr = NULL; switch_subrace(SUBRACE_SAVE, TRUE); @@ -60,6 +63,8 @@ static void player_gain_vampire_teeth() static void player_gain_vampire_strength() { + auto &race_mod_info = game->edit_data.race_mod_info; + player_race_mod *rmp_ptr = &race_mod_info[SUBRACE_SAVE]; rmp_ptr->ps.mhp += +1; @@ -79,6 +84,8 @@ static void player_gain_vampire_strength() static void player_gain_vampire() { + auto &race_mod_info = game->edit_data.race_mod_info; + player_race_mod *rmp_ptr = &race_mod_info[SUBRACE_SAVE]; if (rmp_ptr->title == "Vampire") @@ -694,7 +701,7 @@ static bool_ player_can_gain_corruption(int corruption_idx) if (corruption_idx == CORRUPT_TROLL_BLOOD) { /* Ok trolls should not get this one. never. */ - if (streq(rp_ptr->title, "Troll")) + if (rp_ptr->title == "Troll") { allowed = FALSE; } @@ -704,7 +711,7 @@ static bool_ player_can_gain_corruption(int corruption_idx) if (game_module_idx == MODULE_THEME) { - if (streq(rp_ptr->title, "Maia")) + if (rp_ptr->title == "Maia") { /* We use a whitelist of corruptions for Maiar */ bool_ allow = FALSE; diff --git a/src/dungeon.cc b/src/dungeon.cc index 92f5862e..6f1c8c5a 100644 --- a/src/dungeon.cc +++ b/src/dungeon.cc @@ -1014,7 +1014,7 @@ static bool_ grace_delay_trigger() */ static void process_world_gods() { - const char *race_name = rp_ptr->title; + auto const &race_name = rp_ptr->title; auto const &subrace_name = rmp_ptr->title; if (p_ptr->pgod == GOD_VARDA) @@ -1027,10 +1027,10 @@ static void process_world_gods() inc_piety(GOD_ALL, 2); } - if (streq(race_name, "Orc") || - streq(race_name, "Troll") || - streq(race_name, "Dragon") || - streq(race_name, "Demon")) + if ((race_name == "Orc") || + (race_name == "Troll") || + (race_name == "Dragon") || + (race_name == "Demon")) { /* Varda hates evil races */ inc_piety(GOD_ALL, -2); @@ -1053,16 +1053,16 @@ static void process_world_gods() { int i; /* Ulmo likes the Edain (except Easterlings) */ - if (streq(race_name, "Human") || - streq(race_name, "Dunadan") || - streq(race_name, "Druadan") || - streq(race_name, "RohanKnight")) + if ((race_name == "Human") || + (race_name == "Dunadan") || + (race_name == "Druadan") || + (race_name == "RohanKnight")) { inc_piety(GOD_ALL, 2); } - else if (streq(race_name, "Easterling") || - streq(race_name, "Demon") || - streq(race_name, "Orc")) + else if ((race_name == "Easterling") || + (race_name == "Demon") || + (race_name == "Orc")) { /* hated races */ inc_piety(GOD_ALL, -2); @@ -1097,10 +1097,10 @@ static void process_world_gods() /* Aule likes Dwarves and Dark Elves (Eol's * influence here) */ - if (!(streq(race_name, "Dwarf") || - streq(race_name, "Petty-dwarf") || - streq(race_name, "Gnome") || - streq(race_name, "Dark-Elf"))) + if (!((race_name == "Dwarf") || + (race_name == "Petty-dwarf") || + (race_name == "Gnome") || + (race_name == "Dark-Elf"))) { inc_piety(GOD_ALL, -1); } @@ -1182,14 +1182,14 @@ static void process_world_gods() } /* He likes High Elves only, though, as races */ - if (!streq(race_name, "High-Elf")) + if (!(race_name == "High-Elf")) { inc_piety(GOD_ALL, -1); } /* Really hates vampires and demons */ if ((subrace_name == "Vampire") || - streq(race_name, "Demon")) + (race_name == "Demon")) { inc_piety(GOD_ALL, -10); } @@ -1766,7 +1766,7 @@ static void process_world(void) int dec = 5 - wisdom_scale(3); /* Blech what an hideous hack */ - if (!strcmp(rp_ptr->title, "Ent")) + if (!(rp_ptr->title == "Ent")) { dec -= wisdom_scale(2); } @@ -5016,7 +5016,7 @@ static void load_all_pref_files(void) /* Access the "race" pref file */ - sprintf(buf, "%s.prf", rp_ptr->title); + sprintf(buf, "%s.prf", rp_ptr->title.c_str()); /* Process that file */ process_pref_file(buf); diff --git a/src/files.cc b/src/files.cc index 24545ef3..cec925df 100644 --- a/src/files.cc +++ b/src/files.cc @@ -214,6 +214,8 @@ s16b tokenize(char *buf, s16b num, char **tokens, char delim1, char delim2) */ errr process_pref_file_aux(char *buf) { + auto &race_mod_info = game->edit_data.race_mod_info; + int i, j, n1, n2; char *zz[16]; @@ -293,7 +295,7 @@ errr process_pref_file_aux(char *buf) i = (huge)strtol(zz[0], NULL, 0); n1 = strtol(zz[1], NULL, 0); n2 = strtol(zz[2], NULL, 0); - if (i >= max_rmp_idx) return (1); + if (i >= static_cast<int>(race_mod_info.size())) return (1); rmp_ptr = &race_mod_info[i]; if (n1) rmp_ptr->g_attr = n1; if (n2) @@ -891,7 +893,7 @@ static cptr process_pref_file_expr(char **sp, char *fp) /* Race */ else if (streq(b + 1, "RACE")) { - v = rp_ptr->title; + v = rp_ptr->title.c_str(); // The string SHOULD be stable enough for this } /* Race */ @@ -4568,6 +4570,7 @@ static void display_scores_aux(int highscore_fd, int from, int to, int note, hig */ void show_highclass(int building) { + auto const &race_info = game->edit_data.race_info; int i = 0, j, m = 0; int pr, pc, clev; @@ -4642,7 +4645,7 @@ void show_highclass(int building) ((building == 1) && (clev >= PY_MAX_LEVEL))) { sprintf(out_val, "%3d) %s the %s (Level %2d)", - (m + 1), the_score.who, race_info[pr].title, clev); + (m + 1), the_score.who, race_info[pr].title.c_str(), clev); prt(out_val, (m + 7), 0); m++; } @@ -4653,7 +4656,7 @@ void show_highclass(int building) if ((building == 1) && (p_ptr->lev >= PY_MAX_LEVEL)) { sprintf(out_val, "You) %s the %s (Level %2d)", - player_name, race_info[p_ptr->prace].title, p_ptr->lev); + player_name, race_info[p_ptr->prace].title.c_str(), p_ptr->lev); prt(out_val, (m + 8), 0); } else if ((building != 1)) @@ -4661,7 +4664,7 @@ void show_highclass(int building) if ((p_ptr->lev > clev) && (p_ptr->pclass == (building - 10))) { sprintf(out_val, "You) %s the %s (Level %2d)", - player_name, race_info[p_ptr->prace].title, p_ptr->lev); + player_name, race_info[p_ptr->prace].title.c_str(), p_ptr->lev); prt(out_val, (m + 8), 0); } } @@ -4681,6 +4684,8 @@ void show_highclass(int building) */ void race_score(int race_num) { + auto const &race_info = game->edit_data.race_info; + int i = 0, j, m = 0; int pr, clev, lastlev; high_score the_score; @@ -4690,7 +4695,7 @@ void race_score(int race_num) lastlev = 0; /* rr9: TODO - pluralize the race */ - sprintf(tmp_str, "The Greatest of all the %s", race_info[race_num].title); + sprintf(tmp_str, "The Greatest of all the %s", race_info[race_num].title.c_str()); prt(tmp_str, 5, 3); /* Build the filename */ @@ -4726,7 +4731,7 @@ void race_score(int race_num) { sprintf(out_val, "%3d) %s the %s (Level %3d)", (m + 1), the_score.who, - race_info[pr].title, clev); + race_info[pr].title.c_str(), clev); prt(out_val, (m + 7), 0); m++; lastlev = clev; @@ -4738,7 +4743,7 @@ void race_score(int race_num) if ((p_ptr->prace == race_num) && (p_ptr->lev >= lastlev)) { sprintf(out_val, "You) %s the %s (Level %3d)", - player_name, race_info[p_ptr->prace].title, p_ptr->lev); + player_name, race_info[p_ptr->prace].title.c_str(), p_ptr->lev); prt(out_val, (m + 8), 0); } @@ -4752,15 +4757,17 @@ void race_score(int race_num) */ void race_legends(void) { - int i, j; + auto const &race_info = game->edit_data.race_info; - for (i = 0; i < max_rp_idx; i++) + for (size_t i = 0; i < race_info.size(); i++) { race_score(i); msg_print("Hit any key to continue"); msg_print(NULL); - for (j = 5; j < 19; j++) + for (int j = 5; j < 19; j++) + { prt("", j, 0); + } } } diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp index c6f45dc0..7addfd65 100644 --- a/src/game_edit_data.hpp +++ b/src/game_edit_data.hpp @@ -2,6 +2,8 @@ #include "owner_type.hpp" #include "player_class.hpp" +#include "player_race.hpp" +#include "player_race_mod.hpp" #include "randart_gen_type.hpp" #include "randart_part_type.hpp" #include "store_action_type.hpp" @@ -46,4 +48,14 @@ struct GameEditData { */ std::vector<player_class> class_info; + /** + * Player races. + */ + std::vector<player_race> race_info; + + /** + * Player subraces. + */ + std::vector<player_race_mod> race_mod_info; + }; diff --git a/src/help.cc b/src/help.cc index 55051bfa..1997717e 100644 --- a/src/help.cc +++ b/src/help.cc @@ -703,14 +703,14 @@ static context_help_type *find_context_help(context_help_type table[], cptr key) /* * Racial help */ -void help_race(cptr race) +void help_race(std::string const &race) { - show_context_help(find_context_help(race_table, race)); + show_context_help(find_context_help(race_table, race.c_str())); } -void help_subrace(cptr subrace) +void help_subrace(std::string const &subrace) { - show_context_help(find_context_help(subrace_table, subrace)); + show_context_help(find_context_help(subrace_table, subrace.c_str())); } void help_class(std::string const &klass) diff --git a/src/help.hpp b/src/help.hpp index 5272226e..5de6e6c6 100644 --- a/src/help.hpp +++ b/src/help.hpp @@ -5,8 +5,8 @@ #include <string> extern void init_hooks_help(); -extern void help_race(cptr race); -extern void help_subrace(cptr subrace); +extern void help_race(std::string const &race); +extern void help_subrace(std::string const &subrace); extern void help_class(std::string const &klass); extern void help_god(cptr god); extern void help_skill(cptr skill); diff --git a/src/init1.cc b/src/init1.cc index b4c0a5ac..3b0bb701 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -703,13 +703,12 @@ static errr grab_one_class_flag(u32b *choice, cptr what) static errr grab_one_race_allow_flag(u32b *choice, cptr what) { - int i; - cptr s; + auto const &race_info = game->edit_data.race_info; /* Scan classes flags */ - for (i = 0; i < max_rp_idx && (s = race_info[i].title); i++) + for (std::size_t i = 0; i < race_info.size(); i++) { - if (streq(what, s)) + if (race_info[i].title == what) { (choice[i / 32]) |= (1L << i); return (0); @@ -921,6 +920,8 @@ static int read_ability(std::vector<player_race_ability_type> *abilities, char * errr init_player_info_txt(FILE *fp) { auto &class_info = game->edit_data.class_info; + auto &race_info = game->edit_data.race_info; + auto &race_mod_info = game->edit_data.race_mod_info; int lev = 1; int tit_idx = 0; @@ -1014,18 +1015,15 @@ errr init_player_info_txt(FILE *fp) /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_rp_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - rp_ptr = &race_info[i]; + rp_ptr = &expand_to_fit_index(race_info, i); + assert(rp_ptr->title.empty()); /* Copy title */ - assert(!rp_ptr->title); - rp_ptr->title = my_strdup(s); + rp_ptr->title = s; /* Initialize */ lev = 1; @@ -1037,18 +1035,15 @@ errr init_player_info_txt(FILE *fp) /* Process 'D' for "Description" */ if ((buf[0] == 'R') && (buf[2] == 'D')) { - /* Acquire the text */ - char const *s = buf + 4; - - if (!rp_ptr->desc) - { - rp_ptr->desc = my_strdup(s); - } - else + // Need newline? + if (!rp_ptr->desc.empty()) { - strappend(&rp_ptr->desc, format("\n%s", s)); + rp_ptr->desc += '\n'; } + // Append + rp_ptr->desc += (buf + 4); + /* Next... */ continue; } @@ -1236,14 +1231,12 @@ errr init_player_info_txt(FILE *fp) /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_rmp_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - rmp_ptr = &race_mod_info[i]; + rmp_ptr = &expand_to_fit_index(race_mod_info, i); + assert(rmp_ptr->title.empty()); /* Copy title */ rmp_ptr->title = s; @@ -6950,15 +6943,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst /* Maximum player types */ else if (zz[0][0] == 'P') { - if (zz[1][0] == 'R') - { - max_rp_idx = atoi(zz[2]); - } - else if (zz[1][0] == 'S') - { - max_rmp_idx = atoi(zz[2]); - } - else if (zz[1][0] == 'H') + if (zz[1][0] == 'H') { max_bg_idx = atoi(zz[2]); } @@ -7204,7 +7189,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) /* Race */ else if (streq(b + 1, "RACE")) { - v = rp_ptr->title; + v = rp_ptr->title.c_str(); // The string SHOULD be stable enough for this } /* Race Mod */ diff --git a/src/init2.cc b/src/init2.cc index 9800c4f4..1596c057 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -551,8 +551,6 @@ namespace { static void allocate() { - race_info = new player_race[max_rp_idx]; - race_mod_info = new player_race_mod[max_rmp_idx]; bg = make_array<hist_type>(max_bg_idx); gen_skill = new skill_modifiers; } diff --git a/src/loadsave.cc b/src/loadsave.cc index 82603563..5354af9a 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -438,6 +438,8 @@ static void do_player_level_flag(player_level_flag *lflag, ls_flag_t flag) */ static void do_subrace(ls_flag_t flag) { + auto &race_mod_info = game->edit_data.race_mod_info; + player_race_mod *sr_ptr = &race_mod_info[SUBRACE_SAVE]; int i; @@ -2428,6 +2430,8 @@ static bool do_player_hd(ls_flag_t flag) static bool_ do_savefile_aux(ls_flag_t flag) { auto &class_info = game->edit_data.class_info; + auto const &race_info = game->edit_data.race_info; + auto const &race_mod_info = game->edit_data.race_mod_info; /* Mention the savefile version */ if (flag == ls_flag_t::LOAD) diff --git a/src/object1.cc b/src/object1.cc index 0d93c917..e0b4f60b 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -18,6 +18,7 @@ #include "ego_item_type.hpp" #include "feature_type.hpp" #include "files.hpp" +#include "game.hpp" #include "hook_get_in.hpp" #include "hooks.hpp" #include "lua_bind.hpp" @@ -632,6 +633,8 @@ void flavor_init(void) */ void reset_visuals(void) { + auto &race_mod_info = game->edit_data.race_mod_info; + int i; /* Extract some info about terrain features */ @@ -685,13 +688,11 @@ void reset_visuals(void) } /* Reset attr/char code for race modifier overlay graphics */ - for (i = 0; i < max_rmp_idx; i++) + for (player_race_mod &rmp: race_mod_info) { - player_race_mod *rmp_ptr = &race_mod_info[i]; - /* Default attr/char */ - rmp_ptr->g_attr = 0; - rmp_ptr->g_char = 0; + rmp.g_attr = 0; + rmp.g_char = 0; } /* Reset attr/char code for trap overlay graphics */ diff --git a/src/player_race.hpp b/src/player_race.hpp index 560ba34f..a2f4699c 100644 --- a/src/player_race.hpp +++ b/src/player_race.hpp @@ -12,6 +12,7 @@ #include "skill_modifiers.hpp" #include <array> +#include <string> #include <vector> @@ -20,8 +21,8 @@ */ struct player_race { - const char *title = nullptr; /* Type of race */ - char *desc = nullptr; + std::string title; /* Type of race */ + std::string desc; char luck = '\0'; /* Luck */ diff --git a/src/util.cc b/src/util.cc index cde2fcb6..cd1c0c4f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -8,6 +8,7 @@ #include "cli_comm.hpp" #include "cmd3.hpp" #include "cmd4.hpp" +#include "game.hpp" #include "init1.hpp" #include "messages.hpp" #include "monster_ego.hpp" @@ -3422,6 +3423,9 @@ std::string get_day(s32b day_no) std::string get_player_race_name(int pr, int ps) { + auto const &race_info = game->edit_data.race_info; + auto const &race_mod_info = game->edit_data.race_mod_info; + if (ps) { if (race_mod_info[ps].place) diff --git a/src/variable.cc b/src/variable.cc index 30d07469..426d4b3a 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -422,8 +422,8 @@ player_type *p_ptr = nullptr; * Pointer to the player tables * (sex, race, race mod, class, magic) */ -player_race *rp_ptr; -player_race_mod *rmp_ptr; +player_race const *rp_ptr; +player_race_mod const *rmp_ptr; player_class const *cp_ptr; player_spec const *spp_ptr; @@ -488,16 +488,6 @@ skill_type *s_info; skill_descriptor *s_descriptors; /* - * Player race arrays - */ -player_race *race_info; - -/* - * Player mod race arrays - */ -player_race_mod *race_mod_info; - -/* * The wilderness features arrays */ wilderness_type_info *wf_info; @@ -680,12 +670,6 @@ u16b max_st_idx; u16b max_set_idx = 1; /* - * Maximum number of players info in p_info.txt - */ -u16b max_rp_idx; -u16b max_rmp_idx; - -/* * Maximum number of objects in the level */ u16b max_o_idx; diff --git a/src/variable.hpp b/src/variable.hpp index a86f4d2e..80520f67 100644 --- a/src/variable.hpp +++ b/src/variable.hpp @@ -156,8 +156,8 @@ extern byte tval_to_attr[128]; extern char tval_to_char[128]; extern char *keymap_act[KEYMAP_MODES][256]; extern player_type *p_ptr; -extern player_race *rp_ptr; -extern player_race_mod *rmp_ptr; +extern player_race const *rp_ptr; +extern player_race_mod const *rmp_ptr; extern player_class const *cp_ptr; extern player_spec const *spp_ptr; extern char player_name[32]; @@ -172,8 +172,6 @@ extern ego_item_type *e_info; extern monster_race *r_info; extern monster_ego *re_info; extern dungeon_info_type *d_info; -extern player_race *race_info; -extern player_race_mod *race_mod_info; extern trap_type *t_info; extern wilderness_type_info *wf_info; extern int wildc2i[256]; @@ -201,8 +199,6 @@ extern u16b max_d_idx; extern u16b max_o_idx; extern u16b max_m_idx; extern u16b max_t_idx; -extern u16b max_rp_idx; -extern u16b max_rmp_idx; extern u16b max_st_idx; extern u16b max_wf_idx; extern u16b max_set_idx; diff --git a/src/xtra1.cc b/src/xtra1.cc index 037a1f46..aff76b71 100644 --- a/src/xtra1.cc +++ b/src/xtra1.cc @@ -1050,7 +1050,7 @@ static void prt_frame(void) int i; /* Race and Class */ - prt_field(rp_ptr->title, ROW_RACE, COL_RACE); + prt_field(rp_ptr->title.c_str(), ROW_RACE, COL_RACE); prt_field(spp_ptr->title, ROW_CLASS, COL_CLASS); /* Title */ diff --git a/src/xtra2.cc b/src/xtra2.cc index 5ed06491..040299ff 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -5288,9 +5288,11 @@ static void corrupt_corrupted(void) /* * Change to an other subrace */ -void switch_subrace(int racem, bool_ copy_old) +void switch_subrace(std::size_t racem, bool_ copy_old) { - if ((racem < 0) && (racem >= max_rmp_idx)) return; + auto &race_mod_info = game->edit_data.race_mod_info; + + assert(racem < race_mod_info.size()); /* If we switch to the saved subrace, we copy over the old subrace data */ if (copy_old && (racem == SUBRACE_SAVE)) diff --git a/src/xtra2.hpp b/src/xtra2.hpp index a5e07cd3..c81bef73 100644 --- a/src/xtra2.hpp +++ b/src/xtra2.hpp @@ -8,7 +8,7 @@ #include <memory> extern void do_rebirth(void); -extern void switch_subrace(int racem, bool_ copy_old); +extern void switch_subrace(std::size_t racem, bool_ copy_old); extern void drop_from_wild(void); extern bool_ set_roots(int v, s16b ac, s16b dam); extern bool_ set_project(int v, s16b gf, s16b dam, s16b rad, s16b flag); |