OSDN Git Service

Merge pull request #2469 from habu1010/feature/fix-refill-by-oil-flask
[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/player-update-types.h"
5 #include "core/stuff-handler.h"
6 #include "core/window-redrawer.h"
7 #include "flavor/flavor-describer.h"
8 #include "flavor/object-flavor-types.h"
9 #include "floor/floor-object.h"
10 #include "game-option/auto-destruction-options.h"
11 #include "game-option/play-record-options.h"
12 #include "inventory/inventory-describer.h"
13 #include "inventory/inventory-slot-types.h"
14 #include "inventory/player-inventory.h"
15 #include "io/write-diary.h"
16 #include "object-enchant/special-object-flags.h"
17 #include "object-hook/hook-perception.h"
18 #include "object-hook/hook-weapon.h"
19 #include "object/item-tester-hooker.h"
20 #include "object/item-use-flags.h"
21 #include "object/object-info.h"
22 #include "object/object-mark-types.h"
23 #include "perception/identification.h"
24 #include "perception/object-perception.h"
25 #include "system/object-type-definition.h"
26 #include "system/player-type-definition.h"
27 #include "util/bit-flags-calculator.h"
28 #include "view/display-messages.h"
29 #include "world/world.h"
30
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->k_idx) {
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, ObjectType *o_ptr)
60 {
61     GAME_TEXT o_name[MAX_NLEN];
62     describe_flavor(player_ptr, o_name, o_ptr, 0);
63
64     bool old_known = false;
65     if (any_bits(o_ptr->ident, IDENT_KNOWN)) {
66         old_known = true;
67     }
68
69     if (!o_ptr->is_fully_known()) {
70         if (o_ptr->is_artifact() || one_in_(5)) {
71             chg_virtue(player_ptr, V_KNOWLEDGE, 1);
72         }
73     }
74
75     object_aware(player_ptr, o_ptr);
76     object_known(o_ptr);
77     set_bits(o_ptr->marked, OM_TOUCHED);
78
79     set_bits(player_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
80     set_bits(player_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
81
82     strcpy(record_o_name, o_name);
83     record_turn = w_ptr->game_turn;
84
85     describe_flavor(player_ptr, o_name, o_ptr, OD_NAME_ONLY);
86
87     if (record_fix_art && !old_known && o_ptr->is_fixed_artifact()) {
88         exe_write_diary(player_ptr, DIARY_ART, 0, o_name);
89     }
90     if (record_rand_art && !old_known && o_ptr->art_name) {
91         exe_write_diary(player_ptr, DIARY_ART, 0, o_name);
92     }
93
94     return old_known;
95 }
96
97 /*!
98  * @brief アイテム鑑定のメインルーチン処理 /
99  * Identify an object in the inventory (or on the floor)
100  * @param player_ptr プレイヤーへの参照ポインタ
101  * @param only_equip 装備品のみを対象とするならばTRUEを返す
102  * @return 実際に鑑定を行ったならばTRUEを返す
103  * @details
104  * This routine does *not* automatically combine objects.
105  * Returns TRUE if something was identified, else FALSE.
106  */
107 bool ident_spell(PlayerType *player_ptr, bool only_equip)
108 {
109     std::unique_ptr<ItemTester> item_tester = std::make_unique<FuncItemTester>(only_equip ? object_is_not_identified_weapon_armor : object_is_not_identified);
110
111     concptr q;
112     if (can_get_item(player_ptr, *item_tester)) {
113         q = _("どのアイテムを鑑定しますか? ", "Identify which item? ");
114     } else {
115         if (only_equip) {
116             item_tester = std::make_unique<FuncItemTester>(&ObjectType::is_weapon_armour_ammo);
117         } else {
118             item_tester = std::make_unique<AllMatchItemTester>();
119         }
120         q = _("すべて鑑定済みです。 ", "All items are identified. ");
121     }
122
123     concptr s = _("鑑定するべきアイテムがない。", "You have nothing to identify.");
124     OBJECT_IDX item;
125     ObjectType *o_ptr;
126     o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), *item_tester);
127     if (!o_ptr) {
128         return false;
129     }
130
131     bool old_known = identify_item(player_ptr, o_ptr);
132
133     GAME_TEXT o_name[MAX_NLEN];
134     describe_flavor(player_ptr, o_name, o_ptr, 0);
135     if (item >= INVEN_MAIN_HAND) {
136         msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(player_ptr, item), o_name, index_to_label(item));
137     } else if (item >= 0) {
138         msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
139     } else {
140         msg_format(_("床上: %s。", "On the ground: %s."), o_name);
141     }
142
143     autopick_alter_item(player_ptr, item, (bool)(destroy_identify && !old_known));
144     return true;
145 }
146
147 /*!
148  * @brief アイテム*鑑定*のメインルーチン処理 /
149  * Identify an object in the inventory (or on the floor)
150  * @param player_ptr プレイヤーへの参照ポインタ
151  * @param only_equip 装備品のみを対象とするならばTRUEを返す
152  * @return 実際に鑑定を行ったならばTRUEを返す
153  * @details
154  * Fully "identify" an object in the inventory -BEN-
155  * This routine returns TRUE if an item was identified.
156  */
157 bool identify_fully(PlayerType *player_ptr, bool only_equip)
158 {
159     std::unique_ptr<ItemTester> item_tester = std::make_unique<FuncItemTester>(only_equip ? object_is_not_fully_identified_weapon_armour : object_is_not_fully_identified);
160
161     concptr q;
162     if (can_get_item(player_ptr, *item_tester)) {
163         q = _("どのアイテムを*鑑定*しますか? ", "*Identify* which item? ");
164     } else {
165         if (only_equip) {
166             item_tester = std::make_unique<FuncItemTester>(&ObjectType::is_weapon_armour_ammo);
167         } else {
168             item_tester = std::make_unique<AllMatchItemTester>();
169         }
170         q = _("すべて*鑑定*済みです。 ", "All items are *identified*. ");
171     }
172
173     concptr s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*.");
174
175     OBJECT_IDX item;
176     ObjectType *o_ptr;
177     o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), *item_tester);
178     if (!o_ptr) {
179         return false;
180     }
181
182     bool old_known = identify_item(player_ptr, o_ptr);
183
184     o_ptr->ident |= (IDENT_FULL_KNOWN);
185
186     /* Refrect item informaiton onto subwindows without updating inventory */
187     player_ptr->update &= ~(PU_COMBINE | PU_REORDER);
188     handle_stuff(player_ptr);
189     player_ptr->update |= (PU_COMBINE | PU_REORDER);
190
191     GAME_TEXT o_name[MAX_NLEN];
192     describe_flavor(player_ptr, o_name, o_ptr, 0);
193     if (item >= INVEN_MAIN_HAND) {
194         msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(player_ptr, item), o_name, index_to_label(item));
195     } else if (item >= 0) {
196         msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
197     } else {
198         msg_format(_("床上: %s。", "On the ground: %s."), o_name);
199     }
200
201     (void)screen_object(player_ptr, o_ptr, 0L);
202     autopick_alter_item(player_ptr, item, (bool)(destroy_identify && !old_known));
203     return true;
204 }