OSDN Git Service

[Refactor] #37353 'kubi'/'shoukinkubi'を'bounty'に変更 / Changed 'kubi' and 'shoukinkubi...
[hengband/hengband.git] / src / object-hook.c
index b0ba633..4d8c5e9 100644 (file)
@@ -5,9 +5,13 @@
 #include "object-hook.h"
 #include "monster.h"
 #include "artifact.h"
+#include "player-class.h"
 #include "player-skill.h"
+#include "player-race.h"
 #include "quest.h"
 #include "world.h"
+#include "objectkind.h"
+#include "view-mainwindow.h"
 
 /*!
 * @brief 対象のアイテムが矢やクロスボウの矢の材料になるかを返す。/
@@ -120,7 +124,7 @@ bool item_tester_hook_eatable(object_type *o_ptr)
        if (o_ptr->tval == TV_FOOD) return TRUE;
 
 #if 0
-       if (prace_is_(RACE_SKELETON))
+       if (PRACE_IS_(p_ptr, RACE_SKELETON))
        {
                if (o_ptr->tval == TV_SKELETON ||
                        (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
@@ -129,15 +133,15 @@ bool item_tester_hook_eatable(object_type *o_ptr)
        else
 #endif
 
-       if (prace_is_(RACE_SKELETON) ||
-               prace_is_(RACE_GOLEM) ||
-               prace_is_(RACE_ZOMBIE) ||
-               prace_is_(RACE_SPECTRE))
+       if (PRACE_IS_(p_ptr, RACE_SKELETON) ||
+               PRACE_IS_(p_ptr, RACE_GOLEM) ||
+               PRACE_IS_(p_ptr, RACE_ZOMBIE) ||
+               PRACE_IS_(p_ptr, RACE_SPECTRE))
        {
                if (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND)
                        return TRUE;
        }
-       else if (prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON))
+       else if (PRACE_IS_(p_ptr, RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON))
        {
                if (o_ptr->tval == TV_CORPSE &&
                        o_ptr->sval == SV_CORPSE &&
@@ -193,7 +197,7 @@ bool item_tester_hook_wear(object_type *o_ptr)
                if (p_ptr->psex == SEX_MALE) return FALSE;
 
        /* Check for a usable slot */
-       if (wield_slot(o_ptr) >= INVEN_RARM) return (TRUE);
+       if (wield_slot(p_ptr, o_ptr) >= INVEN_RARM) return (TRUE);
 
        return (FALSE);
 }
@@ -237,7 +241,7 @@ bool item_tester_hook_use(object_type *o_ptr)
                /* HACK - only items from the equipment can be activated */
                for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
                {
-                       if (&inventory[i] == o_ptr)
+                       if (&p_ptr->inventory_list[i] == o_ptr)
                        {
                                object_flags(o_ptr, flgs);
 
@@ -262,7 +266,7 @@ bool item_tester_hook_quaff(object_type *o_ptr)
 {
        if (o_ptr->tval == TV_POTION) return TRUE;
 
-       if (prace_is_(RACE_ANDROID))
+       if (PRACE_IS_(p_ptr, RACE_ANDROID))
        {
                if (o_ptr->tval == TV_FLASK && o_ptr->sval == SV_FLASK_OIL)
                        return TRUE;
@@ -520,7 +524,7 @@ bool object_is_potion(object_type *o_ptr)
  * @param o_ptr 対象のオブジェクト構造体ポインタ
  * @return オブジェクトが報酬対象になるならTRUEを返す
  */
-bool object_is_shoukinkubi(object_type *o_ptr)
+bool object_is_bounty(object_type *o_ptr)
 {
        int i;
 
@@ -537,9 +541,9 @@ bool object_is_shoukinkubi(object_type *o_ptr)
        if (o_ptr->pval == MON_TSUCHINOKO) return TRUE;
 
        /* Unique monster */
-       for (i = 0; i < MAX_KUBI; i++)
+       for (i = 0; i < MAX_BOUNTY; i++)
                if (o_ptr->pval == current_world_ptr->bounty_r_idx[i]) break;
-       if (i < MAX_KUBI) return TRUE;
+       if (i < MAX_BOUNTY) return TRUE;
 
        /* Not wanted */
        return FALSE;
@@ -945,9 +949,9 @@ bool can_player_destroy_object(object_type *o_ptr)
  */
 bool object_is_quest_target(object_type *o_ptr)
 {
-       if (p_ptr->inside_quest)
+       if (p_ptr->current_floor_ptr->inside_quest)
        {
-               ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
+               ARTIFACT_IDX a_idx = quest[p_ptr->current_floor_ptr->inside_quest].k_idx;
                if (a_idx)
                {
                        artifact_type *a_ptr = &a_info[a_idx];
@@ -963,4 +967,57 @@ bool object_is_quest_target(object_type *o_ptr)
        return FALSE;
 }
 
+/*
+ * Here is a "hook" used during calls to "get_item()" and
+ * "show_inven()" and "show_equip()", and the choice window routines.
+ */
+bool(*item_tester_hook)(object_type*);
+
+/*
+ * Here is a "pseudo-hook" used during calls to "get_item()" and
+ * "show_inven()" and "show_equip()", and the choice window routines.
+ */
+OBJECT_TYPE_VALUE item_tester_tval;
+
+/*!
+ * @brief アイテムがitem_tester_hookグローバル関数ポインタの条件を満たしているかを返す汎用関数
+ * Check an item against the item tester info
+ * @param o_ptr 判定を行いたいオブジェクト構造体参照ポインタ
+ * @return item_tester_hookの参照先、その他いくつかの例外に応じてTRUE/FALSEを返す。
+ */
+bool item_tester_okay(object_type *o_ptr, OBJECT_TYPE_VALUE tval)
+{
+       /* Hack -- allow listing empty slots */
+       // if (item_tester_full) return (TRUE); // TODO:DELETE
+
+       /* Require an item */
+       if (!o_ptr->k_idx) return (FALSE);
+
+       /* Hack -- ignore "gold" */
+       if (o_ptr->tval == TV_GOLD)
+       {
+               /* See xtra2.c */
+               extern bool show_gold_on_floor;
 
+               if (!show_gold_on_floor) return (FALSE);
+       }
+
+       /* Check the tval */
+       if (tval)
+       {
+               /* Is it a spellbook? If so, we need a hack -- TY */
+               if ((tval <= TV_DEATH_BOOK) && (tval >= TV_LIFE_BOOK))
+                       return check_book_realm(o_ptr->tval, o_ptr->sval);
+               else
+                       if (tval != o_ptr->tval) return (FALSE);
+       }
+
+       /* Check the hook */
+       if (item_tester_hook)
+       {
+               if (!(*item_tester_hook)(o_ptr)) return (FALSE);
+       }
+
+       /* Assume okay */
+       return (TRUE);
+}