OSDN Git Service

[Refactor] #2807 Renamed monster-race-definition.h to monster-race-info.h
[hengbandforosx/hengbandosx.git] / src / autopick / autopick-matcher.cpp
index e8e9751..b1a6eb0 100644 (file)
 #include "autopick/autopick-matcher.h"
 #include "autopick/autopick-flags-table.h"
 #include "autopick/autopick-key-flag-process.h"
+#include "autopick/autopick-util.h"
 #include "inventory/inventory-slot-types.h"
 #include "monster-race/monster-race.h"
 #include "monster-race/race-flags1.h"
 #include "object-enchant/item-feeling.h"
 #include "object-enchant/special-object-flags.h"
 #include "object-hook/hook-armor.h"
-#include "object-hook/hook-bow.h"
-#include "object-hook/hook-checker.h"
-#include "object-hook/hook-enchant.h"
 #include "object-hook/hook-quest.h"
 #include "object-hook/hook-weapon.h"
 #include "object/object-info.h"
-#include "object/object-kind.h"
 #include "object/object-stack.h"
 #include "object/object-value.h"
 #include "perception/object-perception.h"
+#include "player-base/player-class.h"
 #include "player/player-realm.h"
+#include "system/baseitem-info-definition.h"
 #include "system/floor-type-definition.h"
-#include "system/monster-race-definition.h"
+#include "system/item-entity.h"
+#include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
 #include "util/string-processor.h"
 
-/*
- * A function for Auto-picker/destroyer
- * Examine whether the object matches to the entry
+/*!
+ * @brief A function for Auto-picker/destroyer Examine whether the object matches to the entry
  */
-bool is_autopick_match(player_type *player_ptr, object_type *o_ptr, autopick_type *entry, concptr o_name)
+bool is_autopick_match(PlayerType *player_ptr, ItemEntity *o_ptr, autopick_type *entry, concptr o_name)
 {
-    concptr ptr = entry->name;
-    if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
-        return FALSE;
+    concptr ptr = entry->name.data();
+    if (IS_FLG(FLG_UNAWARE) && o_ptr->is_aware()) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_UNIDENTIFIED) && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
-        return FALSE;
+    if (IS_FLG(FLG_UNIDENTIFIED) && (o_ptr->is_known() || (o_ptr->ident & IDENT_SENSE))) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
-        return FALSE;
+    if (IS_FLG(FLG_IDENTIFIED) && !o_ptr->is_known()) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_STAR_IDENTIFIED) && (!object_is_known(o_ptr) || !object_is_fully_known(o_ptr)))
-        return FALSE;
+    if (IS_FLG(FLG_STAR_IDENTIFIED) && (!o_ptr->is_known() || !o_ptr->is_fully_known())) {
+        return false;
+    }
 
     if (IS_FLG(FLG_BOOSTED)) {
-        object_kind *k_ptr = &k_info[o_ptr->k_idx];
-        if (!object_is_melee_weapon(o_ptr))
-            return FALSE;
+        auto *k_ptr = &baseitems_info[o_ptr->k_idx];
+        if (!o_ptr->is_melee_weapon()) {
+            return false;
+        }
 
-        if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
-            return FALSE;
+        if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds)) {
+            return false;
+        }
 
-        if (!object_is_known(o_ptr) && object_is_quest_target(player_ptr->current_floor_ptr->inside_quest, o_ptr)) {
-            return FALSE;
+        if (!o_ptr->is_known() && object_is_quest_target(player_ptr->current_floor_ptr->quest_number, o_ptr)) {
+            return false;
         }
     }
 
     if (IS_FLG(FLG_MORE_DICE)) {
-        if (o_ptr->dd * o_ptr->ds < entry->dice)
-            return FALSE;
+        if (o_ptr->dd * o_ptr->ds < entry->dice) {
+            return false;
+        }
     }
 
     if (IS_FLG(FLG_MORE_BONUS)) {
-        if (!object_is_known(o_ptr))
-            return FALSE;
+        if (!o_ptr->is_known()) {
+            return false;
+        }
 
         if (o_ptr->pval) {
-            if (o_ptr->pval < entry->bonus)
-                return FALSE;
+            if (o_ptr->pval < entry->bonus) {
+                return false;
+            }
         } else {
-            if (o_ptr->to_h < entry->bonus && o_ptr->to_d < entry->bonus && o_ptr->to_a < entry->bonus && o_ptr->pval < entry->bonus)
-                return FALSE;
+            if (o_ptr->to_h < entry->bonus && o_ptr->to_d < entry->bonus && o_ptr->to_a < entry->bonus && o_ptr->pval < entry->bonus) {
+                return false;
+            }
         }
     }
 
-    if (IS_FLG(FLG_WORTHLESS) && object_value(player_ptr, o_ptr) > 0)
-        return FALSE;
+    if (IS_FLG(FLG_WORTHLESS) && (o_ptr->get_price() > 0)) {
+        return false;
+    }
 
     if (IS_FLG(FLG_ARTIFACT)) {
-        if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
-            return FALSE;
+        if (!o_ptr->is_known() || !o_ptr->is_artifact()) {
+            return false;
+        }
     }
 
     if (IS_FLG(FLG_EGO)) {
-        if (!object_is_ego(o_ptr))
-            return FALSE;
-        if (!object_is_known(o_ptr) && !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
-            return FALSE;
+        if (!o_ptr->is_ego()) {
+            return false;
+        }
+        if (!o_ptr->is_known() && !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT)) {
+            return false;
+        }
     }
 
     if (IS_FLG(FLG_GOOD)) {
-        if (!object_is_equipment(o_ptr))
-            return FALSE;
-        if (object_is_known(o_ptr)) {
-            if (!object_is_nameless(player_ptr, o_ptr))
-                return FALSE;
-
-            if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
-                return FALSE;
+        if (!o_ptr->is_equipment()) {
+            return false;
+        }
+        if (o_ptr->is_known()) {
+            if (!o_ptr->is_nameless()) {
+                return false;
+            }
+
+            if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0) {
+                return false;
+            }
         } else if (o_ptr->ident & IDENT_SENSE) {
             switch (o_ptr->feeling) {
             case FEEL_GOOD:
                 break;
 
             default:
-                return FALSE;
+                return false;
             }
         } else {
-            return FALSE;
+            return false;
         }
     }
 
     if (IS_FLG(FLG_NAMELESS)) {
-        if (!object_is_equipment(o_ptr))
-            return FALSE;
-        if (object_is_known(o_ptr)) {
-            if (!object_is_nameless(player_ptr, o_ptr))
-                return FALSE;
+        if (!o_ptr->is_equipment()) {
+            return false;
+        }
+        if (o_ptr->is_known()) {
+            if (!o_ptr->is_nameless()) {
+                return false;
+            }
         } else if (o_ptr->ident & IDENT_SENSE) {
             switch (o_ptr->feeling) {
             case FEEL_AVERAGE:
@@ -132,160 +150,198 @@ bool is_autopick_match(player_type *player_ptr, object_type *o_ptr, autopick_typ
                 break;
 
             default:
-                return FALSE;
+                return false;
             }
         } else {
-            return FALSE;
+            return false;
         }
     }
 
     if (IS_FLG(FLG_AVERAGE)) {
-        if (!object_is_equipment(o_ptr))
-            return FALSE;
-        if (object_is_known(o_ptr)) {
-            if (!object_is_nameless(player_ptr, o_ptr))
-                return FALSE;
+        if (!o_ptr->is_equipment()) {
+            return false;
+        }
+        if (o_ptr->is_known()) {
+            if (!o_ptr->is_nameless()) {
+                return false;
+            }
 
-            if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
-                return FALSE;
+            if (o_ptr->is_cursed() || o_ptr->is_broken()) {
+                return false;
+            }
 
-            if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
-                return FALSE;
+            if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0) {
+                return false;
+            }
         } else if (o_ptr->ident & IDENT_SENSE) {
             switch (o_ptr->feeling) {
             case FEEL_AVERAGE:
                 break;
 
             default:
-                return FALSE;
+                return false;
             }
         } else {
-            return FALSE;
+            return false;
         }
     }
 
-    if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
-        return FALSE;
+    if (IS_FLG(FLG_RARE) && !o_ptr->is_rare()) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
-        return FALSE;
+    if (IS_FLG(FLG_COMMON) && o_ptr->is_rare()) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_WANTED) && !object_is_bounty(player_ptr, o_ptr))
-        return FALSE;
+    if (IS_FLG(FLG_WANTED) && !object_is_bounty(player_ptr, o_ptr)) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_UNIQUE) && ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) || !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
-        return FALSE;
+    const auto r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
+    if (IS_FLG(FLG_UNIQUE) && ((o_ptr->tval != ItemKindType::CORPSE && o_ptr->tval != ItemKindType::STATUE) || monraces_info[r_idx].kind_flags.has_not(MonsterKindType::UNIQUE))) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_HUMAN) && (o_ptr->tval != TV_CORPSE || !angband_strchr("pht", r_info[o_ptr->pval].d_char)))
-        return FALSE;
+    if (IS_FLG(FLG_HUMAN) && (o_ptr->tval != ItemKindType::CORPSE || !angband_strchr("pht", monraces_info[r_idx].d_char))) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_UNREADABLE) && (o_ptr->tval < TV_LIFE_BOOK || check_book_realm(player_ptr, o_ptr->tval, o_ptr->sval)))
-        return FALSE;
+    if (IS_FLG(FLG_UNREADABLE) && (o_ptr->tval < ItemKindType::LIFE_BOOK || check_book_realm(player_ptr, o_ptr->tval, o_ptr->sval))) {
+        return false;
+    }
 
-    bool realm_except_class = player_ptr->pclass == CLASS_SORCERER || player_ptr->pclass == CLASS_RED_MAGE;
+    PlayerClass pc(player_ptr);
+    auto realm_except_class = pc.equals(PlayerClassType::SORCERER) || pc.equals(PlayerClassType::RED_MAGE);
 
-    if (IS_FLG(FLG_REALM1) && (get_realm1_book(player_ptr) != o_ptr->tval || realm_except_class))
-        return FALSE;
+    if (IS_FLG(FLG_REALM1) && ((get_realm1_book(player_ptr) != o_ptr->tval) || realm_except_class)) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_REALM2) && (get_realm2_book(player_ptr) != o_ptr->tval || realm_except_class))
-        return FALSE;
+    if (IS_FLG(FLG_REALM2) && ((get_realm2_book(player_ptr) != o_ptr->tval) || realm_except_class)) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_FIRST) && (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
-        return FALSE;
+    if (IS_FLG(FLG_FIRST) && ((o_ptr->tval < ItemKindType::LIFE_BOOK) || (o_ptr->sval) != 0)) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_SECOND) && (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
-        return FALSE;
+    if (IS_FLG(FLG_SECOND) && ((o_ptr->tval < ItemKindType::LIFE_BOOK) || (o_ptr->sval) != 1)) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_THIRD) && (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
-        return FALSE;
+    if (IS_FLG(FLG_THIRD) && ((o_ptr->tval < ItemKindType::LIFE_BOOK) || (o_ptr->sval) != 2)) {
+        return false;
+    }
 
-    if (IS_FLG(FLG_FOURTH) && (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
-        return FALSE;
+    if (IS_FLG(FLG_FOURTH) && ((o_ptr->tval < ItemKindType::LIFE_BOOK) || (o_ptr->sval) != 3)) {
+        return false;
+    }
 
     if (IS_FLG(FLG_WEAPONS)) {
-        if (!object_is_weapon(player_ptr, o_ptr))
-            return FALSE;
+        if (!o_ptr->is_weapon()) {
+            return false;
+        }
     } else if (IS_FLG(FLG_FAVORITE_WEAPONS)) {
-        if (!object_is_favorite(player_ptr, o_ptr))
-            return FALSE;
+        if (!object_is_favorite(player_ptr, o_ptr)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_ARMORS)) {
-        if (!object_is_armour(player_ptr, o_ptr))
-            return FALSE;
+        if (!o_ptr->is_armour()) {
+            return false;
+        }
     } else if (IS_FLG(FLG_MISSILES)) {
-        if (!object_is_ammo(o_ptr))
-            return FALSE;
+        if (!o_ptr->is_ammo()) {
+            return false;
+        }
     } else if (IS_FLG(FLG_DEVICES)) {
         switch (o_ptr->tval) {
-        case TV_SCROLL:
-        case TV_STAFF:
-        case TV_WAND:
-        case TV_ROD:
+        case ItemKindType::SCROLL:
+        case ItemKindType::STAFF:
+        case ItemKindType::WAND:
+        case ItemKindType::ROD:
             break;
         default:
-            return FALSE;
+            return false;
         }
     } else if (IS_FLG(FLG_LIGHTS)) {
-        if (!(o_ptr->tval == TV_LITE))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::LITE)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_JUNKS)) {
         switch (o_ptr->tval) {
-        case TV_SKELETON:
-        case TV_BOTTLE:
-        case TV_JUNK:
-        case TV_STATUE:
+        case ItemKindType::SKELETON:
+        case ItemKindType::BOTTLE:
+        case ItemKindType::JUNK:
+        case ItemKindType::STATUE:
             break;
         default:
-            return FALSE;
+            return false;
         }
     } else if (IS_FLG(FLG_CORPSES)) {
-        if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
-            return FALSE;
+        if (o_ptr->tval != ItemKindType::CORPSE && o_ptr->tval != ItemKindType::SKELETON) {
+            return false;
+        }
     } else if (IS_FLG(FLG_SPELLBOOKS)) {
-        if (!(o_ptr->tval >= TV_LIFE_BOOK))
-            return FALSE;
+        if (!(o_ptr->tval >= ItemKindType::LIFE_BOOK)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_HAFTED)) {
-        if (!(o_ptr->tval == TV_HAFTED))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::HAFTED)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_SHIELDS)) {
-        if (!(o_ptr->tval == TV_SHIELD))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::SHIELD)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_BOWS)) {
-        if (!(o_ptr->tval == TV_BOW))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::BOW)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_RINGS)) {
-        if (!(o_ptr->tval == TV_RING))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::RING)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_AMULETS)) {
-        if (!(o_ptr->tval == TV_AMULET))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::AMULET)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_SUITS)) {
-        if (!(o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR || o_ptr->tval == TV_SOFT_ARMOR))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::DRAG_ARMOR || o_ptr->tval == ItemKindType::HARD_ARMOR || o_ptr->tval == ItemKindType::SOFT_ARMOR)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_CLOAKS)) {
-        if (!(o_ptr->tval == TV_CLOAK))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::CLOAK)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_HELMS)) {
-        if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::CROWN || o_ptr->tval == ItemKindType::HELM)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_GLOVES)) {
-        if (!(o_ptr->tval == TV_GLOVES))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::GLOVES)) {
+            return false;
+        }
     } else if (IS_FLG(FLG_BOOTS)) {
-        if (!(o_ptr->tval == TV_BOOTS))
-            return FALSE;
+        if (!(o_ptr->tval == ItemKindType::BOOTS)) {
+            return false;
+        }
     }
 
     if (*ptr == '^') {
         ptr++;
-        if (strncmp(o_name, ptr, strlen(ptr)))
-            return FALSE;
+        if (strncmp(o_name, ptr, strlen(ptr))) {
+            return false;
+        }
     } else {
-        if (!angband_strstr(o_name, ptr))
-            return FALSE;
+        if (!angband_strstr(o_name, ptr)) {
+            return false;
+        }
     }
 
-    if (!IS_FLG(FLG_COLLECTING))
-        return TRUE;
+    if (!IS_FLG(FLG_COLLECTING)) {
+        return true;
+    }
 
     for (int j = 0; j < INVEN_PACK; j++) {
         /*
@@ -293,9 +349,10 @@ bool is_autopick_match(player_type *player_ptr, object_type *o_ptr, autopick_typ
          * into an inventory slot.
          * But an item can not be absorbed into itself!
          */
-        if ((&player_ptr->inventory_list[j] != o_ptr) && object_similar(&player_ptr->inventory_list[j], o_ptr))
-            return TRUE;
+        if ((&player_ptr->inventory_list[j] != o_ptr) && object_similar(&player_ptr->inventory_list[j], o_ptr)) {
+            return true;
+        }
     }
 
-    return FALSE;
+    return false;
 }