From c4746c0f6d328baa429c96e54d86d2d7f97ccbcc Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Remove r_name, r_text, r_head in favor of simple strings --- src/bldg.cc | 12 ++++------- src/cmd3.cc | 4 ++-- src/cmd4.cc | 19 ++++++++--------- src/cmd5.cc | 4 ++-- src/dungeon.cc | 3 +-- src/externs.h | 3 --- src/files.cc | 2 +- src/generate.cc | 5 ++--- src/init1.cc | 66 +++++++++++++++++++++++++++++---------------------------- src/init2.cc | 11 +--------- src/melee1.cc | 9 ++++---- src/monster1.cc | 14 ++++++++---- src/monster2.cc | 48 ++++++++++++++++++++++++----------------- src/object1.cc | 8 +++---- src/q_rand.cc | 10 ++++----- src/spells1.cc | 10 ++++----- src/spells2.cc | 10 +++++---- src/types.h | 4 ++-- src/util.cc | 5 ++--- src/variable.cc | 2 -- src/wizard1.cc | 10 ++++----- src/xtra1.cc | 4 ++-- src/xtra2.cc | 47 +++++++++++++++++++++------------------- 23 files changed, 152 insertions(+), 158 deletions(-) diff --git a/src/bldg.cc b/src/bldg.cc index 1685eece..d9ceac4e 100644 --- a/src/bldg.cc +++ b/src/bldg.cc @@ -228,9 +228,6 @@ static void arena_comm(int cmd) monster_race *r_ptr; - cptr name; - - switch (cmd) { case BACT_ARENA: @@ -276,8 +273,7 @@ static void arena_comm(int cmd) else { r_ptr = &r_info[arena_monsters[p_ptr->arena_number]]; - name = (r_name + r_ptr->name); - strnfmt(tmp_str, 80, "Do I hear any challenges against: %s", name); + strnfmt(tmp_str, 80, "Do I hear any challenges against: %s", r_ptr->name); msg_print(tmp_str); msg_print(NULL); } @@ -1241,7 +1237,7 @@ static void show_quest_monster(void) msg_format("Quest monster: %s. " "Need to turn in %d corpse%s to receive reward.", - r_name + r_ptr->name, bounties[0][1], + r_ptr->name, bounties[0][1], (bounties[0][1] > 1 ? "s" : "")); msg_print(NULL); } @@ -1267,7 +1263,7 @@ static void show_bounties(void) { r_ptr = &r_info[bounties[i][0]]; - strnfmt(buff, 80, "%-30s (%d gp)", r_name + r_ptr->name, bounties[i][1]); + strnfmt(buff, 80, "%-30s (%d gp)", r_ptr->name, bounties[i][1]); prt(buff, j, 2); @@ -1490,7 +1486,7 @@ static void sell_quest_monster(void) msg_print(format("Well done! As a reward I'll teach you everything " "about the %s, (check your recall)", - r_name + r_ptr->name)); + r_ptr->name)); r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR; diff --git a/src/cmd3.cc b/src/cmd3.cc index efb17cf2..cd924365 100644 --- a/src/cmd3.cc +++ b/src/cmd3.cc @@ -1367,7 +1367,7 @@ static void roff_top(int r_idx) } /* Dump the name */ - Term_addstr( -1, TERM_WHITE, (r_name + r_ptr->name)); + Term_addstr( -1, TERM_WHITE, r_ptr->name); /* Append the "standard" attr/char info */ Term_addstr( -1, TERM_WHITE, " ('"); @@ -1484,7 +1484,7 @@ void do_cmd_query_symbol(void) { char mon_name[80]; - strcpy(mon_name, r_name + r_ptr->name); + strcpy(mon_name, r_ptr->name); strlower(mon_name); if (!strstr(mon_name, temp)) continue; diff --git a/src/cmd4.cc b/src/cmd4.cc index 1878379e..5aff3358 100644 --- a/src/cmd4.cc +++ b/src/cmd4.cc @@ -2179,7 +2179,7 @@ void do_cmd_visuals(void) if (!r_ptr->name) continue; /* Dump a comment */ - fprintf(fff, "# %s\n", (r_name + r_ptr->name)); + fprintf(fff, "# %s\n", r_ptr->name); /* Dump the monster attr/char info */ fprintf(fff, "R:%d:0x%02X:0x%02X\n\n", i, @@ -2326,7 +2326,7 @@ void do_cmd_visuals(void) /* Label the object */ Term_putstr(5, 17, -1, TERM_WHITE, format("Monster = %d, Name = %-40.40s", - r, (r_name + r_ptr->name))); + r, r_ptr->name)); /* Label the Default values */ Term_putstr(10, 19, -1, TERM_WHITE, @@ -3449,14 +3449,14 @@ static void do_cmd_knowledge_uniques(void) fprintf(fff, "[[[[[%c%c] [[[[[R%-68s is dead]\n", conv_color[r_ptr->d_attr], r_ptr->d_char, - (r_name + r_ptr->name)); + r_ptr->name); } else { fprintf(fff, "[[[[[%c%c] [[[[[w%-68s is alive]\n", conv_color[r_ptr->d_attr], r_ptr->d_char, - (r_name + r_ptr->name)); + r_ptr->name); } } } @@ -3722,8 +3722,7 @@ static void do_cmd_knowledge_kill_count(void) if (dead) { /* Print a message */ - fprintf(fff, " %s\n", - (r_name + r_ptr->name)); + fprintf(fff, " %s\n", r_ptr->name); Total++; } } @@ -3735,19 +3734,19 @@ static void do_cmd_knowledge_kill_count(void) { if (This < 2) { - if (strstr(r_name + r_ptr->name, "coins")) + if (strstr(r_ptr->name, "coins")) { - fprintf(fff, " 1 pile of %s\n", (r_name + r_ptr->name)); + fprintf(fff, " 1 pile of %s\n", r_ptr->name); } else { - fprintf(fff, " 1 %s\n", (r_name + r_ptr->name)); + fprintf(fff, " 1 %s\n", r_ptr->name); } } else { char to_plural[80]; - strcpy(to_plural, (r_name + r_ptr->name)); + strcpy(to_plural, r_ptr->name); plural_aux(to_plural); fprintf(fff, " %d %s\n", This, to_plural); } diff --git a/src/cmd5.cc b/src/cmd5.cc index e03793be..35d146e9 100644 --- a/src/cmd5.cc +++ b/src/cmd5.cc @@ -823,7 +823,7 @@ cptr symbiote_name(bool_ capitalize) if (r_ptr->flags1 & RF1_UNIQUE) { /* Unique monster; no preceding "your", and ignore our name. */ - strncpy(buf, r_name + r_ptr->name, sizeof(buf)); + strncpy(buf, r_ptr->name, sizeof(buf)); } else if (o_ptr->note && (s = strstr(quark_str(o_ptr->note), "#named ")) != NULL) @@ -835,7 +835,7 @@ cptr symbiote_name(bool_ capitalize) { /* No special cases, just return "Your ". */ strcpy(buf, "your "); - strncpy(buf + 5, r_name + r_ptr->name, sizeof(buf) - 5); + strncpy(buf + 5, r_ptr->name, sizeof(buf) - 5); } } diff --git a/src/dungeon.cc b/src/dungeon.cc index 02715e43..6b5153a1 100644 --- a/src/dungeon.cc +++ b/src/dungeon.cc @@ -3066,8 +3066,7 @@ static void process_world(void) if ((r_ptr->flags9 & RF9_IMPRESED) && can_create_companion()) { - msg_format("And you have given the imprint to your %s!", - r_name + r_ptr->name); + msg_format("And you have given the imprint to your %s!", r_ptr->name); m_ptr->status = MSTATUS_COMPANION; } diff --git a/src/externs.h b/src/externs.h index c5fd4c73..d8297277 100644 --- a/src/externs.h +++ b/src/externs.h @@ -363,10 +363,7 @@ extern char *e_text; extern header *ra_head; extern randart_part_type *ra_info; extern randart_gen_type ra_gen[30]; -extern header *r_head; extern monster_race *r_info; -extern char *r_name; -extern char *r_text; extern header *re_head; extern monster_ego *re_info; extern char *re_name; diff --git a/src/files.cc b/src/files.cc index 728a01ad..b2177ed2 100644 --- a/src/files.cc +++ b/src/files.cc @@ -2183,7 +2183,7 @@ void display_player(int mode) sprintf(buf, "%s", get_player_race_name(p_ptr->prace, p_ptr->pracem)); c_put_str(TERM_L_BLUE, buf, 4, 9); c_put_str(TERM_L_BLUE, spp_ptr->title + c_name, 5, 9); - c_put_str(TERM_L_BLUE, r_name + r_ptr->name, 6, 9); + c_put_str(TERM_L_BLUE, r_ptr->name, 6, 9); c_put_str(TERM_L_BLUE, deity_info[p_ptr->pgod].name, 7, 9); /* Age, Height, Weight, Social */ diff --git a/src/generate.cc b/src/generate.cc index 73503e4d..593a37cd 100644 --- a/src/generate.cc +++ b/src/generate.cc @@ -2738,8 +2738,7 @@ static bool_ vault_aux_chapel(int r_idx) if (r_ptr->flags1 & (RF1_UNIQUE)) return (FALSE); /* Require "priest" or Angel */ - if (!((r_ptr->d_char == 'A') || - strstr((r_name + r_ptr->name), "riest"))) + if (!((r_ptr->d_char == 'A') || strstr(r_ptr->name, "riest"))) { return (FALSE); } @@ -3452,7 +3451,7 @@ static void build_type6(int by0, int bx0) for (i = 0; i < 8; i++) { /* Message */ - msg_print(r_name + r_info[what[i]].name); + msg_print(r_info[what[i]].name); } } } diff --git a/src/init1.cc b/src/init1.cc index 8696e18a..4fc3513d 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1498,6 +1498,33 @@ static byte monster_ego_modify(char c) } } +/** + * Append one string to the end of another, reallocating if + * necessary. + */ +static void strappend(char **s, char *t) +{ + // Do we need to initialize the destination string? + if (*s == nullptr) + { + // Costs an extra allocation which could be avoided + // but this leads to simpler code. + *s = strdup(""); + } + // We should really be preserving the original pointer and + // do something else in case of failure to realloc(), but + // instead we just do the lazy thing and call abort() if + // reallocation fails. In practice it won't. + *s = static_cast(realloc(*s, strlen(*s) + strlen(t) + 1)); + if (*s == nullptr) + { + abort(); // Cannot handle failure to reallocate + } + + /* Append 't' to the destination string */ + strcat(*s, t); +} + /* * Implements fp stacks, for included files */ @@ -7485,10 +7512,6 @@ errr init_r_info_txt(FILE *fp, char *buf) error_line = -1; - /* Start the "fake" stuff */ - r_head->name_size = 0; - r_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -7550,7 +7573,7 @@ errr init_r_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= r_head->info_num) return (2); + if (i >= max_r_idx) return (2); /* Save the index */ error_idx = i; @@ -7558,17 +7581,9 @@ errr init_r_info_txt(FILE *fp, char *buf) /* Point at the "info" */ r_ptr = &r_info[i]; - /* Hack -- Verify space */ - if (r_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!r_ptr->name) r_ptr->name = ++r_head->name_size; - - /* Append chars to the name */ - strcpy(r_name + r_head->name_size, s); - - /* Advance the index */ - r_head->name_size += strlen(s); + /* Allocate name string. */ + assert(!r_ptr->name); // Sanity check that we aren't overwriting anything + r_ptr->name = strdup(s); /* HACK -- Those ones HAVE to have a set default value */ r_ptr->drops.treasure = OBJ_GENE_TREASURE; @@ -7591,17 +7606,8 @@ errr init_r_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (r_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!r_ptr->text) r_ptr->text = ++r_head->text_size; - - /* Append chars to the name */ - strcpy(r_text + r_head->text_size, s); - - /* Advance the index */ - r_head->text_size += strlen(s); + /* Append to description */ + strappend(&r_ptr->text, s); /* Next... */ continue; @@ -7853,11 +7859,7 @@ errr init_r_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++r_head->name_size; - ++r_head->text_size; - + /* Postprocessing */ for (i = 1; i < max_r_idx; i++) { /* Invert flag WILD_ONLY <-> RF8_DUNGEON */ diff --git a/src/init2.cc b/src/init2.cc index af6d2799..deb33324 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -841,19 +841,10 @@ static errr init_r_info(void) char buf[1024]; - /*** Make the header ***/ - r_head = make_header(max_r_idx); - - /*** Make the fake arrays ***/ /* Allocate the "r_info" array */ - r_info = make_array(r_head->info_num); - - /* Hack -- make "fake" arrays */ - r_name = make_array(FAKE_NAME_SIZE); - r_text = make_array(FAKE_TEXT_SIZE); - + r_info = make_array(max_r_idx); /*** Load the ascii template file ***/ diff --git a/src/melee1.cc b/src/melee1.cc index 59c6a9a3..09caa4aa 100644 --- a/src/melee1.cc +++ b/src/melee1.cc @@ -12,7 +12,9 @@ #include "angband.h" +#include +using boost::algorithm::iequals; /* * Critical blow. All hits that do 95% of total possible damage, @@ -1648,7 +1650,7 @@ bool_ make_attack_normal(int m_idx, byte divis) { act = "bites you."; do_cut = 1; - if (magik(5) && (strstr(r_name + r_ptr->name, "Vampire") || strstr(r_name + r_ptr->name, "vampire"))) + if (magik(5) && iequals(r_ptr->name, "vampire")) do_vampire = TRUE; touched = TRUE; sound(SOUND_BITE); @@ -1774,7 +1776,7 @@ bool_ make_attack_normal(int m_idx, byte divis) case RBM_MOAN: { - if (strstr((r_name + r_ptr->name), "Mathilde, the Science Student")) + if (strstr(r_ptr->name, "Mathilde, the Science Student")) act = desc_moan[rand_int(3) + 4]; else act = desc_moan[rand_int(4)]; @@ -2141,8 +2143,7 @@ bool_ make_attack_normal(int m_idx, byte divis) } else { - if (strstr((r_name + r_ptr->name), "black market") - && randint(2) != 1) + if (strstr(r_ptr->name, "black market") && randint(2) != 1) { s16b o_idx; diff --git a/src/monster1.cc b/src/monster1.cc index 81800962..f1968807 100644 --- a/src/monster1.cc +++ b/src/monster1.cc @@ -337,7 +337,7 @@ static void roff_aux(int r_idx, int ego, int remem) char buf[2048]; /* Simple method */ - strcpy(buf, r_text + r_ptr->text); + strcpy(buf, r_ptr->text); /* Dump it */ text_out(buf); @@ -1534,12 +1534,18 @@ static void roff_name(int r_idx, int ego) /* Dump the name */ if (ego) { - if (re_info[ego].before) Term_addstr( -1, TERM_WHITE, format("%s %s", re_name + re_info[ego].name, r_name + r_ptr->name)); - else Term_addstr( -1, TERM_WHITE, format("%s %s", r_name + r_ptr->name, re_name + re_info[ego].name)); + if (re_info[ego].before) + { + Term_addstr( -1, TERM_WHITE, format("%s %s", re_name + re_info[ego].name, r_ptr->name)); + } + else + { + Term_addstr( -1, TERM_WHITE, format("%s %s", r_ptr->name, re_name + re_info[ego].name)); + } } else { - Term_addstr( -1, TERM_WHITE, r_name + r_ptr->name); + Term_addstr( -1, TERM_WHITE, r_ptr->name); } /* Append the "standard" attr/char info */ diff --git a/src/monster2.cc b/src/monster2.cc index 21cb790a..1c814a71 100644 --- a/src/monster2.cc +++ b/src/monster2.cc @@ -1217,19 +1217,24 @@ void monster_desc(char *desc, monster_type *m_ptr, int mode) { cptr res; monster_race *r_ptr = race_inf(m_ptr); - cptr b_name = (r_name + r_ptr->name); char silly_name[80], name[100]; bool_ seen, pron; int insanity = (p_ptr->msane - p_ptr->csane) * 100 / p_ptr->msane; if (m_ptr->ego) { - if (re_info[m_ptr->ego].before) sprintf(name, "%s %s", re_name + re_info[m_ptr->ego].name, b_name); - else sprintf(name, "%s %s", b_name, re_name + re_info[m_ptr->ego].name); + if (re_info[m_ptr->ego].before) + { + sprintf(name, "%s %s", re_name + re_info[m_ptr->ego].name, r_ptr->name); + } + else + { + sprintf(name, "%s %s", r_ptr->name, re_name + re_info[m_ptr->ego].name); + } } else { - sprintf(name, "%s", b_name); + sprintf(name, "%s", r_ptr->name); } /* @@ -1248,7 +1253,7 @@ void monster_desc(char *desc, monster_type *m_ptr, int mode) } while (hallu_race->flags1 & RF1_UNIQUE); - strcpy(silly_name, (r_name + hallu_race->name)); + strcpy(silly_name, hallu_race->name); } else { @@ -1425,17 +1430,22 @@ void monster_desc(char *desc, monster_type *m_ptr, int mode) void monster_race_desc(char *desc, int r_idx, int ego) { monster_race *r_ptr = &r_info[r_idx]; - cptr b_name = (r_name + r_ptr->name); char name[80]; if (ego) { - if (re_info[ego].before) sprintf(name, "%s %s", re_name + re_info[ego].name, b_name); - else sprintf(name, "%s %s", b_name, re_name + re_info[ego].name); + if (re_info[ego].before) + { + sprintf(name, "%s %s", re_name + re_info[ego].name, r_ptr->name); + } + else + { + sprintf(name, "%s %s", r_ptr->name, re_name + re_info[ego].name); + } } else { - sprintf(name, "%s", b_name); + sprintf(name, "%s", r_ptr->name); } /* It could be a Unique */ @@ -2115,8 +2125,6 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status) monster_race *r_ptr = &r_info[r_idx]; - cptr name = (r_name + r_ptr->name); - /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */ if (p_ptr->wild_mode) { @@ -2269,7 +2277,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status) if (r_ptr->flags1 & (RF1_UNIQUE)) { /* Message for cheaters */ - if ((cheat_hear) || (p_ptr->precognition)) msg_format("Deep Unique (%s).", name); + if ((cheat_hear) || (p_ptr->precognition)) msg_format("Deep Unique (%s).", r_ptr->name); /* Boost rating by twice delta-depth */ rating += (r_ptr->level - dun_level) * 2; @@ -2279,7 +2287,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status) else { /* Message for cheaters */ - if ((cheat_hear) || (p_ptr->precognition)) msg_format("Deep Monster (%s).", name); + if ((cheat_hear) || (p_ptr->precognition)) msg_format("Deep Monster (%s).", r_ptr->name); /* Boost rating by delta-depth */ rating += (r_ptr->level - dun_level); @@ -2290,7 +2298,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status) else if (r_ptr->flags1 & (RF1_UNIQUE)) { /* Unique monsters induce message */ - if ((cheat_hear) || (p_ptr->precognition)) msg_format("Unique (%s).", name); + if ((cheat_hear) || (p_ptr->precognition)) msg_format("Unique (%s).", r_ptr->name); } @@ -3185,7 +3193,7 @@ bool_ summon_specific_okay(int r_idx) case SUMMON_DAWN: { - okay = ((strstr((r_name + r_ptr->name), "the Dawn")) && + okay = ((strstr(r_ptr->name, "the Dawn")) && !(r_ptr->flags1 & (RF1_UNIQUE))); break; } @@ -3234,14 +3242,14 @@ bool_ summon_specific_okay(int r_idx) case SUMMON_PHANTOM: { - okay = ((strstr((r_name + r_ptr->name), "Phantom")) && + okay = ((strstr(r_ptr->name, "Phantom")) && !(r_ptr->flags1 & (RF1_UNIQUE))); break; } case SUMMON_ELEMENTAL: { - okay = ((strstr((r_name + r_ptr->name), "lemental")) && + okay = ((strstr(r_ptr->name, "lemental")) && !(r_ptr->flags1 & (RF1_UNIQUE))); break; } @@ -3254,21 +3262,21 @@ bool_ summon_specific_okay(int r_idx) case SUMMON_BLUE_HORROR: { - okay = ((strstr((r_name + r_ptr->name), "lue horror")) && + okay = ((strstr(r_ptr->name, "lue horror")) && !(r_ptr->flags1 & (RF1_UNIQUE))); break; } case SUMMON_BUG: { - okay = ((strstr((r_name + r_ptr->name), "Software bug")) && + okay = ((strstr(r_ptr->name, "Software bug")) && !(r_ptr->flags1 & (RF1_UNIQUE))); break; } case SUMMON_RNG: { - okay = ((strstr((r_name + r_ptr->name), "Random Number Generator")) && + okay = ((strstr(r_ptr->name, "Random Number Generator")) && !(r_ptr->flags1 & (RF1_UNIQUE))); break; } diff --git a/src/object1.cc b/src/object1.cc index 9e01eebd..fe38d081 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1497,9 +1497,9 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) monster_race* r_ptr = &r_info[o_ptr->pval2]; modstr = basenm; if (r_ptr->flags1 & RF1_UNIQUE) - basenm = format("& %s's #~", r_name + r_ptr->name); + basenm = format("& %s's #~", r_ptr->name); else - basenm = format("& %s #~", r_name + r_ptr->name); + basenm = format("& %s #~", r_ptr->name); break; } @@ -1508,7 +1508,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) monster_race* r_ptr = &r_info[o_ptr->pval2]; modstr = basenm; - basenm = format("& %s #~", r_name + r_ptr->name); + basenm = format("& %s #~", r_ptr->name); break; } @@ -1517,7 +1517,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* We print hit points further down. --dsb */ monster_race* r_ptr = &r_info[o_ptr->pval]; modstr = basenm; - basenm = format("& %s~", r_name + r_ptr->name); + basenm = format("& %s~", r_ptr->name); break; } diff --git a/src/q_rand.cc b/src/q_rand.cc index 4dabeacc..ec84db69 100644 --- a/src/q_rand.cc +++ b/src/q_rand.cc @@ -418,10 +418,10 @@ static bool_ quest_random_feeling_hook(void *, void *, void *) if (is_randhero(dun_level)) { cmsg_format(TERM_YELLOW, "A strange man wrapped in a dark cloak steps out of the shadows:"); - cmsg_format(TERM_YELLOW, "'Oh, please help me! A horrible %s stole my sword! I'm nothing without it.'", r_info[random_quests[dun_level].r_idx].name + r_name); + cmsg_format(TERM_YELLOW, "'Oh, please help me! A horrible %s stole my sword! I'm nothing without it.'", r_info[random_quests[dun_level].r_idx].name); } else - cmsg_format(TERM_YELLOW, "You hear someone shouting: 'Leave me alone, stupid %s'", r_info[random_quests[dun_level].r_idx].name + r_name); + cmsg_format(TERM_YELLOW, "You hear someone shouting: 'Leave me alone, stupid %s'", r_info[random_quests[dun_level].r_idx].name); return (FALSE); } @@ -598,14 +598,12 @@ bool_ quest_random_describe(FILE *fff) { fprintf(fff, "#####yCaptured princess!\n"); fprintf(fff, "A princess is being held prisoner and tortured here!\n"); - fprintf(fff, "Save her from the horrible %s.\n", - r_info[random_quests[dun_level].r_idx].name + r_name); + fprintf(fff, "Save her from the horrible %s.\n", r_info[random_quests[dun_level].r_idx].name); } else { fprintf(fff, "#####yLost sword!\n"); - fprintf(fff, "An adventurer lost his sword to a bunch of %s!\n", - r_info[random_quests[dun_level].r_idx].name + r_name); + fprintf(fff, "An adventurer lost his sword to a bunch of %s!\n", r_info[random_quests[dun_level].r_idx].name); fprintf(fff, "Kill them all to get it back.\n"); } fprintf(fff, "Number: %d, Killed: %ld.\n", diff --git a/src/spells1.cc b/src/spells1.cc index 0eda200c..c7b02580 100644 --- a/src/spells1.cc +++ b/src/spells1.cc @@ -4354,8 +4354,6 @@ bool_ project_m(int who, int r, int y, int x, int dam, int typ) char killer [80]; - cptr name = (r_name + r_ptr->name); - /* Is the monster "seen"? */ bool_ seen; @@ -4827,8 +4825,8 @@ bool_ project_m(int who, int r, int y, int x, int dam, int typ) { if (seen) obvious = TRUE; if ((r_ptr->d_char == 'E') && - (prefix(name, "W") || - (strstr((r_name + r_ptr->name), "Unmaker")))) + (prefix(r_ptr->name, "W") || + (strstr(r_ptr->name, "Unmaker")))) { note = " is immune."; dam = 0; @@ -4848,8 +4846,8 @@ bool_ project_m(int who, int r, int y, int x, int dam, int typ) { if (seen) obvious = TRUE; if ((r_ptr->d_char == 'E') && - (prefix(name, "W") || - (strstr((r_name + r_ptr->name), "Unmaker")))) + (prefix(r_ptr->name, "W") || + (strstr(r_ptr->name, "Unmaker")))) { note = " is immune."; dam = 0; diff --git a/src/spells2.cc b/src/spells2.cc index a5add8d4..c837a059 100644 --- a/src/spells2.cc +++ b/src/spells2.cc @@ -5110,8 +5110,9 @@ bool_ genocide_aux(bool_ player_cast, char typ) { int wx, wy; int attempts = 500; + char buf[256]; - monster_race_desc(r_name, m_ptr->r_idx, 0); + monster_race_desc(buf, m_ptr->r_idx, 0); do { @@ -5121,7 +5122,7 @@ bool_ genocide_aux(bool_ player_cast, char typ) if (place_monster_aux(wy, wx, m_ptr->r_idx, FALSE, TRUE, MSTATUS_ENEMY)) { - cmsg_format(TERM_L_BLUE, "The spell seems to produce an ... interesting effect on the %s.", r_name); + cmsg_format(TERM_L_BLUE, "The spell seems to produce an ... interesting effect on the %s.", buf); } return TRUE; @@ -5235,8 +5236,9 @@ bool_ mass_genocide(bool_ player_cast) { int wx, wy; int attempts = 500; + char buf[256]; - monster_race_desc(r_name, m_ptr->r_idx, 0); + monster_race_desc(buf, m_ptr->r_idx, 0); do { @@ -5246,7 +5248,7 @@ bool_ mass_genocide(bool_ player_cast) if (place_monster_aux(wy, wx, m_ptr->r_idx, FALSE, TRUE, MSTATUS_ENEMY)) { - cmsg_format(TERM_L_BLUE, "The spell seems to produce an ... interesting effect on the %s.", r_name); + cmsg_format(TERM_L_BLUE, "The spell seems to produce an ... interesting effect on the %s.", buf); } return TRUE; diff --git a/src/types.h b/src/types.h index e741c6a8..b6ddbf36 100644 --- a/src/types.h +++ b/src/types.h @@ -424,8 +424,8 @@ typedef struct monster_race monster_race; struct monster_race { - u32b name; /* Name (offset) */ - u32b text; /* Text (offset) */ + const char *name; /* Name */ + char *text; /* Text */ u16b hdice; /* Creatures hit dice count */ u16b hside; /* Creatures hit dice sides */ diff --git a/src/util.cc b/src/util.cc index a9769d31..f4f03d0c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -3364,7 +3364,6 @@ void strlower(char *buf) * must exactly match (look out for commas and the like!), or else 0 is * returned. Case doesn't matter. -GSN- */ - int test_monster_name(cptr name) { int i; @@ -3373,11 +3372,11 @@ int test_monster_name(cptr name) for (i = 1; i < max_r_idx; i++) { monster_race *r_ptr = &r_info[i]; - cptr mon_name = r_name + r_ptr->name; - if (iequals(name, mon_name)) return (i); + if (r_ptr->name && iequals(name, r_ptr->name)) return (i); } return (0); } + int test_mego_name(cptr name) { int i; diff --git a/src/variable.cc b/src/variable.cc index f812243a..ca4603c8 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -672,8 +672,6 @@ char *t_text; */ header *r_head; monster_race *r_info; -char *r_name; -char *r_text; /* * The monster ego race arrays diff --git a/src/wizard1.cc b/src/wizard1.cc index 883ed5a6..3f68a5ea 100644 --- a/src/wizard1.cc +++ b/src/wizard1.cc @@ -1370,16 +1370,14 @@ static void spoil_mon_desc(cptr fname) { monster_race *r_ptr = &r_info[who_i]; - cptr name = (r_name + r_ptr->name); - /* Get the "name" */ if (r_ptr->flags1 & (RF1_UNIQUE)) { - sprintf(nam, "[U] %s", name); + sprintf(nam, "[U] %s", r_ptr->name); } else { - sprintf(nam, "The %s", name); + sprintf(nam, "The %s", r_ptr->name); } @@ -1525,7 +1523,7 @@ static void spoil_mon_info(cptr fname) } /* Name */ - sprintf(buf, "%s (", (r_name + r_ptr->name)); /* ---)--- */ + sprintf(buf, "%s (", r_ptr->name); /* ---)--- */ spoil_out(buf); /* Color */ @@ -1584,7 +1582,7 @@ static void spoil_mon_info(cptr fname) /* Describe */ - spoil_out(r_text + r_ptr->text); + spoil_out(r_ptr->text); spoil_out(" "); diff --git a/src/xtra1.cc b/src/xtra1.cc index aeb31a06..035da22d 100644 --- a/src/xtra1.cc +++ b/src/xtra1.cc @@ -1431,11 +1431,11 @@ static void fix_m_list(void) /* Dump the monster name */ if (r_ptr->total_visible == 1) { - c_prt(attr, (r_name + r_ptr->name), (num % (h - 1)) + 1, (num / (h - 1) * 26)); + c_prt(attr, r_ptr->name, (num % (h - 1)) + 1, (num / (h - 1) * 26)); } else { - c_prt(attr, format("%s (x%d)", r_name + r_ptr->name, r_ptr->total_visible), (num % (h - 1)) + 1, (num / (h - 1)) * 26); + c_prt(attr, format("%s (x%d)", r_ptr->name, r_ptr->total_visible), (num % (h - 1)) + 1, (num / (h - 1)) * 26); } num++; diff --git a/src/xtra2.cc b/src/xtra2.cc index 2fb56f59..f972299f 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -2250,7 +2250,7 @@ void lose_exp(s32b amount) */ int get_coin_type(monster_race *r_ptr) { - cptr name = (r_name + r_ptr->name); + cptr name = r_ptr->name; /* Analyze "coin" monsters */ if (r_ptr->d_char == '$') @@ -2687,7 +2687,7 @@ void monster_death(int m_idx) object_level = (dun_level + m_ptr->level) / 2; /* Mega^2-hack -- destroying the Stormbringer gives it us! */ - if (strstr((r_name + r_ptr->name), "Stormbringer")) + if (strstr(r_ptr->name, "Stormbringer")) { /* Get local object */ q_ptr = &forge; @@ -2737,7 +2737,7 @@ void monster_death(int m_idx) * Mega^3-hack: killing a 'Warrior of the Dawn' is likely to * spawn another in the fallen one's place! */ - else if (strstr((r_name + r_ptr->name), "the Dawn")) + else if (strstr(r_ptr->name, "the Dawn")) { if (!(randint(20) == 13)) { @@ -2773,13 +2773,13 @@ void monster_death(int m_idx) } /* One more ultra-hack: An Unmaker goes out with a big bang! */ - else if (strstr((r_name + r_ptr->name), "Unmaker")) + else if (strstr(r_ptr->name, "Unmaker")) { int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL; (void)project(m_idx, 6, y, x, 100, GF_CHAOS, flg); } /* Pink horrors are replaced with 2 Blue horrors */ - else if (strstr((r_name + r_ptr->name), "ink horror")) + else if (strstr(r_ptr->name, "ink horror")) { for (i = 0; i < 2; i++) { @@ -2806,7 +2806,7 @@ void monster_death(int m_idx) /* Mega-Hack -- drop "winner" treasures */ else if (r_ptr->flags1 & (RF1_DROP_CHOSEN)) { - if (strstr((r_name + r_ptr->name), "Morgoth, Lord of Darkness")) + if (strstr(r_ptr->name, "Morgoth, Lord of Darkness")) { /* Get local object */ q_ptr = &forge; @@ -2844,7 +2844,7 @@ void monster_death(int m_idx) /* Drop it in the dungeon */ drop_near(q_ptr, -1, y, x); } - else if (strstr((r_name + r_ptr->name), "Smeagol")) + else if (strstr(r_ptr->name, "Smeagol")) { /* Get local object */ q_ptr = &forge; @@ -2883,7 +2883,7 @@ void monster_death(int m_idx) create_artifact(q_ptr, TRUE, FALSE); /* Save the inscription */ - q_ptr->art_name = quark_add(format("of %s", r_name + r_ptr->name)); + q_ptr->art_name = quark_add(format("of %s", r_ptr->name)); q_ptr->found = OBJ_FOUND_MONSTER; q_ptr->found_aux1 = m_ptr->r_idx; @@ -2900,32 +2900,32 @@ void monster_death(int m_idx) int chance = 0; int I_kind = 0; - if (strstr((r_name + r_ptr->name), "Marda, rider of the Gold Laronth")) + if (strstr(r_ptr->name, "Marda, rider of the Gold Laronth")) { a_idx = ART_MARDA; chance = 50; } - else if (strstr((r_name + r_ptr->name), "Saruman of Many Colours")) + else if (strstr(r_ptr->name, "Saruman of Many Colours")) { a_idx = ART_PALANTIR; chance = 30; } - else if (strstr((r_name + r_ptr->name), "Hagen, son of Alberich")) + else if (strstr(r_ptr->name, "Hagen, son of Alberich")) { a_idx = ART_NIMLOTH; chance = 66; } - else if (strstr((r_name + r_ptr->name), "Durin's Bane")) + else if (strstr(r_ptr->name, "Durin's Bane")) { a_idx = ART_CALRIS; chance = 60; } - else if (strstr((r_name + r_ptr->name), "Gothmog, the High Captain of Balrogs")) + else if (strstr(r_ptr->name, "Gothmog, the High Captain of Balrogs")) { a_idx = ART_GOTHMOG; chance = 50; } - else if (strstr((r_name + r_ptr->name), "Eol, the Dark Elf")) + else if (strstr(r_ptr->name, "Eol, the Dark Elf")) { a_idx = ART_ANGUIREL; chance = 50; @@ -3438,11 +3438,8 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note) { char note[80]; - /* Get true name even if blinded/hallucinating */ - cptr monst = (r_name + r_ptr->name); - /* Write note */ - sprintf(note, "Killed %s", monst); + sprintf(note, "Killed %s", r_ptr->name); add_note(note, 'U'); } @@ -5706,7 +5703,7 @@ void make_wish(void) if (r_ptr->flags9 & RF9_NEVER_GENE) continue; if (r_ptr->flags1 & RF1_UNIQUE) continue; - sprintf(buf, "%s", r_ptr->name + r_name); + sprintf(buf, "%s", r_ptr->name); strlower(buf); if (strstr(mname, buf)) @@ -5722,12 +5719,18 @@ void make_wish(void) if (j) { - if (re_ptr->before) sprintf(buf, "%s %s", re_name + re_ptr->name, r_ptr->name + r_name); - else sprintf(buf, "%s %s", r_ptr->name + r_name, re_name + re_ptr->name); + if (re_ptr->before) + { + sprintf(buf, "%s %s", re_name + re_ptr->name, r_ptr->name); + } + else + { + sprintf(buf, "%s %s", r_ptr->name, re_name + re_ptr->name); + } } else { - sprintf(buf, "%s", r_ptr->name + r_name); + sprintf(buf, "%s", r_ptr->name); } strlower(buf); -- cgit v1.2.3