OSDN Git Service

[Refactor] #963 Separated take_turn() and free_turn() from player-status.cpp/h to...
[hengbandforosx/hengbandosx.git] / src / cmd-item / cmd-item.cpp
1 /*!
2  *  @brief プレイヤーのアイテムに関するコマンドの実装1 / Inventory and equipment commands
3  *  @date 2014/01/02
4  *  @author
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6  *
7  * This software may be copied and distributed for educational, research,
8  * and not for profit purposes provided that this copyright and statement
9  * are included in all such copies.  Other copyrights may also apply.
10  */
11
12 #include "cmd-item/cmd-item.h"
13 #include "action/action-limited.h"
14 #include "action/activation-execution.h"
15 #include "action/weapon-shield.h"
16 #include "cmd-action/cmd-open-close.h"
17 #include "cmd-action/cmd-pet.h"
18 #include "cmd-item/cmd-eat.h"
19 #include "cmd-item/cmd-quaff.h"
20 #include "cmd-item/cmd-read.h"
21 #include "cmd-item/cmd-usestaff.h"
22 #include "cmd-item/cmd-zaprod.h"
23 #include "cmd-item/cmd-zapwand.h"
24 #include "combat/shoot.h"
25 #include "core/asking-player.h"
26 #include "core/player-redraw-types.h"
27 #include "core/player-update-types.h"
28 #include "core/window-redrawer.h"
29 #include "flavor/flavor-describer.h"
30 #include "flavor/object-flavor-types.h"
31 #include "floor/floor-object.h"
32 #include "game-option/input-options.h"
33 #include "inventory/inventory-object.h"
34 #include "inventory/inventory-slot-types.h"
35 #include "io/input-key-acceptor.h"
36 #include "io/input-key-requester.h"
37 #include "mind/snipe-types.h"
38 #include "object-activation/activation-switcher.h"
39 #include "object-hook/hook-checker.h"
40 #include "object-hook/hook-magic.h"
41 #include "object-use/quaff-execution.h"
42 #include "object-use/read-execution.h"
43 #include "object/item-tester-hooker.h"
44 #include "object/item-use-flags.h"
45 #include "perception/identification.h"
46 #include "perception/object-perception.h"
47 #include "player-info/self-info.h"
48 #include "player-status/player-energy.h"
49 #include "player/attack-defense-types.h"
50 #include "player/player-class.h"
51 #include "player/player-personality-types.h"
52 #include "player/player-race-types.h"
53 #include "player/player-status.h"
54 #include "player/special-defense-types.h"
55 #include "racial/racial-android.h"
56 #include "realm/realm-hex-numbers.h"
57 #include "realm/realm-types.h"
58 #include "status/action-setter.h"
59 #include "system/object-type-definition.h"
60 #include "system/player-type-definition.h"
61 #include "term/screen-processor.h"
62 #include "util/bit-flags-calculator.h"
63 #include "util/int-char-converter.h"
64 #include "util/quarks.h"
65 #include "view/display-inventory.h"
66 #include "view/display-messages.h"
67
68 /*!
69  * @brief 持ち物一覧を表示するコマンドのメインルーチン / Display inventory_list
70  * @return なし
71  */
72 void do_cmd_inven(player_type *creature_ptr)
73 {
74     char out_val[160];
75     command_wrk = FALSE;
76     if (easy_floor)
77         command_wrk = USE_INVEN;
78
79     screen_save();
80     (void)show_inventory(creature_ptr, 0, USE_FULL, TV_NONE);
81     WEIGHT weight = calc_inventory_weight(creature_ptr);
82     WEIGHT weight_lim = calc_weight_limit(creature_ptr);
83 #ifdef JP
84     sprintf(out_val, "持ち物: 合計 %3d.%1d kg (限界の%ld%%) コマンド: ", (int)lbtokg1(weight), (int)lbtokg2(weight),
85 #else
86     sprintf(out_val, "Inventory: carrying %d.%d pounds (%ld%% of capacity). Command: ", (int)(weight / 10),
87         (int)(weight % 10),
88 #endif
89         (long int)(weight * 100) / weight_lim);
90
91     prt(out_val, 0, 0);
92     command_new = inkey();
93     screen_load();
94     if (command_new != ESCAPE) {
95         command_see = TRUE;
96         return;
97     }
98
99     TERM_LEN wid, hgt;
100     term_get_size(&wid, &hgt);
101     command_new = 0;
102     command_gap = wid - 30;
103 }
104
105 /*!
106  * @brief アイテムを落とすコマンドのメインルーチン / Drop an item
107  * @return なし
108  */
109 void do_cmd_drop(player_type *creature_ptr)
110 {
111     OBJECT_IDX item;
112     int amt = 1;
113     object_type *o_ptr;
114     if (creature_ptr->special_defense & KATA_MUSOU)
115         set_action(creature_ptr, ACTION_NONE);
116
117     concptr q = _("どのアイテムを落としますか? ", "Drop which item? ");
118     concptr s = _("落とせるアイテムを持っていない。", "You have nothing to drop.");
119     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | IGNORE_BOTHHAND_SLOT), TV_NONE);
120     if (!o_ptr)
121         return;
122
123     if ((item >= INVEN_MAIN_HAND) && object_is_cursed(o_ptr)) {
124         msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
125         return;
126     }
127
128     if (o_ptr->number > 1) {
129         amt = get_quantity(NULL, o_ptr->number);
130         if (amt <= 0)
131             return;
132     }
133
134     take_turn(creature_ptr, 50);
135     drop_from_inventory(creature_ptr, item, amt);
136     if (item >= INVEN_MAIN_HAND) {
137         verify_equip_slot(creature_ptr, item);
138         calc_android_exp(creature_ptr);
139     }
140
141     creature_ptr->redraw |= (PR_EQUIPPY);
142 }
143
144 /*!
145  * @brief アイテムを調査するコマンドのメインルーチン / Observe an item which has been *identify*-ed
146  * @return なし
147  */
148 void do_cmd_observe(player_type *creature_ptr)
149 {
150     OBJECT_IDX item;
151     object_type *o_ptr;
152     GAME_TEXT o_name[MAX_NLEN];
153     concptr q = _("どのアイテムを調べますか? ", "Examine which item? ");
154     concptr s = _("調べられるアイテムがない。", "You have nothing to examine.");
155     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), TV_NONE);
156     if (!o_ptr)
157         return;
158
159     if (!object_is_fully_known(o_ptr)) {
160         msg_print(_("このアイテムについて特に知っていることはない。", "You have no special knowledge about that item."));
161         return;
162     }
163
164     describe_flavor(creature_ptr, o_name, o_ptr, 0);
165     msg_format(_("%sを調べている...", "Examining %s..."), o_name);
166     if (!screen_object(creature_ptr, o_ptr, SCROBJ_FORCE_DETAIL))
167         msg_print(_("特に変わったところはないようだ。", "You see nothing special."));
168 }
169
170 /*!
171  * @brief アイテムの銘を消すコマンドのメインルーチン
172  * Remove the inscription from an object XXX Mention item (when done)?
173  * @return なし
174  */
175 void do_cmd_uninscribe(player_type *creature_ptr)
176 {
177     OBJECT_IDX item;
178     object_type *o_ptr;
179     concptr q = _("どのアイテムの銘を消しますか? ", "Un-inscribe which item? ");
180     concptr s = _("銘を消せるアイテムがない。", "You have nothing to un-inscribe.");
181     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), TV_NONE);
182     if (!o_ptr)
183         return;
184
185     if (!o_ptr->inscription) {
186         msg_print(_("このアイテムには消すべき銘がない。", "That item had no inscription to remove."));
187         return;
188     }
189
190     msg_print(_("銘を消した。", "Inscription removed."));
191     o_ptr->inscription = 0;
192     set_bits(creature_ptr->update, PU_COMBINE);
193     set_bits(creature_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_FLOOR_ITEM_LIST);
194     set_bits(creature_ptr->update, PU_BONUS);
195 }
196
197 /*!
198  * @brief アイテムの銘を刻むコマンドのメインルーチン
199  * Inscribe an object with a comment
200  * @return なし
201  */
202 void do_cmd_inscribe(player_type *creature_ptr)
203 {
204     OBJECT_IDX item;
205     object_type *o_ptr;
206     GAME_TEXT o_name[MAX_NLEN];
207     char out_val[80];
208     concptr q = _("どのアイテムに銘を刻みますか? ", "Inscribe which item? ");
209     concptr s = _("銘を刻めるアイテムがない。", "You have nothing to inscribe.");
210     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), TV_NONE);
211     if (!o_ptr)
212         return;
213
214     describe_flavor(creature_ptr, o_name, o_ptr, OD_OMIT_INSCRIPTION);
215     msg_format(_("%sに銘を刻む。", "Inscribing %s."), o_name);
216     msg_print(NULL);
217     strcpy(out_val, "");
218     if (o_ptr->inscription)
219         strcpy(out_val, quark_str(o_ptr->inscription));
220
221     if (get_string(_("銘: ", "Inscription: "), out_val, 80)) {
222         o_ptr->inscription = quark_add(out_val);
223         set_bits(creature_ptr->update, PU_COMBINE);
224         set_bits(creature_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_FLOOR_ITEM_LIST);
225         set_bits(creature_ptr->update, PU_BONUS);
226     }
227 }
228
229 /*!
230  * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
231  * Use an item
232  * @return なし
233  * @details
234  * XXX - Add actions for other item types
235  */
236 void do_cmd_use(player_type *creature_ptr)
237 {
238     OBJECT_IDX item;
239     object_type *o_ptr;
240     if (creature_ptr->wild_mode || cmd_limit_arena(creature_ptr))
241         return;
242
243     if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
244         set_action(creature_ptr, ACTION_NONE);
245
246     item_tester_hook = item_tester_hook_use;
247     concptr q = _("どれを使いますか?", "Use which item? ");
248     concptr s = _("使えるものがありません。", "You have nothing to use.");
249     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR | IGNORE_BOTHHAND_SLOT), TV_NONE);
250     if (!o_ptr)
251         return;
252
253     switch (o_ptr->tval) {
254     case TV_SPIKE:
255         do_cmd_spike(creature_ptr);
256         break;
257     case TV_FOOD:
258         exe_eat_food(creature_ptr, item);
259         break;
260     case TV_WAND:
261         exe_aim_wand(creature_ptr, item);
262         break;
263     case TV_STAFF:
264         exe_use_staff(creature_ptr, item);
265         break;
266     case TV_ROD:
267         exe_zap_rod(creature_ptr, item);
268         break;
269     case TV_POTION:
270         exe_quaff_potion(creature_ptr, item);
271         break;
272     case TV_SCROLL:
273         if (cmd_limit_blind(creature_ptr) || cmd_limit_confused(creature_ptr))
274             return;
275
276         exe_read(creature_ptr, item, TRUE);
277         break;
278     case TV_SHOT:
279     case TV_ARROW:
280     case TV_BOLT:
281         exe_fire(creature_ptr, item, &creature_ptr->inventory_list[INVEN_BOW], SP_NONE);
282         break;
283     default:
284         exe_activate(creature_ptr, item);
285         break;
286     }
287 }
288
289 /*!
290  * @brief 装備を発動するコマンドのメインルーチン /
291  * @param user_ptr プレーヤーへの参照ポインタ
292  * @return なし
293  */
294 void do_cmd_activate(player_type *user_ptr)
295 {
296     OBJECT_IDX item;
297     if (user_ptr->wild_mode || cmd_limit_arena(user_ptr))
298         return;
299
300     if (user_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
301         set_action(user_ptr, ACTION_NONE);
302
303     item_tester_hook = item_tester_hook_activate;
304
305     concptr q = _("どのアイテムを始動させますか? ", "Activate which item? ");
306     concptr s = _("始動できるアイテムを装備していない。", "You have nothing to activate.");
307     if (!choose_object(user_ptr, &item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), TV_NONE))
308         return;
309
310     exe_activate(user_ptr, item);
311 }