OSDN Git Service

[fix] #41503 超能力者でゲームを開始しようとするとクラッシュ
[hengband/hengband.git] / src / cmd-item / cmd-item.c
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/attack-defense-types.h"
49 #include "player/player-class.h"
50 #include "player/player-personalities-types.h"
51 #include "player/player-race-types.h"
52 #include "player/player-status.h"
53 #include "player/special-defense-types.h"
54 #include "racial/racial-android.h"
55 #include "realm/realm-hex-numbers.h"
56 #include "realm/realm-types.h"
57 #include "status/action-setter.h"
58 #include "term/screen-processor.h"
59 #include "util/int-char-converter.h"
60 #include "util/quarks.h"
61 #include "view/display-inventory.h"
62 #include "view/display-messages.h"
63
64 /*!
65  * @brief 持ち物一覧を表示するコマンドのメインルーチン / Display inventory_list
66  * @return なし
67  */
68 void do_cmd_inven(player_type *creature_ptr)
69 {
70     char out_val[160];
71     command_wrk = FALSE;
72     if (easy_floor)
73         command_wrk = USE_INVEN;
74
75     screen_save();
76     (void)show_inventory(creature_ptr, 0, USE_FULL, 0);
77     WEIGHT weight = calc_inventory_weight(creature_ptr);
78     WEIGHT weight_lim = calc_weight_limit(creature_ptr);
79 #ifdef JP
80     sprintf(out_val, "持ち物: 合計 %3d.%1d kg (限界の%ld%%) コマンド: ", (int)lbtokg1(weight), (int)lbtokg2(weight),
81 #else
82     sprintf(out_val, "Inventory: carrying %d.%d pounds (%ld%% of capacity). Command: ", (int)(weight / 10),
83         (int)(weight % 10),
84 #endif
85         (long int)(weight * 100) / weight_lim);
86
87     prt(out_val, 0, 0);
88     command_new = inkey();
89     screen_load();
90     if (command_new != ESCAPE) {
91         command_see = TRUE;
92         return;
93     }
94
95     TERM_LEN wid, hgt;
96     term_get_size(&wid, &hgt);
97     command_new = 0;
98     command_gap = wid - 30;
99 }
100
101 /*!
102  * @brief アイテムを落とすコマンドのメインルーチン / Drop an item
103  * @return なし
104  */
105 void do_cmd_drop(player_type *creature_ptr)
106 {
107     OBJECT_IDX item;
108     int amt = 1;
109     object_type *o_ptr;
110     if (creature_ptr->special_defense & KATA_MUSOU)
111         set_action(creature_ptr, ACTION_NONE);
112
113     concptr q = _("どのアイテムを落としますか? ", "Drop which item? ");
114     concptr s = _("落とせるアイテムを持っていない。", "You have nothing to drop.");
115     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | IGNORE_BOTHHAND_SLOT), 0);
116     if (!o_ptr)
117         return;
118
119     if ((item >= INVEN_MAIN_HAND) && object_is_cursed(o_ptr)) {
120         msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
121         return;
122     }
123
124     if (o_ptr->number > 1) {
125         amt = get_quantity(NULL, o_ptr->number);
126         if (amt <= 0)
127             return;
128     }
129
130     take_turn(creature_ptr, 50);
131     drop_from_inventory(creature_ptr, item, amt);
132     if (item >= INVEN_MAIN_HAND) {
133         verify_equip_slot(creature_ptr, item);
134         calc_android_exp(creature_ptr);
135     }
136
137     creature_ptr->redraw |= (PR_EQUIPPY);
138 }
139
140 /*!
141  * @brief アイテムを調査するコマンドのメインルーチン / Observe an item which has been *identify*-ed
142  * @return なし
143  */
144 void do_cmd_observe(player_type *creature_ptr)
145 {
146     OBJECT_IDX item;
147     object_type *o_ptr;
148     GAME_TEXT o_name[MAX_NLEN];
149     concptr q = _("どのアイテムを調べますか? ", "Examine which item? ");
150     concptr s = _("調べられるアイテムがない。", "You have nothing to examine.");
151     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
152     if (!o_ptr)
153         return;
154
155     if (!object_is_fully_known(o_ptr)) {
156         msg_print(_("このアイテムについて特に知っていることはない。", "You have no special knowledge about that item."));
157         return;
158     }
159
160     describe_flavor(creature_ptr, o_name, o_ptr, 0);
161     msg_format(_("%sを調べている...", "Examining %s..."), o_name);
162     if (!screen_object(creature_ptr, o_ptr, SCROBJ_FORCE_DETAIL))
163         msg_print(_("特に変わったところはないようだ。", "You see nothing special."));
164 }
165
166 /*!
167  * @brief アイテムの銘を消すコマンドのメインルーチン
168  * Remove the inscription from an object XXX Mention item (when done)?
169  * @return なし
170  */
171 void do_cmd_uninscribe(player_type *creature_ptr)
172 {
173     OBJECT_IDX item;
174     object_type *o_ptr;
175     concptr q = _("どのアイテムの銘を消しますか? ", "Un-inscribe which item? ");
176     concptr s = _("銘を消せるアイテムがない。", "You have nothing to un-inscribe.");
177     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
178     if (!o_ptr)
179         return;
180
181     if (!o_ptr->inscription) {
182         msg_print(_("このアイテムには消すべき銘がない。", "That item had no inscription to remove."));
183         return;
184     }
185
186     msg_print(_("銘を消した。", "Inscription removed."));
187     o_ptr->inscription = 0;
188     creature_ptr->update |= (PU_COMBINE);
189     creature_ptr->window |= (PW_INVEN | PW_EQUIP);
190     creature_ptr->update |= (PU_BONUS);
191 }
192
193 /*!
194  * @brief アイテムの銘を刻むコマンドのメインルーチン
195  * Inscribe an object with a comment
196  * @return なし
197  */
198 void do_cmd_inscribe(player_type *creature_ptr)
199 {
200     OBJECT_IDX item;
201     object_type *o_ptr;
202     GAME_TEXT o_name[MAX_NLEN];
203     char out_val[80];
204     concptr q = _("どのアイテムに銘を刻みますか? ", "Inscribe which item? ");
205     concptr s = _("銘を刻めるアイテムがない。", "You have nothing to inscribe.");
206     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
207     if (!o_ptr)
208         return;
209
210     describe_flavor(creature_ptr, o_name, o_ptr, OD_OMIT_INSCRIPTION);
211     msg_format(_("%sに銘を刻む。", "Inscribing %s."), o_name);
212     msg_print(NULL);
213     strcpy(out_val, "");
214     if (o_ptr->inscription)
215         strcpy(out_val, quark_str(o_ptr->inscription));
216
217     if (get_string(_("銘: ", "Inscription: "), out_val, 80)) {
218         o_ptr->inscription = quark_add(out_val);
219         creature_ptr->update |= (PU_COMBINE);
220         creature_ptr->window |= (PW_INVEN | PW_EQUIP);
221         creature_ptr->update |= (PU_BONUS);
222     }
223 }
224
225 /*!
226  * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
227  * Use an item
228  * @return なし
229  * @details
230  * XXX - Add actions for other item types
231  */
232 void do_cmd_use(player_type *creature_ptr)
233 {
234     OBJECT_IDX item;
235     object_type *o_ptr;
236     if (creature_ptr->wild_mode || cmd_limit_arena(creature_ptr))
237         return;
238
239     if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
240         set_action(creature_ptr, ACTION_NONE);
241
242     item_tester_hook = item_tester_hook_use;
243     concptr q = _("どれを使いますか?", "Use which item? ");
244     concptr s = _("使えるものがありません。", "You have nothing to use.");
245     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
246     if (!o_ptr)
247         return;
248
249     switch (o_ptr->tval) {
250     case TV_SPIKE:
251         do_cmd_spike(creature_ptr);
252         break;
253     case TV_FOOD:
254         exe_eat_food(creature_ptr, item);
255         break;
256     case TV_WAND:
257         exe_aim_wand(creature_ptr, item);
258         break;
259     case TV_STAFF:
260         exe_use_staff(creature_ptr, item);
261         break;
262     case TV_ROD:
263         exe_zap_rod(creature_ptr, item);
264         break;
265     case TV_POTION:
266         exe_quaff_potion(creature_ptr, item);
267         break;
268     case TV_SCROLL:
269         if (cmd_limit_blind(creature_ptr) || cmd_limit_confused(creature_ptr))
270             return;
271
272         exe_read(creature_ptr, item, TRUE);
273         break;
274     case TV_SHOT:
275     case TV_ARROW:
276     case TV_BOLT:
277         exe_fire(creature_ptr, item, &creature_ptr->inventory_list[INVEN_BOW], SP_NONE);
278         break;
279     default:
280         exe_activate(creature_ptr, item);
281         break;
282     }
283 }
284
285 /*!
286  * @brief 装備を発動するコマンドのメインルーチン /
287  * @param user_ptr プレーヤーへの参照ポインタ
288  * @return なし
289  */
290 void do_cmd_activate(player_type *user_ptr)
291 {
292     OBJECT_IDX item;
293     if (user_ptr->wild_mode || cmd_limit_arena(user_ptr))
294         return;
295
296     if (user_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
297         set_action(user_ptr, ACTION_NONE);
298
299     item_tester_hook = item_tester_hook_activate;
300
301     concptr q = _("どのアイテムを始動させますか? ", "Activate which item? ");
302     concptr s = _("始動できるアイテムを装備していない。", "You have nothing to activate.");
303     if (!choose_object(user_ptr, &item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0))
304         return;
305
306     exe_activate(user_ptr, item);
307 }