summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-12-11 08:09:30 +0100
committerBardur Arantsson <bardur@scientician.net>2015-12-11 08:09:30 +0100
commit00be445e9127922933dae91a3d68660a57f53c5b (patch)
treea9ce274cb7cdba65e81994e719a8a40a8057d38e
parentf88c896138589fd2328002a7a4f097c582f79f9b (diff)
Refactor race_info_idx() to avoid "invisible" static pointers
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/cave.cc19
-rw-r--r--src/cmd1.cc73
-rw-r--r--src/cmd2.cc6
-rw-r--r--src/cmd4.cc6
-rw-r--r--src/cmd7.cc3
-rw-r--r--src/dungeon.cc23
-rw-r--r--src/melee1.cc5
-rw-r--r--src/melee2.cc254
-rw-r--r--src/modules.cc2
-rw-r--r--src/monster1.cc49
-rw-r--r--src/monster2.cc205
-rw-r--r--src/monster2.hpp6
-rw-r--r--src/monster3.cc2
-rw-r--r--src/monster_type.cc8
-rw-r--r--src/monster_type.hpp8
-rw-r--r--src/powers.cc18
-rw-r--r--src/spells1.cc62
-rw-r--r--src/spells2.cc41
-rw-r--r--src/spells3.cc9
-rw-r--r--src/traps.cc2
-rw-r--r--src/xtra1.cc17
-rw-r--r--src/xtra2.cc77
-rw-r--r--src/xtra2.hpp4
24 files changed, 422 insertions, 478 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dcd1e51..1fc6a3b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -40,6 +40,7 @@ SET(SRCS_COMMON
messages.cc
mimic.cc
modules.cc
+ monster_type.cc
monster1.cc
monster2.cc
monster3.cc
diff --git a/src/cave.cc b/src/cave.cc
index 1dc5cbd..6a1c513 100644
--- a/src/cave.cc
+++ b/src/cave.cc
@@ -550,7 +550,7 @@ static byte breath_to_attr[32][2] =
*
* If a monster does not breath anything, it can be any color.
*/
-static byte multi_hued_attr(monster_race *r_ptr)
+static byte multi_hued_attr(std::shared_ptr<monster_race> r_ptr)
{
byte allowed_attrs[15];
@@ -1094,7 +1094,7 @@ static void map_info(int y, int x, byte *ap, char *cp)
if (c_ptr->m_idx)
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags9 & RF9_MIMIC)
{
@@ -1125,8 +1125,6 @@ static void map_info(int y, int x, byte *ap, char *cp)
/* Visible monster */
if (m_ptr->ml)
{
- monster_race *r_ptr = race_inf(m_ptr);
-
/* Desired attr/char */
c = r_ptr->x_char;
a = r_ptr->x_attr;
@@ -1526,7 +1524,7 @@ void map_info_default(int y, int x, byte *ap, char *cp)
if (c_ptr->m_idx)
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags9 & RF9_MIMIC)
{
@@ -1557,8 +1555,6 @@ void map_info_default(int y, int x, byte *ap, char *cp)
/* Visible monster */
if (m_ptr->ml)
{
- monster_race *r_ptr = race_inf(m_ptr);
-
/* Default attr/char */
c = r_ptr->d_char;
a = r_ptr->d_attr;
@@ -1775,7 +1771,7 @@ void note_spot(int y, int x)
if (c_ptr->m_idx)
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto r_ptr = m_ptr->race();
if (r_ptr->flags9 & RF9_MIMIC)
{
@@ -3617,7 +3613,6 @@ void update_mon_lite(void)
for (i = 1; i < m_max; i++)
{
monster_type *m_ptr = &m_list[i];
- monster_race *r_ptr;
/* Skip dead monsters */
if (!m_ptr->r_idx) continue;
@@ -3625,8 +3620,8 @@ void update_mon_lite(void)
/* Skip out-of-sight monsters (MAX_SIGHT + max radius) */
if (m_ptr->cdis > MAX_SIGHT + 1) continue;
- /* Access monster race info (with possible ego mods) */
- r_ptr = race_info_idx(m_ptr->r_idx, m_ptr->ego);
+ /* Access monster race */
+ auto r_ptr = m_ptr->race();
/* Skip monsters not carrying light source */
if (!(r_ptr->flags9 & RF9_HAS_LITE)) continue;
@@ -4030,7 +4025,7 @@ void wiz_lite(void)
if (c_ptr->m_idx)
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags9 & RF9_MIMIC)
{
diff --git a/src/cmd1.cc b/src/cmd1.cc
index ac8e34a..6320703 100644
--- a/src/cmd1.cc
+++ b/src/cmd1.cc
@@ -236,7 +236,7 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr,
{
int mult = 1;
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
u32b f1, f2, f3, f4, f5, esp;
@@ -681,10 +681,7 @@ static void hit_trap(void)
void touch_zap_player(monster_type *m_ptr)
{
- int aura_damage = 0;
-
- monster_race *r_ptr = race_inf(m_ptr);
-
+ auto r_ptr = m_ptr->race();
if (r_ptr->flags2 & (RF2_AURA_FIRE))
{
@@ -692,7 +689,7 @@ void touch_zap_player(monster_type *m_ptr)
{
char aura_dam[80];
- aura_damage =
+ int aura_damage =
damroll(1 + (m_ptr->level / 26), 1 + (m_ptr->level / 17));
/* Hack -- Get the "died from" name */
@@ -717,7 +714,7 @@ void touch_zap_player(monster_type *m_ptr)
{
char aura_dam[80];
- aura_damage =
+ int aura_damage =
damroll(1 + (m_ptr->level / 26), 1 + (m_ptr->level / 17));
/* Hack -- Get the "died from" name */
@@ -746,8 +743,6 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath,
monster_race *r_ptr;
- monster_race *tr_ptr = race_inf(t_ptr);
-
int ap_cnt;
int ac, rlev, pt;
@@ -1168,6 +1163,7 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath,
if (touched)
{
+ auto tr_ptr = t_ptr->race();
/* Aura fire */
if ((tr_ptr->flags2 & RF2_AURA_FIRE) &&
!(r_ptr->flags3 & RF3_IM_FIRE))
@@ -1268,9 +1264,7 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath,
{
monster_type *t_ptr = &m_list[m_idx];
- monster_race *r_ptr;
-
- monster_race *tr_ptr = race_inf(t_ptr);
+ auto tr_ptr = t_ptr->race();
int ap_cnt;
@@ -1289,7 +1283,7 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath,
if (!p_ptr->body_monster) return;
- r_ptr = race_info_idx(p_ptr->body_monster, 0);
+ auto r_ptr = &r_info[p_ptr->body_monster];
/* Not allowed to attack */
if (r_ptr->flags1 & RF1_NEVER_BLOW) return;
@@ -1834,12 +1828,10 @@ static void flavored_attack(int percent, char *output)
*/
void attack_special(monster_type *m_ptr, s32b special, int dam)
{
- char m_name[80];
-
- monster_race *r_ptr = race_inf(m_ptr);
-
+ auto const r_ptr = m_ptr->race();
/* Extract monster name (or "it") */
+ char m_name[80];
monster_desc(m_name, m_ptr, 0);
/* Special - Cut monster */
@@ -1912,12 +1904,10 @@ void attack_special(monster_type *m_ptr, s32b special, int dam)
static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special)
{
s16b special_effect = 0, stun_effect = 0, times = 0;
- martial_arts *ma_ptr, *old_ptr, *blow_table = ma_blows;
- int resist_stun = 0, max = MAX_MA;
- monster_race *r_ptr = race_inf(m_ptr);
- char m_name[80];
+ martial_arts *blow_table = ma_blows;
+ int resist_stun = 0;
+ int max = MAX_MA;
bool_ desc = FALSE;
- bool_ done_crit;
int plev = p_ptr->lev;
if ((!p_ptr->body_monster) && (p_ptr->mimic_form == resolve_mimic_name("Bear")) &&
@@ -1933,12 +1923,11 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special)
max = MAX_MA;
plev = get_skill(SKILL_HAND);
}
- ma_ptr = &blow_table[0];
- old_ptr = &blow_table[0];
+ martial_arts *ma_ptr = &blow_table[0];
+ martial_arts *old_ptr = &blow_table[0];
/* Extract monster name (or "it") */
- monster_desc(m_name, m_ptr, 0);
-
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags1 & RF1_UNIQUE) resist_stun += 88;
if (r_ptr->flags3 & RF3_NO_CONF) resist_stun += 44;
if (r_ptr->flags3 & RF3_NO_SLEEP) resist_stun += 44;
@@ -1975,6 +1964,11 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special)
*k = damroll(ma_ptr->dd, ma_ptr->ds);
+ /* Extract name */
+ char m_name[80];
+ monster_desc(m_name, m_ptr, 0);
+
+ /* Describe attack */
if (ma_ptr->effect & MA_KNEE)
{
if (r_ptr->flags1 & RF1_MALE)
@@ -2028,6 +2022,7 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special)
desc = TRUE;
}
+ bool_ done_crit;
*k = critical_norm(plev * (randint(10)), ma_ptr->min_level, *k, -1, &done_crit);
if ((special_effect & MA_KNEE) && ((*k + p_ptr->to_d) < m_ptr->hp))
@@ -2065,7 +2060,7 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special)
/*
* Apply nazgul effects
*/
-void do_nazgul(int *k, int *num, int num_blow, int weap, monster_race *r_ptr,
+static void do_nazgul(int *k, int *num, int num_blow, int weap, std::shared_ptr<monster_race> r_ptr,
object_type *o_ptr)
{
u32b f1, f2, f3, f4, f5, esp;
@@ -2170,12 +2165,6 @@ void py_attack(int y, int x, int max_blow)
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
- object_type *o_ptr;
-
- char m_name[80];
-
bool_ fear = FALSE;
bool_ mdeath = FALSE;
@@ -2230,6 +2219,7 @@ void py_attack(int y, int x, int max_blow)
/* Extract monster name (or "it") */
+ char m_name[80];
monster_desc(m_name, m_ptr, 0);
/* Auto-Recall if possible and visible */
@@ -2309,7 +2299,10 @@ void py_attack(int y, int x, int max_blow)
num = 0;
/* Access the weapon */
- o_ptr = &p_ptr->inventory[INVEN_WIELD + weap];
+ object_type *o_ptr = &p_ptr->inventory[INVEN_WIELD + weap];
+
+ /* Get race info */
+ auto r_ptr = m_ptr->race();
/* Calculate the "attack quality" */
bonus = p_ptr->to_h + p_ptr->to_h_melee + o_ptr->to_h;
@@ -2686,7 +2679,7 @@ void py_attack(int y, int x, int max_blow)
monster_desc(m_name, m_ptr, 0);
/* Hack -- Get new race */
- r_ptr = race_inf(m_ptr);
+ r_ptr = m_ptr->race();
fear = FALSE;
}
@@ -3070,7 +3063,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], *mr_ptr;
+ monster_race *r_ptr = &r_info[p_ptr->body_monster];
char m_name[80];
@@ -3242,7 +3235,7 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm)
/* Get the monster */
m_ptr = &m_list[c_ptr->m_idx];
- mr_ptr = race_inf(m_ptr);
+ auto const mr_ptr = m_ptr->race();
if (p_ptr->inventory[INVEN_WIELD].art_name)
{
@@ -4984,8 +4977,6 @@ bool_ execute_inscription(byte i, byte y, byte x)
case INSCRIP_CHASM:
{
- monster_type *m_ptr;
- monster_race *r_ptr;
int ii = x, ij = y;
cave_set_feat(ij, ii, FEAT_DARK_PIT);
@@ -4995,8 +4986,8 @@ bool_ execute_inscription(byte i, byte y, byte x)
if (c_ptr->m_idx)
{
- m_ptr = &m_list[c_ptr->m_idx];
- r_ptr = race_inf(m_ptr);
+ monster_type *m_ptr = &m_list[c_ptr->m_idx];
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags7 & RF7_CAN_FLY)
{
diff --git a/src/cmd2.cc b/src/cmd2.cc
index 768e79c..fef0dd8 100644
--- a/src/cmd2.cc
+++ b/src/cmd2.cc
@@ -3336,7 +3336,7 @@ void do_cmd_fire(void)
cave_type *c_ptr = &cave[y][x];
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Check the visibility */
visible = m_ptr->ml;
@@ -3750,7 +3750,7 @@ void do_cmd_throw(void)
cave_type *c_ptr = &cave[y][x];
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto r_ptr = m_ptr->race();
/* Check the visibility */
visible = m_ptr->ml;
@@ -4077,7 +4077,7 @@ void do_cmd_boomerang(void)
cave_type *c_ptr = &cave[y][x];
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Check the visibility */
visible = m_ptr->ml;
diff --git a/src/cmd4.cc b/src/cmd4.cc
index c18718a..b0162a5 100644
--- a/src/cmd4.cc
+++ b/src/cmd4.cc
@@ -3535,12 +3535,14 @@ static void do_cmd_knowledge_pets(void)
/* Calculate "upkeep" for friendly monsters */
if (m_ptr->status >= MSTATUS_PET)
{
- char pet_name[80];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
t_friends++;
t_levels += m_ptr->level;
+
+ char pet_name[80];
monster_desc(pet_name, m_ptr, 0x88);
+
fprintf(fff, "%s%s (%s)\n",
(r_ptr->flags1 & RF1_UNIQUE) ? "#####G" : "",
pet_name,
diff --git a/src/cmd7.cc b/src/cmd7.cc
index ef314ef..6f0412d 100644
--- a/src/cmd7.cc
+++ b/src/cmd7.cc
@@ -4104,7 +4104,6 @@ void do_cmd_symbiotic(void)
int dir, x, y;
cave_type *c_ptr;
monster_type *m_ptr;
- monster_race *r_ptr;
object_type *q_ptr;
object_type forge;
@@ -4116,7 +4115,7 @@ void do_cmd_symbiotic(void)
if (c_ptr->m_idx)
{
m_ptr = &m_list[c_ptr->m_idx];
- r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
if (!(r_ptr->flags1 & RF1_NEVER_MOVE))
{
diff --git a/src/dungeon.cc b/src/dungeon.cc
index 9aaf77e..57c592c 100644
--- a/src/dungeon.cc
+++ b/src/dungeon.cc
@@ -809,7 +809,6 @@ static void regen_monsters(void)
{
/* Check the i'th monster */
monster_type *m_ptr = &m_list[i];
- monster_race *r_ptr = race_inf(m_ptr);
/* Skip dead monsters */
if (!m_ptr->r_idx) continue;
@@ -827,9 +826,9 @@ static void regen_monsters(void)
if (!frac) frac = 1;
/* Hack -- Some monsters regenerate quickly */
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags2 & (RF2_REGENERATE)) frac *= 2;
-
/* Hack -- Regenerate */
m_ptr->hp += frac;
@@ -2962,8 +2961,6 @@ static void process_world(void)
/* Hatch eggs */
if (o_ptr->tval == TV_EGG)
{
- int mx, my;
-
if (o_ptr->timeout == 0)
{
o_ptr->pval--;
@@ -2971,17 +2968,14 @@ static void process_world(void)
/* Notice changes */
if (o_ptr->pval <= 0)
{
- monster_type *m_ptr;
- monster_race *r_ptr;
-
- mx = p_ptr->px;
- my = p_ptr->py + 1;
+ int mx = p_ptr->px;
+ int my = p_ptr->py + 1;
get_pos_player(5, &my, &mx);
msg_print("Your egg hatches!");
place_monster_aux(my, mx, o_ptr->pval2, FALSE, FALSE, MSTATUS_PET);
- m_ptr = &m_list[cave[my][mx].m_idx];
- r_ptr = race_inf(m_ptr);
+ monster_type *m_ptr = &m_list[cave[my][mx].m_idx];
+ auto const r_ptr = m_ptr->race();
if ((r_ptr->flags9 & RF9_IMPRESED) && can_create_companion())
{
@@ -4518,17 +4512,14 @@ static void process_player(void)
/* Shimmer multi-hued monsters */
for (i = 1; i < m_max; i++)
{
- monster_type *m_ptr;
- monster_race *r_ptr;
-
/* Access monster */
- m_ptr = &m_list[i];
+ monster_type *m_ptr = &m_list[i];
/* Skip dead monsters */
if (!m_ptr->r_idx) continue;
/* Access the monster race */
- r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Skip non-multi-hued monsters */
if (!(r_ptr->flags1 & (RF1_ATTR_MULTI))) continue;
diff --git a/src/melee1.cc b/src/melee1.cc
index 4eabe22..9ec5f0c 100644
--- a/src/melee1.cc
+++ b/src/melee1.cc
@@ -1349,8 +1349,6 @@ bool_ make_attack_normal(int m_idx, byte divis)
{
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
int ap_cnt;
int i, j, k, tmp, ac, rlev;
@@ -1370,7 +1368,8 @@ bool_ make_attack_normal(int m_idx, byte divis)
bool_ touched = FALSE, fear = FALSE, alive = TRUE;
bool_ explode = FALSE;
- /* Not allowed to attack */
+ /* Not allowed to attack? */
+ auto r_ptr = m_ptr->race();
if (r_ptr->flags1 & (RF1_NEVER_BLOW)) return (FALSE);
/* ...nor if friendly */
diff --git a/src/melee2.cc b/src/melee2.cc
index 05d91f3..8478add 100644
--- a/src/melee2.cc
+++ b/src/melee2.cc
@@ -60,14 +60,11 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note)
{
monster_type *m_ptr = &m_list[m_idx], *s_ptr = &m_list[s_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
- s32b div, new_exp, new_exp_frac;
-
/* Redraw (later) if needed */
if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME);
- /* Some mosnters are immune to death */
+ /* Some monsters are immune to death */
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags7 & RF7_NO_DEATH) return FALSE;
/* Wake it up */
@@ -142,13 +139,13 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note)
if (get_skill(SKILL_LORE) && (s_ptr->status >= MSTATUS_PET))
{
/* Maximum player level */
- div = p_ptr->max_plv;
+ s32b div = p_ptr->max_plv;
/* Give some experience for the kill */
- new_exp = ((long)r_ptr->mexp * m_ptr->level) / div;
+ s32b new_exp = ((long)r_ptr->mexp * m_ptr->level) / div;
/* Handle fractional experience */
- new_exp_frac = ((((long)r_ptr->mexp * m_ptr->level) % div)
+ s32b new_exp_frac = ((((long)r_ptr->mexp * m_ptr->level) % div)
* 0x10000L / div) + p_ptr->exp_frac;
/* Keep track of experience */
@@ -203,12 +200,8 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note)
void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear)
{
- monster_race *r_ptr = NULL;
-
assert(m_ptr != NULL);
- r_ptr = race_inf(m_ptr);
-
/* Mega-Hack -- Pain cancels fear */
if (m_ptr->monfear && (dam > 0))
{
@@ -233,6 +226,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear)
}
/* Sometimes a monster gets scared by damage */
+ auto const r_ptr = m_ptr->race();
if (!m_ptr->monfear && !(r_ptr->flags3 & (RF3_NO_FEAR)))
{
int percentage;
@@ -291,7 +285,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear)
/*
* Internal probability routine
*/
-static bool_ int_outof(monster_race *r_ptr, int prob)
+static bool_ int_outof(std::shared_ptr<monster_race> r_ptr, int prob)
{
/* Non-Smart monsters are half as "smart" */
if (!(r_ptr->flags2 & (RF2_SMART))) prob = prob / 2;
@@ -308,7 +302,6 @@ static bool_ int_outof(monster_race *r_ptr, int prob)
static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
{
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
u32b f4 = (*f4p);
u32b f5 = (*f5p);
@@ -317,7 +310,8 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
u32b smart = 0L;
- /* Too stupid to know anything */
+ /* Too stupid to know anything? */
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags2 & (RF2_STUPID)) return;
@@ -763,7 +757,6 @@ static bool_ spell_heal(byte spell)
static int choose_attack_spell(int m_idx, byte spells[], byte num)
{
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
byte escape[96], escape_num = 0;
byte attack[96], attack_num = 0;
@@ -773,9 +766,8 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
byte haste[96], haste_num = 0;
byte heal[96], heal_num = 0;
- int i;
-
/* Stupid monsters choose randomly */
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags2 & (RF2_STUPID))
{
/* Pick at random */
@@ -783,7 +775,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
}
/* Categorize spells */
- for (i = 0; i < num; i++)
+ for (int i = 0; i < num; i++)
{
/* Escape spell? */
if (spell_escape(spells[i])) escape[escape_num++] = spells[i];
@@ -887,7 +879,7 @@ static void breath(int m_idx, int typ, int dam_hp, int rad)
int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Determine the radius of the blast */
if (rad < 1) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2;
@@ -907,7 +899,7 @@ static void monst_breath_monst(int m_idx, int y, int x, int typ, int dam_hp, int
int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Determine the radius of the blast */
if (rad < 1) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2;
@@ -996,17 +988,13 @@ int monst_spell_monst_spell = -1;
static bool_ monst_spell_monst(int m_idx)
{
int y = 0, x = 0;
- int i = 1, k, t_idx;
- int chance, thrown_spell, count = 0;
+ int i = 1;
+ int thrown_spell;
byte spell[96], num = 0;
char m_name[80], t_name[80];
char m_poss[80];
char ddesc[80];
- int rlev; /* monster level */
monster_type *m_ptr = &m_list[m_idx]; /* Attacker */
- monster_race *r_ptr = race_inf(m_ptr);
- monster_type *t_ptr; /* Putative target */
- monster_race *tr_ptr;
u32b f4, f5, f6; /* racial spell flags */
bool_ direct = TRUE;
bool_ wake_up = FALSE;
@@ -1030,7 +1018,8 @@ static bool_ monst_spell_monst(int m_idx)
if (m_ptr->confused) return (FALSE);
/* Hack -- Extract the spell probability */
- chance = (r_ptr->freq_inate + r_ptr->freq_spell) / 2;
+ const auto r_ptr = m_ptr->race();
+ const int chance = (r_ptr->freq_inate + r_ptr->freq_spell) / 2;
/* Not allowed to cast spells */
if ((!chance) && (monst_spell_monst_spell == -1)) return (FALSE);
@@ -1050,9 +1039,10 @@ static bool_ monst_spell_monst(int m_idx)
{
- t_idx = i;
- t_ptr = &m_list[t_idx];
- tr_ptr = race_inf(t_ptr);
+ int t_idx = i;
+
+ monster_type *t_ptr = &m_list[t_idx];
+ auto const tr_ptr = t_ptr->race();
/* Hack -- no fighting >100 squares from player */
if (t_ptr->cdis > MAX_RANGE) return FALSE;
@@ -1065,7 +1055,7 @@ static bool_ monst_spell_monst(int m_idx)
x = t_ptr->fx;
/* Extract the monster level */
- rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1);
+ const int rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1);
/* Extract the racial spell flags */
f4 = r_ptr->flags4;
@@ -1087,19 +1077,19 @@ static bool_ monst_spell_monst(int m_idx)
}
/* Extract the "inate" spells */
- for (k = 0; k < 32; k++)
+ for (int k = 0; k < 32; k++)
{
if (f4 & (1L << k)) spell[num++] = k + 32 * 3;
}
/* Extract the "normal" spells */
- for (k = 0; k < 32; k++)
+ for (int k = 0; k < 32; k++)
{
if (f5 & (1L << k)) spell[num++] = k + 32 * 4;
}
/* Extract the "bizarre" spells */
- for (k = 0; k < 32; k++)
+ for (int k = 0; k < 32; k++)
{
if (f6 & (1L << k)) spell[num++] = k + 32 * 5;
}
@@ -1140,6 +1130,7 @@ static bool_ monst_spell_monst(int m_idx)
see_either = (see_m || see_t);
see_both = (see_m && see_t);
+ int count = 0;
switch (thrown_spell)
{
/* RF4_SHRIEK */
@@ -1165,7 +1156,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons an animal!", m_name);
- for (k = 0; k < 1; k++)
+ for (int k = 0; k < 1; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE);
@@ -2244,7 +2235,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons some animals!", m_name);
- for (k = 0; k < 4; k++)
+ for (int k = 0; k < 4; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE);
@@ -2376,7 +2367,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically codes some software bugs.", m_name);
- for (k = 0; k < 6; k++)
+ for (int k = 0; k < 6; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_BUG, TRUE);
@@ -2393,7 +2384,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically codes some RNGs.", m_name);
- for (k = 0; k < 6; k++)
+ for (int k = 0; k < 6; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_RNG, TRUE);
@@ -2411,7 +2402,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons a Thunderlord!", m_name);
- for (k = 0; k < 1; k++)
+ for (int k = 0; k < 1; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_THUNDERLORD, TRUE);
@@ -2432,7 +2423,7 @@ static bool_ monst_spell_monst(int m_idx)
((r_ptr->flags1) & RF1_UNIQUE ?
"minions" : "kin"));
summon_kin_type = r_ptr->d_char; /* Big hack */
- for (k = 0; k < 6; k++)
+ for (int k = 0; k < 6; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_KIN, TRUE);
@@ -2465,7 +2456,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons help!", m_name);
- for (k = 0; k < 1; k++)
+ for (int k = 0; k < 1; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_NO_UNIQUES, TRUE);
@@ -2482,7 +2473,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons monsters!", m_name);
- for (k = 0; k < 8; k++)
+ for (int k = 0; k < 8; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_NO_UNIQUES, TRUE);
@@ -2499,7 +2490,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons ants.", m_name);
- for (k = 0; k < 6; k++)
+ for (int k = 0; k < 6; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_ANT, TRUE);
@@ -2516,7 +2507,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons spiders.", m_name);
- for (k = 0; k < 6; k++)
+ for (int k = 0; k < 6; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_SPIDER, TRUE);
@@ -2533,7 +2524,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons hounds.", m_name);
- for (k = 0; k < 6; k++)
+ for (int k = 0; k < 6; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_HOUND, TRUE);
@@ -2550,7 +2541,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons hydras.", m_name);
- for (k = 0; k < 6; k++)
+ for (int k = 0; k < 6; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_HYDRA, TRUE);
@@ -2567,7 +2558,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons an angel!", m_name);
- for (k = 0; k < 1; k++)
+ for (int k = 0; k < 1; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_ANGEL, TRUE);
@@ -2584,7 +2575,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons a demon!", m_name);
- for (k = 0; k < 1; k++)
+ for (int k = 0; k < 1; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_DEMON, TRUE);
@@ -2601,7 +2592,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons an undead adversary!", m_name);
- for (k = 0; k < 1; k++)
+ for (int k = 0; k < 1; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_UNDEAD, TRUE);
@@ -2618,7 +2609,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons a dragon!", m_name);
- for (k = 0; k < 1; k++)
+ for (int k = 0; k < 1; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_DRAGON, TRUE);
@@ -2635,7 +2626,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons greater undead!", m_name);
- for (k = 0; k < 8; k++)
+ for (int k = 0; k < 8; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE);
@@ -2655,7 +2646,7 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons ancient dragons!", m_name);
- for (k = 0; k < 8; k++)
+ for (int k = 0; k < 8; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_HI_DRAGON_NO_UNIQUES, TRUE);
@@ -2677,7 +2668,7 @@ static bool_ monst_spell_monst(int m_idx)
else monster_msg("%^s magically summons a wraith!", m_name);
- for (k = 0; k < 8; k++)
+ for (int k = 0; k < 8; k++)
{
count += summon_specific(y, x, rlev, SUMMON_WRAITH);
}
@@ -2695,12 +2686,12 @@ static bool_ monst_spell_monst(int m_idx)
if (disturb_other) disturb(1);
if (blind || !see_m) monster_msg("%^s mumbles.", m_name);
else monster_msg("%^s magically summons special opponents!", m_name);
- for (k = 0; k < 8; k++)
+ for (int k = 0; k < 8; k++)
{
if (!friendly)
count += summon_specific(y, x, rlev, SUMMON_UNIQUE);
}
- for (k = 0; k < 8; k++)
+ for (int k = 0; k < 8; k++)
{
if (friendly)
count += summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE);
@@ -2922,8 +2913,6 @@ static bool_ make_attack_spell(int m_idx)
int k, chance, thrown_spell, rlev, failrate;
byte spell[96], num = 0;
u32b f4, f5, f6;
- monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
char m_name[80];
bool_ no_inate = FALSE;
int x, y;
@@ -2934,6 +2923,9 @@ static bool_ make_attack_spell(int m_idx)
/* Extract the blind-ness */
bool_ blind = (p_ptr->blind ? TRUE : FALSE);
+ /* Get a pointer to the monster */
+ monster_type *m_ptr = &m_list[m_idx];
+
/* Extract the "see-able-ness" */
bool_ seen = (!blind && m_ptr->ml);
@@ -2963,6 +2955,7 @@ static bool_ make_attack_spell(int m_idx)
if (is_friend(m_ptr) >= 0) return (FALSE);
/* Cannot attack the player if mortal and player fated to never die by the ... */
+ auto const r_ptr = m_ptr->race();
if ((r_ptr->flags7 & RF7_MORTAL) && (p_ptr->no_mortal)) return (FALSE);
/* Hack -- Extract the spell probability */
@@ -4693,23 +4686,17 @@ static int mon_will_run(int m_idx)
*/
static bool_ get_fear_moves_aux(int m_idx, int *yp, int *xp)
{
- int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
- int when = 0, score = -1;
- int i;
-
- monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
/* Monster flowing disabled */
if (!flow_by_sound) return (FALSE);
/* Monster location */
- fy = m_ptr->fy;
- fx = m_ptr->fx;
+ monster_type *m_ptr = &m_list[m_idx];
+ const int fy = m_ptr->fy;;
+ const int fx = m_ptr->fx;
/* Desired destination */
- y1 = fy - (*yp);
- x1 = fx - (*xp);
+ int y1 = fy - (*yp);
+ int x1 = fx - (*xp);
/* The player is not currently near the monster grid */
if (cave[fy][fx].when < cave[p_ptr->py][p_ptr->px].when)
@@ -4719,17 +4706,24 @@ static bool_ get_fear_moves_aux(int m_idx, int *yp, int *xp)
}
/* Monster is too far away to use flow information */
+ auto const r_ptr = m_ptr->race();
if (cave[fy][fx].cost > MONSTER_FLOW_DEPTH) return (FALSE);
if (cave[fy][fx].cost > r_ptr->aaf) return (FALSE);
+ /* Loop state */
+ int when = 0;
+ int gy = 0;
+ int gx = 0;
+ int score = -1;
+
/* Check nearby grids, diagonals first */
- for (i = 7; i >= 0; i--)
+ for (int i = 7; i >= 0; i--)
{
int dis, s;
/* Get the location */
- y = fy + ddy_ddd[i];
- x = fx + ddx_ddd[i];
+ const int y = fy + ddy_ddd[i];
+ const int x = fx + ddx_ddd[i];
/* Ignore illegal locations */
if (cave[y][x].when == 0) continue;
@@ -5013,9 +5007,6 @@ static void get_target_monster(int m_idx)
static bool_ get_moves(int m_idx, int *mm)
{
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
- int y, ay, x, ax;
int move_val = 0;
@@ -5051,6 +5042,9 @@ static bool_ get_moves(int m_idx, int *mm)
}
}
+ /* Get the race */
+ const auto r_ptr = m_ptr->race();
+
/* A possessor is not interrested in the player, it only wants a corpse */
if (r_ptr->flags7 & RF7_POSSESSOR)
{
@@ -5082,8 +5076,8 @@ static bool_ get_moves(int m_idx, int *mm)
}
/* Extract the "pseudo-direction" */
- y = m_ptr->fy - y2;
- x = m_ptr->fx - x2;
+ int y = m_ptr->fy - y2;
+ int x = m_ptr->fx - x2;
/* Tease the player */
if (r_ptr->flags7 & RF7_AI_ANNOY)
@@ -5213,8 +5207,8 @@ static bool_ get_moves(int m_idx, int *mm)
if (!x && !y) return (FALSE);
/* Extract the "absolute distances" */
- ax = ABS(x);
- ay = ABS(y);
+ int ay = ABS(y);
+ int ax = ABS(x);
/* Do something weird */
if (y < 0) move_val += 8;
@@ -5407,36 +5401,39 @@ int check_hit2(int power, int level, int ac)
/* Monster attacks monster */
static bool_ monst_attack_monst(int m_idx, int t_idx)
{
- monster_type *m_ptr = &m_list[m_idx], *t_ptr = &m_list[t_idx];
- monster_race *r_ptr = race_inf(m_ptr);
- monster_race *tr_ptr = race_inf(t_ptr);
- int ap_cnt;
- int ac, rlev, pt;
- char m_name[80], t_name[80];
- char ddesc[80], temp[80];
- bool_ blinked = FALSE, touched = FALSE;
+ char temp[80];
+ bool_ blinked = FALSE;
+ bool_ touched = FALSE;
bool_ explode = FALSE;
bool_ fear = FALSE;
+ monster_type *t_ptr = &m_list[t_idx];
byte y_saver = t_ptr->fy;
byte x_saver = t_ptr->fx;
+ /* Get the racial information on the two monsters */
+ monster_type *m_ptr = &m_list[m_idx];
+ const auto r_ptr = m_ptr->race();
+ const auto tr_ptr = t_ptr->race();
/* Not allowed to attack */
if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
/* Total armor */
- ac = t_ptr->ac;
+ const int ac = t_ptr->ac;
/* Extract the effective monster level */
- rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1);
+ const int rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1);
/* Get the monster name (or "it") */
+ char m_name[80];
monster_desc(m_name, m_ptr, 0);
/* Get the monster name (or "it") */
+ char t_name[80];
monster_desc(t_name, t_ptr, 0);
/* Get the "died from" information (i.e. "a kobold") */
+ char ddesc[80];
monster_desc(ddesc, m_ptr, 0x88);
/* Assume no blink */
@@ -5448,7 +5445,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx)
}
/* Scan through all four blows */
- for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
+ for (int ap_cnt = 0; ap_cnt < 4; ap_cnt++)
{
bool_ visible = FALSE;
bool_ obvious = FALSE;
@@ -5690,7 +5687,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx)
/* Hack need more punch against monsters */
damage *= 3;
- pt = GF_MISSILE;
+ int pt = GF_MISSILE;
/* Apply appropriate damage */
switch (effect)
@@ -5962,12 +5959,9 @@ static u32b noise = 0L;
/* Determine whether the player is invisible to a monster */
static bool_ player_invis(monster_type * m_ptr)
{
- s16b inv, mlv;
- monster_race *r_ptr = race_inf(m_ptr);
-
- inv = p_ptr->invis;
-
- mlv = (s16b) m_ptr->level;
+ const auto r_ptr = m_ptr->race();
+ s16b inv = p_ptr->invis;
+ s16b mlv = m_ptr->level;
if (r_ptr->flags3 & RF3_NO_SLEEP)
mlv += 10;
@@ -6026,34 +6020,14 @@ static bool_ player_invis(monster_type * m_ptr)
*/
static void process_monster(int m_idx, bool_ is_frien)
{
- monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
- cave_type *c_ptr = &cave[m_ptr->fy][m_ptr->fx];
-
int i, d, oy, ox, ny, nx;
int mm[8];
- monster_type *y_ptr;
-
- bool_ do_turn;
- bool_ do_move;
- bool_ do_view;
-
- bool_ did_open_door;
- bool_ did_bash_door;
- bool_ did_take_item;
- bool_ did_kill_item;
- bool_ did_move_body;
- bool_ did_kill_body;
- bool_ did_pass_wall;
- bool_ did_kill_wall;
- bool_ gets_angry = FALSE;
- bool_ inv;
- bool_ xxx = FALSE;
-
- inv = player_invis(m_ptr);
+ monster_type *m_ptr = &m_list[m_idx];
+ const bool_ inv = player_invis(m_ptr);
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags9 & RF9_DOPPLEGANGER) doppleganger = m_idx;
/* Handle "bleeding" */
@@ -6063,6 +6037,7 @@ static void process_monster(int m_idx, bool_ is_frien)
if (d > m_ptr->bleeding) d = m_ptr->bleeding;
/* Exit if the monster dies */
+ bool_ xxx = FALSE;
if (mon_take_hit(m_idx, d, &xxx, " bleeds to death.")) return;
/* Hack -- Recover from bleeding */
@@ -6102,6 +6077,7 @@ static void process_monster(int m_idx, bool_ is_frien)
if (d < 1) d = 1;
/* Exit if the monster dies */
+ bool_ xxx = FALSE;
if (mon_take_hit(m_idx, d, &xxx, " dies of poison.")) return;
/* Hack -- Recover from bleeding */
@@ -6278,6 +6254,9 @@ static void process_monster(int m_idx, bool_ is_frien)
}
}
+ /* Do the monster get angry? */
+ bool_ gets_angry = FALSE;
+
/* No one wants to be your friend if you're aggravating */
if ((m_ptr->status > MSTATUS_NEUTRAL) && (m_ptr->status < MSTATUS_COMPANION) && (p_ptr->aggravate) && !(r_ptr->flags7 & RF7_PET))
gets_angry = TRUE;
@@ -6456,23 +6435,23 @@ static void process_monster(int m_idx, bool_ is_frien)
}
/* Paranoia -- quest code could delete it */
+ cave_type *c_ptr = &cave[m_ptr->fy][m_ptr->fx];
if (!c_ptr->m_idx) return;
/* Assume nothing */
- do_turn = FALSE;
- do_move = FALSE;
- do_view = FALSE;
+ bool_ do_turn = FALSE;
+ bool_ do_move = FALSE;
+ bool_ do_view = FALSE;
/* Assume nothing */
- did_open_door = FALSE;
- did_bash_door = FALSE;
- did_take_item = FALSE;
- did_kill_item = FALSE;
- did_move_body = FALSE;
- did_kill_body = FALSE;
- did_pass_wall = FALSE;
- did_kill_wall = FALSE;
-
+ bool_ did_open_door = FALSE;
+ bool_ did_bash_door = FALSE;
+ bool_ did_take_item = FALSE;
+ bool_ did_kill_item = FALSE;
+ bool_ did_move_body = FALSE;
+ bool_ did_kill_body = FALSE;
+ bool_ did_pass_wall = FALSE;
+ bool_ did_kill_wall = FALSE;
/* Take a zero-terminated array of "directions" */
for (i = 0; mm[i]; i++)
@@ -6491,7 +6470,7 @@ static void process_monster(int m_idx, bool_ is_frien)
c_ptr = &cave[ny][nx];
/* Access that cave grid's contents */
- y_ptr = &m_list[c_ptr->m_idx];
+ monster_type *y_ptr = &m_list[c_ptr->m_idx];
/* Floor is open? */
@@ -6841,7 +6820,7 @@ static void process_monster(int m_idx, bool_ is_frien)
/* A monster is in the way */
if (do_move && c_ptr->m_idx)
{
- monster_race *z_ptr = race_inf(y_ptr);
+ auto z_ptr = y_ptr->race();
monster_type *m2_ptr = &m_list[c_ptr->m_idx];
/* Assume no movement */
@@ -7288,7 +7267,6 @@ void process_monsters(void)
bool_ is_frien = FALSE;
monster_type *m_ptr;
- monster_race *r_ptr;
int old_monster_race_idx;
@@ -7318,7 +7296,7 @@ void process_monsters(void)
if (monster_race_idx)
{
/* Acquire current monster */
- r_ptr = &r_info[monster_race_idx];
+ monster_race *r_ptr = &r_info[monster_race_idx];
/* Memorize flags */
old_r_flags1 = r_ptr->r_flags1;
@@ -7394,7 +7372,7 @@ void process_monsters(void)
/* Access the race */
- r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Access the location */
fx = m_ptr->fx;
@@ -7473,7 +7451,7 @@ void process_monsters(void)
if (monster_race_idx && (monster_race_idx == old_monster_race_idx))
{
/* Acquire monster race */
- r_ptr = &r_info[monster_race_idx];
+ monster_race *r_ptr = &r_info[monster_race_idx];
/* Check for knowledge change */
if ((old_r_flags1 != r_ptr->r_flags1) ||
diff --git a/src/modules.cc b/src/modules.cc
index 611afe6..c5d065f 100644
--- a/src/modules.cc
+++ b/src/modules.cc
@@ -776,7 +776,7 @@ static bool_ theme_push_past(void *data, void *in_, void *out_)
if (c_ptr->m_idx > 0)
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *mr_ptr = race_inf(m_ptr);
+ auto const mr_ptr = m_ptr->race();
if (m_ptr->status >= MSTATUS_NEUTRAL)
{
diff --git a/src/monster1.cc b/src/monster1.cc
index 77f916a..4e3e2c4 100644
--- a/src/monster1.cc
+++ b/src/monster1.cc
@@ -40,10 +40,8 @@ static cptr wd_his[3] = { "its", "his", "her" };
* Determine if the "armor" is known
* The higher the level, the fewer kills needed.
*/
-static bool_ know_armour(int r_idx)
+static bool_ know_armour(std::shared_ptr<monster_race const> r_ptr)
{
- monster_race *r_ptr = &r_info[r_idx];
-
s32b level = r_ptr->level;
s32b kills = r_ptr->r_tkills;
@@ -67,10 +65,8 @@ static bool_ know_armour(int r_idx)
* the higher the level of the monster, the fewer the attacks you need,
* the more damage an attack does, the more attacks you need
*/
-static bool_ know_damage(int r_idx, int i)
+static bool_ know_damage(std::shared_ptr<monster_race const> r_ptr, int i)
{
- monster_race *r_ptr = &r_info[r_idx];
-
s32b level = r_ptr->level;
s32b a = r_ptr->r_blows[i];
@@ -106,10 +102,8 @@ static bool_ know_damage(int r_idx, int i)
* left edge of the screen, on a cleared line, in which the recall is
* to take place. One extra blank line is left after the recall.
*/
-static void roff_aux(int r_idx, int ego, int remem)
+static void roff_aux(std::shared_ptr<monster_race> r_ptr, int remem)
{
- monster_race *r_ptr;
-
bool_ old = FALSE;
bool_ sin = FALSE;
@@ -137,12 +131,6 @@ static void roff_aux(int r_idx, int ego, int remem)
monster_race save_mem;
-
-
- /* Access the race and lore */
- r_ptr = race_info_idx(r_idx, ego);
-
-
/* Cheat -- Know everything */
if (cheat_know)
{
@@ -808,7 +796,7 @@ static void roff_aux(int r_idx, int ego, int remem)
/* Describe monster "toughness" */
- if (know_armour(r_idx))
+ if (know_armour(r_ptr))
{
/* Armor */
text_out(format("%^s has an armor rating of ", wd_he[msex]));
@@ -1469,7 +1457,7 @@ static void roff_aux(int r_idx, int ego, int remem)
text_out_c(TERM_YELLOW, q);
/* Describe damage (if known) */
- if (d1 && d2 && know_damage(r_idx, m))
+ if (d1 && d2 && know_damage(r_ptr, m))
{
/* Display the damage */
text_out(" with damage");
@@ -1517,18 +1505,15 @@ static void roff_aux(int r_idx, int ego, int remem)
*/
static void roff_name(int r_idx, int ego)
{
- monster_race *r_ptr = race_info_idx(r_idx, ego);
-
- byte a1, a2;
- char c1, c2;
+ const auto r_ptr = race_info_idx(r_idx, ego);
/* Access the chars */
- c1 = r_ptr->d_char;
- c2 = r_ptr->x_char;
+ const char c1 = r_ptr->d_char;
+ const char c2 = r_ptr->x_char;
/* Access the attrs */
- a1 = r_ptr->d_attr;
- a2 = r_ptr->x_attr;
+ const byte a1 = r_ptr->d_attr;
+ const byte a2 = r_ptr->x_attr;
/* A title (use "The" for non-uniques) */
if (!(r_ptr->flags1 & (RF1_UNIQUE)))
@@ -1583,6 +1568,8 @@ static void roff_top(int r_idx, int ego)
*/
void screen_roff(int r_idx, int ego, int remember)
{
+ auto r_ptr = race_info_idx(r_idx, ego);
+
/* Flush messages */
msg_print(NULL);
@@ -1590,19 +1577,20 @@ void screen_roff(int r_idx, int ego, int remember)
Term_erase(0, 1, 255);
/* Recall monster */
- roff_aux(r_idx, ego, remember);
+ roff_aux(r_ptr, remember);
/* Describe monster */
roff_top(r_idx, ego);
}
/*
- * Ddescribe the given monster race at the current pos of the "term" window
+ * Describe the given monster race at the current pos of the "term" window
*/
void monster_description_out(int r_idx, int ego)
{
+ auto r_ptr = race_info_idx(r_idx, ego);
roff_name(r_idx, ego);
- roff_aux(r_idx, ego, 0);
+ roff_aux(r_ptr, 0);
}
/*
@@ -1625,7 +1613,8 @@ void display_roff(int r_idx, int ego)
Term_gotoxy(0, 1);
/* Recall monster */
- roff_aux(r_idx, ego, 0);
+ auto r_ptr = race_info_idx(r_idx, ego);
+ roff_aux(r_ptr, 0);
/* Describe monster */
roff_top(r_idx, ego);
@@ -1835,7 +1824,7 @@ void set_mon_num_hook(void)
/*
* Check if monster can cross terrain
*/
-bool_ monster_can_cross_terrain(byte feat, monster_race *r_ptr)
+bool_ monster_can_cross_terrain(byte feat, std::shared_ptr<monster_race> r_ptr)
{
/* Deep water */
if (feat == FEAT_DEEP_WATER)
diff --git a/src/monster2.cc b/src/monster2.cc
index 513ebf0..0be1cc3 100644
--- a/src/monster2.cc
+++ b/src/monster2.cc
@@ -266,34 +266,45 @@ static int pick_ego_monster(monster_race const *r_ptr)
* Return a (monster_race*) with the combination of the monster
* properties and the ego type
*/
-monster_race* race_info_idx(int r_idx, int ego)
+std::shared_ptr<monster_race> race_info_idx(int r_idx, int ego)
{
- static monster_race race;
- monster_ego *re_ptr = &re_info[ego];
- monster_race *r_ptr = &r_info[r_idx], *nr_ptr = &race;
- int i;
+ monster_race *r_ptr = &r_info[r_idx];
- /* No work needed */
- if (!ego) return r_ptr;
+ /* We don't need to allocate anything if it's an ordinary monster. */
+ if (!ego) {
+ return std::shared_ptr<monster_race>(r_ptr, [](monster_race *) {
+ // No need to delete -- will be freed when the r_info array is freed.
+ });
+ }
- /* Copy the base monster */
+ /* We allocate a copy of the "base" monster race to refer to. */
+ auto nr_ptr = std::make_shared<monster_race>();
*nr_ptr = *r_ptr;
+ /* Get a reference to the ego monster modifiers */
+ monster_ego *re_ptr = &re_info[ego];
+
/* Adjust the values */
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
- s32b j, k;
-
- j = modify_aux(nr_ptr->blow[i].d_dice, re_ptr->blow[i].d_dice, re_ptr->blowm[i][0]);
+ s32b j = modify_aux(nr_ptr->blow[i].d_dice, re_ptr->blow[i].d_dice, re_ptr->blowm[i][0]);
if (j < 0) j = 0;
- k = modify_aux(nr_ptr->blow[i].d_side, re_ptr->blow[i].d_side, re_ptr->blowm[i][1]);
+
+ s32b k = modify_aux(nr_ptr->blow[i].d_side, re_ptr->blow[i].d_side, re_ptr->blowm[i][1]);
if (k < 0) k = 0;
nr_ptr->blow[i].d_dice = j;
nr_ptr->blow[i].d_side = k;
- if (re_ptr->blow[i].method) nr_ptr->blow[i].method = re_ptr->blow[i].method;
- if (re_ptr->blow[i].effect) nr_ptr->blow[i].effect = re_ptr->blow[i].effect;
+ if (re_ptr->blow[i].method)
+ {
+ nr_ptr->blow[i].method = re_ptr->blow[i].method;
+ }
+
+ if (re_ptr->blow[i].effect)
+ {
+ nr_ptr->blow[i].effect = re_ptr->blow[i].effect;
+ }
}
MODIFY(nr_ptr->hdice, re_ptr->hdice, 1);
@@ -354,11 +365,6 @@ monster_race* race_info_idx(int r_idx, int ego)
return nr_ptr;
}
-monster_race* race_inf(monster_type *m_ptr)
-{
- return race_info_idx(m_ptr->r_idx, m_ptr->ego);
-}
-
static cptr horror_desc[MAX_HORROR] =
{
"abominable",
@@ -433,17 +439,13 @@ static cptr funny_comments[MAX_COMMENT] =
*/
void delete_monster_idx(int i)
{
- monster_type *m_ptr = &m_list[i];
-
- monster_race *r_ptr = race_inf(m_ptr);
-
- bool_ had_lite = FALSE;
-
/* Get location */
+ monster_type *m_ptr = &m_list[i];
int y = m_ptr->fy;
int x = m_ptr->fx;
/* Hack -- Reduce the racial counter */
+ auto const r_ptr = m_ptr->race();
r_ptr->cur_num--;
r_ptr->on_saved = FALSE;
@@ -451,6 +453,7 @@ void delete_monster_idx(int i)
if (r_ptr->flags4 & (RF4_MULTIPLY)) num_repro--;
/* XXX XXX XXX remove monster light source */
+ bool_ had_lite = FALSE;
if (r_ptr->flags9 & (RF9_HAS_LITE)) had_lite = TRUE;
@@ -659,8 +662,7 @@ void compact_monsters(int size)
for (i = 1; i < m_max; i++)
{
monster_type *m_ptr = &m_list[i];
-
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Paranoia -- skip "dead" monsters */
if (!m_ptr->r_idx) continue;
@@ -724,14 +726,13 @@ void wipe_m_list(void)
{
monster_type *m_ptr = &m_list[i];
- monster_race *r_ptr = race_inf(m_ptr);
-
/* Skip dead monsters */
if (!m_ptr->r_idx) continue;
/* Mega-Hack -- preserve Unique's XXX XXX XXX */
/* Hack -- Reduce the racial counter */
+ auto r_ptr = m_ptr->race();
r_ptr->cur_num--;
/* Monster is gone */
@@ -1215,8 +1216,7 @@ s16b get_mon_num(int level)
*/
void monster_desc(char *desc, monster_type *m_ptr, int mode)
{
- cptr res;
- monster_race *r_ptr = race_inf(m_ptr);
+ auto r_ptr = m_ptr->race();
char silly_name[80], name[100];
bool_ seen, pron;
int insanity = (p_ptr->msane - p_ptr->csane) * 100 / p_ptr->msane;
@@ -1269,7 +1269,6 @@ void monster_desc(char *desc, monster_type *m_ptr, int mode)
/* Sexed Pronouns (seen and allowed, or unseen and allowed) */
pron = (m_ptr && ((seen && (mode & 0x20)) || (!seen && (mode & 0x10))));
-
/* First, try using pronouns, or describing hidden monsters */
if (!seen || pron)
{
@@ -1285,7 +1284,7 @@ void monster_desc(char *desc, monster_type *m_ptr, int mode)
/* Assume simple result */
- res = "it";
+ cptr res = "it";
/* Brute force: split on the possibilities */
switch (kind | (mode & 0x07))
@@ -1534,16 +1533,17 @@ static void sanity_blast(monster_type * m_ptr, bool_ necro)
if (!necro)
{
- char m_name[80];
- monster_race *r_ptr;
+ if (m_ptr == nullptr) {
+ return;
+ }
- if (m_ptr != NULL) r_ptr = race_inf(m_ptr);
- else return;
+ auto const r_ptr = m_ptr->race();
power = (m_ptr->level) + 10;
if (m_ptr != NULL)
{
+ char m_name[80];
monster_desc(m_name, m_ptr, 0);
if (!(r_ptr->flags1 & RF1_UNIQUE))
@@ -1605,6 +1605,7 @@ static void sanity_blast(monster_type * m_ptr, bool_ necro)
{
msg_print("Your sanity is shaken by reading the Necronomicon!");
}
+
if (randint(power) < p_ptr->skill_sav) /* Mind blast */
{
if (!p_ptr->resist_conf)
@@ -1727,13 +1728,11 @@ void update_mon(int m_idx, bool_ full)
{
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
/* The current monster location */
- int fy = m_ptr->fy;
- int fx = m_ptr->fx;
+ const int fy = m_ptr->fy;
+ const int fx = m_ptr->fx;
- bool_ old_ml = m_ptr->ml;
+ const bool_ old_ml = m_ptr->ml;
/* Seen at all */
bool_ flag = FALSE;
@@ -1750,18 +1749,17 @@ void update_mon(int m_idx, bool_ full)
bool_ do_invisible = FALSE;
bool_ do_cold_blood = FALSE;
+ auto const r_ptr = m_ptr->race();
/* Calculate distance */
if (full)
{
- int d, dy, dx;
-
/* Distance components */
- dy = (p_ptr->py > fy) ? (p_ptr->py - fy) : (fy - p_ptr->py);
- dx = (p_ptr->px > fx) ? (p_ptr->px - fx) : (fx - p_ptr->px);
+ const int dy = (p_ptr->py > fy) ? (p_ptr->py - fy) : (fy - p_ptr->py);
+ const int dx = (p_ptr->px > fx) ? (p_ptr->px - fx) : (fx - p_ptr->px);
/* Approximate distance */
- d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
+ const int d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
/* Save the distance (in a byte) */
m_ptr->cdis = (d < 255) ? d : 255;
@@ -1778,7 +1776,6 @@ void update_mon(int m_idx, bool_ full)
if (m_ptr->mflag & (MFLAG_MARK)) flag = TRUE;
}
-
/* Process "nearby" monsters on the current "panel" */
else if (panel_contains(fy, fx))
{
@@ -2118,12 +2115,6 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
bool_ add_level = FALSE;
int min_level = 0, max_level = 0;
- cave_type *c_ptr;
-
- monster_type *m_ptr;
-
- monster_race *r_ptr = &r_info[r_idx];
-
/* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
if (p_ptr->wild_mode)
{
@@ -2186,30 +2177,35 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
return 0;
}
- /* Paranoia */
- if (!r_ptr->name)
+ /* Check for original monster race flags */
{
- return 0;
- }
+ monster_race *r_ptr = &r_info[r_idx];
- /* Are we allowed to continue ? */
- {
- struct hook_new_monster_in in = { r_idx };
- if (process_hooks_new(HOOK_NEW_MONSTER, &in, NULL))
+ /* Paranoia */
+ if (!r_ptr->name)
{
return 0;
}
- }
- /* Ego Uniques are NOT to be created */
- if ((r_ptr->flags1 & RF1_UNIQUE) && ego)
- {
- return 0;
+ /* Are we allowed to continue ? */
+ {
+ struct hook_new_monster_in in = { r_idx };
+ if (process_hooks_new(HOOK_NEW_MONSTER, &in, NULL))
+ {
+ return 0;
+ }
+ }
+
+ /* Ego Uniques are NOT to be created */
+ if ((r_ptr->flags1 & RF1_UNIQUE) && ego)
+ {
+ return 0;
+ }
}
/* Now could we generate an Ego Monster */
/* Grab the special race if needed */
- r_ptr = race_info_idx(r_idx, ego);
+ auto r_ptr = race_info_idx(r_idx, ego);
if (!monster_can_cross_terrain(cave[y][x].feat, r_ptr))
{
@@ -2302,7 +2298,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
/* Access the location */
- c_ptr = &cave[y][x];
+ cave_type *c_ptr = &cave[y][x];
/* Make a new monster */
c_ptr->m_idx = m_pop();
@@ -2316,7 +2312,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
/* Get a new monster record */
- m_ptr = &m_list[c_ptr->m_idx];
+ monster_type *m_ptr = &m_list[c_ptr->m_idx];
/* Save the race */
m_ptr->r_idx = r_idx;
@@ -2372,15 +2368,14 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
/* Only if not fated to die */
if ((dungeon_type != DUNGEON_DEATH) && (!place_monster_one_no_drop))
{
- bool_ good = (r_ptr->flags1 & (RF1_DROP_GOOD)) ? TRUE : FALSE;
- bool_ great = (r_ptr->flags1 & (RF1_DROP_GREAT)) ? TRUE : FALSE;
+ const bool_ good = (r_ptr->flags1 & (RF1_DROP_GOOD)) ? TRUE : FALSE;
+ const bool_ great = (r_ptr->flags1 & (RF1_DROP_GREAT)) ? TRUE : FALSE;
- bool_ do_gold = (!(r_ptr->flags1 & (RF1_ONLY_ITEM)));
- bool_ do_item = (!(r_ptr->flags1 & (RF1_ONLY_GOLD)));
- bool_ do_mimic = (r_ptr->flags9 & (RF9_MIMIC));
- int j;
+ const bool_ do_gold = (!(r_ptr->flags1 & (RF1_ONLY_ITEM)));
+ const bool_ do_item = (!(r_ptr->flags1 & (RF1_ONLY_GOLD)));
+ const bool_ do_mimic = (r_ptr->flags9 & (RF9_MIMIC));
- int force_coin = get_coin_type(r_ptr);
+ const int force_coin = get_coin_type(r_ptr);
int dump_item = 0;
int dump_gold = 0;
@@ -2408,7 +2403,6 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
{
int tries = 1000;
obj_theme theme;
- int i;
/* Get local object */
q_ptr = &forge;
@@ -2426,7 +2420,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
/* Rebuild allocation table */
get_obj_num_prep();
- i = 0;
+ int i = 0;
while (tries)
{
tries--;
@@ -2455,7 +2449,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
}
/* Drop some objects */
- for (j = 0; j < number; j++)
+ for (int j = 0; j < number; j++)
{
/* Get local object */
q_ptr = &forge;
@@ -2604,11 +2598,14 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status)
/* Hack -- Notice new multi-hued monsters */
if (r_ptr->flags1 & (RF1_ATTR_MULTI)) shimmer_monsters = TRUE;
- /* Hack -- we need to modify the REAL r_info, not the fake one */
- r_ptr = &r_info[r_idx];
+ /* 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];
- /* Hack -- Count the monsters on the level */
- r_ptr->cur_num++;
+ /* Hack -- Count the monsters on the level */
+ r_ptr->cur_num++;
+ }
/* Unique monsters on saved levels should be "marked" */
if ((r_ptr->flags1 & RF1_UNIQUE) && get_dungeon_save(dummy))
@@ -3625,10 +3622,8 @@ static bool_ mutate_monster_okay(int r_idx)
*/
bool_ multiply_monster(int m_idx, bool_ charm, bool_ clone)
{
- monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
- int i, y, x, new_race;
+ monster_type *m_ptr = &m_list[m_idx];
+ auto const r_ptr = m_ptr->race();
bool_ result = FALSE;
@@ -3639,18 +3634,17 @@ bool_ multiply_monster(int m_idx, bool_ charm, bool_ clone)
}
/* Try up to 18 times */
- for (i = 0; i < 18; i++)
+ for (int i = 0; i < 18; i++)
{
- int d = 1;
-
-
/* Pick a location */
- scatter(&y, &x, m_ptr->fy, m_ptr->fx, d);
+ int x;
+ int y;
+ scatter(&y, &x, m_ptr->fy, m_ptr->fx, 1);
/* Require an "empty" floor grid */
if (!cave_empty_bold(y, x)) continue;
- new_race = m_ptr->r_idx;
+ int new_race = m_ptr->r_idx;
/* It can mutate into a nastier monster */
if ((rand_int(100) < 3) && (!clone))
@@ -3720,13 +3714,10 @@ void message_pain_hook(cptr message, cptr name)
void message_pain(int m_idx, int dam)
{
- long oldhp, newhp, tmp;
- int percentage;
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
- char m_name[80];
/* Get the monster name */
+ char m_name[80];
monster_desc(m_name, m_ptr, 0);
capitalize(m_name);
@@ -3738,11 +3729,13 @@ void message_pain(int m_idx, int dam)
}
/* Note -- subtle fix -CFT */
- newhp = (long)(m_ptr->hp);
- oldhp = newhp + (long)(dam);
- tmp = (newhp * 100L) / oldhp;
- percentage = (int)(tmp);
+ long newhp = (long)(m_ptr->hp);
+ long oldhp = newhp + (long)(dam);
+ long tmp = (newhp * 100L) / oldhp;
+ int percentage = (int)(tmp);
+ /* Get racial information */
+ auto const r_ptr = m_ptr->race();
/* Jelly's, Mold's, Vortex's, Quthl's */
if (strchr("jmvQ", r_ptr->d_char))
@@ -3830,12 +3823,12 @@ void update_smart_learn(int m_idx, int what)
{
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
-
/* Not allowed to learn */
if (!smart_learn) return;
+ /* Get racial flags */
+ auto const r_ptr = m_ptr->race();
+
/* Too stupid to learn anything */
if (r_ptr->flags2 & (RF2_STUPID)) return;
diff --git a/src/monster2.hpp b/src/monster2.hpp
index ffe7b3c..84f79e3 100644
--- a/src/monster2.hpp
+++ b/src/monster2.hpp
@@ -4,6 +4,7 @@
#include "monster_race_fwd.hpp"
#include "monster_type_fwd.hpp"
#include "object_type_fwd.hpp"
+#include <memory>
extern s32b monster_exp(s16b level);
extern void monster_set_level(int m_idx, int level);
@@ -12,8 +13,7 @@ extern void monster_msg_simple(cptr s);
extern bool_ mego_ok(monster_race const *r_ptr, int ego);
extern void monster_check_experience(int m_idx, bool_ silent);
extern void monster_gain_exp(int m_idx, u32b exp, bool_ silent);
-extern monster_race* race_info_idx(int r_idx, int ego);
-extern monster_race* race_inf(monster_type *m_ptr);
+extern std::shared_ptr<monster_race> race_info_idx(int r_idx, int ego);
extern void delete_monster_idx(int i);
extern void delete_monster(int y, int x);
extern void compact_monsters(int size);
@@ -49,4 +49,4 @@ extern bool_ monster_dungeon(int r_idx);
extern bool_ monster_quest(int r_idx);
extern void set_mon_num_hook(void);
extern void set_mon_num2_hook(int y, int x);
-extern bool_ monster_can_cross_terrain(byte feat, monster_race *r_ptr);
+extern bool_ monster_can_cross_terrain(byte feat, std::shared_ptr<monster_race> r_ptr);
diff --git a/src/monster3.cc b/src/monster3.cc
index e7e8e6d..915a856 100644
--- a/src/monster3.cc
+++ b/src/monster3.cc
@@ -72,7 +72,7 @@ bool_ is_enemy(monster_type *m_ptr, monster_type *t_ptr)
bool_ change_side(monster_type *m_ptr)
{
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* neutrals and companions */
switch (m_ptr->status)
diff --git a/src/monster_type.cc b/src/monster_type.cc
new file mode 100644
index 0000000..5731e43
--- /dev/null
+++ b/src/monster_type.cc
@@ -0,0 +1,8 @@
+#include "monster_type_fwd.hpp"
+#include "monster_type.hpp"
+#include "monster2.hpp"
+
+std::shared_ptr<monster_race> monster_type::race() const
+{
+ return race_info_idx(r_idx, ego);
+}
diff --git a/src/monster_type.hpp b/src/monster_type.hpp
index 912c97d..8353f22 100644
--- a/src/monster_type.hpp
+++ b/src/monster_type.hpp
@@ -2,9 +2,11 @@
#include "h-basic.h"
#include "monster_blow.hpp"
+#include "monster_race_fwd.hpp"
#include <cassert>
#include <vector>
+#include <memory>
/**
* Monster information for a specific monster.
@@ -67,6 +69,12 @@ struct monster_type
s16b possessor = 0; /* Is it under the control of a possessor ? */
/**
+ * @brief get the "effective race" of the monster. This incorporates
+ * the effects of the "ego" of the monster, if any.
+ */
+ std::shared_ptr<monster_race> race() const;
+
+ /**
* @brief wipe the object's state
*/
void wipe()
diff --git a/src/powers.cc b/src/powers.cc
index ce71585..e1f15d5 100644
--- a/src/powers.cc
+++ b/src/powers.cc
@@ -546,7 +546,6 @@ static void power_activate(int power)
int dir, x, y;
cave_type *c_ptr;
monster_type *m_ptr;
- monster_race *r_ptr;
object_type *q_ptr;
object_type forge;
@@ -558,7 +557,7 @@ static void power_activate(int power)
if (c_ptr->m_idx)
{
m_ptr = &m_list[c_ptr->m_idx];
- r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->status == MSTATUS_PET) && (!(r_ptr->flags9 & RF9_SPECIAL_GENE)))
{
@@ -987,23 +986,18 @@ static void power_activate(int power)
case PWR_BANISH:
{
- int x, y;
- cave_type *c_ptr;
- monster_type *m_ptr;
- monster_race *r_ptr;
-
if (!get_rep_dir(&dir)) return;
- y = p_ptr->py + ddy[dir];
- x = p_ptr->px + ddx[dir];
- c_ptr = &cave[y][x];
+ const int x = p_ptr->px + ddx[dir];
+ const int y = p_ptr->py + ddy[dir];
+ cave_type *c_ptr = &cave[y][x];
if (!(c_ptr->m_idx))
{
msg_print("You sense no evil there!");
break;
}
- m_ptr = &m_list[c_ptr->m_idx];
- r_ptr = race_inf(m_ptr);
+ monster_type *m_ptr = &m_list[c_ptr->m_idx];
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags3 & RF3_EVIL)
{
diff --git a/src/spells1.cc b/src/spells1.cc
index ccfb59a..f74f32b 100644
--- a/src/spells1.cc
+++ b/src/spells1.cc
@@ -246,13 +246,9 @@ void teleport_player_directed(int rad, int dir)
*/
void teleport_away(int m_idx, int dis)
{
- int ny = 0, nx = 0, oy, ox, d, i, min;
- int tries = 0;
-
bool_ look = TRUE;
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
if (p_ptr->resist_continuum)
{
@@ -264,13 +260,16 @@ void teleport_away(int m_idx, int dis)
if (!m_ptr->r_idx) return;
/* Save the old location */
- oy = m_ptr->fy;
- ox = m_ptr->fx;
+ const int oy = m_ptr->fy;
+ const int ox = m_ptr->fx;
/* Minimum distance */
- min = dis / 2;
+ int min = dis / 2;
/* Look until done */
+ int tries = 0;
+ int ny = 0;
+ int nx = 0;
while (look)
{
tries++;
@@ -279,14 +278,14 @@ void teleport_away(int m_idx, int dis)
if (dis > 200) dis = 200;
/* Try several locations */
- for (i = 0; i < 500; i++)
+ for (int i = 0; i < 500; i++)
{
/* Pick a (possibly illegal) location */
while (1)
{
ny = rand_spread(oy, dis);
nx = rand_spread(ox, dis);
- d = distance(oy, ox, ny, nx);
+ int d = distance(oy, ox, ny, nx);
if ((d >= min) && (d <= dis)) break;
}
@@ -350,7 +349,11 @@ void teleport_away(int m_idx, int dis)
lite_spot(ny, nx);
/* Update monster light */
- if (r_ptr->flags9 & RF9_HAS_LITE) p_ptr->update |= (PU_MON_LITE);
+ auto const r_ptr = m_ptr->race();
+ if (r_ptr->flags9 & RF9_HAS_LITE)
+ {
+ p_ptr->update |= (PU_MON_LITE);
+ }
}
@@ -359,13 +362,8 @@ void teleport_away(int m_idx, int dis)
*/
static void teleport_to_player(int m_idx)
{
- int ny = 0, nx = 0, oy, ox, d, i, min;
- int dis = 2;
-
- bool_ look = TRUE;
-
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
int attempts = 500;
@@ -382,27 +380,33 @@ static void teleport_to_player(int m_idx)
if (randint(100) > m_ptr->level) return;
/* Save the old location */
- oy = m_ptr->fy;
- ox = m_ptr->fx;
+ const int oy = m_ptr->fy;
+ const int ox = m_ptr->fx;
/* Minimum distance */
- min = dis / 2;
+ int dis = 2;
+ int min = dis / 2;
+
+ /* End destination */
+ int ny = 0;
+ int nx = 0;
/* Look until done */
+ bool_ look = TRUE;
while (look && --attempts)
{
/* Verify max distance */
if (dis > 200) dis = 200;
/* Try several locations */
- for (i = 0; i < 500; i++)
+ for (int i = 0; i < 500; i++)
{
/* Pick a (possibly illegal) location */
while (1)
{
ny = rand_spread(p_ptr->py, dis);
nx = rand_spread(p_ptr->px, dis);
- d = distance(p_ptr->py, p_ptr->px, ny, nx);
+ const int d = distance(p_ptr->py, p_ptr->px, ny, nx);
if ((d >= min) && (d <= dis)) break;
}
@@ -591,12 +595,9 @@ void teleport_player(int dis)
{
if (cave[oy + yy][ox + xx].m_idx)
{
- monster_race *r_ptr = race_inf(&m_list[cave[oy + yy][ox + xx].m_idx]);
+ auto const r_ptr = m_list[cave[oy + yy][ox + xx].m_idx].race();
- if ((r_ptr->flags6
- & RF6_TPORT) &&
- !(r_ptr->flags3
- & RF3_RES_TELE))
+ if ((r_ptr->flags6 & RF6_TPORT) && !(r_ptr->flags3 & RF3_RES_TELE))
/*
* The latter limitation is to avoid
* totally unkillable suckers...
@@ -4360,8 +4361,6 @@ bool_ project_m(int who, int r, int y, int x, int dam, int typ)
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
char killer [80];
/* Is the monster "seen"? */
@@ -4442,6 +4441,9 @@ bool_ project_m(int who, int r, int y, int x, int dam, int typ)
/* Get the monster name (BEFORE polymorphing) */
monster_desc(m_name, m_ptr, 0);
+ /* Get race information */
+ auto r_ptr = m_ptr->race();
+
/* Mega Gachk */
if (r_ptr->flags2 & RF2_DEATH_ORB)
{
@@ -6892,7 +6894,7 @@ bool_ project_m(int who, int r, int y, int x, int dam, int typ)
m_ptr = &m_list[c_ptr->m_idx];
/* Hack -- Get new race */
- r_ptr = race_inf(m_ptr);
+ r_ptr = m_ptr->race();
}
}
@@ -8714,7 +8716,7 @@ bool_ project(int who, int rad, int y, int x, int dam, int typ, int flg)
}
else
{
- monster_race *ref_ptr = race_inf(&m_list[cave[y][x].m_idx]);
+ auto ref_ptr = m_list[cave[y][x].m_idx].race();
if ((ref_ptr->flags2 & (RF2_REFLECTING)) && (randint(10) != 1)
&& (dist_hack > 1))
diff --git a/src/spells2.cc b/src/spells2.cc
index 9498ef9..b2f294b 100644
--- a/src/spells2.cc
+++ b/src/spells2.cc
@@ -2315,11 +2315,11 @@ template<typename P, typename U> static bool detect_monsters_fn(int radius, P p,
continue;
}
/* Detect monsters which fulfill the predicate */
- auto r_ptr = race_inf(m_ptr);
- if (p(r_ptr))
+ auto r_ptr = m_ptr->race();
+ if (p(r_ptr.get()))
{
/* Update */
- u(r_ptr);
+ u(r_ptr.get());
/* We're assuming the update function does
* *something*, so we'll need to update
@@ -2399,7 +2399,7 @@ template <typename P> bool detect_objects_fn(int radius, const char *object_mess
{
/* Access the monster */
monster_type *m_ptr = &m_list[o_ptr->held_m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
if (!(r_ptr->flags9 & RF9_MIMIC))
{
@@ -3919,7 +3919,6 @@ void aggravate_monsters(int who)
for (i = 1; i < m_max; i++)
{
monster_type *m_ptr = &m_list[i];
- monster_race *r_ptr = race_inf(m_ptr);
/* Paranoia -- Skip dead monsters */
if (!m_ptr->r_idx) continue;
@@ -3942,6 +3941,8 @@ void aggravate_monsters(int who)
/* Speed up monsters in line of sight */
if (player_has_los_bold(m_ptr->fy, m_ptr->fx))
{
+ auto const r_ptr = m_ptr->race();
+
/* Speed up (instantly) to racial base + 10 */
if (m_ptr->mspeed < r_ptr->speed + 10)
{
@@ -3969,7 +3970,7 @@ void aggravate_monsters(int who)
/*
* Generic genocide race selection
*/
-bool_ get_genocide_race(cptr msg, char *typ)
+static bool get_genocide_race(cptr msg, char *typ)
{
int i, j;
cave_type *c_ptr;
@@ -3982,14 +3983,14 @@ bool_ get_genocide_race(cptr msg, char *typ)
if (c_ptr->m_idx)
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
*typ = r_ptr->d_char;
- return TRUE;
+ return true;
}
msg_print("You must select a monster.");
- return FALSE;
+ return false;
}
@@ -4007,7 +4008,7 @@ bool_ genocide_aux(bool_ player_cast, char typ)
for (i = 1; i < m_max; i++)
{
monster_type *m_ptr = &m_list[i];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Paranoia -- Skip dead monsters */
if (!m_ptr->r_idx) continue;
@@ -4133,7 +4134,7 @@ bool_ mass_genocide(bool_ player_cast)
for (i = 1; i < m_max; i++)
{
monster_type *m_ptr = &m_list[i];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Paranoia -- Skip dead monsters */
if (!m_ptr->r_idx) continue;
@@ -4661,7 +4662,7 @@ void earthquake(int cy, int cx, int r)
if (c_ptr->m_idx)
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Most monsters cannot co-exist with rock */
if (!(r_ptr->flags2 & (RF2_KILL_WALL)) &&
@@ -4909,8 +4910,7 @@ static void cave_temp_room_lite(void)
int chance = 25;
monster_type *m_ptr = &m_list[c_ptr->m_idx];
-
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Update the monster */
update_mon(c_ptr->m_idx, FALSE);
@@ -5247,17 +5247,13 @@ bool_ fire_wall(int typ, int dir, int dam, int time)
void teleport_swap(int dir)
{
- int tx, ty;
- cave_type * c_ptr;
- monster_type * m_ptr;
- monster_race * r_ptr;
-
if (p_ptr->resist_continuum)
{
msg_print("The space-time continuum can't be disrupted.");
return;
}
+ int tx, ty;
if ((dir == 5) && target_okay())
{
tx = target_col;
@@ -5268,7 +5264,8 @@ void teleport_swap(int dir)
tx = p_ptr->px + ddx[dir];
ty = p_ptr->py + ddy[dir];
}
- c_ptr = &cave[ty][tx];
+
+ cave_type *c_ptr = &cave[ty][tx];
if (!c_ptr->m_idx)
{
@@ -5276,8 +5273,8 @@ void teleport_swap(int dir)
}
else
{
- m_ptr = &m_list[c_ptr->m_idx];
- r_ptr = race_inf(m_ptr);
+ monster_type *m_ptr = &m_list[c_ptr->m_idx];
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags3 & RF3_RES_TELE)
{
diff --git a/src/spells3.cc b/src/spells3.cc
index e209feb..78dec53 100644
--- a/src/spells3.cc
+++ b/src/spells3.cc
@@ -2125,14 +2125,13 @@ const char *manwe_call_info()
void do_melkor_curse(int m_idx)
{
- monster_type *m_ptr = NULL;
assert(m_idx >= 0);
- m_ptr = &m_list[m_idx];
+ monster_type *m_ptr = &m_list[m_idx];
if (get_level_s(MELKOR_CURSE, 50) >= 35)
{
- monster_race *r_ptr = race_info_idx(m_ptr->r_idx, m_ptr->ego);
+ auto const r_ptr = m_ptr->race();
m_ptr->maxhp = m_ptr->maxhp - r_ptr->hside;
if (m_ptr->maxhp < 1)
@@ -2269,12 +2268,12 @@ casting_result melkor_mind_steal()
{
monster_type *m_ptr = &m_list[target_who];
int chance = get_level_s(MELKOR_MIND_STEAL, 50);
- monster_race *r_ptr = race_info_idx(m_ptr->r_idx, m_ptr->ego);
- char buf[128];
+ char buf[128];
monster_desc(buf, m_ptr, 0);
buf[0] = toupper(buf[0]);
+ auto const r_ptr = m_ptr->race();
if ((randint(m_ptr->level) < chance) &&
((r_ptr->flags1 & RF1_UNIQUE) == 0))
{
diff --git a/src/traps.cc b/src/traps.cc
index bc4ef99..d111951 100644
--- a/src/traps.cc
+++ b/src/traps.cc
@@ -217,7 +217,7 @@ static bool_ player_handle_trap_of_walls(void)
if (cv_ptr->m_idx)
{
monster_type *m_ptr = &m_list[cv_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Most monsters cannot co-exist with rock */
if ((!(r_ptr->flags2 & RF2_KILL_WALL)) &&
diff --git a/src/xtra1.cc b/src/xtra1.cc
index 87ecd62..d213aa3 100644
--- a/src/xtra1.cc
+++ b/src/xtra1.cc
@@ -1291,7 +1291,10 @@ static void fix_monster(void)
Term_activate(angband_term[j]);
/* Display monster race info */
- if (monster_race_idx) display_roff(monster_race_idx, monster_ego_idx);
+ if (monster_race_idx)
+ {
+ display_roff(monster_race_idx, monster_ego_idx);
+ }
/* Fresh */
Term_fresh();
@@ -3708,20 +3711,19 @@ void calc_bonuses(bool_ silent)
/* Monsters that only have their "natural" attacks */
else if (!r_info[p_ptr->body_monster].body_parts[BODY_WEAPON])
{
- int str_index, dex_index;
- int num = 0, wgt = 0, mul = 0;
- monster_race *r_ptr = race_info_idx(p_ptr->body_monster, 0);
-
+ int num = 0;
+ int wgt = 0;
+ int mul = 0;
analyze_blow(&num, &wgt, &mul);
/* Access the strength vs weight */
- str_index = (adj_str_blow[p_ptr->stat_ind[A_STR]] * mul / 3);
+ int str_index = (adj_str_blow[p_ptr->stat_ind[A_STR]] * mul / 3);
/* Maximal value */
if (str_index > 11) str_index = 11;
/* Index by dexterity */
- dex_index = (adj_dex_blow[p_ptr->stat_ind[A_DEX]]);
+ int dex_index = (adj_dex_blow[p_ptr->stat_ind[A_DEX]]);
/* Maximal value */
if (dex_index > 11) dex_index = 11;
@@ -3739,6 +3741,7 @@ void calc_bonuses(bool_ silent)
if (p_ptr->num_blow < 1) p_ptr->num_blow = 1;
/* Limit as defined by monster body */
+ auto r_ptr = race_info_idx(p_ptr->body_monster, 0);
for (num = 0; num < p_ptr->num_blow; num++)
if (!r_ptr->blow[num].effect)
break;
diff --git a/src/xtra2.cc b/src/xtra2.cc
index d1eaa97..87bfe0d 100644
--- a/src/xtra2.cc
+++ b/src/xtra2.cc
@@ -2137,7 +2137,7 @@ void lose_exp(s32b amount)
*
* XXX XXX XXX Note the use of actual "monster names"
*/
-int get_coin_type(monster_race *r_ptr)
+int get_coin_type(std::shared_ptr<monster_race const> r_ptr)
{
cptr name = r_ptr->name;
@@ -2169,16 +2169,15 @@ int get_coin_type(monster_race *r_ptr)
*/
void place_corpse(monster_type *m_ptr)
{
- monster_race *r_ptr = race_inf(m_ptr);
+ const int x = m_ptr->fx;
+ const int y = m_ptr->fy;
- object_type *i_ptr;
+ /* Get local object */
object_type object_type_body;
+ object_type *i_ptr = &object_type_body;
- int x = m_ptr->fx;
- int y = m_ptr->fy;
-
- /* Get local object */
- i_ptr = &object_type_body;
+ /* Get the race information */
+ auto const r_ptr = m_ptr->race();
/* It has a physical form */
if (r_ptr->flags9 & RF9_DROP_CORPSE)
@@ -2469,18 +2468,15 @@ static void monster_death_gods(int m_idx, monster_type *m_ptr)
*/
void monster_death(int m_idx)
{
- int i, y, x, ny, nx;
-
int dump_item = 0;
int dump_gold = 0;
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
bool_ visible = (m_ptr->ml || (r_ptr->flags1 & (RF1_UNIQUE)));
-
bool_ create_stairs = FALSE;
int force_coin = get_coin_type(r_ptr);
@@ -2488,8 +2484,8 @@ void monster_death(int m_idx)
object_type *q_ptr;
/* Get the location */
- y = m_ptr->fy;
- x = m_ptr->fx;
+ int y = m_ptr->fy;
+ int x = m_ptr->fx;
/* Process the appropriate hooks */
{
@@ -2658,7 +2654,7 @@ void monster_death(int m_idx)
/* Pink horrors are replaced with 2 Blue horrors */
else if (strstr(r_ptr->name, "ink horror"))
{
- for (i = 0; i < 2; i++)
+ for (int i = 0; i < 2; i++)
{
int wy = p_ptr->py, wx = p_ptr->px;
int attempts = 100;
@@ -2877,7 +2873,7 @@ void monster_death(int m_idx)
}
/* Let monsters explode! */
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
if (m_ptr->blow[i].method == RBM_EXPLODE)
{
@@ -3005,25 +3001,26 @@ void monster_death(int m_idx)
lore_treasure(m_idx, dump_item, dump_gold);
}
- /* Current quest */
- i = p_ptr->inside_quest;
-
/* Create a magical staircase */
if (create_stairs && (dun_level < d_info[dungeon_type].maxdepth))
{
- int i, j;
-
- for (i = -1; i <= 1; i++)
- for (j = -1; j <= 1; j++)
- if (!(f_info[cave[y + j][x + i].feat].flags1 & FF1_PERMANENT)) cave_set_feat(y + j, x + i, d_info[dungeon_type].floor1);
+ for (int i = -1; i <= 1; i++)
+ {
+ for (int j = -1; j <= 1; j++)
+ {
+ if (!(f_info[cave[y + j][x + i].feat].flags1 & FF1_PERMANENT))
+ {
+ cave_set_feat(y + j, x + i, d_info[dungeon_type].floor1);
+ }
+ }
+ }
/* Stagger around */
while (!cave_valid_bold(y, x))
{
- int d = 1;
-
/* Pick a location */
- scatter(&ny, &nx, y, x, d);
+ int ny, nx;
+ scatter(&ny, &nx, y, x, 1);
/* Stagger */
y = ny;
@@ -3077,9 +3074,8 @@ void monster_death(int m_idx)
bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note)
{
monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
- s32b div, new_exp, new_exp_frac;
-
+ auto const r_idx = m_ptr->r_idx;
+ auto const r_ptr = m_ptr->race();
/* Redraw (later) if needed */
if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME);
@@ -3165,15 +3161,15 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note)
}
/* Maximum player level */
- div = p_ptr->max_plv;
+ const s32b div = p_ptr->max_plv;
if (m_ptr->status < MSTATUS_FRIEND)
{
/* Give some experience for the kill */
- new_exp = ((long)r_ptr->mexp * m_ptr->level) / div;
+ int new_exp = ((long)r_ptr->mexp * m_ptr->level) / div;
/* Handle fractional experience */
- new_exp_frac = ((((long)r_ptr->mexp * m_ptr->level) % div)
+ const s32b new_exp_frac = ((((long)r_ptr->mexp * m_ptr->level) % div)
* 0x10000L / div) + p_ptr->exp_frac;
/* Keep track of experience */
@@ -3204,7 +3200,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note)
if ((o_ptr->k_idx) && (f4 & TR4_LEVELS))
{
/* Give some experience for the kill */
- new_exp = ((long)r_ptr->mexp * m_ptr->level) / (div * 2);
+ const int new_exp = ((long)r_ptr->mexp * m_ptr->level) / (div * 2);
/* Gain experience */
o_ptr->exp += new_exp;
@@ -3305,7 +3301,7 @@ bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note)
* XXX XXX XXX Not yet completed quest is
* to kill a unique you've just killed
*/
- if (r_ptr == &r_info[q_ptr->r_idx])
+ if (r_idx == q_ptr->r_idx)
{
/* Invalidate it */
q_ptr->type = 0;
@@ -3667,14 +3663,11 @@ void resize_window(void)
*/
static cptr look_mon_desc(int m_idx)
{
- monster_type *m_ptr = &m_list[m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
-
bool_ living = TRUE;
- int perc;
-
/* Determine if the monster is "living" (vs "undead") */
+ monster_type *m_ptr = &m_list[m_idx];
+ auto const r_ptr = m_ptr->race();
if (r_ptr->flags3 & (RF3_UNDEAD)) living = FALSE;
if (r_ptr->flags3 & (RF3_DEMON)) living = FALSE;
if (r_ptr->flags3 & (RF3_NONLIVING)) living = FALSE;
@@ -3690,7 +3683,7 @@ static cptr look_mon_desc(int m_idx)
/* Calculate a health "percentage" */
- perc = 100L * m_ptr->hp / m_ptr->maxhp;
+ const int perc = 100L * m_ptr->hp / m_ptr->maxhp;
if (perc >= 60)
{
@@ -4209,7 +4202,7 @@ static int target_set_aux(int y, int x, int mode, cptr info)
if (c_ptr->m_idx)
{
monster_type *m_ptr = &m_list[c_ptr->m_idx];
- monster_race *r_ptr = race_inf(m_ptr);
+ auto const r_ptr = m_ptr->race();
/* Mimics special treatment -- looks like an object */
if ((r_ptr->flags9 & RF9_MIMIC) && (m_ptr->csleep))
diff --git a/src/xtra2.hpp b/src/xtra2.hpp
index cb16f6d..10d752a 100644
--- a/src/xtra2.hpp
+++ b/src/xtra2.hpp
@@ -5,6 +5,8 @@
#include "object_type_fwd.hpp"
#include "player_race_mod_fwd.hpp"
+#include <memory>
+
extern void do_rebirth(void);
extern void set_subrace_title(player_race_mod *rmp_ptr, cptr name);
extern void set_subrace_description(player_race_mod *rmp_ptr, cptr desc);
@@ -69,7 +71,7 @@ extern void check_experience(void);
extern void check_experience_obj(object_type *o_ptr);
extern void gain_exp(s32b amount);
extern void lose_exp(s32b amount);
-extern int get_coin_type(monster_race *r_ptr);
+extern int get_coin_type(std::shared_ptr<monster_race const> r_ptr);
extern void monster_death(int m_idx);
extern bool_ mon_take_hit(int m_idx, int dam, bool_ *fear, cptr note);
extern bool_ change_panel(int dy, int dx);