summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-10-05 18:45:08 +0200
committerBardur Arantsson <bardur@scientician.net>2016-10-05 18:49:37 +0200
commit0c2f30b56c221a826ba64f0ec864c29d0f717644 (patch)
treea7b38e7b9cf9a06aacd56ec8a7177d44d001c1df
parent5ddcbbf1cdce68e565376819efedd519892512ad (diff)
Move r_info into GameEditData
-rw-r--r--lib/edit/misc.txt4
-rw-r--r--lib/mods/theme/edit/misc.txt4
-rw-r--r--src/birth.cc5
-rw-r--r--src/cave.cc10
-rw-r--r--src/cmd1.cc31
-rw-r--r--src/cmd2.cc32
-rw-r--r--src/cmd3.cc22
-rw-r--r--src/cmd4.cc43
-rw-r--r--src/cmd5.cc8
-rw-r--r--src/cmd6.cc21
-rw-r--r--src/cmd7.cc8
-rw-r--r--src/dungeon.cc7
-rw-r--r--src/files.cc81
-rw-r--r--src/game_edit_data.hpp6
-rw-r--r--src/generate.cc55
-rw-r--r--src/init1.cc31
-rw-r--r--src/init2.cc20
-rw-r--r--src/loadsave.cc12
-rw-r--r--src/melee1.cc5
-rw-r--r--src/melee2.cc25
-rw-r--r--src/monster1.cc52
-rw-r--r--src/monster2.cc68
-rw-r--r--src/monster3.cc19
-rw-r--r--src/object1.cc42
-rw-r--r--src/object2.cc40
-rw-r--r--src/q_bounty.cc4
-rw-r--r--src/q_eol.cc5
-rw-r--r--src/q_main.cc19
-rw-r--r--src/q_poison.cc5
-rw-r--r--src/q_rand.cc5
-rw-r--r--src/q_shroom.cc5
-rw-r--r--src/spells1.cc14
-rw-r--r--src/spells2.cc4
-rw-r--r--src/traps.cc12
-rw-r--r--src/util.cc12
-rw-r--r--src/variable.cc10
-rw-r--r--src/variable.hpp3
-rw-r--r--src/wild.cc7
-rw-r--r--src/wizard2.cc14
-rw-r--r--src/wizard2.hpp2
-rw-r--r--src/xtra1.cc37
-rw-r--r--src/xtra2.cc13
42 files changed, 540 insertions, 282 deletions
diff --git a/lib/edit/misc.txt b/lib/edit/misc.txt
index 2c24b14b..02e286b4 100644
--- a/lib/edit/misc.txt
+++ b/lib/edit/misc.txt
@@ -12,10 +12,6 @@ M:X:101
# Maximum y size of the wilderness
M:Y:66
-# Maximum number of monsters in r_info.txt
-# WARNING ! add one more to the real count for the player ghost !!
-M:R:1078
-
# 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 017089e7..19077acb 100644
--- a/lib/mods/theme/edit/misc.txt
+++ b/lib/mods/theme/edit/misc.txt
@@ -12,10 +12,6 @@ M:X:101
# Maximum y size of the wilderness
M:Y:66
-# Maximum number of monsters in r_info.txt
-# WARNING ! add one more to the real count for the player ghost !!
-M:R:1081
-
# Maximum number of items in k_info.txt
M:K:886
diff --git a/src/birth.cc b/src/birth.cc
index fe814978..083fe06c 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -720,6 +720,7 @@ static void birth_put_stats(void)
static void player_wipe(void)
{
auto const &d_info = game->edit_data.d_info;
+ auto &r_info = game->edit_data.r_info;
/* Wipe special levels */
wipe_saved();
@@ -805,9 +806,9 @@ static void player_wipe(void)
/* Reset the "monsters" */
- for (std::size_t i = 1; i < max_r_idx; i++)
+ for (auto &r_ref: r_info)
{
- monster_race *r_ptr = &r_info[i];
+ auto r_ptr = &r_ref;
/* Hack -- Reset the counter */
r_ptr->cur_num = 0;
diff --git a/src/cave.cc b/src/cave.cc
index 92f57c95..08482dcc 100644
--- a/src/cave.cc
+++ b/src/cave.cc
@@ -402,6 +402,8 @@ bool_ cave_valid_bold(int y, int x)
*/
static void image_monster(byte *ap, char *cp)
{
+ auto const &r_info = game->edit_data.r_info;
+
// Cached state which keeps a list of all the "live" monster race entries.
static std::vector<size_t> *instance = nullptr;
@@ -411,7 +413,7 @@ static void image_monster(byte *ap, char *cp)
// Create the list of "live" indexes
instance = new std::vector<size_t>();
// Start at 1 to avoid 'player'
- for (size_t i = 1; i < max_r_idx; i++)
+ for (size_t i = 1; i < r_info.size(); i++)
{
if (r_info[i].name)
{
@@ -847,6 +849,7 @@ static byte darker_attrs[16] =
static void map_info(int y, int x, byte *ap, char *cp)
{
auto const &st_info = game->edit_data.st_info;
+ auto const &r_info = game->edit_data.r_info;
byte a;
@@ -1240,7 +1243,7 @@ static void map_info(int y, int x, byte *ap, char *cp)
if ((y == p_ptr->py) && (x == p_ptr->px) &&
(!p_ptr->invis || p_ptr->see_inv))
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
/* Get the "player" attr */
if (!options->avoid_other && (r_ptr->flags & RF_ATTR_MULTI))
@@ -1282,6 +1285,7 @@ static void map_info(int y, int x, byte *ap, char *cp)
void map_info_default(int y, int x, byte *ap, char *cp)
{
auto const &st_info = game->edit_data.st_info;
+ auto const &r_info = game->edit_data.r_info;
byte a;
@@ -1673,7 +1677,7 @@ void map_info_default(int y, int x, byte *ap, char *cp)
(!p_ptr->invis ||
(p_ptr->invis && p_ptr->see_inv)))
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
/* Get the "player" attr */
if (!avoid_other && (r_ptr->flags & RF_ATTR_MULTI))
diff --git a/src/cmd1.cc b/src/cmd1.cc
index 19a52062..87ef7a6c 100644
--- a/src/cmd1.cc
+++ b/src/cmd1.cc
@@ -620,6 +620,8 @@ void touch_zap_player(monster_type *m_ptr)
static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath,
int x, int y)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_type *t_ptr = &m_list[m_idx];
int ap_cnt;
@@ -641,7 +643,7 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath,
if (!o_ptr->k_idx) return;
/* Get monster race of the symbiote */
- monster_race *r_ptr = &r_info[o_ptr->pval];
+ auto r_ptr = &r_info[o_ptr->pval];
/* Not allowed to attack */
if (r_ptr->flags & RF_NEVER_BLOW) return;
@@ -1111,6 +1113,8 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath,
static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath,
int x, int y)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_type *t_ptr = &m_list[m_idx];
auto tr_ptr = t_ptr->race();
@@ -1973,6 +1977,8 @@ static void do_nazgul(int *k, int *num, int num_blow, int weap, std::shared_ptr<
*/
void py_attack(int y, int x, int max_blow)
{
+ auto const &r_info = game->edit_data.r_info;
+
int num = 0, k, bonus, chance;
s32b special = 0;
@@ -2536,6 +2542,8 @@ void py_attack(int y, int x, int max_blow)
bool_ player_can_enter(byte feature)
{
+ auto const &r_info = game->edit_data.r_info;
+
bool_ pass_wall;
bool_ only_wall = FALSE;
@@ -2620,11 +2628,13 @@ bool_ player_can_enter(byte feature)
static bool_ easy_open_door(int y, int x)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, j;
cave_type *c_ptr = &cave[y][x];
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR))
@@ -2726,6 +2736,7 @@ static bool_ easy_open_door(int y, int x)
void move_player_aux(int dir, int do_pickup, int run, bool_ disarm)
{
auto const &d_info = game->edit_data.d_info;
+ auto const &r_info = game->edit_data.r_info;
int y, x, tmp;
@@ -2733,7 +2744,7 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm)
monster_type *m_ptr;
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
char m_name[80];
@@ -4041,6 +4052,8 @@ void run_step(int dir)
*/
void do_cmd_pet(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i = 0;
int num = 0;
@@ -4301,11 +4314,9 @@ void do_cmd_pet(void)
/* Process the monsters (backwards) */
for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
{
- monster_race *r_ptr;
-
/* Access the monster */
m_ptr = &m_list[pet_ctr];
- r_ptr = &r_info[m_ptr->r_idx];
+ auto r_ptr = &r_info[m_ptr->r_idx];
if ((!(r_ptr->flags & RF_NO_DEATH)) && ((m_ptr->status == MSTATUS_PET) || (m_ptr->status == MSTATUS_FRIEND))) /* Get rid of it! */
{
@@ -4370,11 +4381,9 @@ void do_cmd_pet(void)
/* Process the monsters (backwards) */
for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
{
- monster_race *r_ptr;
-
/* Access the monster */
m_ptr = &m_list[pet_ctr];
- r_ptr = &r_info[m_ptr->r_idx];
+ auto r_ptr = &r_info[m_ptr->r_idx];
if ((!(r_ptr->flags & RF_NO_DEATH)) && ((m_ptr->status == MSTATUS_COMPANION))) /* Get rid of it! */
{
@@ -4501,9 +4510,11 @@ void do_cmd_integrate_body()
*/
bool_ do_cmd_leave_body(bool_ drop_body)
{
+ auto const &r_info = game->edit_data.r_info;
+
object_type *o_ptr, forge;
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
int i;
diff --git a/src/cmd2.cc b/src/cmd2.cc
index 641e2738..9afcb7b4 100644
--- a/src/cmd2.cc
+++ b/src/cmd2.cc
@@ -79,11 +79,13 @@ static bool_ do_cmd_bash_altar(int y, int x)
*/
static bool_ do_cmd_bash_fountain(int y, int x)
{
+ auto const &r_info = game->edit_data.r_info;
+
int bash, temp;
bool_ more = TRUE;
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_BASH_DOOR))
@@ -767,6 +769,8 @@ static void chest_trap(int y, int x, s16b o_idx)
*/
static bool_ do_cmd_open_chest(int y, int x, s16b o_idx)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, j;
bool_ flag = TRUE;
@@ -775,7 +779,7 @@ static bool_ do_cmd_open_chest(int y, int x, s16b o_idx)
object_type *o_ptr = &o_list[o_idx];
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR))
@@ -1011,13 +1015,15 @@ static int coords_to_dir(int y, int x)
*/
static bool_ do_cmd_open_aux(int y, int x, int dir)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, j;
cave_type *c_ptr;
bool_ more = FALSE;
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR))
@@ -1118,6 +1124,8 @@ static bool_ do_cmd_open_aux(int y, int x, int dir)
*/
void do_cmd_open(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int y, x, dir;
s16b o_idx;
@@ -1126,7 +1134,7 @@ void do_cmd_open(void)
bool_ more = FALSE;
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR))
@@ -1242,11 +1250,13 @@ void do_cmd_open(void)
*/
static bool_ do_cmd_close_aux(int y, int x, int dir)
{
+ auto const &r_info = game->edit_data.r_info;
+
cave_type *c_ptr;
bool_ more = FALSE;
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR))
@@ -2131,13 +2141,15 @@ void do_cmd_disarm(void)
*/
static bool_ do_cmd_bash_aux(int y, int x, int dir)
{
+ auto const &r_info = game->edit_data.r_info;
+
int bash, temp;
cave_type *c_ptr;
bool_ more = FALSE;
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_BASH_DOOR))
@@ -2242,13 +2254,15 @@ static bool_ do_cmd_bash_aux(int y, int x, int dir)
*/
void do_cmd_bash(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int y, x, dir;
cave_type *c_ptr;
bool_ more = FALSE;
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_BASH_DOOR))
@@ -4514,6 +4528,8 @@ static void do_cmd_sacrifice_aule()
*/
void do_cmd_sacrifice(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
byte on_what = cave[p_ptr->py][p_ptr->px].feat;
/* Check valididty */
@@ -4736,6 +4752,8 @@ std::vector<s16b> show_monster_inven(int m_idx)
*/
void do_cmd_steal()
{
+ auto const &r_info = game->edit_data.r_info;
+
int dir = 0, item = -1, k = -1;
bool_ done = FALSE;
diff --git a/src/cmd3.cc b/src/cmd3.cc
index 66991c70..d65087f8 100644
--- a/src/cmd3.cc
+++ b/src/cmd3.cc
@@ -12,6 +12,7 @@
#include "cave_type.hpp"
#include "cli_comm.hpp"
#include "files.hpp"
+#include "game.hpp"
#include "gods.hpp"
#include "hook_drop_in.hpp"
#include "hook_wield_in.hpp"
@@ -1220,6 +1221,8 @@ static cptr ident_info[] =
*/
static bool compare_monster_experience(int w1, int w2)
{
+ auto const &r_info = game->edit_data.r_info;
+
/* Extract experience */
s32b z1 = r_info[w1].mexp;
s32b z2 = r_info[w2].mexp;
@@ -1237,6 +1240,8 @@ static bool compare_monster_experience(int w1, int w2)
*/
static bool compare_monster_level(int w1, int w2)
{
+ auto const &r_info = game->edit_data.r_info;
+
/* Extract levels */
byte z1 = r_info[w1].level;
byte z2 = r_info[w2].level;
@@ -1254,6 +1259,8 @@ static bool compare_monster_level(int w1, int w2)
*/
static bool compare_player_kills(int w1, int w2)
{
+ auto const &r_info = game->edit_data.r_info;
+
/* Extract player kills */
s16b z1 = r_info[w1].r_pkills;
s16b z2 = r_info[w2].r_pkills;
@@ -1272,7 +1279,9 @@ static bool compare_player_kills(int w1, int w2)
*/
static void roff_top(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
byte a1, a2;
@@ -1330,7 +1339,7 @@ static void roff_top(int r_idx)
*/
void do_cmd_query_symbol(void)
{
- int i, r_idx;
+ auto const &r_info = game->edit_data.r_info;
char sym, query;
@@ -1358,6 +1367,7 @@ void do_cmd_query_symbol(void)
"or (Ctrl-A, Ctrl-U, Ctrl-N, Ctrl-M):", &sym)) return;
/* Find that character info, and describe it */
+ std::size_t i;
for (i = 0; ident_info[i]; ++i)
{
if (sym == ident_info[i][0]) break;
@@ -1399,10 +1409,10 @@ void do_cmd_query_symbol(void)
prt(buf, 0, 0);
/* Collect matching monsters */
- std::vector<u16b> who;
- for (i = 1; i < max_r_idx; i++)
+ std::vector<std::size_t> who;
+ for (std::size_t i = 1; i < r_info.size(); i++)
{
- monster_race *r_ptr = &r_info[i];
+ auto r_ptr = &r_info[i];
/* Require non-unique monsters if needed */
if (norm && (r_ptr->flags & RF_UNIQUE)) continue;
@@ -1480,7 +1490,7 @@ void do_cmd_query_symbol(void)
while (1)
{
/* Extract a race */
- r_idx = who[i];
+ auto r_idx = who[i];
/* Hack -- Auto-recall */
monster_race_track(r_idx, 0);
diff --git a/src/cmd4.cc b/src/cmd4.cc
index b06947dc..85ed490d 100644
--- a/src/cmd4.cc
+++ b/src/cmd4.cc
@@ -2014,6 +2014,8 @@ void do_cmd_macros(void)
*/
void do_cmd_visuals(void)
{
+ auto &r_info = game->edit_data.r_info;
+
int i;
FILE *fff;
@@ -2108,9 +2110,9 @@ void do_cmd_visuals(void)
fprintf(fff, "# Monster attr/char definitions\n\n");
/* Dump monsters */
- for (i = 0; i < max_r_idx; i++)
+ for (std::size_t i = 0; i < r_info.size(); i++)
{
- monster_race *r_ptr = &r_info[i];
+ auto r_ptr = &r_info[i];
/* Skip non-entries */
if (!r_ptr->name) continue;
@@ -2119,7 +2121,7 @@ void do_cmd_visuals(void)
fprintf(fff, "# %s\n", r_ptr->name);
/* Dump the monster attr/char info */
- fprintf(fff, "R:%d:0x%02X:0x%02X\n\n", i,
+ fprintf(fff, "R:%zu:0x%02X:0x%02X\n\n", i,
static_cast<unsigned int>(r_ptr->x_attr),
static_cast<unsigned int>(r_ptr->x_char));
}
@@ -2253,7 +2255,7 @@ void do_cmd_visuals(void)
/* Hack -- query until done */
while (1)
{
- monster_race *r_ptr = &r_info[r];
+ auto r_ptr = &r_info[r];
byte da = (r_ptr->d_attr);
char dc = (r_ptr->d_char);
@@ -2288,8 +2290,8 @@ void do_cmd_visuals(void)
if (i == ESCAPE) break;
/* Analyze */
- if (i == 'n') r = (r + max_r_idx + 1) % max_r_idx;
- if (i == 'N') r = (r + max_r_idx - 1) % max_r_idx;
+ if (i == 'n') r = (r + r_info.size() + 1) % r_info.size();
+ if (i == 'N') r = (r + r_info.size() - 1) % r_info.size();
if (i == 'a') r_ptr->x_attr = (ca + 1);
if (i == 'A') r_ptr->x_attr = (ca - 1);
if (i == 'c') r_ptr->x_char = (cc + 1);
@@ -3263,7 +3265,10 @@ void do_cmd_knowledge_traps(void)
}
-static int monster_get_race_level(int r_idx) {
+static int monster_get_race_level(int r_idx)
+{
+ auto const &r_info = game->edit_data.r_info;
+
/* Hack -- Morgoth is always last */
if (r_idx == 862) {
return 20000;
@@ -3277,11 +3282,13 @@ static int monster_get_race_level(int r_idx) {
*/
static void do_cmd_knowledge_uniques(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
// Extract the unique race indexes.
- std::vector<int> unique_r_idxs;
- for (int k = 1; k < max_r_idx; k++)
+ std::vector<std::size_t> unique_r_idxs;
+ for (std::size_t k = 1; k < r_info.size(); k++)
{
- monster_race *r_ptr = &r_info[k];
+ auto r_ptr = &r_info[k];
/* Only print Uniques */
if ((r_ptr->flags & RF_UNIQUE) &&
@@ -3295,15 +3302,15 @@ static void do_cmd_knowledge_uniques(void)
// Sort races by level.
std::sort(std::begin(unique_r_idxs),
std::end(unique_r_idxs),
- [](int r_idx1, int r_idx2) -> bool {
+ [](auto r_idx1, auto r_idx2) -> bool {
return monster_get_race_level(r_idx1) < monster_get_race_level(r_idx2);
});
// Scan the monster races
fmt::MemoryWriter w;
- for (int r_idx : unique_r_idxs)
+ for (std::size_t r_idx : unique_r_idxs)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
/* Only print Uniques */
if (r_ptr->flags & RF_UNIQUE)
@@ -3488,6 +3495,8 @@ static void do_cmd_knowledge_pets(void)
*/
static void do_cmd_knowledge_kill_count(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
s32b Total = 0;
// Buffer
@@ -3496,9 +3505,9 @@ static void do_cmd_knowledge_kill_count(void)
// Summary of monsters slain
{
/* For all monsters */
- for (int kk = 1; kk < max_r_idx; kk++)
+ for (auto const &r_ref: r_info)
{
- monster_race *r_ptr = &r_info[kk];
+ auto r_ptr = &r_ref;
if (r_ptr->flags & RF_UNIQUE)
{
@@ -3530,9 +3539,9 @@ static void do_cmd_knowledge_kill_count(void)
Total = 0;
/* Scan the monster races */
- for (int k = 0; k < max_r_idx; k++)
+ for (auto const &r_ref: r_info)
{
- monster_race *r_ptr = &r_info[k];
+ auto r_ptr = &r_ref;
if (r_ptr->flags & RF_UNIQUE)
{
diff --git a/src/cmd5.cc b/src/cmd5.cc
index bcf22124..a94f925a 100644
--- a/src/cmd5.cc
+++ b/src/cmd5.cc
@@ -542,6 +542,8 @@ void fetch(int dir, int wgt, bool_ require_los)
*/
std::string symbiote_name(bool capitalize)
{
+ auto const &r_info = game->edit_data.r_info;
+
object_type *o_ptr = &p_ptr->inventory[INVEN_CARRY];
std::string buf;
@@ -554,7 +556,7 @@ std::string symbiote_name(bool capitalize)
}
else
{
- monster_race *r_ptr = &r_info[o_ptr->pval];
+ auto r_ptr = &r_info[o_ptr->pval];
std::size_t i = 0;
if (r_ptr->flags & RF_UNIQUE)
@@ -1780,6 +1782,8 @@ static int use_monster_power_aux(monster_race const *r_ptr, bool great, bool sym
*/
int use_symbiotic_power(int r_idx, bool great)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_race const *r_ptr = &r_info[r_idx];
return use_monster_power_aux(r_ptr, great, true, [](monster_power const *) {
// Don't need to do anything post-cast.
@@ -1791,6 +1795,8 @@ int use_symbiotic_power(int r_idx, bool great)
*/
void use_monster_power(int r_idx, bool great)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_race const *r_ptr = &r_info[r_idx];
use_monster_power_aux(r_ptr, great, false, [r_ptr](monster_power const *power) {
// Sometimes give a free cast.
diff --git a/src/cmd6.cc b/src/cmd6.cc
index 195d9648..630f1e0e 100644
--- a/src/cmd6.cc
+++ b/src/cmd6.cc
@@ -154,7 +154,9 @@ static select_by_name_t select_object_by_name(std::string const &prompt)
*/
static void corpse_effect(object_type *o_ptr, bool_ cutting)
{
- monster_race *r_ptr = &r_info[o_ptr->pval2];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[o_ptr->pval2];
/* Assume no bad effects */
bool_ harmful = FALSE;
@@ -980,12 +982,12 @@ static object_filter_t const &item_tester_hook_eatable()
*/
void do_cmd_eat_food(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int ident, lev, fval = 0;
object_type *q_ptr, forge;
- monster_race *r_ptr;
-
bool_ destroy = TRUE;
/* Get an item */
@@ -1360,7 +1362,7 @@ void do_cmd_eat_food(void)
/* Corpses... */
else
{
- r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
/* Analyse the corpse */
switch (o_ptr->sval)
@@ -1539,6 +1541,8 @@ void do_cmd_eat_food(void)
*/
void do_cmd_cut_corpse(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int item, meat = 0, not_meat = 0;
/* Get an item */
@@ -1554,7 +1558,7 @@ void do_cmd_cut_corpse(void)
/* Get the item */
object_type *o_ptr = get_object(item);
- monster_race *r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
if ((o_ptr->sval != SV_CORPSE_CORPSE) && (o_ptr->sval != SV_CORPSE_HEAD))
{
@@ -2869,6 +2873,7 @@ static object_filter_t const &item_tester_hook_readable()
void do_cmd_read_scroll(void)
{
auto const &d_info = game->edit_data.d_info;
+ auto &r_info = game->edit_data.r_info;
/* Check some conditions */
if (p_ptr->blind)
@@ -2936,12 +2941,12 @@ void do_cmd_read_scroll(void)
msg_print("You feel the souls of the dead coming back "
"from the Halls of Mandos.");
- for (int k = 0; k < max_r_idx; k++)
+ for (auto &r_ref: r_info)
{
- monster_race *r_ptr = &r_info[k];
+ auto r_ptr = &r_ref;
if (r_ptr->flags & RF_UNIQUE &&
- !(r_ptr->flags & RF_SPECIAL_GENE))
+ !(r_ptr->flags & RF_SPECIAL_GENE))
{
r_ptr->max_num = 1;
}
diff --git a/src/cmd7.cc b/src/cmd7.cc
index 3f039f32..db496995 100644
--- a/src/cmd7.cc
+++ b/src/cmd7.cc
@@ -1780,6 +1780,8 @@ void summon_monster(int sumtype)
*/
void do_cmd_possessor()
{
+ auto const &r_info = game->edit_data.r_info;
+
char ch, ext;
@@ -3568,6 +3570,8 @@ static object_filter_t const &item_tester_hook_totemable()
*/
void do_cmd_summoner_extract()
{
+ auto const &r_info = game->edit_data.r_info;
+
object_type forge, *q_ptr;
/* Not when confused */
@@ -3640,11 +3644,13 @@ void do_cmd_summoner_extract()
void summon_true(int r_idx, int item)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, status, x = 1, y = 1, rx, ry = 0, chance;
bool_ used;
- monster_race *r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
/* Uniques are less likely to be nice */
diff --git a/src/dungeon.cc b/src/dungeon.cc
index d3554e50..c044021f 100644
--- a/src/dungeon.cc
+++ b/src/dungeon.cc
@@ -775,6 +775,8 @@ static void regenmana(int percent)
*/
static void regen_monsters(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, frac;
object_type *o_ptr = &p_ptr->inventory[INVEN_CARRY];
@@ -782,7 +784,7 @@ static void regen_monsters(void)
if (o_ptr->k_idx)
{
- monster_race *r_ptr = &r_info[o_ptr->pval];
+ auto r_ptr = &r_info[o_ptr->pval];
/* Allow regeneration (if needed) */
if (o_ptr->pval2 < o_ptr->pval3)
@@ -1216,6 +1218,7 @@ static void process_world_gods()
static void process_world(void)
{
auto const &d_info = game->edit_data.d_info;
+ auto const &r_info = game->edit_data.r_info;
timer_type *t_ptr;
@@ -1291,7 +1294,7 @@ static void process_world(void)
if (o_ptr->k_idx)
{
- monster_race *r_ptr = &r_info[o_ptr->pval];
+ auto r_ptr = &r_info[o_ptr->pval];
if ((randint(1000) < r_ptr->level - ((p_ptr->lev * 2) + get_skill(SKILL_SYMBIOTIC))))
{
diff --git a/src/files.cc b/src/files.cc
index f897b515..cfd80362 100644
--- a/src/files.cc
+++ b/src/files.cc
@@ -219,6 +219,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;
+ auto &r_info = game->edit_data.r_info;
int i, j, n1, n2;
@@ -251,17 +252,26 @@ errr process_pref_file_aux(char *buf)
{
if (tokenize(buf + 2, 3, zz, ':', '/') == 3)
{
- monster_race *r_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_r_idx) return (1);
- r_ptr = &r_info[i];
- if (n1) r_ptr->x_attr = n1;
+
+ if (i >= r_info.size())
+ {
+ return (1);
+ }
+
+ auto r_ptr = &r_info[i];
+
+ if (n1)
+ {
+ r_ptr->x_attr = n1;
+ }
if (n2)
{
r_ptr->x_char = n2;
}
+
return (0);
}
}
@@ -1385,6 +1395,8 @@ static cptr likert(int x, int y)
*/
static void display_player_various(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int tmp, tmp2, damdice, damsides, dambonus, blows;
int xthn, xthb, xfos, xsrh;
int xdis, xdev, xsav, xstl;
@@ -1566,6 +1578,8 @@ static void display_player_various(void)
static object_flag_set wield_monster_flags()
{
+ auto const &r_info = game->edit_data.r_info;
+
object_flag_set flags;
/* Get the carried monster */
@@ -1603,6 +1617,8 @@ static void apply_lflags(LF const &lflags, object_flag_set *f)
*/
object_flag_set player_flags()
{
+ auto const &r_info = game->edit_data.r_info;
+
/* Clear */
object_flag_set f;
@@ -1713,26 +1729,26 @@ object_flag_set player_flags()
}
else
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
-
- if (r_ptr->flags & RF_REFLECTING) f |= TR_REFLECT;
- if (r_ptr->flags & RF_REGENERATE) f |= TR_REGEN;
- if (r_ptr->flags & RF_AURA_FIRE) f |= TR_SH_FIRE;
- if (r_ptr->flags & RF_AURA_ELEC) f |= TR_SH_ELEC;
- if (r_ptr->flags & RF_PASS_WALL) f |= TR_WRAITH;
- if (r_ptr->flags & RF_SUSCEP_FIRE) f |= TR_SENS_FIRE;
- if (r_ptr->flags & RF_IM_ACID) f |= TR_RES_ACID;
- if (r_ptr->flags & RF_IM_ELEC) f |= TR_RES_ELEC;
- if (r_ptr->flags & RF_IM_FIRE) f |= TR_RES_FIRE;
- if (r_ptr->flags & RF_IM_POIS) f |= TR_RES_POIS;
- if (r_ptr->flags & RF_IM_COLD) f |= TR_RES_COLD;
- if (r_ptr->flags & RF_RES_NETH) f |= TR_RES_NETHER;
- if (r_ptr->flags & RF_RES_NEXU) f |= TR_RES_NEXUS;
- if (r_ptr->flags & RF_RES_DISE) f |= TR_RES_DISEN;
- if (r_ptr->flags & RF_NO_FEAR) f |= TR_RES_FEAR;
- if (r_ptr->flags & RF_NO_SLEEP) f |= TR_FREE_ACT;
- if (r_ptr->flags & RF_NO_CONF) f |= TR_RES_CONF;
- if (r_ptr->flags & RF_CAN_FLY) f |= TR_FEATHER;
+ auto &r_ref = r_info[p_ptr->body_monster];
+
+ if (r_ref.flags & RF_REFLECTING) f |= TR_REFLECT;
+ if (r_ref.flags & RF_REGENERATE) f |= TR_REGEN;
+ if (r_ref.flags & RF_AURA_FIRE) f |= TR_SH_FIRE;
+ if (r_ref.flags & RF_AURA_ELEC) f |= TR_SH_ELEC;
+ if (r_ref.flags & RF_PASS_WALL) f |= TR_WRAITH;
+ if (r_ref.flags & RF_SUSCEP_FIRE) f |= TR_SENS_FIRE;
+ if (r_ref.flags & RF_IM_ACID) f |= TR_RES_ACID;
+ if (r_ref.flags & RF_IM_ELEC) f |= TR_RES_ELEC;
+ if (r_ref.flags & RF_IM_FIRE) f |= TR_RES_FIRE;
+ if (r_ref.flags & RF_IM_POIS) f |= TR_RES_POIS;
+ if (r_ref.flags & RF_IM_COLD) f |= TR_RES_COLD;
+ if (r_ref.flags & RF_RES_NETH) f |= TR_RES_NETHER;
+ if (r_ref.flags & RF_RES_NEXU) f |= TR_RES_NEXUS;
+ if (r_ref.flags & RF_RES_DISE) f |= TR_RES_DISEN;
+ if (r_ref.flags & RF_NO_FEAR) f |= TR_RES_FEAR;
+ if (r_ref.flags & RF_NO_SLEEP) f |= TR_FREE_ACT;
+ if (r_ref.flags & RF_NO_CONF) f |= TR_RES_CONF;
+ if (r_ref.flags & RF_CAN_FLY) f |= TR_FEATHER;
}
f |= p_ptr->xtra_flags;
@@ -2219,6 +2235,8 @@ static void display_player_ben_one(int page)
*/
void display_player(int mode)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i;
char buf[80];
@@ -2230,7 +2248,7 @@ void display_player(int mode)
/* Standard */
if ((mode == 0) || (mode == 1))
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
/* Name, Sex, Race, Class */
put_str("Name :", 2, 1);
@@ -2580,6 +2598,7 @@ errr file_character(cptr name, bool_ full)
{
auto const &d_info = game->edit_data.d_info;
auto const &wf_info = game->edit_data.wf_info;
+ auto const &r_info = game->edit_data.r_info;
int i, x, y;
byte a;
@@ -2746,12 +2765,11 @@ errr file_character(cptr name, bool_ full)
/* Monsters slain */
{
- int k;
s32b Total = 0;
- for (k = 1; k < max_r_idx; k++)
+ for (auto const &r_ref: r_info)
{
- monster_race *r_ptr = &r_info[k];
+ auto r_ptr = &r_ref;
if (r_ptr->flags & RF_UNIQUE)
{
@@ -4033,6 +4051,7 @@ void autosave_checkpoint()
static long total_points(void)
{
auto const &d_info = game->edit_data.d_info;
+ auto const &r_info = game->edit_data.r_info;
s16b max_dl = 0;
long temp, Total = 0;
@@ -4106,9 +4125,9 @@ static long total_points(void)
}
}
- for (std::size_t k = 1; k < max_r_idx; k++)
+ for (auto const &r_ref: r_info)
{
- monster_race *r_ptr = &r_info[k];
+ auto r_ptr = &r_ref;
if (r_ptr->flags & RF_UNIQUE)
{
diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp
index 8b118397..16a97da7 100644
--- a/src/game_edit_data.hpp
+++ b/src/game_edit_data.hpp
@@ -4,6 +4,7 @@
#include "dungeon_info_type.hpp"
#include "hist_type.hpp"
#include "monster_ego.hpp"
+#include "monster_race.hpp"
#include "owner_type.hpp"
#include "player_class.hpp"
#include "player_race.hpp"
@@ -91,6 +92,11 @@ struct GameEditData {
*/
std::vector<skill_descriptor> s_descriptors;
+ /*
+ * The monster races
+ */
+ std::vector<monster_race> r_info;
+
/**
* Monster race egos
*/
diff --git a/src/generate.cc b/src/generate.cc
index 96f4ebaf..9bd01010 100644
--- a/src/generate.cc
+++ b/src/generate.cc
@@ -2685,7 +2685,9 @@ static void build_type4(int by0, int bx0)
*/
static bool_ vault_aux_jelly(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2706,7 +2708,9 @@ static bool_ vault_aux_jelly(int r_idx)
*/
static bool_ vault_aux_animal(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2724,7 +2728,9 @@ static bool_ vault_aux_animal(int r_idx)
*/
static bool_ vault_aux_undead(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2742,7 +2748,9 @@ static bool_ vault_aux_undead(int r_idx)
*/
static bool_ vault_aux_chapel(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2763,7 +2771,9 @@ static bool_ vault_aux_chapel(int r_idx)
*/
static bool_ vault_aux_kennel(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2779,7 +2789,9 @@ static bool_ vault_aux_kennel(int r_idx)
*/
static bool_ vault_aux_treasure(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2811,6 +2823,8 @@ static bool_ vault_aux_clone(int r_idx)
*/
static bool_ vault_aux_symbol(int r_idx)
{
+ auto const &r_info = game->edit_data.r_info;
+
return ((r_info[r_idx].d_char == (r_info[template_race].d_char))
&& !(r_info[r_idx].flags & RF_UNIQUE));
}
@@ -2821,7 +2835,9 @@ static bool_ vault_aux_symbol(int r_idx)
*/
static bool_ vault_aux_orc(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2840,7 +2856,9 @@ static bool_ vault_aux_orc(int r_idx)
*/
static bool_ vault_aux_troll(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2858,7 +2876,9 @@ static bool_ vault_aux_troll(int r_idx)
*/
static bool_ vault_aux_giant(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2876,7 +2896,9 @@ static bool_ vault_aux_giant(int r_idx)
*/
static bool_ vault_aux_demon(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -2915,6 +2937,8 @@ static bool_ vault_aux_demon(int r_idx)
*/
static void build_type5(int by0, int bx0)
{
+ auto const &r_info = game->edit_data.r_info;
+
int y, x, y1, x1, y2, x2, xval, yval;
int tmp, i;
cptr name;
@@ -2979,7 +3003,7 @@ static void build_type5(int by0, int bx0)
{
while (1)
{
- template_race = randint(max_r_idx - 2);
+ template_race = rand_int(r_info.size());
/* Reject uniques */
if (r_info[template_race].flags & RF_UNIQUE) continue;
@@ -3153,6 +3177,8 @@ static void build_type5(int by0, int bx0)
*/
static void build_type6(int by0, int bx0)
{
+ auto const &r_info = game->edit_data.r_info;
+
int tmp, what[16];
int i, j, y, x, y1, x1, y2, x2, xval, yval;
bool_ empty = FALSE;
@@ -3251,7 +3277,7 @@ static void build_type6(int by0, int bx0)
do
{
- template_race = randint(max_r_idx - 2);
+ template_race = rand_int(r_info.size() - 1);
}
while ((r_info[template_race].flags & RF_UNIQUE)
|| (((r_info[template_race].level) + randint(5)) >
@@ -3322,7 +3348,9 @@ static void build_type6(int by0, int bx0)
/* Restrict monster selection */
get_mon_num_hook = [](int r_idx) -> bool_ {
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Decline unique monsters */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
@@ -7619,6 +7647,7 @@ static void supersize_grid_tile(int sy, int sx, int ty, int tx)
static bool_ cave_gen(void)
{
auto const &d_info = game->edit_data.d_info;
+ auto const &r_info = game->edit_data.r_info;
auto d_ptr = &d_info[dungeon_type];
diff --git a/src/init1.cc b/src/init1.cc
index 17024337..3dcee907 100644
--- a/src/init1.cc
+++ b/src/init1.cc
@@ -4097,9 +4097,9 @@ static errr grab_one_monster_spell_flag(monster_spell_flag_set *flags, cptr what
*/
errr init_r_info_txt(FILE *fp)
{
- int i;
+ auto &r_info = game->edit_data.r_info;
+
char buf[1024];
- char *s, *t;
/* Current entry */
monster_race *r_ptr = NULL;
@@ -4128,7 +4128,7 @@ errr init_r_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);
@@ -4140,19 +4140,16 @@ errr init_r_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_r_idx) return (2);
-
/* Save the index */
error_idx = i;
/* Point at the "info" */
- r_ptr = &r_info[i];
+ r_ptr = &expand_to_fit_index(r_info, i);
/* Allocate name string. */
assert(!r_ptr->name); // Sanity check that we aren't overwriting anything
@@ -4178,11 +4175,8 @@ errr init_r_info_txt(FILE *fp)
/* Process 'D' for "Description" */
if (buf[0] == 'D')
{
- /* Acquire the text */
- s = buf + 2;
-
/* Append to description */
- strappend(&r_ptr->text, s);
+ strappend(&r_ptr->text, buf + 2);
/* Next... */
continue;
@@ -4324,7 +4318,9 @@ errr init_r_info_txt(FILE *fp)
/* Process 'B' for "Blows" (up to four lines) */
if (buf[0] == 'B')
{
- int n1, n2;
+ int i, n1, n2;
+ char *s;
+ char *t;
/* Find the next empty blow slot (if any) */
for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
@@ -4397,7 +4393,8 @@ errr init_r_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))
@@ -6782,12 +6779,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst
max_real_towns = atoi(zz[1]);
}
- /* Maximum r_idx */
- else if (zz[0][0] == 'R')
- {
- max_r_idx = atoi(zz[1]);
- }
-
/* Maximum k_idx */
else if (zz[0][0] == 'K')
{
diff --git a/src/init2.cc b/src/init2.cc
index da011da7..79b5a0a3 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -405,7 +405,7 @@ namespace {
static void allocate()
{
- r_info = new monster_race[max_r_idx];
+ // Nothing to do
}
static errr parse(FILE *fp)
@@ -722,11 +722,12 @@ void create_stores_stock(int t)
static errr init_other(void)
{
auto const &d_info = game->edit_data.d_info;
+ auto const &r_info = game->edit_data.r_info;
/*** Prepare the "dungeon" information ***/
/* Allocate and Wipe the special gene flags */
- m_allow_special = make_array<bool_>(max_r_idx);
+ m_allow_special = make_array<bool_>(r_info.size());
k_allow_special = make_array<bool_>(max_k_idx);
a_allow_special = make_array<bool_>(max_a_idx);
@@ -802,12 +803,12 @@ static errr init_other(void)
*/
static errr init_alloc(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, j;
object_kind *k_ptr;
- monster_race *r_ptr;
-
alloc_entry *table;
s16b num[MAX_DEPTH_MONSTER];
@@ -915,10 +916,10 @@ static errr init_alloc(void)
alloc_race_size = 0;
/* Scan the monsters */
- for (i = 1; i < max_r_idx; i++)
+ for (auto &r_ref: r_info)
{
/* Get the i'th race */
- r_ptr = &r_info[i];
+ auto r_ptr = &r_ref;
/* Legal monsters */
if (r_ptr->rarity)
@@ -951,10 +952,10 @@ static errr init_alloc(void)
table = alloc_race_table;
/* Scan the monsters */
- for (i = 1; i < max_r_idx; i++)
+ for (i = 1; i < r_info.size(); i++)
{
/* Get the i'th race */
- r_ptr = &r_info[i];
+ auto r_ptr = &r_info[i];
/* Count valid pairs */
if (r_ptr->rarity)
@@ -1017,6 +1018,7 @@ static void init_sets_aux()
static void init_guardians(void)
{
auto const &d_info = game->edit_data.d_info;
+ auto &r_info = game->edit_data.r_info;
/* Scan dungeons */
for (std::size_t i = 0; i < d_info.size(); i++)
@@ -1026,7 +1028,7 @@ static void init_guardians(void)
/* Mark the guadian monster */
if (d_ptr->final_guardian)
{
- monster_race *r_ptr = &r_info[d_ptr->final_guardian];
+ auto r_ptr = &r_info[d_ptr->final_guardian];
r_ptr->flags |= RF_SPECIAL_GENE;
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 41bd86d1..8d05cb43 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -1366,6 +1366,8 @@ static bool do_objects(ls_flag_t flag, bool no_companions)
static bool do_monsters(ls_flag_t flag, bool no_companions)
{
+ auto &r_info = game->edit_data.r_info;
+
u16b n_monsters = m_max;
if (flag == ls_flag_t::SAVE)
@@ -1618,7 +1620,9 @@ bool_ file_exist(cptr buf)
*/
static void do_lore(std::size_t r_idx, ls_flag_t flag)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
do_s16b(&r_ptr->r_pkills, flag);
do_s16b(&r_ptr->max_num, flag);
@@ -2082,11 +2086,13 @@ static void do_stores(ls_flag_t flag)
*/
static bool do_monster_lore(ls_flag_t flag)
{
- u16b tmp16u = max_r_idx;
+ auto const &r_info = game->edit_data.r_info;
+
+ u16b tmp16u = r_info.size();
do_u16b(&tmp16u, flag);
- if ((flag == ls_flag_t::LOAD) && (tmp16u > max_r_idx))
+ if ((flag == ls_flag_t::LOAD) && (tmp16u > r_info.size()))
{
note("Too many monster races!");
return false;
diff --git a/src/melee1.cc b/src/melee1.cc
index 5a61a424..458e2fd3 100644
--- a/src/melee1.cc
+++ b/src/melee1.cc
@@ -10,6 +10,7 @@
#include "cave.hpp"
#include "cmd5.hpp"
+#include "game.hpp"
#include "gods.hpp"
#include "mimic.hpp"
#include "monster2.hpp"
@@ -223,7 +224,9 @@ int get_attack_power(int effect)
*/
bool_ carried_make_attack_normal(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
int ap_cnt;
diff --git a/src/melee2.cc b/src/melee2.cc
index 773cdad1..d1fc3767 100644
--- a/src/melee2.cc
+++ b/src/melee2.cc
@@ -20,6 +20,7 @@
#include "feature_flag.hpp"
#include "feature_type.hpp"
#include "files.hpp"
+#include "game.hpp"
#include "hook_mon_speak_in.hpp"
#include "hook_monster_ai_in.hpp"
#include "hook_monster_ai_out.hpp"
@@ -4175,19 +4176,20 @@ static bool_ find_hiding(int m_idx, int *yp, int *xp)
/* Find an appropriate corpse */
void find_corpse(monster_type *m_ptr, int *y, int *x)
{
+ auto const &r_info = game->edit_data.r_info;
+
int k, last = -1;
for (k = 0; k < max_o_idx; k++)
{
object_type *o_ptr = &o_list[k];
- monster_race *rt_ptr, *rt2_ptr;
if (!o_ptr->k_idx) continue;
if (o_ptr->tval != TV_CORPSE) continue;
if ((o_ptr->sval != SV_CORPSE_CORPSE) && (o_ptr->sval != SV_CORPSE_SKELETON)) continue;
- rt_ptr = &r_info[o_ptr->pval2];
+ auto rt_ptr = &r_info[o_ptr->pval2];
/* Cannot incarnate into a higher level monster */
if (rt_ptr->level > m_ptr->level) continue;
@@ -4197,9 +4199,16 @@ void find_corpse(monster_type *m_ptr, int *y, int *x)
if (last != -1)
{
- rt2_ptr = &r_info[o_list[last].pval2];
- if (rt_ptr->level > rt2_ptr->level) last = k;
- else continue;
+ auto rt2_ptr = &r_info[o_list[last].pval2];
+
+ if (rt_ptr->level > rt2_ptr->level)
+ {
+ last = k;
+ }
+ else
+ {
+ continue;
+ }
}
else
{
@@ -4220,6 +4229,8 @@ void find_corpse(monster_type *m_ptr, int *y, int *x)
*/
static void get_target_monster(int m_idx)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_type *m_ptr = &m_list[m_idx];
int i, t = -1, d = 9999;
@@ -4229,7 +4240,7 @@ static void get_target_monster(int m_idx)
/* Access the monster */
monster_type *t_ptr = &m_list[i];
/* hack should call the function for ego monsters ... but no_target i not meant to be added by ego and it speeds up the code */
- monster_race *rt_ptr = &r_info[t_ptr->r_idx];
+ auto rt_ptr = &r_info[t_ptr->r_idx];
int dd;
/* Ignore "dead" monsters */
@@ -6389,6 +6400,8 @@ void summon_maint(int m_idx)
*/
void process_monsters(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, e;
int fx, fy;
diff --git a/src/monster1.cc b/src/monster1.cc
index 2f874259..5ad3c696 100644
--- a/src/monster1.cc
+++ b/src/monster1.cc
@@ -1379,7 +1379,9 @@ void display_roff(int r_idx, int ego)
bool_ monster_quest(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Random quests are in the dungeon */
if (r_ptr->flags & RF_WILD_ONLY) return FALSE;
@@ -1396,7 +1398,9 @@ bool_ monster_quest(int r_idx)
bool_ monster_dungeon(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (!(r_ptr->flags & RF_WILD_ONLY))
return TRUE;
@@ -1407,7 +1411,9 @@ bool_ monster_dungeon(int r_idx)
static bool_ monster_ocean(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_WILD_OCEAN)
return TRUE;
@@ -1418,7 +1424,9 @@ static bool_ monster_ocean(int r_idx)
static bool_ monster_shore(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_WILD_SHORE)
return TRUE;
@@ -1429,7 +1437,9 @@ static bool_ monster_shore(int r_idx)
static bool_ monster_waste(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_WILD_WASTE)
return TRUE;
@@ -1440,7 +1450,9 @@ static bool_ monster_waste(int r_idx)
static bool_ monster_town(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_WILD_TOWN)
return TRUE;
@@ -1451,7 +1463,9 @@ static bool_ monster_town(int r_idx)
static bool_ monster_wood(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_WILD_WOOD)
return TRUE;
@@ -1462,7 +1476,9 @@ static bool_ monster_wood(int r_idx)
static bool_ monster_volcano(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_WILD_VOLCANO)
return TRUE;
@@ -1473,7 +1489,9 @@ static bool_ monster_volcano(int r_idx)
static bool_ monster_mountain(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_WILD_MOUNTAIN)
return TRUE;
@@ -1484,7 +1502,9 @@ static bool_ monster_mountain(int r_idx)
static bool_ monster_grass(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_WILD_GRASS)
return TRUE;
@@ -1495,7 +1515,9 @@ static bool_ monster_grass(int r_idx)
static bool_ monster_deep_water(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (!monster_dungeon(r_idx)) return FALSE;
@@ -1508,7 +1530,9 @@ static bool_ monster_deep_water(int r_idx)
static bool_ monster_shallow_water(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (!monster_dungeon(r_idx)) return FALSE;
@@ -1521,7 +1545,9 @@ static bool_ monster_shallow_water(int r_idx)
static bool_ monster_lava(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (!monster_dungeon(r_idx)) return FALSE;
diff --git a/src/monster2.cc b/src/monster2.cc
index 108642df..dccf47dc 100644
--- a/src/monster2.cc
+++ b/src/monster2.cc
@@ -65,8 +65,10 @@ s32b monster_exp(s16b level)
/* Monster gain a few levels ? */
void monster_check_experience(int m_idx, bool_ silent)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ auto r_ptr = &r_info[m_ptr->r_idx];
char m_name[80];
/* Get the name */
@@ -268,8 +270,10 @@ static int pick_ego_monster(monster_race const *r_ptr)
*/
std::shared_ptr<monster_race> 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;
+ auto const &re_info = game->edit_data.re_info;
+ auto &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* We don't need to allocate anything if it's an ordinary monster. */
if (!ego) {
@@ -840,7 +844,7 @@ errr get_mon_num_prep(void)
* Some dungeon types restrict the possible monsters.
* Return TRUE is the monster is OK and FALSE otherwise
*/
-bool_ apply_rule(monster_race *r_ptr, byte rule)
+static bool_ apply_rule(monster_race const *r_ptr, byte rule)
{
auto const &d_info = game->edit_data.d_info;
@@ -893,9 +897,10 @@ bool_ apply_rule(monster_race *r_ptr, byte rule)
bool_ restrict_monster_to_dungeon(int r_idx)
{
auto const &d_info = game->edit_data.d_info;
+ auto const &r_info = game->edit_data.r_info;
auto d_ptr = &d_info[dungeon_type];
- monster_race *r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
/* Select a random rule */
byte rule = d_ptr->rule_percents[rand_int(100)];
@@ -940,14 +945,12 @@ bool_ summon_hack = FALSE;
*/
s16b get_mon_num(int level)
{
- int i, j, p;
+ auto const &r_info = game->edit_data.r_info;
+ int i, j, p;
int r_idx;
-
long value, total;
- monster_race *r_ptr;
-
alloc_entry *table = alloc_race_table;
int in_tome;
@@ -996,7 +999,7 @@ s16b get_mon_num(int level)
r_idx = table[i].index;
/* Access the actual race */
- r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
/* Hack -- "unique" monsters must be "unique" */
if ((r_ptr->flags & RF_UNIQUE) &&
@@ -1163,7 +1166,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 const &re_info = game->edit_data.re_info;
+ auto const &r_info = game->edit_data.r_info;
auto r_ptr = m_ptr->race();
char silly_name[80], name[100];
@@ -1196,11 +1200,11 @@ void monster_desc(char *desc, monster_type *m_ptr, int mode)
{
if (rand_int(2) == 0)
{
- monster_race *hallu_race;
+ monster_race const *hallu_race;
do
{
- hallu_race = &r_info[randint(max_r_idx - 2)];
+ hallu_race = &*uniform_element(r_info);
}
while ((!hallu_race->name) || (hallu_race->flags & RF_UNIQUE));
@@ -1379,9 +1383,10 @@ 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;
+ auto const &re_info = game->edit_data.re_info;
+ auto const &r_info = game->edit_data.r_info;
- monster_race *r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
char name[80];
if (ego)
@@ -1985,6 +1990,8 @@ bool_ place_monster_one_no_drop = FALSE;
static s16b hack_m_idx_ii = 0;
s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
{
+ auto &r_info = game->edit_data.r_info;
+
int i;
char dummy[5];
bool_ add_level = FALSE;
@@ -2054,7 +2061,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
/* Check for original monster race flags */
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
/* Paranoia */
if (!r_ptr->name)
@@ -2479,7 +2486,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
/* Count monsters on the level */
{
/* Hack -- we need to modify the REAL r_info, not the fake one */
- monster_race *r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
/* Hack -- Count the monsters on the level */
r_ptr->cur_num++;
@@ -2513,7 +2520,9 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
*/
static bool_ place_monster_group(int y, int x, int r_idx, bool_ slp, int status)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
int old, n, i;
int total = 0, extra = 0;
@@ -2608,9 +2617,10 @@ static int place_monster_idx = 0;
*/
static bool_ place_monster_okay(int r_idx)
{
- monster_race *r_ptr = &r_info[place_monster_idx];
+ auto const &r_info = game->edit_data.r_info;
- monster_race *z_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[place_monster_idx];
+ auto z_ptr = &r_info[r_idx];
/* Hack - Escorts have to have the same dungeon flag */
if (monster_dungeon(place_monster_idx) != monster_dungeon(r_idx)) return (FALSE);
@@ -2652,8 +2662,10 @@ static bool_ place_monster_okay(int r_idx)
*/
bool_ place_monster_aux(int y, int x, int r_idx, bool_ slp, bool_ grp, int status)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i;
- monster_race *r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
bool_ (*old_get_mon_num_hook)(int r_idx);
@@ -2776,9 +2788,11 @@ bool_ place_monster(int y, int x, bool_ slp, bool_ grp)
bool_ alloc_horde(int y, int x)
{
+ auto const &r_info = game->edit_data.r_info;
+
int r_idx = 0;
- monster_race * r_ptr = NULL;
- monster_type * m_ptr;
+ monster_race const *r_ptr = NULL;
+ monster_type *m_ptr;
int attempts = 1000;
set_mon_num2_hook(y, x);
@@ -2907,7 +2921,9 @@ static int summon_specific_type = 0;
*/
static bool_ summon_specific_okay(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
bool_ okay = FALSE;
@@ -3482,7 +3498,9 @@ void monster_swap(int y1, int x1, int y2, int x2)
*/
static bool_ mutate_monster_okay(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
bool_ okay = FALSE;
diff --git a/src/monster3.cc b/src/monster3.cc
index f8bb0837..9a7921a7 100644
--- a/src/monster3.cc
+++ b/src/monster3.cc
@@ -11,6 +11,7 @@
#include "cave_type.hpp"
#include "cmd2.hpp"
#include "cmd5.hpp"
+#include "game.hpp"
#include "gods.hpp"
#include "melee2.hpp"
#include "monster2.hpp"
@@ -60,7 +61,11 @@ int is_friend(monster_type *m_ptr)
/* Should they attack each others */
bool_ is_enemy(monster_type *m_ptr, monster_type *t_ptr)
{
- monster_race *r_ptr = &r_info[m_ptr->r_idx], *rt_ptr = &r_info[t_ptr->r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[m_ptr->r_idx];
+ auto rt_ptr = &r_info[t_ptr->r_idx];
+
int s1 = is_friend(m_ptr), s2 = is_friend(t_ptr);
/* Monsters hates breeders */
@@ -146,11 +151,13 @@ bool_ ai_multiply(int m_idx)
/* Possessor incarnates */
bool_ ai_possessor(int m_idx, int o_idx)
{
+ auto &r_info = game->edit_data.r_info;
+
object_type *o_ptr = &o_list[o_idx];
monster_type *m_ptr = &m_list[m_idx];
int r_idx = m_ptr->r_idx, r2_idx = o_ptr->pval2;
int i;
- monster_race *r_ptr = &r_info[r2_idx];
+ auto r_ptr = &r_info[r2_idx];
char m_name[80], m_name2[80];
monster_desc(m_name, m_ptr, 0x00);
@@ -226,9 +233,11 @@ bool_ ai_possessor(int m_idx, int o_idx)
void ai_deincarnate(int m_idx)
{
+ auto &r_info = game->edit_data.r_info;
+
monster_type *m_ptr = &m_list[m_idx];
int r2_idx = m_ptr->possessor, r_idx = m_ptr->r_idx;
- monster_race *r_ptr = &r_info[r2_idx];
+ auto r_ptr = &r_info[r2_idx];
int i;
char m_name[80];
@@ -413,12 +422,14 @@ bool_ do_control_drop(void)
bool_ do_control_magic(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i;
bool_ flag, redraw;
int ask;
char choice;
char out_val[160];
- monster_race *r_ptr = &r_info[m_list[p_ptr->control].r_idx];
+ auto r_ptr = &r_info[m_list[p_ptr->control].r_idx];
int label;
if (!p_ptr->control) return FALSE;
diff --git a/src/object1.cc b/src/object1.cc
index 8be0655a..466488fe 100644
--- a/src/object1.cc
+++ b/src/object1.cc
@@ -636,6 +636,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;
+ auto &r_info = game->edit_data.r_info;
int i;
@@ -668,13 +669,11 @@ void reset_visuals(void)
}
/* Extract default attr/char code for monsters */
- for (i = 0; i < max_r_idx; i++)
+ for (auto &r_ref: r_info)
{
- monster_race *r_ptr = &r_info[i];
-
/* Default attr/char */
- r_ptr->x_attr = r_ptr->d_attr;
- r_ptr->x_char = r_ptr->d_char;
+ r_ref.x_attr = r_ref.d_attr;
+ r_ref.x_char = r_ref.d_char;
}
/* Reset attr/char code for ego monster overlay graphics */
@@ -1020,6 +1019,7 @@ static object_flag_set compute_pval_mask()
*/
static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
{
+ auto const &r_info = game->edit_data.r_info;
static auto const TR_PVAL_MASK = compute_pval_mask();
bool_ hack_name = FALSE;
@@ -1300,7 +1300,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
case TV_CORPSE:
{
- monster_race* r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
+
modstr = basenm;
if (r_ptr->flags & RF_UNIQUE)
{
@@ -1315,7 +1316,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
case TV_EGG:
{
- monster_race* r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
+
modstr = basenm;
basenm = fmt::format("& {} #~", r_ptr->name);
break;
@@ -1324,7 +1326,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
case TV_HYPNOS:
{
/* We print hit points further down. --dsb */
- monster_race* r_ptr = &r_info[o_ptr->pval];
+ auto r_ptr = &r_info[o_ptr->pval];
+
modstr = basenm;
basenm = fmt::format("& {}~", r_ptr->name);
break;
@@ -1411,16 +1414,6 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
{
cptr ego = NULL;
- monster_race* r_ptr;
- if (o_ptr->tval == TV_CORPSE)
- {
- r_ptr = &r_info[o_ptr->pval2];
- }
- else
- {
- r_ptr = &r_info[o_ptr->pval];
- }
-
/* Grab any ego-item name */
if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN))
{
@@ -1459,12 +1452,15 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode)
t += ' ';
}
- else if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags & RF_UNIQUE))
- {}
-
+ else if ((o_ptr->tval == TV_CORPSE) && (r_info[o_ptr->pval2].flags & RF_UNIQUE))
+ {
+ /* Nothing */
+ }
- else if ((o_ptr->tval == TV_HYPNOS) && (r_ptr->flags & RF_UNIQUE))
- {}
+ else if ((o_ptr->tval == TV_HYPNOS) && (r_info[o_ptr->pval].flags & RF_UNIQUE))
+ {
+ /* Nothing */
+ }
/* Hack -- The only one of its kind */
else if (known && artifact_p(o_ptr))
diff --git a/src/object2.cc b/src/object2.cc
index 913bf4f6..eb0a66e8 100644
--- a/src/object2.cc
+++ b/src/object2.cc
@@ -769,6 +769,8 @@ bool object_tried_p(object_type const *o_ptr)
*/
static s32b object_value_base(object_type const *o_ptr)
{
+ auto const &r_info = game->edit_data.r_info;
+
object_kind *k_ptr = &k_info[o_ptr->k_idx];
/* Aware item -- use template cost */
@@ -816,7 +818,7 @@ static s32b object_value_base(object_type const *o_ptr)
/* Eggs */
case TV_EGG:
{
- monster_race *r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
/* Pay the monster level */
return (r_ptr->level * 100) + 100;
@@ -1070,6 +1072,8 @@ s32b flag_cost(object_type const *o_ptr, int plusses)
*/
s32b object_value_real(object_type const *o_ptr)
{
+ auto const &r_info = game->edit_data.r_info;
+
s32b value;
object_kind *k_ptr = &k_info[o_ptr->k_idx];
@@ -1202,7 +1206,7 @@ s32b object_value_real(object_type const *o_ptr)
/* Eggs */
case TV_EGG:
{
- monster_race *r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
/* Pay the monster level */
value += r_ptr->level * 100;
@@ -3214,6 +3218,8 @@ static int get_stick_max_level(byte tval, int level, int spl)
*/
static void a_m_aux_4(object_type *o_ptr, int level, int power)
{
+ auto const &r_info = game->edit_data.r_info;
+
s32b bonus_lvl, max_lvl;
object_kind *k_ptr = &k_info[o_ptr->k_idx];
@@ -3279,14 +3285,18 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
case TV_CORPSE:
{
/* Hack -- choose a monster */
- monster_race* r_ptr;
int r_idx = get_mon_num(dun_level);
- r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
if (!(r_ptr->flags & RF_UNIQUE))
+ {
o_ptr->pval2 = r_idx;
+ }
else
+ {
o_ptr->pval2 = 2;
+ }
+
o_ptr->pval3 = 0;
break;
}
@@ -3294,14 +3304,13 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
case TV_EGG:
{
/* Hack -- choose a monster */
- monster_race* r_ptr;
int r_idx, count = 0;
bool_ OK = FALSE;
while ((!OK) && (count < 1000))
{
r_idx = get_mon_num(dun_level);
- r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->flags & RF_HAS_EGG)
{
@@ -3310,9 +3319,13 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
}
count++;
}
- if (count == 1000) o_ptr->pval2 = 940; /* Blue fire-lizard */
- r_ptr = &r_info[o_ptr->pval2];
+ if (count == 1000)
+ {
+ o_ptr->pval2 = 940; /* Blue fire-lizard */
+ }
+
+ auto r_ptr = &r_info[o_ptr->pval2];
o_ptr->weight = (r_ptr->weight + rand_int(r_ptr->weight) / 100) + 1;
o_ptr->pval = r_ptr->weight * 3 + rand_int(r_ptr->weight) + 1;
break;
@@ -3321,9 +3334,8 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
case TV_HYPNOS:
{
/* Hack -- choose a monster */
- monster_race* r_ptr;
int r_idx = get_mon_num(dun_level);
- r_ptr = &r_info[r_idx];
+ auto r_ptr = &r_info[r_idx];
if (!(r_ptr->flags & RF_NEVER_MOVE))
o_ptr->pval = r_idx;
@@ -6311,9 +6323,11 @@ s16b floor_carry(int y, int x, object_type *j_ptr)
*/
void pack_decay(int item)
{
+ auto const &r_info = game->edit_data.r_info;
+
object_type *o_ptr = &p_ptr->inventory[item];
- monster_race *r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
object_type *i_ptr;
object_type object_type_body;
@@ -6396,9 +6410,11 @@ void pack_decay(int item)
*/
void floor_decay(int item)
{
+ auto const &r_info = game->edit_data.r_info;
+
object_type *o_ptr = &o_list[item];
- monster_race *r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
object_type *i_ptr;
object_type object_type_body;
diff --git a/src/q_bounty.cc b/src/q_bounty.cc
index e0a7ae2a..1bdb1fe6 100644
--- a/src/q_bounty.cc
+++ b/src/q_bounty.cc
@@ -22,7 +22,9 @@
static bool_ lua_mon_hook_bounty(int r_idx)
{
- monster_race* r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
/* Reject uniques */
if (r_ptr->flags & RF_UNIQUE) return (FALSE);
diff --git a/src/q_eol.cc b/src/q_eol.cc
index 1c141624..4392b001 100644
--- a/src/q_eol.cc
+++ b/src/q_eol.cc
@@ -2,6 +2,7 @@
#include "cave.hpp"
#include "cave_type.hpp"
+#include "game.hpp"
#include "generate.hpp"
#include "hook_stair_in.hpp"
#include "hook_quest_finish_in.hpp"
@@ -184,8 +185,10 @@ static bool_ quest_eol_death_hook(void *, void *in_, void *)
static bool_ quest_eol_stair_hook(void *, void *in_, void *)
{
+ auto const &r_info = game->edit_data.r_info;
+
struct hook_stair_in *in = static_cast<struct hook_stair_in *>(in_);
- monster_race *r_ptr = &r_info[get_eol()];
+ auto r_ptr = &r_info[get_eol()];
if (p_ptr->inside_quest != QUEST_EOL) return FALSE;
diff --git a/src/q_main.cc b/src/q_main.cc
index 81b6ac85..159d0f7b 100644
--- a/src/q_main.cc
+++ b/src/q_main.cc
@@ -1,5 +1,6 @@
#include "q_main.hpp"
+#include "game.hpp"
#include "hook_chardump_in.hpp"
#include "hook_monster_death_in.hpp"
#include "hook_new_monster_in.hpp"
@@ -30,6 +31,8 @@ static void quest_describe(int q_idx)
static bool_ quest_main_monsters_hook(void *, void *in_, void *)
{
+ auto const &r_info = game->edit_data.r_info;
+
struct hook_new_monster_in *in = static_cast<struct hook_new_monster_in *>(in_);
s32b r_idx = in->r_idx;
@@ -50,7 +53,9 @@ static bool_ quest_main_monsters_hook(void *, void *in_, void *)
static bool_ quest_morgoth_hook(void *, void *, void *)
{
- monster_race *r_ptr = &r_info[get_morgoth()];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[get_morgoth()];
/* Need to kill him */
if (!r_ptr->max_num)
@@ -126,7 +131,9 @@ bool_ quest_morgoth_init_hook()
static bool_ quest_sauron_hook(void *, void *, void *)
{
- monster_race *r_ptr = &r_info[get_sauron()];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[get_sauron()];
/* Need to kill him */
if (!r_ptr->max_num)
@@ -149,10 +156,12 @@ static bool_ quest_sauron_hook(void *, void *, void *)
static bool_ quest_sauron_resurect_hook(void *, void *in_, void *)
{
+ auto &r_info = game->edit_data.r_info;
+
struct hook_monster_death_in *in = static_cast<struct hook_monster_death_in *>(in_);
s32b m_idx = in->m_idx;
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ auto r_ptr = &r_info[m_ptr->r_idx];
if ((r_ptr->flags & RF_NAZGUL) && r_info[get_sauron()].max_num)
{
@@ -180,7 +189,9 @@ bool_ quest_sauron_init_hook()
static bool_ quest_necro_hook(void *, void *, void *)
{
- monster_race *r_ptr = &r_info[get_necromancer()];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[get_necromancer()];
/* Need to kill him */
if (!r_ptr->max_num)
diff --git a/src/q_poison.cc b/src/q_poison.cc
index 54df78f9..24d0320c 100644
--- a/src/q_poison.cc
+++ b/src/q_poison.cc
@@ -2,6 +2,7 @@
#include "cave.hpp"
#include "cave_type.hpp"
+#include "game.hpp"
#include "hook_chardump_in.hpp"
#include "hook_drop_in.hpp"
#include "hook_init_quest_in.hpp"
@@ -32,7 +33,9 @@ static int wild_locs[4][2] =
static bool_ create_molds_hook(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
if (r_ptr->spells & SF_MULTIPLY) return FALSE;
diff --git a/src/q_rand.cc b/src/q_rand.cc
index 9606ea7b..019f4b71 100644
--- a/src/q_rand.cc
+++ b/src/q_rand.cc
@@ -56,6 +56,7 @@ GENERATE_MONSTER_LOOKUP_FN(get_adventurer, "Adventurer")
void initialize_random_quests(int n)
{
auto const &d_info = game->edit_data.d_info;
+ auto &r_info = game->edit_data.r_info;
int step, lvl, i, k;
int old_type = dungeon_type;
@@ -437,6 +438,8 @@ static bool_ quest_random_turn_hook(void *, void *, void *)
static bool_ quest_random_feeling_hook(void *, void *, void *)
{
+ auto const &r_info = game->edit_data.r_info;
+
if (!(dungeon_flags & DF_PRINCIPAL)) return (FALSE);
if ((dun_level < 1) || (dun_level >= MAX_RANDOM_QUEST)) return (FALSE);
if (!random_quests[dun_level].type) return (FALSE);
@@ -616,6 +619,8 @@ static bool_ quest_random_dump_hook(void *, void *in_, void *)
std::string quest_random_describe()
{
+ auto const &r_info = game->edit_data.r_info;
+
// Only emit description if we're actually on a
// random quest level.
if (!(dungeon_flags & DF_PRINCIPAL)) return "";
diff --git a/src/q_shroom.cc b/src/q_shroom.cc
index 4fd1e066..ee5f9d1f 100644
--- a/src/q_shroom.cc
+++ b/src/q_shroom.cc
@@ -1,6 +1,7 @@
#include "q_shroom.hpp"
#include "cave.hpp"
+#include "game.hpp"
#include "hook_chat_in.hpp"
#include "hook_give_in.hpp"
#include "hook_monster_death_in.hpp"
@@ -128,6 +129,8 @@ static bool_ quest_shroom_death_hook(void *, void *in_, void *)
static bool_ quest_shroom_give_hook(void *, void *in_, void *)
{
+ auto const &r_info = game->edit_data.r_info;
+
struct hook_give_in *in = static_cast<struct hook_give_in *>(in_);
object_type *o_ptr;
monster_type *m_ptr;
@@ -213,6 +216,8 @@ static bool_ quest_shroom_give_hook(void *, void *in_, void *)
static void check_dogs_alive(s32b m_idx)
{
+ auto const &r_info = game->edit_data.r_info;
+
if ((r_info[get_grip()].max_num == 0) ||
(r_info[get_wolf()].max_num == 0) ||
(r_info[get_fang()].max_num == 0))
diff --git a/src/spells1.cc b/src/spells1.cc
index 8be8b06a..ed10c525 100644
--- a/src/spells1.cc
+++ b/src/spells1.cc
@@ -92,7 +92,9 @@ using std::chrono::milliseconds;
*/
s16b poly_r_idx(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[r_idx];
int i, r;
@@ -3812,6 +3814,8 @@ static int raise_ego[MAX_RAISE] =
*/
static bool_ project_o(int who, int r, int y, int x, int dam, int typ)
{
+ auto const &r_info = game->edit_data.r_info;
+
cave_type *c_ptr = &cave[y][x];
bool_ obvious = FALSE;
@@ -3864,8 +3868,9 @@ static bool_ project_o(int who, int r, int y, int x, int dam, int typ)
{
if (o_ptr->tval == TV_CORPSE)
{
- monster_race *r_ptr = &r_info[o_ptr->pval2];
- s32b dama, radius = 7;
+ auto r_ptr = &r_info[o_ptr->pval2];
+ s32b radius = 7;
+ s32b dama;
if (r_ptr->flags & RF_FORCE_MAXHP)
dama = maxroll(r_ptr->hdice, r_ptr->hside);
@@ -4094,7 +4099,7 @@ static bool_ project_o(int who, int r, int y, int x, int dam, int typ)
}
case GF_RAISE_DEMON:
{
- monster_race *r_ptr = &r_info[o_ptr->pval2];
+ auto r_ptr = &r_info[o_ptr->pval2];
cptr name;
if (o_ptr->tval != TV_CORPSE) break;
@@ -6907,6 +6912,7 @@ bool_ unsafe = FALSE;
static bool_ project_p(int who, int r, int y, int x, int dam, int typ, int a_rad)
{
auto const &d_info = game->edit_data.d_info;
+ auto const &r_info = game->edit_data.r_info;
int k = 0, do_move = 0, a = 0, b = 0, x1 = 0, y1 = 0;
diff --git a/src/spells2.cc b/src/spells2.cc
index 02b51056..1cd03430 100644
--- a/src/spells2.cc
+++ b/src/spells2.cc
@@ -801,6 +801,8 @@ bool_ alchemy(void) /* Turns an object into gold, gain some of its value in a sh
*/
void self_knowledge(FILE *fff)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i = 0, j, k;
int iter; /* Iterator for a loop */
@@ -838,7 +840,7 @@ void self_knowledge(FILE *fff)
/* Racial powers... */
if (p_ptr->body_monster != 0)
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
if (r_ptr->flags & RF_CHAR_CLEAR ||
r_ptr->flags & RF_ATTR_CLEAR)
diff --git a/src/traps.cc b/src/traps.cc
index 067934b9..0f6c1f5d 100644
--- a/src/traps.cc
+++ b/src/traps.cc
@@ -2353,6 +2353,8 @@ bool_ mon_hit_trap_aux_staff(int m_idx, object_type *o_ptr)
*/
bool_ mon_hit_trap_aux_scroll(int m_idx, int sval)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_type *m_ptr = &m_list[m_idx];
int dam = 0, typ = 0;
int rad = 0;
@@ -2448,7 +2450,7 @@ bool_ mon_hit_trap_aux_scroll(int m_idx, int sval)
break;
case SV_SCROLL_GENOCIDE:
{
- monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ auto r_ptr = &r_info[m_ptr->r_idx];
genocide_aux(FALSE, r_ptr->d_char);
/* although there's no point in a multiple genocide trap... */
return (!(r_ptr->flags & RF_UNIQUE));
@@ -2490,6 +2492,8 @@ bool_ mon_hit_trap_aux_wand(int m_idx, object_type *o_ptr)
*/
bool_ mon_hit_trap_aux_potion(int m_idx, object_type *o_ptr)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_type *m_ptr = &m_list[m_idx];
int dam = 0, typ = 0;
int y = m_ptr->fy;
@@ -2613,7 +2617,7 @@ bool_ mon_hit_trap_aux_potion(int m_idx, object_type *o_ptr)
break;
case SV_POTION_LIFE:
{
- monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ auto r_ptr = &r_info[m_ptr->r_idx];
if (r_ptr->flags & RF_UNDEAD)
{
typ = GF_HOLY_FIRE;
@@ -2645,8 +2649,10 @@ bool_ mon_hit_trap_aux_potion(int m_idx, object_type *o_ptr)
*/
bool_ mon_hit_trap(int m_idx)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ auto r_ptr = &r_info[m_ptr->r_idx];
object_type object_type_body;
diff --git a/src/util.cc b/src/util.cc
index 231a249f..9351dce1 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -3328,13 +3328,15 @@ void strlower(char *buf)
*/
int test_monster_name(cptr name)
{
- int i;
+ auto const &r_info = game->edit_data.r_info;
- /* Scan the monsters */
- for (i = 1; i < max_r_idx; i++)
+ for (std::size_t i = 0; i < r_info.size(); i++)
{
- monster_race *r_ptr = &r_info[i];
- if (r_ptr->name && iequals(name, r_ptr->name)) return (i);
+ auto r_ptr = &r_info[i];
+ if (r_ptr->name && iequals(name, r_ptr->name))
+ {
+ return (i);
+ }
}
return (0);
}
diff --git a/src/variable.cc b/src/variable.cc
index 1f861563..a58191d5 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -453,11 +453,6 @@ ego_item_type *e_info;
trap_type *t_info;
/*
- * The monster race arrays
- */
-monster_race *r_info;
-
-/*
* The wilderness features arrays
*/
int wildc2i[256];
@@ -579,11 +574,6 @@ s32b get_level_max_stick = -1;
s32b get_level_use_stick = -1;
/*
- * Maximum number of monsters in r_info.txt
- */
-u16b max_r_idx;
-
-/*
* Maximum number of items in k_info.txt
*/
u16b max_k_idx;
diff --git a/src/variable.hpp b/src/variable.hpp
index 1813b762..70c381b9 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_race_fwd.hpp"
#include "monster_type_fwd.hpp"
#include "object_kind_fwd.hpp"
#include "object_type_fwd.hpp"
@@ -157,7 +156,6 @@ extern feature_type *f_info;
extern object_kind *k_info;
extern artifact_type *a_info;
extern ego_item_type *e_info;
-extern monster_race *r_info;
extern trap_type *t_info;
extern int wildc2i[256];
extern cptr DEFAULT_FEAT_TEXT;
@@ -170,7 +168,6 @@ extern char *ANGBAND_DIR_DNGN;
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_k_idx;
extern u16b max_f_idx;
extern u16b max_a_idx;
diff --git a/src/wild.cc b/src/wild.cc
index 5627629a..101e06f5 100644
--- a/src/wild.cc
+++ b/src/wild.cc
@@ -1002,10 +1002,11 @@ static void town_borders(int qy, int qx)
static bool_ create_townpeople_hook(int r_idx)
{
- monster_race *r_ptr = &r_info[r_idx];
+ auto const &r_info = game->edit_data.r_info;
- if (r_ptr->d_char == 't') return TRUE;
- else return FALSE;
+ auto r_ptr = &r_info[r_idx];
+
+ return (r_ptr->d_char == 't');
}
diff --git a/src/wizard2.cc b/src/wizard2.cc
index b2713636..575b6e72 100644
--- a/src/wizard2.cc
+++ b/src/wizard2.cc
@@ -1399,15 +1399,17 @@ static void do_cmd_wiz_summon(int num)
*
* XXX XXX XXX This function is rather dangerous
*/
-static void do_cmd_wiz_named(int r_idx, bool_ slp)
+static void do_cmd_wiz_named(std::size_t r_idx, bool_ slp)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, x, y;
/* Paranoia */
/* if (!r_idx) return; */
/* Prevent illegal monsters */
- if (r_idx >= max_r_idx) return;
+ if (r_idx >= r_info.size()) return;
/* Try 10 times */
for (i = 0; i < 10; i++)
@@ -1439,15 +1441,17 @@ static void do_cmd_wiz_named(int r_idx, bool_ slp)
*
* XXX XXX XXX This function is rather dangerous
*/
-void do_cmd_wiz_named_friendly(int r_idx, bool_ slp)
+void do_cmd_wiz_named_friendly(std::size_t r_idx, bool_ slp)
{
+ auto const &r_info = game->edit_data.r_info;
+
int i, x, y;
/* Paranoia */
/* if (!r_idx) return; */
/* Prevent illegal monsters */
- if (r_idx >= max_r_idx) return;
+ if (r_idx >= r_info.size()) return;
/* Try 10 times */
for (i = 0; i < 10; i++)
@@ -1500,6 +1504,8 @@ static void do_cmd_wiz_body(s16b bidx)
/* Might create problems with equipment slots. For safety,
be nude when calling this function */
{
+ auto const &r_info = game->edit_data.r_info;
+
p_ptr->body_monster = bidx;
p_ptr->disembodied = FALSE;
p_ptr->chp = maxroll( (&r_info[bidx])->hdice, (&r_info[bidx])->hside);
diff --git a/src/wizard2.hpp b/src/wizard2.hpp
index cec515c8..161eb26d 100644
--- a/src/wizard2.hpp
+++ b/src/wizard2.hpp
@@ -4,5 +4,5 @@
extern void do_cmd_rerate(void);
extern void do_cmd_wiz_cure_all(void);
-extern void do_cmd_wiz_named_friendly(int r_idx, bool_ slp);
+extern void do_cmd_wiz_named_friendly(std::size_t r_idx, bool_ slp);
extern void do_cmd_debug();
diff --git a/src/xtra1.cc b/src/xtra1.cc
index 2829b2f6..80cbe09e 100644
--- a/src/xtra1.cc
+++ b/src/xtra1.cc
@@ -1365,10 +1365,12 @@ static void fix_object(void)
static void fix_m_list(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
// Mirror of the r_info array, index by index. We use a
// statically allocated value to avoid frequent allocations.
static auto r_total_visible =
- std::vector<u16b>(max_r_idx, 0);
+ std::vector<u16b>(r_info.size(), 0);
/* Scan windows */
for (std::size_t j = 0; j < 8; j++)
@@ -1404,7 +1406,7 @@ static void fix_m_list(void)
}
/* reset visible count */
- for (std::size_t i = 1; i < max_r_idx; i++)
+ for (std::size_t i = 1; i < r_info.size(); i++)
{
r_total_visible[i] = 0;
}
@@ -1449,7 +1451,7 @@ static void fix_m_list(void)
c_prt(TERM_WHITE, format("You can see %d monster%s", c, (c > 1 ? "s:" : ":")), 0, 0);
- for (std::size_t i = 1; i < max_r_idx; i++)
+ for (std::size_t i = 1; i < r_info.size(); i++)
{
auto const r_ptr = &r_info[i];
auto const total_visible = r_total_visible[i];
@@ -1667,6 +1669,8 @@ static void calc_sanity()
*/
static void calc_mana(void)
{
+ auto const &r_info = game->edit_data.r_info;
+
int msp, levels, cur_wgt, max_wgt;
levels = p_ptr->lev;
@@ -1687,7 +1691,8 @@ static void calc_mana(void)
/* Possessors mana is different */
if (p_ptr->body_monster && (!p_ptr->disembodied))
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
+
int f = 100 / (r_ptr->freq_spell ? r_ptr->freq_spell : 1);
msp = 21 - f;
@@ -1845,6 +1850,7 @@ static void calc_mana(void)
void calc_hitpoints(void)
{
auto const &player_hp = game->player_hp;
+ auto const &r_info = game->edit_data.r_info;
/* Un-inflate "half-hitpoint bonus per level" value */
int const bonus = ((int)(adj_con_mhp[p_ptr->stat_ind[A_CON]]) - 128);
@@ -1884,7 +1890,7 @@ void calc_hitpoints(void)
if (p_ptr->body_monster)
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto r_ptr = &r_info[p_ptr->body_monster];
u32b rhp = maxroll(r_ptr->hdice, r_ptr->hside);
/* Adjust the hp with the possession skill */
@@ -2061,15 +2067,14 @@ int weight_limit(void)
void calc_wield_monster()
{
- object_type *o_ptr;
- monster_race *r_ptr;
+ auto const &r_info = game->edit_data.r_info;
/* Get the carried monster */
- o_ptr = &p_ptr->inventory[INVEN_CARRY];
+ auto o_ptr = &p_ptr->inventory[INVEN_CARRY];
if (o_ptr->k_idx)
{
- r_ptr = &r_info[o_ptr->pval];
+ auto r_ptr = &r_info[o_ptr->pval];
if (r_ptr->flags & RF_INVISIBLE)
p_ptr->invis += 20;
@@ -2090,7 +2095,9 @@ void calc_wield_monster()
*/
void calc_body()
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[p_ptr->body_monster];
int i, b_weapon, b_legs, b_arms;
byte *body_parts, bp[BODY_MAX];
@@ -2209,10 +2216,15 @@ void calc_body()
/* Should be called by every calc_bonus call */
void calc_body_bonus()
{
- monster_race *r_ptr = &r_info[p_ptr->body_monster];
+ auto const &r_info = game->edit_data.r_info;
+
+ auto r_ptr = &r_info[p_ptr->body_monster];
/* If in the player body nothing have to be done */
- if (!p_ptr->body_monster) return;
+ if (!p_ptr->body_monster)
+ {
+ return;
+ }
if (p_ptr->disembodied)
{
@@ -2806,6 +2818,7 @@ static bool_ monk_empty_hands(void)
void calc_bonuses(bool_ silent)
{
auto const &s_descriptors = game->edit_data.s_descriptors;
+ auto const &r_info = game->edit_data.r_info;
auto &s_info = game->s_info;
static bool_ monk_notify_aux = FALSE;
diff --git a/src/xtra2.cc b/src/xtra2.cc
index d9d9746f..482526ef 100644
--- a/src/xtra2.cc
+++ b/src/xtra2.cc
@@ -3618,6 +3618,8 @@ static cptr look_mon_desc(int m_idx)
*/
static bool target_able(int m_idx)
{
+ auto const &r_info = game->edit_data.r_info;
+
monster_type *m_ptr = &m_list[m_idx];
/* Monster must be alive */
@@ -3734,6 +3736,8 @@ static s16b target_pick(point p, int dy, int dx, std::vector<point> const &point
*/
static bool_ target_set_accept(int y, int x)
{
+ auto const &r_info = game->edit_data.r_info;
+
/* Player grid is always interesting */
if ((y == p_ptr->py) && (x == p_ptr->px)) return (TRUE);
@@ -3746,7 +3750,7 @@ static bool_ target_set_accept(int y, int x)
cave_type *c_ptr = &cave[y][x];
/* Visible monsters */
- if (c_ptr->m_idx && c_ptr->m_idx < max_r_idx)
+ if (c_ptr->m_idx && c_ptr->m_idx < static_cast<int>(r_info.size()))
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
@@ -5152,7 +5156,8 @@ static void clean_wish_name(char *buf, char *name)
*/
void make_wish(void)
{
- const auto &re_info = game->edit_data.re_info;
+ auto const &re_info = game->edit_data.re_info;
+ auto const &r_info = game->edit_data.r_info;
char name[200], *mname;
int mstatus = MSTATUS_ENEMY;
@@ -5216,9 +5221,9 @@ void make_wish(void)
mname = name;
}
- for (std::size_t i = 1; i < max_r_idx; i++)
+ for (std::size_t i = 1; i < r_info.size(); i++)
{
- monster_race *r_ptr = &r_info[i];
+ auto r_ptr = &r_info[i];
if (!r_ptr->name) continue;