From e1230547a936c7180b3a69012659fc511027f035 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move re_info into GameEditData --- lib/edit/misc.txt | 5 ----- lib/mods/theme/edit/misc.txt | 5 ----- src/files.cc | 22 ++++++++++++++++------ src/game_edit_data.hpp | 6 ++++++ src/init1.cc | 43 +++++++++++++++++++------------------------ src/init2.cc | 2 +- src/monster1.cc | 2 ++ src/monster2.cc | 36 ++++++++++++++++++++++++------------ src/monster_ego_fwd.hpp | 3 --- src/object1.cc | 11 +++++------ src/util.cc | 15 +++++++++------ src/variable.cc | 10 ---------- src/variable.hpp | 3 --- src/xtra2.cc | 22 ++++++++++++++++------ 14 files changed, 98 insertions(+), 87 deletions(-) delete mode 100644 src/monster_ego_fwd.hpp diff --git a/lib/edit/misc.txt b/lib/edit/misc.txt index 0513f242..8fdf44b3 100644 --- a/lib/edit/misc.txt +++ b/lib/edit/misc.txt @@ -16,11 +16,6 @@ M:Y:66 # WARNING ! add one more to the real count for the player ghost !! M:R:1078 -# Maximum number of monsters in re_info.txt -# WARNING ! Use the exact amount of ego types used, if not you -# will get weird results ! -M:r:14 - # Maximum number of items in k_info.txt M:K:819 diff --git a/lib/mods/theme/edit/misc.txt b/lib/mods/theme/edit/misc.txt index d158a6a9..590c09a9 100644 --- a/lib/mods/theme/edit/misc.txt +++ b/lib/mods/theme/edit/misc.txt @@ -16,11 +16,6 @@ M:Y:66 # WARNING ! add one more to the real count for the player ghost !! M:R:1081 -# Maximum number of monsters in re_info.txt -# WARNING ! Use the exact amount of ego types used, if not you -# will get weird results ! -M:r:14 - # Maximum number of items in k_info.txt M:K:886 diff --git a/src/files.cc b/src/files.cc index 6e795923..6a046b10 100644 --- a/src/files.cc +++ b/src/files.cc @@ -218,6 +218,7 @@ errr process_pref_file_aux(char *buf) { auto &race_mod_info = game->edit_data.race_mod_info; auto &st_info = game->edit_data.st_info; + auto &re_info = game->edit_data.re_info; int i, j, n1, n2; @@ -274,18 +275,27 @@ errr process_pref_file_aux(char *buf) { if (tokenize(buf + 4, 3, zz, ':', '/') == 3) { - monster_ego *re_ptr; - i = (huge)strtol(zz[0], NULL, 0); + std::size_t i = strtoul(zz[0], NULL, 0); n1 = strtol(zz[1], NULL, 0); n2 = strtol(zz[2], NULL, 0); - if (i >= max_re_idx) return (1); - re_ptr = &re_info[i]; - if (n1) re_ptr->g_attr = n1; + + if (i >= re_info.size()) + { + return 1; + } + + auto re_ptr = &re_info[i]; + + if (n1) + { + re_ptr->g_attr = n1; + } if (n2) { re_ptr->g_char = n2; } - return (0); + + return 0; } } diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp index bb480f53..85da3997 100644 --- a/src/game_edit_data.hpp +++ b/src/game_edit_data.hpp @@ -3,6 +3,7 @@ #include "ability_type.hpp" #include "dungeon_info_type.hpp" #include "hist_type.hpp" +#include "monster_ego.hpp" #include "owner_type.hpp" #include "player_class.hpp" #include "player_race.hpp" @@ -89,6 +90,11 @@ struct GameEditData { */ std::vector s_descriptors; + /** + * Monster race egos + */ + std::vector re_info; + /** * Base skills for all characters. */ diff --git a/src/init1.cc b/src/init1.cc index 9431ec46..62211893 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4433,12 +4433,12 @@ errr init_r_info_txt(FILE *fp) */ errr init_re_info_txt(FILE *fp) { - int i, j; + auto &re_info = game->edit_data.re_info; + char buf[1024]; byte blow_num = 0; - int r_char_number = 0, nr_char_number = 0; - - char *s, *t; + int r_char_number = 0; + int nr_char_number = 0; /* Current entry */ monster_ego *re_ptr = NULL; @@ -4466,7 +4466,7 @@ errr init_re_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -4478,19 +4478,16 @@ errr init_re_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_re_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - re_ptr = &re_info[i]; + re_ptr = &expand_to_fit_index(re_info, i); /* Copy name */ assert(!re_ptr->name); @@ -4500,9 +4497,8 @@ errr init_re_info_txt(FILE *fp) blow_num = 0; r_char_number = 0; nr_char_number = 0; - for (j = 0; j < 5; j++) re_ptr->r_char[j] = 0; - for (j = 0; j < 5; j++) re_ptr->nr_char[j] = 0; - for (j = 0; j < 4; j++) + + for (std::size_t j = 0; j < 4; j++) { re_ptr->blow[j].method = 0; re_ptr->blow[j].effect = 0; @@ -4598,6 +4594,8 @@ errr init_re_info_txt(FILE *fp) { int n1, n2, dice, side; char mdice, mside; + char *s; + char *t; /* Oops, no more slots */ if (blow_num == 4) return (1); @@ -4658,7 +4656,7 @@ errr init_re_info_txt(FILE *fp) char r_char; /* Parse every entry */ - s = buf + 2; + char const *s = buf + 2; /* XXX XXX XXX Hack -- Read monster symbols */ if (1 == sscanf(s, "R_CHAR_%c", &r_char)) @@ -4688,7 +4686,7 @@ errr init_re_info_txt(FILE *fp) char r_char; /* Parse every entry */ - s = buf + 2; + char const *s = buf + 2; /* XXX XXX XXX Hack -- Read monster symbols */ if (1 == sscanf(s, "R_CHAR_%c", &r_char)) @@ -4727,7 +4725,7 @@ errr init_re_info_txt(FILE *fp) /* Process 'O' for "Basic Monster -Flags" (multiple lines) */ if (buf[0] == 'O') { - s = buf + 2; + char const *s = buf + 2; /* XXX XXX XXX Hack -- Read no flags */ if (!strcmp(s, "MF_ALL")) @@ -4750,7 +4748,8 @@ errr init_re_info_txt(FILE *fp) /* Process 'S' for "Spell Flags" (multiple lines) */ if (buf[0] == 'S') { - s = buf + 2; + char const *s = buf + 2; + int i; /* XXX XXX XXX Hack -- Read spell frequency */ if (1 == sscanf(s, "1_IN_%d", &i)) @@ -4775,8 +4774,10 @@ errr init_re_info_txt(FILE *fp) if (buf[0] == 'T') { /* Parse every entry */ - for (s = buf + 2; *s; ) + for (char *s = buf + 2; *s; ) { + char *t; + /* Find the end of this entry */ for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; @@ -6789,12 +6790,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_r_idx = atoi(zz[1]); } - /* Maximum re_idx */ - else if (zz[0][0] == 'r') - { - max_re_idx = atoi(zz[1]); - } - /* Maximum k_idx */ else if (zz[0][0] == 'K') { diff --git a/src/init2.cc b/src/init2.cc index 4ca60938..d574deca 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -421,7 +421,7 @@ namespace { static void allocate() { - re_info = new monster_ego[max_re_idx]; + // Nothing to do } static errr parse(FILE *fp) diff --git a/src/monster1.cc b/src/monster1.cc index 6d913367..2060b7af 100644 --- a/src/monster1.cc +++ b/src/monster1.cc @@ -1259,6 +1259,8 @@ static void roff_aux(std::shared_ptr r_ptr) */ static void roff_name(int r_idx, int ego) { + const auto &re_info = game->edit_data.re_info; + const auto r_ptr = race_info_idx(r_idx, ego); /* Access the chars */ diff --git a/src/monster2.cc b/src/monster2.cc index c2b615ee..108642df 100644 --- a/src/monster2.cc +++ b/src/monster2.cc @@ -172,7 +172,9 @@ s32b modify_aux(s32b a, s32b b, char mod) /* Is this ego ok for this monster ? */ bool_ mego_ok(monster_race const *r_ptr, int ego) { - monster_ego *re_ptr = &re_info[ego]; + const auto &re_info = game->edit_data.re_info; + + auto re_ptr = &re_info[ego]; bool_ ok = FALSE; int i; @@ -206,10 +208,11 @@ bool_ mego_ok(monster_race const *r_ptr, int ego) /* Choose an ego type */ static int pick_ego_monster(monster_race const *r_ptr) { + const auto &re_info = game->edit_data.re_info; + /* Assume no ego */ int ego = 0, lvl; - int tries = max_re_idx + 10; - monster_ego *re_ptr; + int tries = re_info.size() + 10; if ((!(dungeon_flags & DF_ELVEN)) && (!(dungeon_flags & DF_DWARVEN))) { @@ -223,8 +226,8 @@ static int pick_ego_monster(monster_race const *r_ptr) while (tries--) { /* Pick one */ - ego = rand_range(1, max_re_idx - 1); - re_ptr = &re_info[ego]; + ego = rand_range(1, re_info.size() - 1); + auto re_ptr = &re_info[ego]; /* No hope so far */ if (!mego_ok(r_ptr, ego)) continue; @@ -266,6 +269,7 @@ static int pick_ego_monster(monster_race const *r_ptr) std::shared_ptr race_info_idx(int r_idx, int ego) { monster_race *r_ptr = &r_info[r_idx]; + const auto &re_info = game->edit_data.re_info; /* We don't need to allocate anything if it's an ordinary monster. */ if (!ego) { @@ -279,7 +283,7 @@ std::shared_ptr race_info_idx(int r_idx, int ego) *nr_ptr = *r_ptr; /* Get a reference to the ego monster modifiers */ - monster_ego *re_ptr = &re_info[ego]; + auto re_ptr = &re_info[ego]; /* Adjust the values */ for (int i = 0; i < 4; i++) @@ -1159,6 +1163,8 @@ s16b get_mon_num(int level) */ void monster_desc(char *desc, monster_type *m_ptr, int mode) { + const auto &re_info = game->edit_data.re_info; + auto r_ptr = m_ptr->race(); char silly_name[80], name[100]; bool_ seen, pron; @@ -1166,13 +1172,15 @@ void monster_desc(char *desc, monster_type *m_ptr, int mode) if (m_ptr->ego) { - if (re_info[m_ptr->ego].before) + auto const &monster_ego = re_info[m_ptr->ego]; + + if (monster_ego.before) { - sprintf(name, "%s %s", re_info[m_ptr->ego].name, r_ptr->name); + sprintf(name, "%s %s", monster_ego.name, r_ptr->name); } else { - sprintf(name, "%s %s", r_ptr->name, re_info[m_ptr->ego].name); + sprintf(name, "%s %s", r_ptr->name, monster_ego.name); } } else @@ -1371,18 +1379,22 @@ void monster_desc(char *desc, monster_type *m_ptr, int mode) void monster_race_desc(char *desc, int r_idx, int ego) { + const auto &re_info = game->edit_data.re_info; + monster_race *r_ptr = &r_info[r_idx]; char name[80]; if (ego) { - if (re_info[ego].before) + auto const &monster_ego = re_info[ego]; + + if (monster_ego.before) { - sprintf(name, "%s %s", re_info[ego].name, r_ptr->name); + sprintf(name, "%s %s", monster_ego.name, r_ptr->name); } else { - sprintf(name, "%s %s", r_ptr->name, re_info[ego].name); + sprintf(name, "%s %s", r_ptr->name, monster_ego.name); } } else diff --git a/src/monster_ego_fwd.hpp b/src/monster_ego_fwd.hpp deleted file mode 100644 index 5b47f3e9..00000000 --- a/src/monster_ego_fwd.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -struct monster_ego; diff --git a/src/object1.cc b/src/object1.cc index 656446c3..c98e2ed5 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -635,6 +635,7 @@ void reset_visuals(void) { auto &st_info = game->edit_data.st_info; auto &race_mod_info = game->edit_data.race_mod_info; + auto &re_info = game->edit_data.re_info; int i; @@ -677,17 +678,15 @@ void reset_visuals(void) } /* Reset attr/char code for ego monster overlay graphics */ - for (i = 0; i < max_re_idx; i++) + for (auto &re_ref: re_info) { - monster_ego *re_ptr = &re_info[i]; - /* Default attr/char */ - re_ptr->g_attr = 0; - re_ptr->g_char = 0; + re_ref.g_attr = 0; + re_ref.g_char = 0; } /* Reset attr/char code for race modifier overlay graphics */ - for (player_race_mod &rmp: race_mod_info) + for (auto &rmp: race_mod_info) { /* Default attr/char */ rmp.g_attr = 0; diff --git a/src/util.cc b/src/util.cc index cd1c0c4f..231a249f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -3339,17 +3339,20 @@ int test_monster_name(cptr name) return (0); } -int test_mego_name(cptr name) +int test_mego_name(cptr needle) { - int i; + const auto &re_info = game->edit_data.re_info; /* Scan the monsters */ - for (i = 1; i < max_re_idx; i++) + for (std::size_t i = 0; i < re_info.size(); i++) { - monster_ego *re_ptr = &re_info[i]; - if (re_ptr->name && iequals(name, re_ptr->name)) return (i); + auto name = re_info[i].name; + if (name && iequals(name, needle)) + { + return i; + } } - return (0); + return 0; } /* diff --git a/src/variable.cc b/src/variable.cc index 0e892bf3..35aeff7f 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -457,11 +457,6 @@ trap_type *t_info; */ monster_race *r_info; -/* - * The monster ego race arrays - */ -monster_ego *re_info; - /* * The wilderness features arrays */ @@ -589,11 +584,6 @@ s32b get_level_use_stick = -1; */ u16b max_r_idx; -/* - * Maximum number of ego monsters in re_info.txt - */ -u16b max_re_idx; - /* * Maximum number of items in k_info.txt */ diff --git a/src/variable.hpp b/src/variable.hpp index 35d482dc..a1cc5266 100644 --- a/src/variable.hpp +++ b/src/variable.hpp @@ -11,7 +11,6 @@ #include "ego_item_type_fwd.hpp" #include "fate.hpp" #include "feature_type_fwd.hpp" -#include "monster_ego_fwd.hpp" #include "monster_race_fwd.hpp" #include "monster_type_fwd.hpp" #include "object_kind_fwd.hpp" @@ -160,7 +159,6 @@ extern object_kind *k_info; extern artifact_type *a_info; extern ego_item_type *e_info; extern monster_race *r_info; -extern monster_ego *re_info; extern trap_type *t_info; extern wilderness_type_info *wf_info; extern int wildc2i[256]; @@ -175,7 +173,6 @@ extern bool_ (*get_mon_num_hook)(int r_idx); extern bool_ (*get_mon_num2_hook)(int r_idx); extern bool_ (*get_obj_num_hook)(int k_idx); extern u16b max_r_idx; -extern u16b max_re_idx; extern u16b max_k_idx; extern u16b max_f_idx; extern u16b max_a_idx; diff --git a/src/xtra2.cc b/src/xtra2.cc index abb9957e..14cc9bc9 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -5151,11 +5151,14 @@ static void clean_wish_name(char *buf, char *name) */ void make_wish(void) { - char buf[200], name[200], *mname; - int i, j, mstatus = MSTATUS_ENEMY; + const auto &re_info = game->edit_data.re_info; + + char name[200], *mname; + int mstatus = MSTATUS_ENEMY; object_type forge, *o_ptr = &forge; /* Make an empty string */ + char buf[200]; buf[0] = 0; /* Ask for the wish */ @@ -5207,8 +5210,12 @@ void make_wish(void) else mstatus = MSTATUS_PET; mname = name + 10; } - else mname = name; - for (i = 1; i < max_r_idx; i++) + else + { + mname = name; + } + + for (std::size_t i = 1; i < max_r_idx; i++) { monster_race *r_ptr = &r_info[i]; @@ -5224,9 +5231,9 @@ void make_wish(void) if (strstr(mname, buf)) { /* try all ego */ - for (j = max_re_idx - 1; j >= 0; j--) + for (std::size_t j = 0; j < re_info.size(); j++) { - monster_ego *re_ptr = &re_info[j]; + auto re_ptr = &re_info[j]; if (j && !re_ptr->name) continue; @@ -5247,6 +5254,7 @@ void make_wish(void) { sprintf(buf, "%s", r_ptr->name); } + strlower(buf); if (iequals(mname, buf)) @@ -5262,7 +5270,9 @@ void make_wish(void) /* Create the monster */ if (place_monster_one(wy, wx, i, j, FALSE, mstatus)) + { msg_print("Your wish becomes truth!"); + } /* Don't search any more */ return; -- cgit v1.2.3