OSDN Git Service

[Refactor] #3677 object_known() をItemEntity のオブジェクトメソッドに繰り込んだ
[hengbandforosx/hengbandosx.git] / src / object / item-tester-hooker.cpp
1 /*!
2  * @brief オブジェクトに関する汎用判定処理
3  * @date 2018/09/24
4  * @author deskull
5  */
6
7 #include "object/item-tester-hooker.h"
8 #include "system/item-entity.h"
9 #include "system/player-type-definition.h"
10 #include "target/target-describer.h"
11
12 /**
13  * @brief Construct a new Tval Item Tester:: Tval Item Tester object
14  *
15  * @param tval テストOKとなるtvalを指定する
16  */
17 TvalItemTester::TvalItemTester(ItemKindType tval)
18     : tval(tval)
19 {
20 }
21
22 /**
23  * @brief Construct a new Func Item Tester:: Func Item Tester object
24  *
25  * @param test_func そのオブジェクトが条件に合うならtrueを返すメンバ関数を指定する
26  */
27 FuncItemTester::FuncItemTester(TestMemberFunctionPtr test_func)
28     : test_func([f = test_func](PlayerType *, const ItemEntity *o_ptr) { return (o_ptr->*f)(); })
29 {
30 }
31
32 /**
33  * @brief Construct a new Func Item Tester:: Func Item Tester object
34  *
35  * @param test_func 引数に ItemEntity へのポインタを取り、そのオブジェクトが条件に合うならtrueを返す関数を指定する
36  */
37 FuncItemTester::FuncItemTester(std::function<bool(const ItemEntity *)> test_func)
38     : test_func([f = std::move(test_func)](PlayerType *, const ItemEntity *o_ptr) { return f(o_ptr); })
39 {
40 }
41
42 /*!
43  * @brief Construct a new Func Item Tester:: Func Item Tester object
44  *
45  * @param test_func 引数に PlayerType へのポインタと ItemEntity へのポインタを取り、そのオブジェクトが条件に合うならtrueを返す関数を指定する
46  * @param player_ptr test_func の PlayerType へのポインタの引数に対して渡すポインタを指定する
47  */
48 FuncItemTester::FuncItemTester(std::function<bool(PlayerType *, const ItemEntity *)> test_func, PlayerType *player_ptr)
49     : test_func(std::move(test_func))
50     , player_ptr(player_ptr)
51 {
52 }
53
54 /*!
55  * @brief Construct a new Func Item Tester:: Func Item Tester object
56  *
57  * @param test_func 引数に PlayerType へのポインタと ItemEntity へのポインタと StoreSaleType を取り、そのオブジェクトが条件に合うならtrueを返す関数を指定する
58  * @param player_ptr test_func の PlayerType へのポインタの引数に対して渡すポインタを指定する
59  */
60 FuncItemTester::FuncItemTester(std::function<bool(PlayerType *, const ItemEntity *, StoreSaleType)> test_func, PlayerType *player_ptr, StoreSaleType store_num)
61     : test_func([test_func = std::move(test_func), store_num](PlayerType *player_ptr, const ItemEntity *o_ptr) { return test_func(player_ptr, o_ptr, store_num); })
62     , player_ptr(player_ptr)
63 {
64 }
65
66 /*!
67  * @brief アイテムが条件を満たしているか調べる
68  * Check an item against the item tester info
69  * @param o_ptr 判定を行いたいオブジェクト構造体参照ポインタ
70  * @return アイテムが条件を満たしているならtrueを返す
71  * @details 最初にbi_idが無効でないか等の共通の判定を行った後に子クラスで実装される okay_impl 関数の結果を返す
72  */
73 bool ItemTester::okay(const ItemEntity *o_ptr) const
74 {
75     if (!o_ptr->is_valid()) {
76         return false;
77     }
78
79     if (o_ptr->bi_key.tval() == ItemKindType::GOLD) {
80         if (!show_gold_on_floor) {
81             return false;
82         }
83     }
84
85     return this->okay_impl(o_ptr);
86 }
87
88 bool TvalItemTester::okay_impl(const ItemEntity *o_ptr) const
89 {
90     return this->tval == o_ptr->bi_key.tval();
91 }
92
93 bool FuncItemTester::okay_impl(const ItemEntity *o_ptr) const
94 {
95     return this->test_func(this->player_ptr, o_ptr);
96 }