diff options
author | Bardur Arantsson <bardur@scientician.net> | 2018-03-25 20:07:31 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2018-03-25 20:07:31 +0200 |
commit | 42ee1b48930e037b825e9e2a3ef3e5989e041870 (patch) | |
tree | bca00e0aae53f8a95aa723e5386423fb0c46a0c7 /src | |
parent | 402ef0fd8530093677d102ee8994c6c519535379 (diff) |
Don't use indexes for get_mon_num{,2}_hook
Diffstat (limited to 'src')
-rw-r--r-- | src/generate.cc | 93 | ||||
-rw-r--r-- | src/monster1.cc | 73 | ||||
-rw-r--r-- | src/monster2.cc | 50 | ||||
-rw-r--r-- | src/monster2.hpp | 4 | ||||
-rw-r--r-- | src/q_bounty.cc | 5 | ||||
-rw-r--r-- | src/q_poison.cc | 14 | ||||
-rw-r--r-- | src/variable.cc | 4 | ||||
-rw-r--r-- | src/variable.hpp | 5 | ||||
-rw-r--r-- | src/wild.cc | 9 |
9 files changed, 80 insertions, 177 deletions
diff --git a/src/generate.cc b/src/generate.cc index 178f60e1..2152c772 100644 --- a/src/generate.cc +++ b/src/generate.cc @@ -336,10 +336,6 @@ void add_level_generator(const char *name, bool_ (*generator)()) */ static dun_data *dun; -/* - * ??? - */ -static int template_race; @@ -2585,11 +2581,8 @@ static void build_type4(int by0, int bx0) */ -static bool vault_aux_jelly(int r_idx) +static bool vault_aux_jelly(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2603,11 +2596,8 @@ static bool vault_aux_jelly(int r_idx) return true; } -static bool vault_aux_animal(int r_idx) +static bool vault_aux_animal(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2618,11 +2608,8 @@ static bool vault_aux_animal(int r_idx) return true; } -static bool vault_aux_undead(int r_idx) +static bool vault_aux_undead(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2633,11 +2620,8 @@ static bool vault_aux_undead(int r_idx) return true; } -static bool vault_aux_chapel(int r_idx) +static bool vault_aux_chapel(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2651,11 +2635,8 @@ static bool vault_aux_chapel(int r_idx) return true; } -static bool vault_aux_kennel(int r_idx) +static bool vault_aux_kennel(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2663,11 +2644,8 @@ static bool vault_aux_kennel(int r_idx) return ((r_ptr->d_char == 'Z') || (r_ptr->d_char == 'C')); } -static bool vault_aux_treasure(int r_idx) +static bool vault_aux_treasure(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2683,25 +2661,21 @@ static bool vault_aux_treasure(int r_idx) return true; } -static bool vault_aux_clone(int r_idx) +static monster_race const *template_race = nullptr; + +static bool vault_aux_clone(monster_race const *r_ptr) { - return (r_idx == template_race); + return (r_ptr == template_race); } -static bool vault_aux_symbol(int r_idx) +static bool vault_aux_symbol(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - - return ((r_ptr->d_char == (r_info[template_race].d_char)) + return ((r_ptr->d_char == (template_race->d_char)) && !(r_ptr->flags & RF_UNIQUE)); } -static bool vault_aux_orc(int r_idx) +static bool vault_aux_orc(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2712,11 +2686,8 @@ static bool vault_aux_orc(int r_idx) return true; } -static bool vault_aux_troll(int r_idx) +static bool vault_aux_troll(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2727,11 +2698,8 @@ static bool vault_aux_troll(int r_idx) return true; } -static bool vault_aux_giant(int r_idx) +static bool vault_aux_giant(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2742,11 +2710,8 @@ static bool vault_aux_giant(int r_idx) return true; } -static bool vault_aux_demon(int r_idx) +static bool vault_aux_demon(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; @@ -2790,7 +2755,7 @@ static void build_type5(int by0, int bx0) int tmp, i; const char *name; bool_ empty = FALSE; - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); s16b what[64]; /* Try to allocate space for room. If fails, exit */ @@ -2850,14 +2815,14 @@ static void build_type5(int by0, int bx0) { while (1) { - template_race = rand_int(r_info.size()); + template_race = &*uniform_element(r_info); /* Reject uniques */ - if (r_info[template_race].flags & RF_UNIQUE) continue; + if (template_race->flags & RF_UNIQUE) continue; /* Reject OoD monsters in a loose fashion */ - if (((r_info[template_race].level) + randint(5)) > - (dun_level + randint(5))) continue; + if ((template_race->level + randint(5)) > + (dun_level + randint(5))) continue; /* Don't like 'break's like this, but this cannot be made better */ break; @@ -3030,7 +2995,7 @@ static void build_type6(int by0, int bx0) int i, j, y, x, y1, x1, y2, x2, xval, yval; bool_ empty = FALSE; const char *name; - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); /* Try to allocate space for room. If fails, exit */ if (!room_alloc(25, 11, TRUE, by0, bx0, &xval, &yval)) return; @@ -3124,11 +3089,11 @@ static void build_type6(int by0, int bx0) do { - template_race = rand_int(r_info.size() - 1); + template_race = &*uniform_element(r_info); } - while ((r_info[template_race].flags & RF_UNIQUE) - || (((r_info[template_race].level) + randint(5)) > - (dun_level + randint(5)))); + while ((template_race->flags & RF_UNIQUE) + || (((template_race->level) + randint(5)) > + (dun_level + randint(5)))); /* Restrict selection */ get_mon_num_hook = vault_aux_symbol; @@ -3194,11 +3159,7 @@ static void build_type6(int by0, int bx0) } /* Restrict monster selection */ - get_mon_num_hook = [](int r_idx) -> bool { - auto const &r_info = game->edit_data.r_info; - - auto r_ptr = &r_info[r_idx]; - + get_mon_num_hook = [](monster_race const *r_ptr) -> bool { /* Decline unique monsters */ if (r_ptr->flags & RF_UNIQUE) return false; diff --git a/src/monster1.cc b/src/monster1.cc index 4cb19e0b..de731e03 100644 --- a/src/monster1.cc +++ b/src/monster1.cc @@ -1377,12 +1377,8 @@ void display_roff(int r_idx, int ego) } -bool monster_quest(int r_idx) +bool monster_quest(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - - auto r_ptr = &r_info[r_idx]; - /* Random quests are in the dungeon */ if (r_ptr->flags & RF_WILD_ONLY) return false; @@ -1395,85 +1391,54 @@ bool monster_quest(int r_idx) return true; } - -bool monster_dungeon(int r_idx) +bool monster_dungeon(const monster_race *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return !(r_ptr->flags & RF_WILD_ONLY); } -static bool monster_ocean(int r_idx) +static bool monster_ocean(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return bool(r_ptr->flags & RF_WILD_OCEAN); } -static bool monster_shore(int r_idx) +static bool monster_shore(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return bool(r_ptr->flags & RF_WILD_SHORE); } -static bool monster_waste(int r_idx) +static bool monster_waste(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return bool(r_ptr->flags & RF_WILD_WASTE); } -static bool monster_town(int r_idx) +static bool monster_town(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return bool(r_ptr->flags & RF_WILD_TOWN); } -static bool monster_wood(int r_idx) +static bool monster_wood(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return bool(r_ptr->flags & RF_WILD_WOOD); } -static bool monster_volcano(int r_idx) +static bool monster_volcano(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return bool(r_ptr->flags & RF_WILD_VOLCANO); } -static bool monster_mountain(int r_idx) +static bool monster_mountain(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return bool(r_ptr->flags & RF_WILD_MOUNTAIN); } -static bool monster_grass(int r_idx) +static bool monster_grass(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return bool(r_ptr->flags & RF_WILD_GRASS); } -static bool monster_deep_water(int r_idx) +static bool monster_deep_water(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - - if (!monster_dungeon(r_idx)) + if (!monster_dungeon(r_ptr)) { return false; } @@ -1481,12 +1446,9 @@ static bool monster_deep_water(int r_idx) return bool(r_ptr->flags & RF_AQUATIC); } -static bool monster_shallow_water(int r_idx) +static bool monster_shallow_water(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - - if (!monster_dungeon(r_idx)) + if (!monster_dungeon(r_ptr)) { return false; } @@ -1494,12 +1456,9 @@ static bool monster_shallow_water(int r_idx) return !(r_ptr->flags & RF_AURA_FIRE); } -static bool monster_lava(int r_idx) +static bool monster_lava(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - - if (!monster_dungeon(r_idx)) + if (!monster_dungeon(r_ptr)) { return false; } diff --git a/src/monster2.cc b/src/monster2.cc index ab849597..0afea2d4 100644 --- a/src/monster2.cc +++ b/src/monster2.cc @@ -798,12 +798,14 @@ errr get_mon_num_prep() { auto &alloc = game->alloc; + auto const &r_info = game->edit_data.r_info; + /* Scan the allocation table */ for (auto &&entry: alloc.race_table) { /* Accept monsters which pass the restriction, if any */ - if ((!get_mon_num_hook || (*get_mon_num_hook)(entry.index)) && - (!get_mon_num2_hook || (*get_mon_num2_hook)(entry.index))) + if ((!get_mon_num_hook || (*get_mon_num_hook)(&r_info[entry.index])) && + (!get_mon_num2_hook || (*get_mon_num2_hook)(&r_info[entry.index]))) { /* Accept this monster */ entry.prob2 = entry.prob1; @@ -2597,32 +2599,27 @@ static bool_ place_monster_group(int y, int x, int r_idx, bool_ slp, int status) /* * Hack -- help pick an escort type */ -static int place_monster_idx = 0; +static monster_race const *place_monster_ptr = nullptr; /* * Hack -- help pick an escort type */ -static bool place_monster_okay(int r_idx) +static bool place_monster_okay(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - - auto r_ptr = &r_info[place_monster_idx]; - auto z_ptr = &r_info[r_idx]; - /* Hack - Escorts have to have the same dungeon flag */ - if (monster_dungeon(place_monster_idx) != monster_dungeon(r_idx)) return false; + if (monster_dungeon(place_monster_ptr) != monster_dungeon(r_ptr)) return false; /* Require similar "race" */ - if (z_ptr->d_char != r_ptr->d_char) return false; + if (r_ptr->d_char != place_monster_ptr->d_char) return false; /* Skip more advanced monsters */ - if (z_ptr->level > r_ptr->level) return false; + if (r_ptr->level > place_monster_ptr->level) return false; /* Skip unique monsters */ - if (z_ptr->flags & RF_UNIQUE) return false; + if (r_ptr->flags & RF_UNIQUE) return false; /* Paranoia -- Skip identical monsters */ - if (place_monster_idx == r_idx) return false; + if (place_monster_ptr == r_ptr) return false; /* Okay */ return true; @@ -2653,7 +2650,7 @@ bool_ place_monster_aux(int y, int x, int r_idx, bool_ slp, bool_ grp, int statu int i; auto r_ptr = &r_info[r_idx]; - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); /* Place one monster, or fail */ @@ -2678,7 +2675,7 @@ bool_ place_monster_aux(int y, int x, int r_idx, bool_ slp, bool_ grp, int statu old_get_mon_num_hook = get_mon_num_hook; /* Set the escort index */ - place_monster_idx = r_idx; + place_monster_ptr = &r_info[r_idx]; /* Set the escort hook */ get_mon_num_hook = place_monster_okay; @@ -2906,14 +2903,10 @@ static int summon_specific_type = 0; /* * Hack -- help decide if a monster race is "okay" to summon */ -static bool summon_specific_okay(int r_idx) +static bool summon_specific_okay(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - - auto r_ptr = &r_info[r_idx]; - /* Hack - Only summon dungeon monsters */ - if (!monster_dungeon(r_idx)) return false; + if (!monster_dungeon(r_ptr)) return false; /* Hack -- no specific type specified */ if (!summon_specific_type) return true; @@ -3183,7 +3176,7 @@ bool_ summon_specific(int y1, int x1, int lev, int type) { int i, x, y, r_idx; bool_ Group_ok = TRUE; - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); /* Look for a location */ for (i = 0; i < 20; ++i) @@ -3267,7 +3260,7 @@ bool_ summon_specific(int y1, int x1, int lev, int type) bool_ summon_specific_friendly(int y1, int x1, int lev, int type, bool_ Group_ok) { int i, x, y, r_idx; - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); /* Look for a location */ for (i = 0; i < 20; ++i) @@ -3443,13 +3436,10 @@ void monster_swap(int y1, int x1, int y2, int x2) /* * Hack -- help decide if a monster race is "okay" to summon */ -static bool mutate_monster_okay(int r_idx) +static bool mutate_monster_okay(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Hack - Only summon dungeon monsters */ - if (!monster_dungeon(r_idx)) return false; + if (!monster_dungeon(r_ptr)) return false; return ((r_ptr->d_char == summon_kin_type) && !(r_ptr->flags & RF_UNIQUE) && (r_ptr->level >= dun_level)); @@ -3490,7 +3480,7 @@ bool_ multiply_monster(int m_idx, bool_ charm, bool_ clone) /* It can mutate into a nastier monster */ if ((rand_int(100) < 3) && (!clone)) { - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); /* Backup the old hook */ old_get_mon_num_hook = get_mon_num_hook; diff --git a/src/monster2.hpp b/src/monster2.hpp index 3ce3ada7..2108c825 100644 --- a/src/monster2.hpp +++ b/src/monster2.hpp @@ -43,8 +43,8 @@ extern bool_ place_monster_one_no_drop; s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status); s16b player_place(int y, int x); void monster_drop_carried_objects(monster_type *m_ptr); -bool monster_dungeon(int r_idx); -bool monster_quest(int r_idx); +bool monster_dungeon(monster_race const *r_ptr); +bool monster_quest(monster_race const *r_ptr); void set_mon_num_hook(); void set_mon_num2_hook(int y, int x); bool_ monster_can_cross_terrain(byte feat, std::shared_ptr<monster_race> r_ptr); diff --git a/src/q_bounty.cc b/src/q_bounty.cc index 4d3ffefc..fe52fe05 100644 --- a/src/q_bounty.cc +++ b/src/q_bounty.cc @@ -20,11 +20,8 @@ #define bounty_quest_monster (cquest.data[0]) -static bool lua_mon_hook_bounty(int r_idx) +static bool lua_mon_hook_bounty(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - /* Reject uniques */ if (r_ptr->flags & RF_UNIQUE) return false; diff --git a/src/q_poison.cc b/src/q_poison.cc index 7624e897..fec7e54c 100644 --- a/src/q_poison.cc +++ b/src/q_poison.cc @@ -31,23 +31,21 @@ static int wild_locs[4][2] = { 34, 48, }, }; -static bool create_molds_hook(int r_idx) +static bool create_molds_hook(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - if (r_ptr->spells & SF_MULTIPLY) return false; if (r_ptr->d_char == 'm') return true; - else if (r_ptr->d_char == ',') return true; - else if (r_ptr->d_char == 'e') return true; - else return false; + if (r_ptr->d_char == ',') return true; + if (r_ptr->d_char == 'e') return true; + + return false; } static bool quest_poison_gen_hook(void *, void *, void *) { int cy = 1, cx = 1, x, y, tries = 10000, r_idx; - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); if (cquest.status != QUEST_STATUS_TAKEN) { diff --git a/src/variable.cc b/src/variable.cc index dcbffc1c..1490918e 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -483,8 +483,8 @@ char *ANGBAND_DIR_XTRA; /* * Hack -- function hooks to restrict "get_mon_num_prep()" function */ -bool (*get_mon_num_hook)(int r_idx); -bool (*get_mon_num2_hook)(int r_idx); +bool (*get_mon_num_hook)(monster_race const *); +bool (*get_mon_num2_hook)(monster_race const *); /* diff --git a/src/variable.hpp b/src/variable.hpp index 56ef455a..33c0c42c 100644 --- a/src/variable.hpp +++ b/src/variable.hpp @@ -8,6 +8,7 @@ #include "dungeon_flag_set.hpp" #include "effect_type.hpp" #include "fate.hpp" +#include "monster_race_fwd.hpp" #include "monster_type_fwd.hpp" #include "object_type_fwd.hpp" #include "options.hpp" @@ -144,8 +145,8 @@ extern char *ANGBAND_DIR; extern char *ANGBAND_DIR_MODULES; extern char *ANGBAND_DIR_CORE; extern char *ANGBAND_DIR_DNGN; -extern bool (*get_mon_num_hook)(int r_idx); -extern bool (*get_mon_num2_hook)(int r_idx); +extern bool (*get_mon_num_hook)(monster_race const *); +extern bool (*get_mon_num2_hook)(monster_race const *); extern bool_ (*get_obj_num_hook)(int k_idx); extern u16b max_o_idx; extern u16b max_m_idx; diff --git a/src/wild.cc b/src/wild.cc index 56aa6b3b..f7e1c1e8 100644 --- a/src/wild.cc +++ b/src/wild.cc @@ -1004,11 +1004,8 @@ static void town_borders(int qy, int qx) } } -static bool create_townpeople_hook(int r_idx) +static bool create_townpeople_hook(monster_race const *r_ptr) { - auto const &r_info = game->edit_data.r_info; - auto r_ptr = &r_info[r_idx]; - return (r_ptr->d_char == 't'); } @@ -1023,7 +1020,7 @@ static bool create_townpeople_hook(int r_idx) static void town_gen_hack(int qy, int qx) { int y, x, floor; - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); /* Do we use dungeon floor or normal one */ if (magik(TOWN_NORMAL_FLOOR)) floor = FEAT_FLOOR; @@ -1114,7 +1111,7 @@ static void town_gen_hack(int qy, int qx) static void town_gen_circle(int qy, int qx) { int y, x, cy, cx, rad, floor; - bool (*old_get_mon_num_hook)(int r_idx); + bool (*old_get_mon_num_hook)(monster_race const *); /* Do we use dungeon floor or normal one */ if (magik(TOWN_NORMAL_FLOOR)) floor = FEAT_FLOOR; |