OSDN Git Service

Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband
[hengband/hengband.git] / src / spell-kind / spells-perception.c
1 #include "spell-kind/spells-perception.h"
2 #include "autopick/autopick.h"
3 #include "core/player-update-types.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-enchant.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 "player-info/avatar.h"
26 #include "system/object-type-definition.h"
27 #include "view/display-messages.h"
28 #include "world/world.h"
29
30 /*!
31  * @brief 全所持アイテム鑑定処理 /
32  * Identify everything being carried.
33  * Done by a potion of "self knowledge".
34  * @param target_ptr プレーヤーへの参照ポインタ
35  * @return なし
36  */
37 void identify_pack(player_type *target_ptr)
38 {
39     for (INVENTORY_IDX i = 0; i < INVEN_TOTAL; i++) {
40         object_type *o_ptr = &target_ptr->inventory_list[i];
41         if (!o_ptr->k_idx)
42             continue;
43
44         identify_item(target_ptr, o_ptr);
45         autopick_alter_item(target_ptr, i, FALSE);
46     }
47 }
48
49 /*!
50  * @brief アイテム鑑定処理 /
51  * Identify an object
52  * @param owner_ptr プレーヤーへの参照ポインタ
53  * @param o_ptr 鑑定されるアイテムの情報参照ポインタ
54  * @return 実際に鑑定できたらTRUEを返す
55  */
56 bool identify_item(player_type *owner_ptr, object_type *o_ptr)
57 {
58     GAME_TEXT o_name[MAX_NLEN];
59     describe_flavor(owner_ptr, o_name, o_ptr, 0);
60
61     bool old_known = FALSE;
62     if (o_ptr->ident & IDENT_KNOWN)
63         old_known = TRUE;
64
65     if (!object_is_fully_known(o_ptr)) {
66         if (object_is_artifact(o_ptr) || one_in_(5))
67             chg_virtue(owner_ptr, V_KNOWLEDGE, 1);
68     }
69
70     object_aware(owner_ptr, o_ptr);
71     object_known(o_ptr);
72     o_ptr->marked |= OM_TOUCHED;
73
74     owner_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
75     owner_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
76
77     strcpy(record_o_name, o_name);
78     record_turn = current_world_ptr->game_turn;
79
80     describe_flavor(owner_ptr, o_name, o_ptr, OD_NAME_ONLY);
81
82     if (record_fix_art && !old_known && object_is_fixed_artifact(o_ptr))
83         exe_write_diary(owner_ptr, DIARY_ART, 0, o_name);
84     if (record_rand_art && !old_known && o_ptr->art_name)
85         exe_write_diary(owner_ptr, DIARY_ART, 0, o_name);
86
87     return old_known;
88 }
89
90 /*!
91  * @brief アイテム鑑定のメインルーチン処理 /
92  * Identify an object in the inventory (or on the floor)
93  * @param caster_ptr プレーヤーへの参照ポインタ
94  * @param only_equip 装備品のみを対象とするならばTRUEを返す
95  * @return 実際に鑑定を行ったならばTRUEを返す
96  * @details
97  * This routine does *not* automatically combine objects.
98  * Returns TRUE if something was identified, else FALSE.
99  */
100 bool ident_spell(player_type *caster_ptr, bool only_equip, tval_type item_tester_tval)
101 {
102     if (only_equip)
103         item_tester_hook = item_tester_hook_identify_weapon_armour;
104     else
105         item_tester_hook = item_tester_hook_identify;
106
107     concptr q;
108     if (can_get_item(caster_ptr, item_tester_tval)) {
109         q = _("どのアイテムを鑑定しますか? ", "Identify which item? ");
110     } else {
111         if (only_equip)
112             item_tester_hook = object_is_weapon_armour_ammo;
113         else
114             item_tester_hook = NULL;
115
116         q = _("すべて鑑定済みです。 ", "All items are identified. ");
117     }
118
119     concptr s = _("鑑定するべきアイテムがない。", "You have nothing to identify.");
120     OBJECT_IDX item;
121     object_type *o_ptr;
122     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
123     if (!o_ptr)
124         return FALSE;
125
126     bool old_known = identify_item(caster_ptr, o_ptr);
127
128     GAME_TEXT o_name[MAX_NLEN];
129     describe_flavor(caster_ptr, o_name, o_ptr, 0);
130     if (item >= INVEN_RARM) {
131         msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(caster_ptr, item), o_name, index_to_label(item));
132     } else if (item >= 0) {
133         msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
134     } else {
135         msg_format(_("床上: %s。", "On the ground: %s."), o_name);
136     }
137
138     autopick_alter_item(caster_ptr, item, (bool)(destroy_identify && !old_known));
139     return TRUE;
140 }
141
142 /*!
143  * @brief アイテム*鑑定*のメインルーチン処理 /
144  * Identify an object in the inventory (or on the floor)
145  * @param caster_ptr プレーヤーへの参照ポインタ
146  * @param only_equip 装備品のみを対象とするならばTRUEを返す
147  * @return 実際に鑑定を行ったならばTRUEを返す
148  * @details
149  * Fully "identify" an object in the inventory -BEN-
150  * This routine returns TRUE if an item was identified.
151  */
152 bool identify_fully(player_type *caster_ptr, bool only_equip, tval_type item_tester_tval)
153 {
154     if (only_equip)
155         item_tester_hook = item_tester_hook_identify_fully_weapon_armour;
156     else
157         item_tester_hook = item_tester_hook_identify_fully;
158
159     concptr q;
160     if (can_get_item(caster_ptr, item_tester_tval)) {
161         q = _("どのアイテムを*鑑定*しますか? ", "*Identify* which item? ");
162     } else {
163         if (only_equip)
164             item_tester_hook = object_is_weapon_armour_ammo;
165         else
166             item_tester_hook = NULL;
167
168         q = _("すべて*鑑定*済みです。 ", "All items are *identified*. ");
169     }
170
171     concptr s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*.");
172
173     OBJECT_IDX item;
174     object_type *o_ptr;
175     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
176     if (!o_ptr)
177         return FALSE;
178
179     bool old_known = identify_item(caster_ptr, o_ptr);
180
181     o_ptr->ident |= (IDENT_FULL_KNOWN);
182     handle_stuff(caster_ptr);
183
184     GAME_TEXT o_name[MAX_NLEN];
185     describe_flavor(caster_ptr, o_name, o_ptr, 0);
186     if (item >= INVEN_RARM) {
187         msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(caster_ptr, item), o_name, index_to_label(item));
188     } else if (item >= 0) {
189         msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
190     } else {
191         msg_format(_("床上: %s。", "On the ground: %s."), o_name);
192     }
193
194     (void)screen_object(caster_ptr, o_ptr, 0L);
195     autopick_alter_item(caster_ptr, item, (bool)(destroy_identify && !old_known));
196     return TRUE;
197 }