From caa23251d8b279529330641032c62f8640ee13ff Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove rp_head, rp_name, rp_text, rmp_head, rmp_name, rmp_text --- src/birth.cc | 26 +++++------ src/cmd5.cc | 4 +- src/corrupt.cc | 13 +++--- src/dungeon.cc | 15 ++++--- src/externs.h | 10 +---- src/files.cc | 16 +++---- src/init1.cc | 110 +++++++++++++---------------------------------- src/init2.cc | 22 +--------- src/loadsave.cc | 16 +++++-- src/object1.cc | 2 +- src/squelch/condition.cc | 6 +-- src/types.h | 17 ++++---- src/util.cc | 12 ++++-- src/variable.cc | 6 --- src/xtra1.cc | 2 +- src/xtra2.cc | 38 ++++++++++++---- 16 files changed, 134 insertions(+), 181 deletions(-) diff --git a/src/birth.cc b/src/birth.cc index a3e49fdb..3ed99a8a 100644 --- a/src/birth.cc +++ b/src/birth.cc @@ -513,7 +513,7 @@ static void get_history(void) while ((chart != bg[i].chart) || (roll > bg[i].roll)) i++; /* Acquire the textual history */ - (void)strcat(buf, bg[i].info + rp_text); + (void)strcat(buf, bg[i].info); /* Add in the social class */ social_class += (int)(bg[i].bonus) - 50; @@ -1049,7 +1049,7 @@ static void player_outfit(void) { int i; cptr class_name = spp_ptr->title; - cptr subrace_name = rmp_ptr->title + rmp_name; + cptr subrace_name = rmp_ptr->title; /* * Get an adventurer guide describing a bit of the @@ -1183,7 +1183,7 @@ static void player_outfit(void) identify_pack_fully(); } - if (streq(rmp_ptr->title + rmp_name, "Vampire")) + if (streq(rmp_ptr->title, "Vampire")) { player_gain_corruption(CORRUPT_VAMPIRE_TEETH); player_gain_corruption(CORRUPT_VAMPIRE_STRENGTH); @@ -1373,8 +1373,6 @@ int dump_races(int sel) char buf[80]; - cptr str; - /* Clean up */ clear_from(12); @@ -1385,7 +1383,6 @@ int dump_races(int sel) /* Analyze */ p_ptr->prace = n; rp_ptr = &race_info[p_ptr->prace]; - str = rp_ptr->title + rp_name; if (sel == n) { @@ -1394,14 +1391,14 @@ int dump_races(int sel) } /* Display */ - strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, str); + strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, rp_ptr->title); /* Print some more info */ if (sel == n) { std::string desc; - desc += (rp_ptr->desc + rp_text); + desc += rp_ptr->desc; if (rp_ptr->flags1 & PR1_EXPERIMENTAL) { desc += "\nEXPERIMENTAL"; @@ -1433,8 +1430,6 @@ int dump_rmods(int sel, int *racem, int max) char buf[80]; - cptr str; - /* Clean up */ clear_from(12); @@ -1446,7 +1441,6 @@ int dump_rmods(int sel, int *racem, int max) /* Analyze */ p_ptr->pracem = racem[n]; rmp_ptr = &race_mod_info[p_ptr->pracem]; - str = rmp_ptr->title + rmp_name; if (sel == n) { @@ -1456,7 +1450,7 @@ int dump_rmods(int sel, int *racem, int max) /* Display */ if (racem[n]) - strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, str); + strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, rmp_ptr->title); else strnfmt(buf, 80, "%c%c%c Classical", p1, I2A(n), p2); @@ -1465,7 +1459,7 @@ int dump_rmods(int sel, int *racem, int max) { std::string desc; - desc += (rmp_ptr->desc + rmp_text); + desc += rmp_ptr->desc; if (rmp_ptr->flags1 & PR1_EXPERIMENTAL) { desc += "\nEXPERIMENTAL"; @@ -1728,7 +1722,7 @@ static bool_ player_birth_aux_ask() if ((k >= 0) && (k < n)) break; if (c == '?') { - help_race(race_info[sel].title + rp_name); + help_race(race_info[sel].title); } else if (c == '=') { @@ -1776,7 +1770,7 @@ static bool_ player_birth_aux_ask() rp_ptr = &race_info[p_ptr->prace]; /* Display */ - c_put_str(TERM_L_BLUE, rp_ptr->title + rp_name, 4, 9); + c_put_str(TERM_L_BLUE, rp_ptr->title, 4, 9); /* Get a random name */ if (!do_quick_start) create_random_name(p_ptr->prace, player_name); @@ -1853,7 +1847,7 @@ static bool_ player_birth_aux_ask() } else if (c == '?') { - help_subrace(race_mod_info[racem[sel]].title + rmp_name); + help_subrace(race_mod_info[racem[sel]].title); } k = (islower(c) ? A2I(c) : -1); diff --git a/src/cmd5.cc b/src/cmd5.cc index 35d146e9..8ecf67dc 100644 --- a/src/cmd5.cc +++ b/src/cmd5.cc @@ -266,8 +266,8 @@ void do_poly_self(void) if (effect_msg[0]) { msg_format("You turn into a%s %s!", - ((is_a_vowel(rp_name[race_info[new_race].title])) ? "n" : ""), - race_info[new_race].title + rp_name); + ((is_a_vowel(*race_info[new_race].title)) ? "n" : ""), + race_info[new_race].title); } else { diff --git a/src/corrupt.cc b/src/corrupt.cc index 0b350f82..e9f8ced5 100644 --- a/src/corrupt.cc +++ b/src/corrupt.cc @@ -57,18 +57,18 @@ static void player_gain_vampire() player_race_mod *rmp_ptr = &race_mod_info[SUBRACE_SAVE]; /* Be a Vampire and be proud of it */ - cptr title = get_subrace_title(SUBRACE_SAVE); - if (streq(title, " ") || streq(title, "Vampire")) + cptr title = rmp_ptr->title; + if (streq(title, "Vampire")) { title = "Vampire"; rmp_ptr->place = FALSE; - set_subrace_title(SUBRACE_SAVE, title); + set_subrace_title(rmp_ptr, title); } else { char buf[512]; sprintf(buf, "Vampire %s", title); - set_subrace_title(SUBRACE_SAVE, buf); + set_subrace_title(rmp_ptr, buf); } /* Bonus/and .. not bonus :) */ @@ -668,7 +668,6 @@ bool_ player_has_corruption(int corruption_idx) static bool_ player_can_gain_corruption(int corruption_idx) { - cptr r_name = rp_ptr->title + rp_name; bool_ allowed = TRUE; /* Allowed by default */ assert(corruption_idx >= 0); @@ -676,7 +675,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(r_name, "Troll")) + if (streq(rp_ptr->title, "Troll")) { allowed = FALSE; } @@ -686,7 +685,7 @@ static bool_ player_can_gain_corruption(int corruption_idx) if (game_module_idx == MODULE_THEME) { - if (streq(r_name, "Maia")) + if (streq(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 020effb4..06ac76ce 100644 --- a/src/dungeon.cc +++ b/src/dungeon.cc @@ -958,8 +958,8 @@ static bool_ grace_delay_trigger() */ static void process_world_gods() { - const char *race_name = rp_ptr->title + rp_name; - const char *subrace_name = rmp_ptr->title + rmp_name; + const char *race_name = rp_ptr->title; + const char *subrace_name = rmp_ptr->title; GOD(GOD_VARDA) { @@ -1705,9 +1705,14 @@ static void process_world(void) int dec = 5 - wisdom_scale(3); /* Blech what an hideous hack */ - if (!strcmp(rp_ptr->title + rp_name, "Ent")) + if (!strcmp(rp_ptr->title, "Ent")) + { dec -= wisdom_scale(2); - if (dec < 1) dec = 1; + } + if (dec < 1) + { + dec = 1; + } inc_piety(GOD_YAVANNA, -dec); } } @@ -4998,7 +5003,7 @@ static void load_all_pref_files(void) /* Access the "race" pref file */ - sprintf(buf, "%s.prf", rp_ptr->title + rp_name); + sprintf(buf, "%s.prf", rp_ptr->title); /* Process that file */ process_pref_file(buf); diff --git a/src/externs.h b/src/externs.h index 127ea0c8..b9d64914 100644 --- a/src/externs.h +++ b/src/externs.h @@ -334,14 +334,8 @@ extern monster_ego *re_info; extern dungeon_info_type *d_info; extern player_class *class_info; extern meta_class_type *meta_class_info; -extern header *rp_head; extern player_race *race_info; -extern char *rp_name; -extern char *rp_text; -extern header *rmp_head; extern player_race_mod *race_mod_info; -extern char *rmp_name; -extern char *rmp_text; extern header *t_head; extern trap_type *t_info; extern char *t_name; @@ -1453,8 +1447,8 @@ extern void dump_fates(FILE *OutFile); /* xtra2.c */ extern void do_rebirth(void); -extern cptr get_subrace_title(int racem); -extern void set_subrace_title(int racem, cptr name); +extern void set_subrace_title(player_race_mod *rmp_ptr, cptr name); +extern void set_subrace_description(player_race_mod *rmp_ptr, cptr desc); extern void switch_subrace(int racem, bool_ copy_old); extern void drop_from_wild(void); extern void clean_wish_name(char *buf, char *name); diff --git a/src/files.cc b/src/files.cc index 005b4ed8..29b216e4 100644 --- a/src/files.cc +++ b/src/files.cc @@ -857,13 +857,13 @@ static cptr process_pref_file_expr(char **sp, char *fp) /* Race */ else if (streq(b + 1, "RACE")) { - v = rp_ptr->title + rp_name; + v = rp_ptr->title; } /* Race */ else if (streq(b + 1, "RACEMOD")) { - v = rmp_ptr->title + rmp_name; + v = rmp_ptr->title; } /* Class */ @@ -4934,7 +4934,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, rp_name + race_info[pr].title, clev); + (m + 1), the_score.who, race_info[pr].title, clev); prt(out_val, (m + 7), 0); m++; } @@ -4945,7 +4945,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, rp_name + race_info[p_ptr->prace].title, p_ptr->lev); + player_name, race_info[p_ptr->prace].title, p_ptr->lev); prt(out_val, (m + 8), 0); } else if ((building != 1)) @@ -4953,7 +4953,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, rp_name + race_info[p_ptr->prace].title, p_ptr->lev); + player_name, race_info[p_ptr->prace].title, p_ptr->lev); prt(out_val, (m + 8), 0); } } @@ -4982,7 +4982,7 @@ void race_score(int race_num) lastlev = 0; /* rr9: TODO - pluralize the race */ - sprintf(tmp_str, "The Greatest of all the %s", rp_name + race_info[race_num].title); + sprintf(tmp_str, "The Greatest of all the %s", race_info[race_num].title); prt(tmp_str, 5, 3); /* Build the filename */ @@ -5018,7 +5018,7 @@ void race_score(int race_num) { sprintf(out_val, "%3d) %s the %s (Level %3d)", (m + 1), the_score.who, - rp_name + race_info[pr].title, clev); + race_info[pr].title, clev); prt(out_val, (m + 7), 0); m++; lastlev = clev; @@ -5030,7 +5030,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, rp_name + race_info[p_ptr->prace].title, p_ptr->lev); + player_name, race_info[p_ptr->prace].title, p_ptr->lev); prt(out_val, (m + 8), 0); } diff --git a/src/init1.cc b/src/init1.cc index aac41a8b..28f8ba10 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1645,7 +1645,7 @@ static errr grab_one_race_allow_flag(u32b *choice, cptr what) cptr s; /* Scan classes flags */ - for (i = 0; i < max_rp_idx && (s = race_info[i].title + rp_name); i++) + for (i = 0; i < max_rp_idx && (s = race_info[i].title); i++) { if (streq(what, s)) { @@ -1849,13 +1849,6 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Just before the first line */ error_line = -1; - - /* Start the "fake" stuff */ - rp_head->name_size = 0; - rp_head->text_size = 0; - rmp_head->name_size = 0; - rmp_head->text_size = 0; - /* Init general skills */ for (z = 0; z < MAX_SKILLS; z++) { @@ -1926,13 +1919,9 @@ errr init_player_info_txt(FILE *fp, char *buf) bg[idx].next = atoi(zz[3]); bg[idx].bonus = atoi(zz[4]); - bg[idx].info = ++rp_head->text_size; - - /* Append chars to the name */ - strcpy(rp_text + rp_head->text_size, zz[5]); - - /* Advance the index */ - rp_head->text_size += strlen(zz[5]); + /* Copy text */ + assert(!bg[idx].info); + bg[idx].info = my_strdup(zz[5]); /* Next... */ continue; @@ -1980,7 +1969,7 @@ errr init_player_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= rp_head->info_num) return (2); + if (i >= max_rp_idx) return (2); /* Save the index */ error_idx = i; @@ -1988,18 +1977,11 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Point at the "info" */ rp_ptr = &race_info[i]; - /* Hack -- Verify space */ - if (rp_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!rp_ptr->title) rp_ptr->title = ++rp_head->name_size; - - /* Append chars to the name */ - strcpy(rp_name + rp_head->name_size, s); - - /* Advance the index */ - rp_head->name_size += strlen(s); + /* Copy title */ + assert(!rp_ptr->title); + rp_ptr->title = my_strdup(s); + /* Initialize */ rp_ptr->powers[0] = rp_ptr->powers[1] = rp_ptr->powers[2] = rp_ptr->powers[3] = -1; powers = 0; lev = 1; @@ -2017,27 +1999,13 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 4; - /* Hack -- Verify space */ - if (rp_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ if (!rp_ptr->desc) { - rp_ptr->desc = ++rp_head->text_size; - - /* Append chars to the name */ - strcpy(rp_text + rp_head->text_size, s); - - /* Advance the index */ - rp_head->text_size += strlen(s); + rp_ptr->desc = my_strdup(s); } else { - /* Append chars to the name */ - strcpy(rp_text + rp_head->text_size, format("\n%s", s)); - - /* Advance the index */ - rp_head->text_size += strlen(s) + 1; + strappend(&rp_ptr->desc, format("\n%s", s)); } /* Next... */ @@ -2354,7 +2322,7 @@ errr init_player_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= rmp_head->info_num) return (2); + if (i >= max_rmp_idx) return (2); /* Save the index */ error_idx = i; @@ -2362,18 +2330,11 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Point at the "info" */ rmp_ptr = &race_mod_info[i]; - /* Hack -- Verify space */ - if (rmp_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!rmp_ptr->title) rmp_ptr->title = ++rmp_head->name_size; - - /* Append chars to the name */ - strcpy(rmp_name + rmp_head->name_size, s); - - /* Advance the index */ - rmp_head->name_size += strlen(s); + /* Copy title */ + assert(!rmp_ptr->title); + rmp_ptr->title = my_strdup(s); + /* Initialize */ rmp_ptr->powers[0] = rmp_ptr->powers[1] = rmp_ptr->powers[2] = rmp_ptr->powers[3] = -1; powers = 0; lev = 1; @@ -2391,30 +2352,25 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 6; - if (buf[4] == 'A') rmp_ptr->place = TRUE; - else rmp_ptr->place = FALSE; - - /* Hack -- Verify space */ - if (rmp_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + /* Place */ + if (buf[4] == 'A') + { + rmp_ptr->place = TRUE; + } + else + { + rmp_ptr->place = FALSE; + } - /* Advance and Save the text index */ + /* Description */ if (!rmp_ptr->desc) { - rmp_ptr->desc = ++rmp_head->text_size; - - /* Append chars to the name */ - strcpy(rmp_text + rmp_head->text_size, s); - - /* Advance the index */ - rmp_head->text_size += strlen(s); + rmp_ptr->desc = my_strdup(s); } else { /* Append chars to the name */ - strcpy(rmp_text + rmp_head->text_size, format("\n%s", s)); - - /* Advance the index */ - rmp_head->text_size += strlen(s) + 1; + strappend(&rmp_ptr->desc, format("\n%s", s)); } /* Next... */ @@ -3406,12 +3362,6 @@ errr init_player_info_txt(FILE *fp, char *buf) return (6); } - /* Complete the "name" and "text" sizes */ - ++rp_head->name_size; - ++rp_head->text_size; - ++rmp_head->name_size; - ++rmp_head->text_size; - /* No version yet */ if (!okay) return (2); @@ -11396,13 +11346,13 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) /* Race */ else if (streq(b + 1, "RACE")) { - v = rp_ptr->title + rp_name; + v = rp_ptr->title; } /* Race Mod */ else if (streq(b + 1, "RACEMOD")) { - v = rmp_ptr->title + rmp_name; + v = rmp_ptr->title; } /* Class */ diff --git a/src/init2.cc b/src/init2.cc index 212a5a34..433a6337 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -972,29 +972,11 @@ static errr init_player_info(void) /* General buffer */ char buf[1024]; - - /*** Make the header ***/ - rp_head = make_header(max_rp_idx); - - - /*** Make the header ***/ - rmp_head = make_header(max_rmp_idx); - - /*** Make the fake arrays ***/ - /* Allocate the "rp_info" array */ - race_info = make_array(rp_head->info_num); - - /* Hack -- make "fake" arrays */ - rp_name = make_array(FAKE_NAME_SIZE); - rp_text = make_array(FAKE_TEXT_SIZE); + race_info = make_array(max_rp_idx); /* Allocate the "rmp_info" array */ - race_mod_info = make_array(rmp_head->info_num); - - /* Hack -- make "fake" arrays */ - rmp_name = make_array(FAKE_NAME_SIZE); - rmp_text = make_array(FAKE_TEXT_SIZE); + race_mod_info = make_array(max_rmp_idx); /* Allocate the "c_info" array */ class_info = make_array(max_c_idx); diff --git a/src/loadsave.cc b/src/loadsave.cc index 7c89bc45..e916e367 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -151,16 +151,24 @@ static void do_subrace(int flag) buf[80] = '\0'; // Make sure string is always NUL terminated if (flag == LS_SAVE) - strncpy(buf, sr_ptr->title + rmp_name, 80); + { + strncpy(buf, sr_ptr->title, 80); + } do_string(buf, 80, flag); if (flag == LS_LOAD) - strncpy(sr_ptr->title + rmp_name, buf, 80); + { + set_subrace_title(sr_ptr, buf); + } if (flag == LS_SAVE) - strncpy(buf, sr_ptr->desc + rmp_text, 80); + { + strncpy(buf, sr_ptr->desc, 80); + } do_string(buf, 80, flag); if (flag == LS_LOAD) - strncpy(sr_ptr->desc + rmp_text, buf, 80); + { + set_subrace_description(sr_ptr, buf); + } do_byte((byte*)&sr_ptr->place, flag); diff --git a/src/object1.cc b/src/object1.cc index 85328bfe..dacf1b93 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -3912,7 +3912,7 @@ s16b wield_slot_ideal(object_type *o_ptr, bool_ ideal) /* Theme has restrictions for winged races. */ if (game_module_idx == MODULE_THEME) { - cptr race_name = rp_ptr->title + rp_name; + cptr race_name = rp_ptr->title; if (streq(race_name, "Dragon") || streq(race_name, "Eagle")) diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc index 1df22328..e187157b 100644 --- a/src/squelch/condition.cc +++ b/src/squelch/condition.cc @@ -511,8 +511,7 @@ void StatusCondition::to_json(json_t *j) const bool RaceCondition::is_match(object_type *o_ptr) const { - return boost::algorithm::iequals(m_race, - rp_ptr->title + rp_name); + return boost::algorithm::iequals(m_race, rp_ptr->title); } std::shared_ptr RaceCondition::from_json(json_t *j) @@ -546,8 +545,7 @@ void RaceCondition::to_json(json_t *j) const bool SubraceCondition::is_match(object_type *o_ptr) const { - return boost::algorithm::iequals(m_subrace, - rmp_ptr->title + rmp_name); + return boost::algorithm::iequals(m_subrace, rmp_ptr->title); } std::shared_ptr SubraceCondition::from_json(json_t *j) diff --git a/src/types.h b/src/types.h index d7ee1245..6240e5f8 100644 --- a/src/types.h +++ b/src/types.h @@ -1033,12 +1033,12 @@ typedef struct player_race player_race; struct player_race { - s32b title; /* Type of race */ - s32b desc; + const char *title; /* Type of race */ + char *desc; - s16b r_adj[6]; /* Racial stat bonuses */ + s16b r_adj[6]; /* Racial stat bonuses */ - char luck; /* Luck */ + char luck; /* Luck */ s16b r_dis; /* disarming */ s16b r_dev; /* magic devices */ @@ -1109,9 +1109,10 @@ typedef struct player_race_mod player_race_mod; struct player_race_mod { - s32b title; /* Type of race mod */ - s32b desc; /* Desc */ - bool_ place; /* TRUE = race race modifier, FALSE = Race modifier race */ + char *title; /* Type of race mod */ + char *desc; /* Desc */ + + bool_ place; /* TRUE = race race modifier, FALSE = Race modifier race */ s16b r_adj[6]; /* (+) Racial stat bonuses */ @@ -2390,7 +2391,7 @@ typedef struct hist_type hist_type; */ struct hist_type { - s32b info; /* Textual History -- uses rp_text */ + char *info; /* Textual History */ byte roll; /* Frequency of this entry */ s16b chart; /* Chart index */ diff --git a/src/util.cc b/src/util.cc index b57a3a03..bceb8822 100644 --- a/src/util.cc +++ b/src/util.cc @@ -3492,12 +3492,18 @@ cptr get_player_race_name(int pr, int ps) if (ps) { - if (race_mod_info[ps].place) sprintf(buf, "%s %s", race_info[pr].title + rp_name, race_mod_info[ps].title + rmp_name); - else sprintf(buf, "%s %s", race_mod_info[ps].title + rmp_name, race_info[pr].title + rp_name); + if (race_mod_info[ps].place) + { + sprintf(buf, "%s %s", race_info[pr].title, race_mod_info[ps].title); + } + else + { + sprintf(buf, "%s %s", race_mod_info[ps].title, race_info[pr].title); + } } else { - sprintf(buf, "%s", race_info[pr].title + rp_name); + sprintf(buf, "%s", race_info[pr].title); } return (buf); diff --git a/src/variable.cc b/src/variable.cc index 690082a4..8781485b 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -675,18 +675,12 @@ char *s_text; /* * Player race arrays */ -header *rp_head; player_race *race_info; -char *rp_name; -char *rp_text; /* * Player mod race arrays */ -header *rmp_head; player_race_mod *race_mod_info; -char *rmp_name; -char *rmp_text; /* * Player class arrays diff --git a/src/xtra1.cc b/src/xtra1.cc index 9e8fface..eb70787d 100644 --- a/src/xtra1.cc +++ b/src/xtra1.cc @@ -999,7 +999,7 @@ static void prt_frame(void) int i; /* Race and Class */ - prt_field(rp_ptr->title + rp_name, ROW_RACE, COL_RACE); + prt_field(rp_ptr->title, 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 d3a6cc63..5896e3bc 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -18,6 +18,8 @@ #include "quark.h" #include "hooks.h" +#include + #include using boost::algorithm::iequals; @@ -5657,27 +5659,47 @@ void switch_subrace(int racem, bool_ copy_old) /* If we switch to the saved subrace, we copy over the old subrace data */ if (copy_old && (racem == SUBRACE_SAVE)) { - s32b old_title = race_mod_info[SUBRACE_SAVE].title; - s32b old_desc = race_mod_info[SUBRACE_SAVE].desc; - + // This code is very reliant on the race_mod_info + // elements being simple PODs, in particular the + // text pointers being *unmanaged* owned pointers. + static_assert(std::is_pod::value, + "This code needs reworking"); + // Keep references to owned pointers. + auto old_title = race_mod_info[SUBRACE_SAVE].title; + auto old_desc = race_mod_info[SUBRACE_SAVE].desc; + // Copy everything race_mod_info[SUBRACE_SAVE] = race_mod_info[p_ptr->pracem]; + // "Undo" copy of title and description (since they're *owned* pointers) race_mod_info[SUBRACE_SAVE].title = old_title; race_mod_info[SUBRACE_SAVE].desc = old_desc; - strcpy(race_mod_info[SUBRACE_SAVE].title + rmp_name, race_mod_info[p_ptr->pracem].title + rmp_name); + // Replace subrace title with the title currently held by player. + set_subrace_title(&race_mod_info[SUBRACE_SAVE], race_mod_info[p_ptr->pracem].title); } p_ptr->pracem = racem; rmp_ptr = &race_mod_info[p_ptr->pracem]; } -cptr get_subrace_title(int racem) +void set_subrace_title(player_race_mod *rmp_ptr, cptr name) { - return race_mod_info[racem].title + rmp_name; + // Free old title. + free(rmp_ptr->title); + // Allocate copy of new title. + rmp_ptr->title = strdup(name); + if (!rmp_ptr->title) { + abort(); + } } -void set_subrace_title(int racem, cptr name) +void set_subrace_description(player_race_mod *rmp_ptr, cptr desc) { - strcpy(race_mod_info[racem].title + rmp_name, name); + // Free old description + free(rmp_ptr->desc); + // Allocate copy of new description. + rmp_ptr->desc = strdup(desc); + if (!rmp_ptr->desc) { + abort(); + } } /* -- cgit v1.2.3