diff options
author | Bardur Arantsson <bardur@scientician.net> | 2019-02-15 19:20:25 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2019-02-15 19:20:25 +0100 |
commit | 993edef8ee17aafc5162cc8cbfd319b113585105 (patch) | |
tree | 545112d64dd3263213f9ec9b3ff3e28a2caef29a /src | |
parent | 40b1ff474224dce87eaace57d5d551c98856ad7d (diff) |
Replace uses of bool_ for get_obj_num_hook()
We refactor the function to just take a direct pointer instead of
indirecting via the k_idx -- it's simpler and less code.
Diffstat (limited to 'src')
-rw-r--r-- | src/generate.cc | 4 | ||||
-rw-r--r-- | src/monster2.cc | 13 | ||||
-rw-r--r-- | src/object2.cc | 112 | ||||
-rw-r--r-- | src/object2.hpp | 5 | ||||
-rw-r--r-- | src/store.cc | 36 | ||||
-rw-r--r-- | src/variable.cc | 2 | ||||
-rw-r--r-- | src/variable.hpp | 3 | ||||
-rw-r--r-- | src/xtra1.cc | 2 |
8 files changed, 90 insertions, 87 deletions
diff --git a/src/generate.cc b/src/generate.cc index c76d0d60..ffb764fd 100644 --- a/src/generate.cc +++ b/src/generate.cc @@ -7634,7 +7634,7 @@ static bool cave_gen() s16b k_idx; /* Apply restriction */ - get_obj_num_hook = kind_is_artifactable; + get_object_hook = kind_is_artifactable; /* Object level a la find object fates */ obj_lev = max_dlv[dungeon_type] + randint(10); @@ -7646,7 +7646,7 @@ static bool cave_gen() k_idx = get_obj_num(obj_lev); /* Reset restriction */ - get_obj_num_hook = kind_is_legal; + get_object_hook = kind_is_legal; /* Invalidate the allocation table */ alloc.kind_table_valid = false; diff --git a/src/monster2.cc b/src/monster2.cc index 1c5872f0..fd64ec44 100644 --- a/src/monster2.cc +++ b/src/monster2.cc @@ -1949,18 +1949,16 @@ static int possible_randart[] = }; -static bool kind_is_randart(int k_idx) +static bool kind_is_randart(object_kind const *k_ptr) { - auto const &k_info = game->edit_data.k_info; - - if (!kind_is_legal(k_idx)) + if (!kind_is_legal(k_ptr)) { return false; } for (int max = 0; possible_randart[max] != -1; max++) { - if (k_info.at(k_idx)->tval == possible_randart[max]) + if (k_ptr->tval == possible_randart[max]) { return true; } @@ -1995,6 +1993,7 @@ static s16b hack_m_idx_ii = 0; s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status) { auto &r_info = game->edit_data.r_info; + auto &k_info = game->edit_data.k_info; auto &alloc = game->alloc; auto const &dungeon_flags = game->dungeon_flags; @@ -2305,7 +2304,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status) init_match_theme(obj_theme::no_theme()); /* Apply restriction */ - get_obj_num_hook = kind_is_legal; + get_object_hook = kind_is_legal; /* Rebuild allocation table */ get_obj_num_prep(); @@ -2317,7 +2316,7 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status) i = get_obj_num(dun_level); if (!i) continue; - if (!kind_is_randart(i)) continue; + if (!kind_is_randart(k_info.at(i).get())) continue; break; } diff --git a/src/object2.cc b/src/object2.cc index 6ad818ca..a037af5a 100644 --- a/src/object2.cc +++ b/src/object2.cc @@ -524,12 +524,13 @@ s16b o_pop() errr get_obj_num_prep() { auto &alloc = game->alloc; + auto const &k_info = game->edit_data.k_info; /* Scan the allocation table */ for (auto &&entry: alloc.kind_table) { /* Accept objects which pass the restriction, if any */ - if (!get_obj_num_hook || (*get_obj_num_hook)(entry.index)) + if (!get_object_hook || (*get_object_hook)(k_info.at(entry.index).get())) { /* Accept this object */ entry.prob2 = entry.prob1; @@ -4125,7 +4126,7 @@ bool init_match_theme(obj_theme const &theme) /* * Maga-Hack -- match certain types of object only. */ -static bool kind_is_theme(obj_theme const *theme, std::shared_ptr<object_kind const> k_ptr) +static bool kind_is_theme(obj_theme const *theme, object_kind const *k_ptr) { assert(theme != nullptr); @@ -4139,7 +4140,7 @@ static bool kind_is_theme(obj_theme const *theme, std::shared_ptr<object_kind co */ if (theme->treasure + theme->combat + theme->magic + theme->tools == 0) { - return TRUE; + return true; } @@ -4295,7 +4296,10 @@ static bool kind_is_theme(obj_theme const *theme, std::shared_ptr<object_kind co } /* Roll to see if it can be made */ - if (rand_int(100) < prob) return (TRUE); + if (rand_int(100) < prob) + { + return true; + } /* Not a match */ return (FALSE); @@ -4304,15 +4308,11 @@ static bool kind_is_theme(obj_theme const *theme, std::shared_ptr<object_kind co /* * Determine if an object must not be generated. */ -bool_ kind_is_legal(int k_idx) +bool kind_is_legal(object_kind const *k_ptr) { - auto const &k_info = game->edit_data.k_info; - - auto k_ptr = k_info.at(k_idx); - if (!kind_is_theme(match_theme, k_ptr)) { - return FALSE; + return false; } if (k_ptr->flags & TR_SPECIAL_GENE) @@ -4323,41 +4323,40 @@ bool_ kind_is_legal(int k_idx) /* No 2 times the same normal artifact */ if ((k_ptr->flags & TR_NORM_ART) && (k_ptr->artifact)) { - return FALSE; + return false; } if (k_ptr->tval == TV_CORPSE) { - if (k_ptr->sval != SV_CORPSE_SKULL && k_ptr->sval != SV_CORPSE_SKELETON && - k_ptr->sval != SV_CORPSE_HEAD && k_ptr->sval != SV_CORPSE_CORPSE) - { - return TRUE; - } - else - { - return FALSE; - } + return (k_ptr->sval != SV_CORPSE_SKULL && k_ptr->sval != SV_CORPSE_SKELETON && + k_ptr->sval != SV_CORPSE_HEAD && k_ptr->sval != SV_CORPSE_CORPSE); } - if (k_ptr->tval == TV_HYPNOS) return FALSE; + if (k_ptr->tval == TV_HYPNOS) + { + return false; + } /* Used only for the Nazgul rings */ - if ((k_ptr->tval == TV_RING) && (k_ptr->sval == SV_RING_SPECIAL)) return FALSE; + if ((k_ptr->tval == TV_RING) && (k_ptr->sval == SV_RING_SPECIAL)) + { + return false; + } /* Assume legal */ - return TRUE; + return true; } /* * Hack -- determine if a template is "good" */ -static bool_ kind_is_good(int k_idx) +static bool kind_is_good(object_kind const *k_ptr) { - auto const &k_info = game->edit_data.k_info; - auto const &k_ptr = k_info.at(k_idx); - - if (!kind_is_legal(k_idx)) return FALSE; + if (!kind_is_legal(k_ptr)) + { + return false; + } /* Analyze the item type */ switch (k_ptr->tval) @@ -4373,8 +4372,7 @@ static bool_ kind_is_good(int k_idx) case TV_HELM: case TV_CROWN: { - if (k_ptr->to_a < 0) return (FALSE); - return (TRUE); + return k_ptr->to_a >= 0; } /* Weapons -- Good unless damaged */ @@ -4387,74 +4385,68 @@ static bool_ kind_is_good(int k_idx) case TV_MSTAFF: case TV_BOOMERANG: { - if (k_ptr->to_h < 0) return (FALSE); - if (k_ptr->to_d < 0) return (FALSE); - return (TRUE); + if (k_ptr->to_h < 0) return false; + if (k_ptr->to_d < 0) return false; + return true; } /* Ammo -- Arrows/Bolts are good */ case TV_BOLT: case TV_ARROW: { - return (TRUE); + return true; } /* Rods - Silver and better are good */ case TV_ROD_MAIN: { - if (k_ptr->sval >= SV_ROD_SILVER) return (TRUE); - return FALSE; + return (k_ptr->sval >= SV_ROD_SILVER); } /* Expensive rod tips are good */ case TV_ROD: { - if (k_ptr->cost >= 4500) return TRUE; - return FALSE; + return (k_ptr->cost >= 4500); } /* The Tomes are good */ case TV_BOOK: { - if (k_ptr->sval <= SV_BOOK_MAX_GOOD) return (TRUE); - return FALSE; + return (k_ptr->sval <= SV_BOOK_MAX_GOOD); } /* Rings -- Rings of Speed are good */ case TV_RING: { - if (k_ptr->sval == SV_RING_SPEED) return (TRUE); - return (FALSE); + return (k_ptr->sval == SV_RING_SPEED); } /* Amulets -- Some are good */ case TV_AMULET: { - if (k_ptr->sval == SV_AMULET_THE_MAGI) return (TRUE); - if (k_ptr->sval == SV_AMULET_DEVOTION) return (TRUE); - if (k_ptr->sval == SV_AMULET_WEAPONMASTERY) return (TRUE); - if (k_ptr->sval == SV_AMULET_TRICKERY) return (TRUE); - if (k_ptr->sval == SV_AMULET_RESISTANCE) return (TRUE); - if (k_ptr->sval == SV_AMULET_REFLECTION) return (TRUE); - if (k_ptr->sval == SV_AMULET_TELEPATHY) return (TRUE); - return (FALSE); + if (k_ptr->sval == SV_AMULET_THE_MAGI) return true; + if (k_ptr->sval == SV_AMULET_DEVOTION) return true; + if (k_ptr->sval == SV_AMULET_WEAPONMASTERY) return true; + if (k_ptr->sval == SV_AMULET_TRICKERY) return true; + if (k_ptr->sval == SV_AMULET_RESISTANCE) return true; + if (k_ptr->sval == SV_AMULET_REFLECTION) return true; + if (k_ptr->sval == SV_AMULET_TELEPATHY) return true; + return false; } } /* Assume not good */ - return (FALSE); + return false; } /* * Determine if template is suitable for building a randart -- dsb */ -bool_ kind_is_artifactable(int k_idx) +bool kind_is_artifactable(object_kind const *k_ptr) { auto const &ra_info = game->edit_data.ra_info; - auto const &k_info = game->edit_data.k_info; - auto k_ptr = k_info.at(k_idx); - if (kind_is_good(k_idx)) + if (kind_is_good(k_ptr)) { // Consider the item artifactable if there is at least one // randart power which could be added to the item. @@ -4465,13 +4457,13 @@ bool_ kind_is_artifactable(int k_idx) if (filter.tval != k_ptr->tval) continue; if (filter.min_sval > k_ptr->sval) continue; if (filter.max_sval < k_ptr->sval) continue; - return TRUE; + return true; } } } /* No match. Too bad. */ - return FALSE; + return false; } @@ -4516,7 +4508,7 @@ bool_ make_object(object_type *j_ptr, bool_ good, bool_ great, obj_theme const & if (good) { /* Activate restriction */ - get_obj_num_hook = kind_is_good; + get_object_hook = kind_is_good; /* Prepare allocation table */ get_obj_num_prep(); @@ -4526,7 +4518,7 @@ bool_ make_object(object_type *j_ptr, bool_ good, bool_ great, obj_theme const & else if (!alloc.kind_table_valid) { /* Activate normal restriction */ - get_obj_num_hook = kind_is_legal; + get_object_hook = kind_is_legal; /* Prepare allocation table */ get_obj_num_prep(); @@ -4542,7 +4534,7 @@ bool_ make_object(object_type *j_ptr, bool_ good, bool_ great, obj_theme const & if (good) { /* Restore normal restriction */ - get_obj_num_hook = kind_is_legal; + get_object_hook = kind_is_legal; /* Prepare allocation table */ get_obj_num_prep(); diff --git a/src/object2.hpp b/src/object2.hpp index cdcace01..692a1d66 100644 --- a/src/object2.hpp +++ b/src/object2.hpp @@ -2,6 +2,7 @@ #include "ego_flag_set.hpp" #include "h-basic.hpp" +#include "object_kind_fwd.hpp" #include "object_type_fwd.hpp" #include "obj_theme_fwd.hpp" @@ -16,8 +17,8 @@ object_type *get_object(int item); s32b calc_total_weight(); void add_random_ego_flag(object_type *o_ptr, ego_flag_set const &fego, bool_ *limit_blows); bool init_match_theme(obj_theme const &theme); -bool_ kind_is_artifactable(int k_idx); -bool_ kind_is_legal(int k_idx); +bool kind_is_artifactable(object_kind const *); +bool kind_is_legal(object_kind const *); void inven_item_charges(int item); void inven_item_describe(int item); void inven_item_increase(int item, int num); diff --git a/src/store.cc b/src/store.cc index 6269fb1a..59bac276 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1153,24 +1153,34 @@ static int store_tval = 0, store_level = 0; /* * Hack -- determine if a template is "good" */ -static bool_ kind_is_storeok(int k_idx) +static bool kind_is_storeok(object_kind const *k_ptr) { - auto const &k_info = game->edit_data.k_info; - - auto k_ptr = k_info.at(k_idx); - if (k_ptr->flags & TR_NORM_ART) - return ( FALSE ); + { + return false; + } if (k_ptr->flags & TR_INSTA_ART) - return ( FALSE ); + { + return false; + } - if (!kind_is_legal(k_idx)) return FALSE; + if (!kind_is_legal(k_ptr)) + { + return false; + } - if (k_ptr->tval != store_tval) return (FALSE); - if (k_ptr->level < (store_level / 2)) return (FALSE); + if (k_ptr->tval != store_tval) + { + return false; + } - return (TRUE); + if (k_ptr->level < (store_level / 2)) + { + return false; + } + + return true; } namespace { // anonymous @@ -1214,7 +1224,7 @@ public: init_match_theme(obj_theme::no_theme()); /* Activate restriction */ - get_obj_num_hook = kind_is_storeok; + get_object_hook = kind_is_storeok; store_tval = f.tval; /* Do we forbid too shallow items ? */ @@ -1318,7 +1328,7 @@ static void store_create() * Even in Black Markets, illegal objects can be * problematic -- Oxymoron? */ - get_obj_num_hook = kind_is_legal; + get_object_hook = kind_is_legal; /* Rebuild the allocation table */ get_obj_num_prep(); diff --git a/src/variable.cc b/src/variable.cc index 7ecde0d3..c93725d6 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -464,7 +464,7 @@ bool (*get_monster_aux_hook)(monster_race const *); /* * Hack -- function hook to restrict "get_obj_num_prep()" function */ -bool_ (*get_obj_num_hook)(int k_idx); +bool (*get_object_hook)(object_kind const *k_ptr) = nullptr; /* * Devices diff --git a/src/variable.hpp b/src/variable.hpp index 386ef99e..57fc1e8e 100644 --- a/src/variable.hpp +++ b/src/variable.hpp @@ -11,6 +11,7 @@ #include "monster_race_fwd.hpp" #include "monster_type_fwd.hpp" #include "object_type_fwd.hpp" +#include "object_kind_fwd.hpp" #include "options.hpp" #include "player_class_fwd.hpp" #include "player_defs.hpp" @@ -146,7 +147,7 @@ extern char *ANGBAND_DIR; extern char *ANGBAND_DIR_MODULES; extern bool (*get_monster_hook)(monster_race const *); extern bool (*get_monster_aux_hook)(monster_race const *); -extern bool_ (*get_obj_num_hook)(int k_idx); +extern bool (*get_object_hook)(object_kind const *k_ptr); extern u16b max_o_idx; extern u16b max_m_idx; extern int init_flags; diff --git a/src/xtra1.cc b/src/xtra1.cc index 3e139ba1..a13361a7 100644 --- a/src/xtra1.cc +++ b/src/xtra1.cc @@ -4348,7 +4348,7 @@ void gain_fate(byte fate) init_match_theme(theme); /* Apply restriction */ - get_obj_num_hook = kind_is_legal; + get_object_hook = kind_is_legal; /* Rebuild allocation table */ get_obj_num_prep(); |