summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:57 +0100
committerBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:57 +0100
commit987fe8afd5245232ef347ad2e1559bf36fd12d44 (patch)
tree9152a63c8d98b043839b34ac03c318fd2ba8c188 /src
parentc4446a2b2cac8166827d0c505b290487a47aaafd (diff)
Reduce ridiculous number of test_monster_name usages
Diffstat (limited to 'src')
-rw-r--r--src/defines.h18
-rw-r--r--src/q_eol.cc17
-rw-r--r--src/q_hobbit.cc27
-rw-r--r--src/q_main.cc26
-rw-r--r--src/q_nazgul.cc14
-rw-r--r--src/q_rand.cc13
-rw-r--r--src/q_shroom.cc54
-rw-r--r--src/q_thrain.cc16
-rw-r--r--src/q_troll.cc19
-rw-r--r--src/q_wight.cc11
-rw-r--r--src/spells3.cc19
-rw-r--r--src/wizard2.cc20
12 files changed, 167 insertions, 87 deletions
diff --git a/src/defines.h b/src/defines.h
index f56634eb..32e26bc4 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -4593,3 +4593,21 @@
#define BOOK_RANDOM 255
#define SCHOOL_BOOKS_SIZE 256
+
+/**
+ * Macro to generate a memoizing named monster lookup function.
+ *
+ * This is meant as a stopgap measure until a better method
+ * can be implemented.
+ */
+#define GENERATE_MONSTER_LOOKUP_FN(fn, name) \
+ static int fn()\
+ {\
+ static int r_idx = -1;\
+ if (r_idx < 0)\
+ {\
+ r_idx = test_monster_name(name);\
+ assert(r_idx);\
+ }\
+ return r_idx;\
+ }
diff --git a/src/q_eol.cc b/src/q_eol.cc
index 9286746d..b00d433b 100644
--- a/src/q_eol.cc
+++ b/src/q_eol.cc
@@ -1,8 +1,11 @@
#include "q_eol.h"
#include "hooks.h"
+#include <cassert>
#define cquest (quest[QUEST_EOL])
+GENERATE_MONSTER_LOOKUP_FN(get_eol, "Eol, the Dark Elf")
+
static bool_ quest_eol_gen_hook(void *, void *, void *)
{
int x, y;
@@ -63,9 +66,13 @@ static bool_ quest_eol_gen_hook(void *, void *, void *)
/* Place eol at the other end */
if (!m_idx)
{
- m_allow_special[test_monster_name("Eol, the Dark Elf")] = TRUE;
- m_idx = place_monster_one(y, x, test_monster_name("Eol, the Dark Elf"), 0, FALSE, MSTATUS_ENEMY);
- m_allow_special[test_monster_name("Eol, the Dark Elf")] = FALSE;
+ // Find Eol's r_info entry
+ int r_idx = get_eol();
+ // "Summon" Eol
+ m_allow_special[r_idx] = TRUE;
+ m_idx = place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[r_idx] = FALSE;
+ // Mark with the QUEST flag
if (m_idx) m_list[m_idx].mflag |= MFLAG_QUEST;
}
@@ -142,7 +149,7 @@ static bool_ quest_eol_death_hook(void *, void *in_, void *)
if (p_ptr->inside_quest != QUEST_EOL) return FALSE;
- if (r_idx == test_monster_name("Eol, the Dark Elf"))
+ if (r_idx == get_eol())
{
cmsg_print(TERM_YELLOW, "Such a sad end...");
cquest.status = QUEST_STATUS_COMPLETED;
@@ -159,7 +166,7 @@ static bool_ quest_eol_death_hook(void *, void *in_, void *)
static bool_ quest_eol_stair_hook(void *, void *in_, void *)
{
struct hook_stair_in *in = static_cast<struct hook_stair_in *>(in_);
- monster_race *r_ptr = &r_info[test_monster_name("Eol, the Dark Elf")];
+ monster_race *r_ptr = &r_info[get_eol()];
if (p_ptr->inside_quest != QUEST_EOL) return FALSE;
diff --git a/src/q_hobbit.cc b/src/q_hobbit.cc
index c52b8653..10e67176 100644
--- a/src/q_hobbit.cc
+++ b/src/q_hobbit.cc
@@ -1,9 +1,13 @@
#include "q_hobbit.h"
#include "messages.h"
#include "hooks.h"
+#include <cassert>
#define cquest (quest[QUEST_HOBBIT])
+GENERATE_MONSTER_LOOKUP_FN(get_melinda_proudfoot, "Melinda Proudfoot")
+GENERATE_MONSTER_LOOKUP_FN(get_merton_proudfoot, "Merton Proudfoot, the lost hobbit")
+
static bool_ quest_hobbit_town_gen_hook(void *, void *in_, void *)
{
struct hook_wild_gen_in *in = static_cast<struct hook_wild_gen_in *>(in_);
@@ -29,9 +33,10 @@ static bool_ quest_hobbit_town_gen_hook(void *, void *in_, void *)
}
/* Place Melinda */
- m_allow_special[test_monster_name("Melinda Proudfoot")] = TRUE;
- place_monster_one(y, x, test_monster_name("Melinda Proudfoot"), 0, FALSE, MSTATUS_ENEMY);
- m_allow_special[test_monster_name("Melinda Proudfoot")] = FALSE;
+ int r_idx = get_melinda_proudfoot();
+ m_allow_special[r_idx] = TRUE;
+ place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[r_idx] = FALSE;
return FALSE;
}
@@ -57,9 +62,10 @@ static bool_ quest_hobbit_gen_hook(void *, void *, void *)
}
/* Place the hobbit */
- m_allow_special[test_monster_name("Merton Proudfoot, the lost hobbit")] = TRUE;
- place_monster_one(y, x, test_monster_name("Merton Proudfoot, the lost hobbit"), 0, FALSE, MSTATUS_FRIEND);
- m_allow_special[test_monster_name("Merton Proudfoot, the lost hobbit")] = FALSE;
+ int r_idx = get_merton_proudfoot();
+ m_allow_special[r_idx] = TRUE;
+ place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_FRIEND);
+ m_allow_special[r_idx] = FALSE;
return FALSE;
}
@@ -75,7 +81,7 @@ static bool_ quest_hobbit_give_hook(void *, void *in_, void *)
o_ptr = &p_ptr->inventory[item];
m_ptr = &m_list[m_idx];
- if (m_ptr->r_idx != test_monster_name("Merton Proudfoot, the lost hobbit")) return (FALSE);
+ if (m_ptr->r_idx != get_merton_proudfoot()) return (FALSE);
if ((o_ptr->tval != TV_SCROLL) || (o_ptr->sval != SV_SCROLL_WORD_OF_RECALL)) return (FALSE);
@@ -99,7 +105,10 @@ static bool_ quest_hobbit_speak_hook(void *, void *in_, void *)
struct hook_mon_speak_in *in = static_cast<struct hook_mon_speak_in *>(in_);
s32b m_idx = in->m_idx;
- if (m_list[m_idx].r_idx != test_monster_name("Melinda Proudfoot")) return (FALSE);
+ if (m_list[m_idx].r_idx != get_melinda_proudfoot())
+ {
+ return (FALSE);
+ }
if (cquest.status < QUEST_STATUS_COMPLETED)
{
@@ -116,7 +125,7 @@ static bool_ quest_hobbit_chat_hook(void *, void *in_, void *)
m_ptr = &m_list[m_idx];
- if (m_ptr->r_idx != test_monster_name("Melinda Proudfoot")) return (FALSE);
+ if (m_ptr->r_idx != get_melinda_proudfoot()) return (FALSE);
if (cquest.status < QUEST_STATUS_COMPLETED)
{
diff --git a/src/q_main.cc b/src/q_main.cc
index 0b6d19e2..73969f1a 100644
--- a/src/q_main.cc
+++ b/src/q_main.cc
@@ -1,5 +1,10 @@
#include "q_main.h"
#include "hooks.h"
+#include <cassert>
+
+GENERATE_MONSTER_LOOKUP_FN(get_necromancer, "The Necromancer of Dol Guldur")
+GENERATE_MONSTER_LOOKUP_FN(get_sauron, "Sauron, the Sorcerer")
+GENERATE_MONSTER_LOOKUP_FN(get_morgoth, "Morgoth, Lord of Darkness")
static void quest_describe(int q_idx)
{
@@ -17,24 +22,23 @@ static bool_ quest_main_monsters_hook(void *, void *in_, void *)
s32b r_idx = in->r_idx;
/* Sauron */
- if (r_idx == 860)
+ if (r_idx == get_sauron())
{
/* No Sauron until Necromancer dies */
- if (r_info[819].max_num) return TRUE;
+ if (r_info[get_necromancer()].max_num) return TRUE;
}
/* Morgoth */
- else if (r_idx == 862)
+ else if (r_idx == get_morgoth())
{
/* No Morgoth until Sauron dies */
- if (r_info[860].max_num) return TRUE;
+ if (r_info[get_sauron()].max_num) return TRUE;
}
return FALSE;
}
static bool_ quest_morgoth_hook(void *, void *, void *)
{
- /* Using test_monster_name() here would be a lot less ugly, but would take much more time */
- monster_race *r_ptr = &r_info[862];
+ monster_race *r_ptr = &r_info[get_morgoth()];
/* Need to kill him */
if (!r_ptr->max_num)
@@ -110,8 +114,7 @@ bool_ quest_morgoth_init_hook(int q_idx)
static bool_ quest_sauron_hook(void *, void *, void *)
{
- /* Using test_monster_name() here would be a lot less ugly, but would take much more time */
- monster_race *r_ptr = &r_info[860];
+ monster_race *r_ptr = &r_info[get_sauron()];
/* Need to kill him */
if (!r_ptr->max_num)
@@ -139,12 +142,12 @@ static bool_ quest_sauron_resurect_hook(void *, void *in_, void *)
monster_type *m_ptr = &m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- if ((r_ptr->flags7 & RF7_NAZGUL) && r_info[860].max_num)
+ if ((r_ptr->flags7 & RF7_NAZGUL) && r_info[get_sauron()].max_num)
{
msg_format("Somehow you feel %s is not totally destroyed...", (r_ptr->flags1 & RF1_FEMALE ? "she" : "he"));
r_ptr->max_num = 1;
}
- else if ((m_ptr->r_idx == 860) && (quest[QUEST_ONE].status < QUEST_STATUS_FINISHED))
+ else if ((m_ptr->r_idx == get_sauron()) && (quest[QUEST_ONE].status < QUEST_STATUS_FINISHED))
{
msg_print("Sauron will not be permanently defeated until the One Ring is either destroyed or used...");
r_ptr->max_num = 1;
@@ -165,8 +168,7 @@ bool_ quest_sauron_init_hook(int q_idx)
static bool_ quest_necro_hook(void *, void *, void *)
{
- /* Using test_monster_name() here would be a lot less ugly, but would take much more time */
- monster_race *r_ptr = &r_info[819];
+ monster_race *r_ptr = &r_info[get_necromancer()];
/* Need to kill him */
if (!r_ptr->max_num)
diff --git a/src/q_nazgul.cc b/src/q_nazgul.cc
index e54f0534..32449f1d 100644
--- a/src/q_nazgul.cc
+++ b/src/q_nazgul.cc
@@ -1,8 +1,11 @@
#include "q_nazgul.h"
#include "hooks.h"
+#include <cassert>
#define cquest (quest[QUEST_NAZGUL])
+GENERATE_MONSTER_LOOKUP_FN(get_uvatha, "Uvatha the Horseman")
+
static bool_ quest_nazgul_gen_hook(void *, void *in_, void *)
{
struct hook_wild_gen_in *in = static_cast<struct hook_wild_gen_in *>(in_);
@@ -27,10 +30,13 @@ static bool_ quest_nazgul_gen_hook(void *, void *in_, void *)
}
/* Place the nazgul */
- m_allow_special[test_monster_name("Uvatha the Horseman")] = TRUE;
- m_idx = place_monster_one(y, x, test_monster_name("Uvatha the Horseman"), 0, FALSE, MSTATUS_ENEMY);
+ int r_idx = get_uvatha();
+
+ m_allow_special[r_idx] = TRUE;
+ m_idx = place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[r_idx] = FALSE;
+
if (m_idx) m_list[m_idx].mflag |= MFLAG_QUEST;
- m_allow_special[test_monster_name("Uvatha the Horseman")] = FALSE;
return FALSE;
}
@@ -99,7 +105,7 @@ static bool_ quest_nazgul_death_hook(void *, void *in_, void *)
s32b r_idx = m_list[m_idx].r_idx;
if (cquest.status != QUEST_STATUS_TAKEN) return (FALSE);
- if (r_idx != test_monster_name("Uvatha the Horseman")) return (FALSE);
+ if (r_idx != get_uvatha()) return (FALSE);
cquest.status = QUEST_STATUS_COMPLETED;
diff --git a/src/q_rand.cc b/src/q_rand.cc
index 94adef86..df1981f8 100644
--- a/src/q_rand.cc
+++ b/src/q_rand.cc
@@ -2,6 +2,7 @@
#include "hooks.h"
#include "util.hpp"
#include "messages.h"
+#include <cassert>
static int randquest_hero[] = { 20, 13, 15, 16, 9, 17, 18, 8, -1 };
@@ -18,6 +19,9 @@ static int random_quests_types[MAX_RANDOM_QUESTS_TYPES] =
/* Enforce OoD monsters until this level */
#define RQ_LEVEL_CAP 49
+// Generate lookup function
+GENERATE_MONSTER_LOOKUP_FN(get_adventurer, "Adventurer")
+
void initialize_random_quests(int n)
{
int step, lvl, i, k;
@@ -348,11 +352,12 @@ static void hero_death(s32b m_idx, s32b r_idx)
if (i < 20)
{
- int m_idx;
+ int r_idx = get_adventurer();
+
+ m_allow_special[r_idx] = TRUE;
+ int m_idx = place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_COMPANION);
+ m_allow_special[r_idx] = FALSE;
- m_allow_special[test_monster_name("Adventurer")] = TRUE;
- m_idx = place_monster_one(y, x, test_monster_name("Adventurer"), 0, FALSE, MSTATUS_COMPANION);
- m_allow_special[test_monster_name("Adventurer")] = FALSE;
if (m_idx)
{
m_list[m_idx].exp = monster_exp(1 + (dun_level * 3 / 2));
diff --git a/src/q_shroom.cc b/src/q_shroom.cc
index 3c606e99..97d76275 100644
--- a/src/q_shroom.cc
+++ b/src/q_shroom.cc
@@ -1,12 +1,18 @@
#include "q_shroom.h"
#include "messages.h"
#include "hooks.h"
+#include <cassert>
#define cquest (quest[QUEST_SHROOM])
static bool_ quest_shroom_speak_hook(void *, void *, void *);
static bool_ quest_shroom_chat_hook(void *, void *, void *);
+GENERATE_MONSTER_LOOKUP_FN(get_grip, "Grip, Farmer Maggot's dog")
+GENERATE_MONSTER_LOOKUP_FN(get_wolf, "Wolf, Farmer Maggot's dog")
+GENERATE_MONSTER_LOOKUP_FN(get_fang, "Fang, Farmer Maggot's dog")
+GENERATE_MONSTER_LOOKUP_FN(get_farmer_maggot, "Farmer Maggot")
+
static bool_ quest_shroom_town_gen_hook(void *, void *in_, void *)
{
struct hook_wild_gen_in *in = static_cast<struct hook_wild_gen_in *>(in_);
@@ -36,24 +42,24 @@ static bool_ quest_shroom_town_gen_hook(void *, void *in_, void *)
/* Throw in some dogs ;) */
y = rand_range((cur_hgt / 2) - 5, (cur_hgt / 2) + 5);
x = rand_range((cur_wid / 2) - 7, (cur_wid / 2) + 7);
- m_allow_special[test_monster_name("Grip, Farmer Maggot's dog")] = TRUE;
- m_idx = place_monster_one(y, x, test_monster_name("Grip, Farmer Maggot's dog"), 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[get_grip()] = TRUE;
+ m_idx = place_monster_one(y, x, get_grip(), 0, FALSE, MSTATUS_ENEMY);
if (m_idx) m_list[m_idx].mflag |= MFLAG_QUEST;
- m_allow_special[test_monster_name("Grip, Farmer Maggot's dog")] = FALSE;
+ m_allow_special[get_grip()] = FALSE;
y = rand_range((cur_hgt / 2) - 5, (cur_hgt / 2) + 5);
x = rand_range((cur_wid / 2) - 7, (cur_wid / 2) + 7);
- m_allow_special[test_monster_name("Wolf, Farmer Maggot's dog")] = TRUE;
- m_idx = place_monster_one(y, x, test_monster_name("Wolf, Farmer Maggot's dog"), 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[get_wolf()] = TRUE;
+ m_idx = place_monster_one(y, x, get_wolf(), 0, FALSE, MSTATUS_ENEMY);
if (m_idx) m_list[m_idx].mflag |= MFLAG_QUEST;
- m_allow_special[test_monster_name("Wolf, Farmer Maggot's dog")] = FALSE;
+ m_allow_special[get_wolf()] = FALSE;
y = rand_range((cur_hgt / 2) - 5, (cur_hgt / 2) + 5);
x = rand_range((cur_wid / 2) - 7, (cur_wid / 2) + 7);
- m_allow_special[test_monster_name("Fang, Farmer Maggot's dog")] = TRUE;
- m_idx = place_monster_one(y, x, test_monster_name("Fang, Farmer Maggot's dog"), 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[get_fang()] = TRUE;
+ m_idx = place_monster_one(y, x, get_fang(), 0, FALSE, MSTATUS_ENEMY);
if (m_idx) m_list[m_idx].mflag |= MFLAG_QUEST;
- m_allow_special[test_monster_name("Fang, Farmer Maggot's dog")] = FALSE;
+ m_allow_special[get_fang()] = FALSE;
msg_print("You hear frenzied barking.");
}
@@ -78,9 +84,9 @@ static bool_ quest_shroom_town_gen_hook(void *, void *in_, void *)
}
/* Place Farmer Maggot */
- m_allow_special[test_monster_name("Farmer Maggot")] = TRUE;
- place_monster_one(y, x, test_monster_name("Farmer Maggot"), 0, FALSE, MSTATUS_ENEMY);
- m_allow_special[test_monster_name("Farmer Maggot")] = FALSE;
+ m_allow_special[get_farmer_maggot()] = TRUE;
+ place_monster_one(y, x, get_farmer_maggot(), 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[get_farmer_maggot()] = FALSE;
return FALSE;
}
@@ -93,9 +99,9 @@ static bool_ quest_shroom_death_hook(void *, void *in_, void *)
if (cquest.status > QUEST_STATUS_COMPLETED) return FALSE;
- if ((r_idx == test_monster_name("Wolf, Farmer Maggot's dog")) ||
- (r_idx == test_monster_name("Grip, Farmer Maggot's dog")) ||
- (r_idx == test_monster_name("Fang, Farmer Maggot's dog")))
+ if ((r_idx == get_wolf()) ||
+ (r_idx == get_grip()) ||
+ (r_idx == get_fang()))
{
msg_print("The dog yells a last time and drops dead on the grass.");
}
@@ -115,12 +121,12 @@ static bool_ quest_shroom_give_hook(void *, void *in_, void *)
o_ptr = &p_ptr->inventory[item];
m_ptr = &m_list[m_idx];
- if (m_ptr->r_idx != test_monster_name("Farmer Maggot")) return (FALSE);
+ if (m_ptr->r_idx != get_farmer_maggot()) return (FALSE);
/* If one is dead .. its bad */
- if ((r_info[test_monster_name("Grip, Farmer Maggot's dog")].max_num == 0) ||
- (r_info[test_monster_name("Wolf, Farmer Maggot's dog")].max_num == 0) ||
- (r_info[test_monster_name("Fang, Farmer Maggot's dog")].max_num == 0))
+ if ((r_info[get_grip()].max_num == 0) ||
+ (r_info[get_wolf()].max_num == 0) ||
+ (r_info[get_fang()].max_num == 0))
{
cquest.status = QUEST_STATUS_FAILED_DONE;
msg_print("My puppy! My poor, defenceless puppy...");
@@ -190,9 +196,9 @@ static bool_ quest_shroom_give_hook(void *, void *in_, void *)
static void check_dogs_alive(s32b m_idx)
{
- if ((r_info[test_monster_name("Grip, Farmer Maggot's dog")].max_num == 0) ||
- (r_info[test_monster_name("Wolf, Farmer Maggot's dog")].max_num == 0) ||
- (r_info[test_monster_name("Fang, Farmer Maggot's dog")].max_num == 0))
+ if ((r_info[get_grip()].max_num == 0) ||
+ (r_info[get_wolf()].max_num == 0) ||
+ (r_info[get_fang()].max_num == 0))
{
cquest.status = QUEST_STATUS_FAILED_DONE;
msg_print("My puppy! My poor, defenceless puppy...");
@@ -216,7 +222,7 @@ static bool_ quest_shroom_speak_hook(void *, void *in_, void *)
struct hook_mon_speak_in *in = static_cast<struct hook_mon_speak_in *>(in_);
s32b m_idx = in->m_idx;
- if (m_list[m_idx].r_idx != test_monster_name("Farmer Maggot")) return (FALSE);
+ if (m_list[m_idx].r_idx != get_farmer_maggot()) return (FALSE);
if (cquest.status == QUEST_STATUS_UNTAKEN)
{
@@ -236,7 +242,7 @@ static bool_ quest_shroom_chat_hook(void *, void *in_, void *)
s32b m_idx = in->m_idx;
monster_type *m_ptr = &m_list[m_idx];
- if (m_ptr->r_idx != test_monster_name("Farmer Maggot")) return (FALSE);
+ if (m_ptr->r_idx != get_farmer_maggot()) return (FALSE);
if (cquest.status == QUEST_STATUS_UNTAKEN)
{
diff --git a/src/q_thrain.cc b/src/q_thrain.cc
index f4e96a2b..d505f1f5 100644
--- a/src/q_thrain.cc
+++ b/src/q_thrain.cc
@@ -2,9 +2,14 @@
#include "quark.h"
#include "messages.h"
#include "hooks.h"
+#include <cassert>
#define cquest (quest[QUEST_THRAIN])
+GENERATE_MONSTER_LOOKUP_FN(get_thrain, "Thrain, the King Under the Mountain")
+GENERATE_MONSTER_LOOKUP_FN(get_dwar, "Dwar, Dog Lord of Waw")
+GENERATE_MONSTER_LOOKUP_FN(get_hoarmurath, "Hoarmurath of Dir")
+
static bool_ quest_thrain_death_hook(void *, void *in_, void *)
{
struct hook_monster_death_in *in = static_cast<struct hook_monster_death_in *>(in_);
@@ -14,7 +19,7 @@ static bool_ quest_thrain_death_hook(void *, void *in_, void *)
if ((cquest.status >= QUEST_STATUS_FINISHED) || (dun_level !=cquest.data[0]) || (dungeon_type != DUNGEON_DOL_GULDUR)) return (FALSE);
m_ptr = &m_list[m_idx];
- if ((m_ptr->r_idx != test_monster_name("Dwar, Dog Lord of Waw")) && (m_ptr->r_idx != test_monster_name("Hoarmurath of Dir"))) return (FALSE);
+ if ((m_ptr->r_idx != get_dwar()) && (m_ptr->r_idx != get_hoarmurath())) return (FALSE);
cquest.data[2]++;
@@ -50,7 +55,7 @@ static bool_ quest_thrain_death_hook(void *, void *in_, void *)
if (!m_ptr->r_idx) continue;
/* Is it the princess? */
- if (m_ptr->r_idx == test_monster_name("Thrain, the King Under the Mountain"))
+ if (m_ptr->r_idx == get_thrain())
{
int x = m_ptr->fx;
int y = m_ptr->fy;
@@ -147,12 +152,11 @@ static bool_ quest_thrain_gen_hook(void *, void *in_, void *)
cave[y][x].info |= CAVE_ICKY | CAVE_ROOM | CAVE_FREE;
if (cave[y][x].feat == FEAT_MARKER)
{
- int i;
+ m_allow_special[get_thrain()] = TRUE;
+ int i = place_monster_one(y, x, get_thrain(), 0, FALSE, MSTATUS_NEUTRAL);
+ m_allow_special[get_thrain()] = FALSE;
- m_allow_special[test_monster_name("Thrain, the King Under the Mountain")] = TRUE;
- i = place_monster_one(y, x, test_monster_name("Thrain, the King Under the Mountain"), 0, FALSE, MSTATUS_NEUTRAL);
if (i) m_list[i].mflag |= MFLAG_QUEST;
- m_allow_special[test_monster_name("Thrain, the King Under the Mountain")] = FALSE;
}
}
diff --git a/src/q_troll.cc b/src/q_troll.cc
index bb5f8729..39e4a28a 100644
--- a/src/q_troll.cc
+++ b/src/q_troll.cc
@@ -1,8 +1,13 @@
#include "q_troll.h"
#include "hooks.h"
+#include <cassert>
#define cquest (quest[QUEST_TROLL])
+GENERATE_MONSTER_LOOKUP_FN(get_tom, "Tom the Stone Troll")
+GENERATE_MONSTER_LOOKUP_FN(get_stone_troll, "Stone troll")
+GENERATE_MONSTER_LOOKUP_FN(get_forest_troll, "Forest troll")
+
static bool_ quest_troll_gen_hook(void *, void *, void *)
{
int x, y;
@@ -35,11 +40,9 @@ static bool_ quest_troll_gen_hook(void *, void *, void *)
{
if (cave[y][x].feat == FEAT_MARKER)
{
- int m_idx;
-
- m_allow_special[test_monster_name("Tom the Stone Troll")] = TRUE;
- m_idx = place_monster_one(y, x, test_monster_name("Tom the Stone Troll"), 0, FALSE, MSTATUS_ENEMY);
- m_allow_special[test_monster_name("Tom the Stone Troll")] = FALSE;
+ m_allow_special[get_tom()] = TRUE;
+ int m_idx = place_monster_one(y, x, get_tom(), 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[get_tom()] = FALSE;
if (m_idx)
{
@@ -125,7 +128,7 @@ static bool_ quest_troll_death_hook(void *, void *in_, void *)
if (p_ptr->inside_quest != QUEST_TROLL) return FALSE;
- if (r_idx == test_monster_name("Tom the Stone Troll"))
+ if (r_idx == get_tom())
{
cave_set_feat(3, 3, FEAT_LESS);
cave[3][3].special = 0;
@@ -154,12 +157,10 @@ static bool_ quest_troll_death_hook(void *, void *in_, void *)
/* Ahah ! */
if (c_ptr->info & CAVE_SPEC)
{
- int r_idx;
-
cave_set_feat(y, x, FEAT_GRASS);
c_ptr->info &= ~CAVE_SPEC;
- r_idx = (rand_int(2) == 0) ? test_monster_name("Forest troll") : test_monster_name("Stone troll");
+ int r_idx = (rand_int(2) == 0) ? get_forest_troll() : get_stone_troll();
place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_ENEMY);
}
}
diff --git a/src/q_wight.cc b/src/q_wight.cc
index dcbf6d7b..68794ead 100644
--- a/src/q_wight.cc
+++ b/src/q_wight.cc
@@ -1,9 +1,12 @@
#include "q_wight.h"
#include "quark.h"
#include "hooks.h"
+#include <cassert>
#define cquest (quest[QUEST_WIGHT])
+GENERATE_MONSTER_LOOKUP_FN(get_wight_king, "The Wight-King of the Barrow-downs")
+
static bool_ quest_wight_gen_hook(void *, void *, void *)
{
int x, y;
@@ -38,9 +41,9 @@ static bool_ quest_wight_gen_hook(void *, void *, void *)
{
int m_idx = 0;
- m_allow_special[test_monster_name("The Wight-King of the Barrow-downs")] = TRUE;
- m_idx = place_monster_one(y, x, test_monster_name("The Wight-King of the Barrow-downs"), 0, FALSE, MSTATUS_ENEMY);
- m_allow_special[test_monster_name("The Wight-King of the Barrow-downs")] = FALSE;
+ m_allow_special[get_wight_king()] = TRUE;
+ m_idx = place_monster_one(y, x, get_wight_king(), 0, FALSE, MSTATUS_ENEMY);
+ m_allow_special[get_wight_king()] = FALSE;
if (m_idx)
{
@@ -113,7 +116,7 @@ static bool_ quest_wight_death_hook(void *, void *in_, void *)
if (p_ptr->inside_quest != QUEST_WIGHT) return FALSE;
- if (r_idx == test_monster_name("The Wight-King of the Barrow-downs"))
+ if (r_idx == get_wight_king())
{
cmsg_print(TERM_YELLOW, "Without their King the wights won't be able to do much.");
diff --git a/src/spells3.cc b/src/spells3.cc
index ab06eb6a..83f7d97b 100644
--- a/src/spells3.cc
+++ b/src/spells3.cc
@@ -207,6 +207,10 @@ static casting_result cplus(casting_result old, bool_ effect)
}
}
+GENERATE_MONSTER_LOOKUP_FN(get_fire_golem, "Fire golem")
+
+// -------------------------------------------------------------
+
casting_result air_noxious_cloud()
{
int dir, type;
@@ -1374,8 +1378,6 @@ bool_ item_tester_hook_fire_golem(object_type *o_ptr)
casting_result fire_golem()
{
- int item, x, y, m_idx;
-
/* Can we reconnect ? */
if (do_control_reconnect())
{
@@ -1384,6 +1386,7 @@ casting_result fire_golem()
}
item_tester_hook = item_tester_hook_fire_golem;
+ int item;
if (!get_item(&item,
"Which light source do you want to use to create the golem?",
"You have no light source for the golem",
@@ -1395,11 +1398,15 @@ casting_result fire_golem()
/* Destroy the source object */
inc_stack_size(item, -1);
- /* Summon it */
- m_allow_special[1043 + 1] = TRUE;
+ /* Find a place for it */
+ int x, y;
find_position(p_ptr->py, p_ptr->px, &y, &x);
- m_idx = place_monster_one(y, x, 1043, 0, FALSE, MSTATUS_FRIEND);
- m_allow_special[1043 + 1] = FALSE;
+
+ /* Summon it */
+ int r_idx = get_fire_golem();
+ m_allow_special[r_idx] = TRUE;
+ int m_idx = place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_FRIEND);
+ m_allow_special[r_idx] = FALSE;
/* level it */
if (m_idx != 0)
diff --git a/src/wizard2.cc b/src/wizard2.cc
index 84ffddad..fa223ffe 100644
--- a/src/wizard2.cc
+++ b/src/wizard2.cc
@@ -1497,8 +1497,14 @@ static void do_cmd_wiz_named(int r_idx, bool_ slp)
/* Place it (allow groups) */
m_allow_special[r_idx] = TRUE;
- if (place_monster_aux(y, x, r_idx, slp, TRUE, MSTATUS_ENEMY)) break;
+ int m_idx = place_monster_aux(y, x, r_idx, slp, TRUE, MSTATUS_ENEMY);
m_allow_special[r_idx] = FALSE;
+
+ // If summoning succeeded, we stop.
+ if (m_idx)
+ {
+ break;
+ }
}
}
@@ -1519,7 +1525,6 @@ void do_cmd_wiz_named_friendly(int r_idx, bool_ slp)
if (r_idx >= max_r_idx) return;
/* Try 10 times */
- m_allow_special[r_idx] = TRUE;
for (i = 0; i < 10; i++)
{
int d = 1;
@@ -1531,9 +1536,16 @@ void do_cmd_wiz_named_friendly(int r_idx, bool_ slp)
if (!cave_empty_bold(y, x)) continue;
/* Place it (allow groups) */
- if (place_monster_aux(y, x, r_idx, slp, TRUE, MSTATUS_PET)) break;
+ m_allow_special[r_idx] = TRUE;
+ int m_idx = place_monster_aux(y, x, r_idx, slp, TRUE, MSTATUS_PET);
+ m_allow_special[r_idx] = FALSE;
+
+ // Stop if we succeeded
+ if (m_idx)
+ {
+ break;
+ }
}
- m_allow_special[r_idx] = FALSE;
}