OSDN Git Service

Merge pull request #3532 from sikabane-works/release/3.0.0.87-alpha
[hengbandforosx/hengbandosx.git] / src / spell-kind / spells-perception.cpp
1 #include "spell-kind/spells-perception.h"
2 #include "autopick/autopick.h"
3 #include "avatar/avatar.h"
4 #include "core/stuff-handler.h"
5 #include "core/window-redrawer.h"
6 #include "flavor/flavor-describer.h"
7 #include "flavor/object-flavor-types.h"
8 #include "floor/floor-object.h"
9 #include "game-option/auto-destruction-options.h"
10 #include "game-option/play-record-options.h"
11 #include "inventory/inventory-describer.h"
12 #include "inventory/inventory-slot-types.h"
13 #include "inventory/player-inventory.h"
14 #include "io/write-diary.h"
15 #include "object-enchant/special-object-flags.h"
16 #include "object-hook/hook-perception.h"
17 #include "object-hook/hook-weapon.h"
18 #include "object/item-tester-hooker.h"
19 #include "object/item-use-flags.h"
20 #include "object/object-info.h"
21 #include "object/object-mark-types.h"
22 #include "perception/identification.h"
23 #include "perception/object-perception.h"
24 #include "system/item-entity.h"
25 #include "system/player-type-definition.h"
26 #include "system/redrawing-flags-updater.h"
27 #include "util/bit-flags-calculator.h"
28 #include "util/string-processor.h"
29 #include "view/display-messages.h"
30 #include "world/world.h"
31 #include <memory>
32
33 /*!
34  * @brief 全所持アイテム鑑定処理 /
35  * Identify everything being carried.
36  * Done by a potion of "self knowledge".
37  * @param player_ptr プレイヤーへの参照ポインタ
38  */
39 void identify_pack(PlayerType *player_ptr)
40 {
41     for (INVENTORY_IDX i = 0; i < INVEN_TOTAL; i++) {
42         auto *o_ptr = &player_ptr->inventory_list[i];
43         if (!o_ptr->is_valid()) {
44             continue;
45         }
46
47         identify_item(player_ptr, o_ptr);
48         autopick_alter_item(player_ptr, i, false);
49     }
50 }
51
52 /*!
53  * @brief アイテム鑑定処理 /
54  * Identify an object
55  * @param player_ptr プレイヤーへの参照ポインタ
56  * @param o_ptr 鑑定されるアイテムの情報参照ポインタ
57  * @return 実際に鑑定できたらTRUEを返す
58  */
59 bool identify_item(PlayerType *player_ptr, ItemEntity *o_ptr)
60 {
61     const auto known_item_name = describe_flavor(player_ptr, o_ptr, 0);
62     const auto old_known = any_bits(o_ptr->ident, IDENT_KNOWN);
63     if (!o_ptr->is_fully_known()) {
64         if (o_ptr->is_fixed_or_random_artifact() || one_in_(5)) {
65             chg_virtue(player_ptr, Virtue::KNOWLEDGE, 1);
66         }
67     }
68
69     object_aware(player_ptr, o_ptr);
70     object_known(o_ptr);
71     o_ptr->marked.set(OmType::TOUCHED);
72
73     auto &rfu = RedrawingFlagsUpdater::get_instance();
74     static constexpr auto flags_srf = {
75         StatusRecalculatingFlag::BONUS,
76         StatusRecalculatingFlag::COMBINATION,
77         StatusRecalculatingFlag::REORDER,
78     };
79     rfu.set_flags(flags_srf);
80     static constexpr auto flags_swrf = {
81         SubWindowRedrawingFlag::INVENTORY,
82         SubWindowRedrawingFlag::EQUIPMENT,
83         SubWindowRedrawingFlag::PLAYER,
84         SubWindowRedrawingFlag::FLOOR_ITEMS,
85         SubWindowRedrawingFlag::FOUND_ITEMS,
86     };
87     rfu.set_flags(flags_swrf);
88     angband_strcpy(record_o_name, known_item_name, MAX_NLEN);
89     record_turn = w_ptr->game_turn;
90
91     const auto item_name = describe_flavor(player_ptr, o_ptr, OD_NAME_ONLY);
92     if (record_fix_art && !old_known && o_ptr->is_fixed_artifact()) {
93         exe_write_diary(player_ptr, DiaryKind::ART, 0, item_name);
94     }
95
96     if (record_rand_art && !old_known && o_ptr->is_random_artifact()) {
97         exe_write_diary(player_ptr, DiaryKind::ART, 0, item_name);
98     }
99
100     return old_known;
101 }
102
103 /*!
104  * @brief アイテム鑑定のメインルーチン処理 /
105  * Identify an object in the inventory (or on the floor)
106  * @param player_ptr プレイヤーへの参照ポインタ
107  * @param only_equip 装備品のみを対象とするならばTRUEを返す
108  * @return 実際に鑑定を行ったならばTRUEを返す
109  * @details
110  * This routine does *not* automatically combine objects.
111  * Returns TRUE if something was identified, else FALSE.
112  */
113 bool ident_spell(PlayerType *player_ptr, bool only_equip)
114 {
115     std::unique_ptr<ItemTester> item_tester = std::make_unique<FuncItemTester>(only_equip ? object_is_not_identified_weapon_armor : object_is_not_identified);
116
117     concptr q;
118     if (can_get_item(player_ptr, *item_tester)) {
119         q = _("どのアイテムを鑑定しますか? ", "Identify which item? ");
120     } else {
121         if (only_equip) {
122             item_tester = std::make_unique<FuncItemTester>(&ItemEntity::is_weapon_armour_ammo);
123         } else {
124             item_tester = std::make_unique<AllMatchItemTester>();
125         }
126         q = _("すべて鑑定済みです。 ", "All items are identified. ");
127     }
128
129     constexpr auto s = _("鑑定するべきアイテムがない。", "You have nothing to identify.");
130     OBJECT_IDX item;
131     auto o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), *item_tester);
132     if (!o_ptr) {
133         return false;
134     }
135
136     auto old_known = identify_item(player_ptr, o_ptr);
137
138     const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
139     if (item >= INVEN_MAIN_HAND) {
140         msg_format(_("%s^: %s(%c)。", "%s^: %s (%c)."), describe_use(player_ptr, item), item_name.data(), index_to_label(item));
141     } else if (item >= 0) {
142         msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), item_name.data(), index_to_label(item));
143     } else {
144         msg_format(_("床上: %s。", "On the ground: %s."), item_name.data());
145     }
146
147     autopick_alter_item(player_ptr, item, (bool)(destroy_identify && !old_known));
148     return true;
149 }
150
151 /*!
152  * @brief アイテム*鑑定*のメインルーチン処理 /
153  * Identify an object in the inventory (or on the floor)
154  * @param player_ptr プレイヤーへの参照ポインタ
155  * @param only_equip 装備品のみを対象とするならばTRUEを返す
156  * @return 実際に鑑定を行ったならばTRUEを返す
157  * @details
158  * Fully "identify" an object in the inventory -BEN-
159  * This routine returns TRUE if an item was identified.
160  */
161 bool identify_fully(PlayerType *player_ptr, bool only_equip)
162 {
163     std::unique_ptr<ItemTester> item_tester = std::make_unique<FuncItemTester>(only_equip ? object_is_not_fully_identified_weapon_armour : object_is_not_fully_identified);
164
165     concptr q;
166     if (can_get_item(player_ptr, *item_tester)) {
167         q = _("どのアイテムを*鑑定*しますか? ", "*Identify* which item? ");
168     } else {
169         if (only_equip) {
170             item_tester = std::make_unique<FuncItemTester>(&ItemEntity::is_weapon_armour_ammo);
171         } else {
172             item_tester = std::make_unique<AllMatchItemTester>();
173         }
174         q = _("すべて*鑑定*済みです。 ", "All items are *identified*. ");
175     }
176
177     constexpr auto s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*.");
178
179     OBJECT_IDX item;
180     auto o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), *item_tester);
181     if (!o_ptr) {
182         return false;
183     }
184
185     auto old_known = identify_item(player_ptr, o_ptr);
186
187     o_ptr->ident |= (IDENT_FULL_KNOWN);
188
189     window_stuff(player_ptr);
190
191     const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
192     if (item >= INVEN_MAIN_HAND) {
193         msg_format(_("%s^: %s(%c)。", "%s^: %s (%c)."), describe_use(player_ptr, item), item_name.data(), index_to_label(item));
194     } else if (item >= 0) {
195         msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), item_name.data(), index_to_label(item));
196     } else {
197         msg_format(_("床上: %s。", "On the ground: %s."), item_name.data());
198     }
199
200     (void)screen_object(player_ptr, o_ptr, 0L);
201     autopick_alter_item(player_ptr, item, (bool)(destroy_identify && !old_known));
202     return true;
203 }