OSDN Git Service

[Refactor] object_is_armor() を object_type のメンバ関数化
authorHabu <habu1010+github@gmail.com>
Thu, 2 Sep 2021 14:16:39 +0000 (23:16 +0900)
committerHabu <habu1010+github@gmail.com>
Thu, 2 Sep 2021 14:40:09 +0000 (23:40 +0900)
18 files changed:
src/artifact/random-art-generator.cpp
src/artifact/random-art-misc.cpp
src/autopick/autopick-matcher.cpp
src/cmd-building/cmd-building.cpp
src/cmd-item/cmd-smith.cpp
src/combat/aura-counterattack.cpp
src/monster-attack/monster-attack-player.cpp
src/object-enchant/object-curse.cpp
src/object-hook/hook-armor.cpp
src/object-hook/hook-armor.h
src/object-hook/hook-weapon.cpp
src/player/player-damage.cpp
src/player/player-status.cpp
src/realm/realm-hex.cpp
src/spell-realm/spells-nature.cpp
src/spell/spells-object.cpp
src/system/object-type-definition.cpp
src/system/object-type-definition.h

index e1f2608..c44ca94 100644 (file)
@@ -255,7 +255,7 @@ static void strengthen_pval(object_type *o_ptr)
  */
 static void invest_positive_modified_value(object_type *o_ptr)
 {
-    if (object_is_armour(o_ptr)) {
+    if (o_ptr->is_armour()) {
         o_ptr->to_a += randint1(o_ptr->to_a > 19 ? 1 : 20 - o_ptr->to_a);
         return;
     }
@@ -276,7 +276,7 @@ static void invest_positive_modified_value(object_type *o_ptr)
  */
 static void invest_negative_modified_value(object_type *o_ptr)
 {
-    if (!object_is_armour(o_ptr))
+    if (!o_ptr->is_armour())
         return;
 
     while ((o_ptr->to_d + o_ptr->to_h) > 20) {
@@ -353,7 +353,7 @@ static int decide_random_art_power_level(object_type *o_ptr, const bool a_cursed
 static void name_unnatural_random_artifact(player_type *player_ptr, object_type *o_ptr, const bool a_scroll, const int power_level, GAME_TEXT *new_name)
 {
     if (!a_scroll) {
-        get_random_name(o_ptr, new_name, object_is_armour(o_ptr), power_level);
+        get_random_name(o_ptr, new_name, o_ptr->is_armour(), power_level);
         return;
     }
 
@@ -426,7 +426,7 @@ bool become_random_artifact(player_type *player_ptr, object_type *o_ptr, bool a_
     if (a_cursed)
         curse_artifact(player_ptr, o_ptr);
 
-    if (!a_cursed && one_in_(object_is_armour(o_ptr) ? ACTIVATION_CHANCE * 2 : ACTIVATION_CHANCE)) {
+    if (!a_cursed && one_in_(o_ptr->is_armour() ? ACTIVATION_CHANCE * 2 : ACTIVATION_CHANCE)) {
         o_ptr->xtra2 = 0;
         give_activation_power(o_ptr);
     }
index b57bf51..d367ca5 100644 (file)
@@ -328,7 +328,7 @@ void random_misc(player_type *player_ptr, object_type *o_ptr)
     case 24:
     case 25:
     case 26:
-        if (object_is_armour(o_ptr))
+        if (o_ptr->is_armour())
             random_misc(player_ptr, o_ptr);
         else
             o_ptr->to_a = 4 + randint1(11);
index d646fa2..c7ec83b 100644 (file)
@@ -210,7 +210,7 @@ bool is_autopick_match(player_type *player_ptr, object_type *o_ptr, autopick_typ
         if (!object_is_favorite(player_ptr, o_ptr))
             return false;
     } else if (IS_FLG(FLG_ARMORS)) {
-        if (!object_is_armour(o_ptr))
+        if (!o_ptr->is_armour())
             return false;
     } else if (IS_FLG(FLG_MISSILES)) {
         if (!object_is_ammo(o_ptr))
index 47dd990..ba828d6 100644 (file)
@@ -62,6 +62,7 @@
 #include "system/building-type-definition.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
+#include "system/object-type-definition.h"
 #include "system/player-type-definition.h"
 #include "term/screen-processor.h"
 #include "util/bit-flags-calculator.h"
@@ -169,7 +170,7 @@ static void bldg_process_command(player_type *player_ptr, building_type *bldg, i
         enchant_item(player_ptr, bcost, 1, 1, 0, FuncItemTester(object_allow_enchant_melee_weapon));
         break;
     case BACT_ENCHANT_ARMOR:
-        enchant_item(player_ptr, bcost, 0, 0, 1, FuncItemTester(object_is_armour));
+        enchant_item(player_ptr, bcost, 0, 0, 1, FuncItemTester(&object_type::is_armour));
         break;
     case BACT_RECHARGE:
         building_recharge(player_ptr);
index 85310ad..da3d5b1 100644 (file)
@@ -799,7 +799,7 @@ static void add_essence(player_type *creature_ptr, int32_t mode)
         else if (es_ptr->add == ESSENCE_ATTACK)
             return std::make_unique<FuncItemTester>(object_allow_enchant_weapon);
         else if (es_ptr->add == ESSENCE_AC)
-            return std::make_unique<FuncItemTester>(object_is_armour);
+            return std::make_unique<FuncItemTester>(&object_type::is_armour);
         else
             return std::make_unique<FuncItemTester>(object_is_weapon_armour_ammo);
     };
index a06629b..fb3f094 100644 (file)
@@ -215,7 +215,7 @@ static void aura_shadow_by_monster_attack(player_type *target_ptr, monap_type *m
     /* Some cursed armours gives an extra effect */
     for (int j = 0; j < 4; j++) {
         o_armed_ptr = &target_ptr->inventory_list[typ[j][0]];
-        if ((o_armed_ptr->k_idx) && object_is_cursed(o_armed_ptr) && object_is_armour(o_armed_ptr))
+        if ((o_armed_ptr->k_idx) && object_is_cursed(o_armed_ptr) && o_armed_ptr->is_armour())
             project(target_ptr, 0, 0, monap_ptr->m_ptr->fy, monap_ptr->m_ptr->fx, (target_ptr->lev * 2), typ[j][1], flg);
     }
 }
index de7ab02..91b0c50 100644 (file)
@@ -279,7 +279,9 @@ static void describe_attack_evasion(player_type *target_ptr, monap_type *monap_p
 
 static void gain_armor_exp(player_type *target_ptr, monap_type *monap_ptr)
 {
-    if (!object_is_armour(&target_ptr->inventory_list[INVEN_MAIN_HAND]) && !object_is_armour(&target_ptr->inventory_list[INVEN_SUB_HAND]))
+    const auto o_ptr_mh = &target_ptr->inventory_list[INVEN_MAIN_HAND];
+    const auto o_ptr_sh = &target_ptr->inventory_list[INVEN_SUB_HAND];
+    if (!o_ptr_mh->is_armour() && !o_ptr_sh->is_armour())
         return;
 
     int cur = target_ptr->skill_exp[SKILL_SHIELD];
index 022edc8..f7109f1 100644 (file)
@@ -47,7 +47,7 @@ TRC get_curse(int power, object_type *o_ptr)
 
         if (new_curse == TRC::LOW_MELEE && !object_is_weapon(o_ptr))
             continue;
-        if (new_curse == TRC::LOW_AC && !object_is_armour(o_ptr))
+        if (new_curse == TRC::LOW_AC && !o_ptr->is_armour())
             continue;
         break;
     }
index 8b671b8..462d285 100644 (file)
@@ -24,16 +24,3 @@ bool item_tester_hook_wear(player_type *player_ptr, const object_type *o_ptr)
 
     return false;
 }
-
-/*!
- * @brief オブジェクトが防具として装備できるかどうかを返す / Check if an object is armour
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return 矢弾として使えるならばTRUEを返す
- */
-bool object_is_armour(const object_type *o_ptr)
-{
-    if (TV_ARMOR_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_ARMOR_END)
-        return true;
-
-    return false;
-}
index b7accb1..4079fe3 100644 (file)
@@ -3,4 +3,3 @@
 typedef struct object_type object_type;
 typedef struct player_type player_type;
 bool item_tester_hook_wear(player_type *player_ptr, const object_type *o_ptr);
-bool object_is_armour(const object_type *o_ptr);
index 9092be5..5a9550e 100644 (file)
@@ -174,7 +174,7 @@ bool object_is_weapon_ammo(const object_type *o_ptr)
  */
 bool object_is_weapon_armour_ammo(const object_type *o_ptr)
 {
-    if (object_is_weapon_ammo(o_ptr) || object_is_armour(o_ptr))
+    if (object_is_weapon_ammo(o_ptr) || o_ptr->is_armour())
         return true;
 
     return false;
index 476af27..641879d 100644 (file)
@@ -105,7 +105,7 @@ static bool acid_minus_ac(player_type *creature_ptr)
         break;
     }
 
-    if ((o_ptr == NULL) || (o_ptr->k_idx == 0) || !object_is_armour(o_ptr))
+    if ((o_ptr == NULL) || (o_ptr->k_idx == 0) || !o_ptr->is_armour())
         return false;
 
     GAME_TEXT o_name[MAX_NLEN];
index 669bc99..58fa393 100644 (file)
@@ -1608,7 +1608,9 @@ static ARMOUR_CLASS calc_base_ac(player_type *creature_ptr)
         ac += o_ptr->ac;
     }
 
-    if (object_is_armour(&creature_ptr->inventory_list[INVEN_MAIN_HAND]) || object_is_armour(&creature_ptr->inventory_list[INVEN_SUB_HAND])) {
+    const auto o_ptr_mh = &creature_ptr->inventory_list[INVEN_MAIN_HAND];
+    const auto o_ptr_sh = &creature_ptr->inventory_list[INVEN_SUB_HAND];
+    if (o_ptr_mh->is_armour() || o_ptr_sh->is_armour()) {
         ac += creature_ptr->skill_exp[SKILL_SHIELD] * (1 + creature_ptr->lev / 22) / 2000;
     }
 
@@ -1727,7 +1729,7 @@ static ARMOUR_CLASS calc_to_ac(player_type *creature_ptr, bool is_real_value)
             object_type *o_ptr = &creature_ptr->inventory_list[i];
             if (!o_ptr->k_idx)
                 continue;
-            if (!object_is_armour(o_ptr))
+            if (!o_ptr->is_armour())
                 continue;
             if (!object_is_cursed(o_ptr))
                 continue;
index 1f0e775..385684c 100644 (file)
@@ -506,7 +506,7 @@ concptr do_hex_spell(player_type *caster_ptr, SPELL_IDX spell, spell_type mode)
             q = _("どれを呪いますか?", "Which piece of armour do you curse?");
             s = _("防具を装備していない。", "You're not wearing any armor.");
 
-            o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP), FuncItemTester(object_is_armour));
+            o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP), FuncItemTester(&object_type::is_armour));
             if (!o_ptr)
                 return "";
 
index 10eb314..3ffed59 100644 (file)
@@ -23,7 +23,7 @@ bool rustproof(player_type *caster_ptr)
     concptr q = _("どの防具に錆止めをしますか?", "Rustproof which piece of armour? ");
     concptr s = _("錆止めできるものがありません。", "You have nothing to rustproof.");
     OBJECT_IDX item;
-    object_type *o_ptr = choose_object(caster_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT, FuncItemTester(object_is_armour));
+    object_type *o_ptr = choose_object(caster_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT, FuncItemTester(&object_type::is_armour));
     if (o_ptr == NULL)
         return false;
 
index a9723db..b05b8a0 100644 (file)
@@ -553,7 +553,7 @@ bool enchant_spell(player_type *caster_ptr, HIT_PROB num_hit, HIT_POINT num_dam,
 
     /* Enchant armor if requested */
     if (num_ac)
-        item_tester = FuncItemTester(object_is_armour);
+        item_tester = FuncItemTester(&object_type::is_armour);
 
     concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
     concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
index 6b232b2..9ef2fa6 100644 (file)
@@ -83,3 +83,12 @@ bool object_type::is_lance() const
     is_lance &= (this->sval == SV_LANCE) || (this->sval == SV_HEAVY_LANCE);
     return is_lance;
 }
+
+/*!
+ * @brief オブジェクトが防具として装備できるかどうかを返す / Check if an object is armour
+ * @return 防具として装備できるならばtrueを返す
+ */
+bool object_type::is_armour() const
+{
+    return (TV_ARMOR_BEGIN <= this->tval) && (this->tval <= TV_ARMOR_END);
+}
index efd1a2b..b4c4dd6 100644 (file)
@@ -58,4 +58,5 @@ typedef struct object_type {
     void copy_from(object_type *j_ptr);
     void prep(KIND_OBJECT_IDX ko_idx);
     bool is_lance() const;
+    bool is_armour() const;
 } object_type;