OSDN Git Service

[Refactor] #40535 Separated action-limited.c/h from cmd-basic.c/h
[hengbandforosx/hengbandosx.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 "art-definition/art-protector-types.h"
15 #include "autopick/autopick-registry.h"
16 #include "autopick/autopick.h"
17 #include "cmd-action/cmd-pet.h"
18 #include "cmd-item/cmd-activate.h"
19 #include "cmd-item/cmd-eat.h"
20 #include "cmd-item/cmd-quaff.h"
21 #include "cmd-item/cmd-read.h"
22 #include "cmd-item/cmd-usestaff.h"
23 #include "cmd-item/cmd-zaprod.h"
24 #include "cmd-item/cmd-zapwand.h"
25 #include "cmd/cmd-basic.h"
26 #include "core/asking-player.h"
27 #include "core/player-redraw-types.h"
28 #include "core/player-update-types.h"
29 #include "core/stuff-handler.h"
30 #include "core/window-redrawer.h"
31 #include "dungeon/quest.h"
32 #include "flavor/flavor-describer.h"
33 #include "flavor/object-flavor-types.h"
34 #include "floor/floor-object.h"
35 #include "game-option/birth-options.h"
36 #include "game-option/input-options.h"
37 #include "game-option/keymap-directory-getter.h"
38 #include "inventory/inventory-describer.h"
39 #include "inventory/inventory-object.h"
40 #include "inventory/inventory-slot-types.h"
41 #include "io/cursor.h"
42 #include "io/input-key-acceptor.h"
43 #include "io/input-key-requester.h"
44 #include "io/screen-util.h"
45 #include "io/targeting.h"
46 #include "main/sound-definitions-table.h"
47 #include "main/sound-of-music.h"
48 #include "mind/racial-android.h"
49 #include "mind/snipe-types.h"
50 #include "object-enchant/item-feeling.h"
51 #include "object-enchant/object-ego.h"
52 #include "object-enchant/special-object-flags.h"
53 #include "object-enchant/trc-types.h"
54 #include "object-hook/hook-armor.h"
55 #include "object-hook/hook-checker.h"
56 #include "object-hook/hook-expendable.h"
57 #include "object-hook/hook-magic.h"
58 #include "object-hook/hook-weapon.h"
59 #include "object-use/quaff-execution.h"
60 #include "object/item-tester-hooker.h"
61 #include "object/item-use-flags.h"
62 #include "object/object-generator.h"
63 #include "object/object-info.h"
64 #include "object/object-mark-types.h"
65 #include "object/object-stack.h"
66 #include "object/object-value.h"
67 #include "perception/identification.h"
68 #include "perception/object-perception.h"
69 #include "player/attack-defense-types.h"
70 #include "player/avatar.h"
71 #include "player/player-class.h"
72 #include "player/player-personalities-types.h"
73 #include "player/player-race-types.h"
74 #include "player/player-status.h"
75 #include "player/selfinfo.h"
76 #include "player/special-defense-types.h"
77 #include "realm/realm-hex-numbers.h"
78 #include "realm/realm-names-table.h"
79 #include "realm/realm-types.h"
80 #include "spell-kind/spells-perception.h"
81 #include "status/action-setter.h"
82 #include "status/experience.h"
83 #include "status/shape-changer.h"
84 #include "sv-definition/sv-lite-types.h"
85 #include "term/screen-processor.h"
86 #include "util/int-char-converter.h"
87 #include "util/quarks.h"
88 #include "view/display-inventory.h"
89 #include "view/display-messages.h"
90 #include "view/main-window-util.h"
91
92 /*!
93  * @brief 持ち物一覧を表示するコマンドのメインルーチン / Display inventory_list
94  * @return なし
95  */
96 void do_cmd_inven(player_type *creature_ptr)
97 {
98     char out_val[160];
99     command_wrk = FALSE;
100     if (easy_floor)
101         command_wrk = (USE_INVEN);
102     screen_save();
103     (void)show_inventory(creature_ptr, 0, USE_FULL, 0);
104
105 #ifdef JP
106     sprintf(out_val, "持ち物: 合計 %3d.%1d kg (限界の%ld%%) コマンド: ", (int)lbtokg1(creature_ptr->total_weight), (int)lbtokg2(creature_ptr->total_weight),
107 #else
108     sprintf(out_val, "Inventory: carrying %d.%d pounds (%ld%% of capacity). Command: ", (int)(creature_ptr->total_weight / 10),
109         (int)(creature_ptr->total_weight % 10),
110 #endif
111         (long int)(creature_ptr->total_weight * 100) / weight_limit(creature_ptr));
112
113     prt(out_val, 0, 0);
114     command_new = inkey();
115     screen_load();
116
117     if (command_new == ESCAPE) {
118         TERM_LEN wid, hgt;
119         Term_get_size(&wid, &hgt);
120         command_new = 0;
121         command_gap = wid - 30;
122     } else {
123         command_see = TRUE;
124     }
125 }
126
127 /*!
128  * @brief 装備一覧を表示するコマンドのメインルーチン / Display equipment
129  * @return なし
130  */
131 void do_cmd_equip(player_type *creature_ptr)
132 {
133     char out_val[160];
134     command_wrk = TRUE;
135     if (easy_floor)
136         command_wrk = (USE_EQUIP);
137     screen_save();
138
139     (void)show_equipment(creature_ptr, 0, USE_FULL, 0);
140
141 #ifdef JP
142     sprintf(out_val, "装備: 合計 %3d.%1d kg (限界の%ld%%) コマンド: ", (int)lbtokg1(creature_ptr->total_weight), (int)lbtokg2(creature_ptr->total_weight),
143         (long int)((creature_ptr->total_weight * 100) / weight_limit(creature_ptr)));
144 #else
145     sprintf(out_val, "Equipment: carrying %d.%d pounds (%ld%% of capacity). Command: ", (int)(creature_ptr->total_weight / 10),
146         (int)(creature_ptr->total_weight % 10), (long int)((creature_ptr->total_weight * 100) / weight_limit(creature_ptr)));
147 #endif
148
149     prt(out_val, 0, 0);
150     command_new = inkey();
151     screen_load();
152
153     if (command_new == ESCAPE) {
154         TERM_LEN wid, hgt;
155         Term_get_size(&wid, &hgt);
156         command_new = 0;
157         command_gap = wid - 30;
158     }
159
160     else {
161         command_see = TRUE;
162     }
163 }
164
165 bool select_ring_slot = FALSE;
166
167 /*!
168  * @brief 装備するコマンドのメインルーチン / Wield or wear a single item from the pack or floor
169  * @param creature_ptr プレーヤーへの参照ポインタ
170  * @return なし
171  */
172 void do_cmd_wield(player_type *creature_ptr)
173 {
174     OBJECT_IDX item, slot;
175     object_type forge;
176     object_type *q_ptr;
177     object_type *o_ptr;
178
179     concptr act;
180     concptr q, s;
181
182     GAME_TEXT o_name[MAX_NLEN];
183
184     OBJECT_IDX need_switch_wielding = 0;
185
186     if (creature_ptr->special_defense & KATA_MUSOU) {
187         set_action(creature_ptr, ACTION_NONE);
188     }
189
190     /* Restrict the choices */
191     item_tester_hook = item_tester_hook_wear;
192
193     q = _("どれを装備しますか? ", "Wear/Wield which item? ");
194     s = _("装備可能なアイテムがない。", "You have nothing you can wear or wield.");
195
196     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
197     if (!o_ptr)
198         return;
199
200     /* Check the slot */
201     slot = wield_slot(creature_ptr, o_ptr);
202
203     switch (o_ptr->tval) {
204     /* Shields and some misc. items */
205     case TV_CAPTURE:
206     case TV_SHIELD:
207     case TV_CARD:
208         /* Dual wielding */
209         if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM)) {
210             /* Restrict the choices */
211             item_tester_hook = item_tester_hook_melee_weapon;
212
213             /* Choose a weapon from the equipment only */
214             q = _("どちらの武器と取り替えますか?", "Replace which weapon? ");
215             s = _("おっと。", "Oops.");
216             if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0))
217                 return;
218             if (slot == INVEN_RARM)
219                 need_switch_wielding = INVEN_LARM;
220         }
221
222         else if (has_melee_weapon(creature_ptr, INVEN_LARM))
223             slot = INVEN_RARM;
224
225         /* Both arms are already used by non-weapon */
226         else if (creature_ptr->inventory_list[INVEN_RARM].k_idx && !object_is_melee_weapon(&creature_ptr->inventory_list[INVEN_RARM])
227             && creature_ptr->inventory_list[INVEN_LARM].k_idx && !object_is_melee_weapon(&creature_ptr->inventory_list[INVEN_LARM])) {
228             /* Restrict the choices */
229             item_tester_hook = item_tester_hook_mochikae;
230
231             /* Choose a hand */
232             q = _("どちらの手に装備しますか?", "Equip which hand? ");
233             s = _("おっと。", "Oops.");
234             if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP), 0))
235                 return;
236         }
237         break;
238
239     /* Melee weapons */
240     case TV_DIGGING:
241     case TV_HAFTED:
242     case TV_POLEARM:
243     case TV_SWORD:
244         /* Asking for dual wielding */
245         if (slot == INVEN_LARM) {
246             if (!get_check(_("二刀流で戦いますか?", "Dual wielding? ")))
247                 slot = INVEN_RARM;
248         }
249
250         else if (!creature_ptr->inventory_list[INVEN_RARM].k_idx && has_melee_weapon(creature_ptr, INVEN_LARM)) {
251             if (!get_check(_("二刀流で戦いますか?", "Dual wielding? ")))
252                 slot = INVEN_LARM;
253         }
254
255         /* Both arms are already used */
256         else if (creature_ptr->inventory_list[INVEN_LARM].k_idx && creature_ptr->inventory_list[INVEN_RARM].k_idx) {
257             /* Restrict the choices */
258             item_tester_hook = item_tester_hook_mochikae;
259
260             /* Choose a hand */
261             q = _("どちらの手に装備しますか?", "Equip which hand? ");
262             s = _("おっと。", "Oops.");
263
264             if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP), 0))
265                 return;
266             if ((slot == INVEN_LARM) && !has_melee_weapon(creature_ptr, INVEN_RARM))
267                 need_switch_wielding = INVEN_RARM;
268         }
269         break;
270
271     /* Rings */
272     case TV_RING:
273         /* Choose a ring slot */
274         if (creature_ptr->inventory_list[INVEN_LEFT].k_idx && creature_ptr->inventory_list[INVEN_RIGHT].k_idx) {
275             q = _("どちらの指輪と取り替えますか?", "Replace which ring? ");
276         } else {
277             q = _("どちらの手に装備しますか?", "Equip which hand? ");
278         }
279         s = _("おっと。", "Oops.");
280
281         /* Restrict the choices */
282         select_ring_slot = TRUE;
283
284         if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0)) {
285             select_ring_slot = FALSE;
286             return;
287         }
288         select_ring_slot = FALSE;
289         break;
290     }
291
292     /* Prevent wielding into a cursed slot */
293     if (object_is_cursed(&creature_ptr->inventory_list[slot])) {
294         describe_flavor(creature_ptr, o_name, &creature_ptr->inventory_list[slot], (OD_OMIT_PREFIX | OD_NAME_ONLY));
295 #ifdef JP
296         msg_format("%s%sは呪われているようだ。", describe_use(creature_ptr, slot), o_name);
297 #else
298         msg_format("The %s you are %s appears to be cursed.", o_name, describe_use(creature_ptr, slot));
299 #endif
300         return;
301     }
302
303     if (confirm_wear
304         && ((object_is_cursed(o_ptr) && object_is_known(o_ptr))
305             || ((o_ptr->ident & IDENT_SENSE) && (FEEL_BROKEN <= o_ptr->feeling) && (o_ptr->feeling <= FEEL_CURSED)))) {
306         char dummy[MAX_NLEN + 80];
307
308         describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
309         sprintf(dummy, _("本当に%s{呪われている}を使いますか?", "Really use the %s {cursed}? "), o_name);
310
311         if (!get_check(dummy))
312             return;
313     }
314
315     if ((o_ptr->name1 == ART_STONEMASK) && object_is_known(o_ptr) && (creature_ptr->prace != RACE_VAMPIRE) && (creature_ptr->prace != RACE_ANDROID)) {
316         char dummy[MAX_NLEN + 100];
317
318         describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
319
320         sprintf(dummy,
321             _("%sを装備すると吸血鬼になります。よろしいですか?", "%s will transforms you into a vampire permanently when equiped. Do you become a vampire?"),
322             o_name);
323
324         if (!get_check(dummy))
325             return;
326     }
327
328     if (need_switch_wielding && !object_is_cursed(&creature_ptr->inventory_list[need_switch_wielding])) {
329         object_type *slot_o_ptr = &creature_ptr->inventory_list[slot];
330         object_type *switch_o_ptr = &creature_ptr->inventory_list[need_switch_wielding];
331         object_type object_tmp;
332         object_type *otmp_ptr = &object_tmp;
333         GAME_TEXT switch_name[MAX_NLEN];
334
335         describe_flavor(creature_ptr, switch_name, switch_o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
336
337         object_copy(otmp_ptr, switch_o_ptr);
338         object_copy(switch_o_ptr, slot_o_ptr);
339         object_copy(slot_o_ptr, otmp_ptr);
340
341         msg_format(_("%sを%sに構えなおした。", "You wield %s at %s hand."), switch_name,
342             (slot == INVEN_RARM) ? (left_hander ? _("左手", "left") : _("右手", "right")) : (left_hander ? _("右手", "right") : _("左手", "left")));
343         slot = need_switch_wielding;
344     }
345
346     check_find_art_quest_completion(creature_ptr, o_ptr);
347
348     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
349         identify_item(creature_ptr, o_ptr);
350
351         /* Auto-inscription */
352         autopick_alter_item(creature_ptr, item, FALSE);
353     }
354
355     take_turn(creature_ptr, 100);
356     q_ptr = &forge;
357
358     /* Obtain local object */
359     object_copy(q_ptr, o_ptr);
360
361     /* Modify quantity */
362     q_ptr->number = 1;
363
364     /* Decrease the item (from the pack) */
365     if (item >= 0) {
366         inven_item_increase(creature_ptr, item, -1);
367         inven_item_optimize(creature_ptr, item);
368     }
369     /* Decrease the item (from the floor) */
370     else {
371         floor_item_increase(creature_ptr->current_floor_ptr, 0 - item, -1);
372         floor_item_optimize(creature_ptr, 0 - item);
373     }
374
375     /* Access the wield slot */
376     o_ptr = &creature_ptr->inventory_list[slot];
377
378     /* Take off existing item */
379     if (o_ptr->k_idx) {
380         /* Take off existing item */
381         (void)inven_takeoff(creature_ptr, slot, 255);
382     }
383
384     /* Wear the new stuff */
385     object_copy(o_ptr, q_ptr);
386
387     o_ptr->marked |= OM_TOUCHED;
388
389     creature_ptr->total_weight += q_ptr->weight;
390
391     /* Increment the equip counter by hand */
392     creature_ptr->equip_cnt++;
393
394 #define STR_WIELD_RARM _("%s(%c)を右手に装備した。", "You are wielding %s (%c) in your right hand.")
395 #define STR_WIELD_LARM _("%s(%c)を左手に装備した。", "You are wielding %s (%c) in your left hand.")
396 #define STR_WIELD_ARMS _("%s(%c)を両手で構えた。", "You are wielding %s (%c) with both hands.")
397
398     /* Where is the item now */
399     switch (slot) {
400     case INVEN_RARM:
401         if (object_allow_two_hands_wielding(o_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_LARM) && can_two_hands_wielding(creature_ptr))
402             act = STR_WIELD_ARMS;
403         else
404             act = (left_hander ? STR_WIELD_LARM : STR_WIELD_RARM);
405         break;
406
407     case INVEN_LARM:
408         if (object_allow_two_hands_wielding(o_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_RARM) && can_two_hands_wielding(creature_ptr))
409             act = STR_WIELD_ARMS;
410         else
411             act = (left_hander ? STR_WIELD_RARM : STR_WIELD_LARM);
412         break;
413
414     case INVEN_BOW:
415         act = _("%s(%c)を射撃用に装備した。", "You are shooting with %s (%c).");
416         break;
417
418     case INVEN_LITE:
419         act = _("%s(%c)を光源にした。", "Your light source is %s (%c).");
420         break;
421
422     default:
423         act = _("%s(%c)を装備した。", "You are wearing %s (%c).");
424         break;
425     }
426
427     describe_flavor(creature_ptr, o_name, o_ptr, 0);
428     msg_format(act, o_name, index_to_label(slot));
429
430     /* Cursed! */
431     if (object_is_cursed(o_ptr)) {
432         msg_print(_("うわ! すさまじく冷たい!", "Oops! It feels deathly cold!"));
433         chg_virtue(creature_ptr, V_HARMONY, -1);
434
435         /* Note the curse */
436         o_ptr->ident |= (IDENT_SENSE);
437     }
438
439     /* The Stone Mask make the player turn into a vampire! */
440     if ((o_ptr->name1 == ART_STONEMASK) && (creature_ptr->prace != RACE_VAMPIRE) && (creature_ptr->prace != RACE_ANDROID)) {
441         /* Turn into a vampire */
442         change_race(creature_ptr, RACE_VAMPIRE, "");
443     }
444
445     creature_ptr->update |= (PU_BONUS | PU_TORCH | PU_MANA);
446     creature_ptr->redraw |= (PR_EQUIPPY);
447     creature_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
448
449     calc_android_exp(creature_ptr);
450 }
451
452 /*!
453  * @brief 持ち替え処理
454  * @param owner_ptr プレーヤーへの参照ポインタ
455  * @param item 持ち替えを行いたい装備部位ID
456  * @return なし
457  */
458 void verify_equip_slot(player_type *owner_ptr, INVENTORY_IDX item)
459 {
460     object_type *o_ptr, *new_o_ptr;
461     GAME_TEXT o_name[MAX_NLEN];
462
463     if (item == INVEN_RARM) {
464         if (!has_melee_weapon(owner_ptr, INVEN_LARM))
465             return;
466
467         o_ptr = &owner_ptr->inventory_list[INVEN_LARM];
468         describe_flavor(owner_ptr, o_name, o_ptr, 0);
469
470         if (object_is_cursed(o_ptr)) {
471             if (object_allow_two_hands_wielding(o_ptr) && can_two_hands_wielding(owner_ptr))
472                 msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
473             return;
474         }
475
476         new_o_ptr = &owner_ptr->inventory_list[INVEN_RARM];
477         object_copy(new_o_ptr, o_ptr);
478         owner_ptr->total_weight += o_ptr->weight;
479         inven_item_increase(owner_ptr, INVEN_LARM, -((int)o_ptr->number));
480         inven_item_optimize(owner_ptr, INVEN_LARM);
481         if (object_allow_two_hands_wielding(o_ptr) && can_two_hands_wielding(owner_ptr))
482             msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
483         else
484             msg_format(_("%sを%sで構えた。", "You are wielding %s in your %s hand."), o_name, (left_hander ? _("左手", "left") : _("右手", "right")));
485         return;
486     }
487
488     if (item != INVEN_LARM)
489         return;
490
491     o_ptr = &owner_ptr->inventory_list[INVEN_RARM];
492     if (o_ptr->k_idx)
493         describe_flavor(owner_ptr, o_name, o_ptr, 0);
494
495     if (has_melee_weapon(owner_ptr, INVEN_RARM)) {
496         if (object_allow_two_hands_wielding(o_ptr) && can_two_hands_wielding(owner_ptr))
497             msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
498         return;
499     }
500
501     if ((empty_hands(owner_ptr, FALSE) & EMPTY_HAND_RARM) || object_is_cursed(o_ptr))
502         return;
503
504     new_o_ptr = &owner_ptr->inventory_list[INVEN_LARM];
505     object_copy(new_o_ptr, o_ptr);
506     owner_ptr->total_weight += o_ptr->weight;
507     inven_item_increase(owner_ptr, INVEN_RARM, -((int)o_ptr->number));
508     inven_item_optimize(owner_ptr, INVEN_RARM);
509     msg_format(_("%sを持ち替えた。", "You switched hand of %s."), o_name);
510 }
511
512 /*!
513  * @brief 装備を外すコマンドのメインルーチン / Take off an item
514  * @return なし
515  */
516 void do_cmd_takeoff(player_type *creature_ptr)
517 {
518     OBJECT_IDX item;
519     object_type *o_ptr;
520     concptr q, s;
521
522     if (creature_ptr->special_defense & KATA_MUSOU) {
523         set_action(creature_ptr, ACTION_NONE);
524     }
525
526     q = _("どれを装備からはずしますか? ", "Take off which item? ");
527     s = _("はずせる装備がない。", "You are not wearing anything to take off.");
528
529     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0);
530     if (!o_ptr)
531         return;
532
533     /* Item is cursed */
534     if (object_is_cursed(o_ptr)) {
535         if ((o_ptr->curse_flags & TRC_PERMA_CURSE) || (creature_ptr->pclass != CLASS_BERSERKER)) {
536             msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
537
538             return;
539         }
540
541         if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && one_in_(7)) || one_in_(4)) {
542             msg_print(_("呪われた装備を力づくで剥がした!", "You tore off a piece of cursed equipment by sheer strength!"));
543
544             o_ptr->ident |= (IDENT_SENSE);
545             o_ptr->curse_flags = 0L;
546             o_ptr->feeling = FEEL_NONE;
547
548             creature_ptr->update |= (PU_BONUS);
549             creature_ptr->window |= (PW_EQUIP);
550
551             msg_print(_("呪いを打ち破った。", "You break the curse."));
552         } else {
553             msg_print(_("装備を外せなかった。", "You couldn't remove the equipment."));
554             take_turn(creature_ptr, 50);
555             return;
556         }
557     }
558
559     take_turn(creature_ptr, 50);
560
561     /* Take off the item */
562     (void)inven_takeoff(creature_ptr, item, 255);
563     verify_equip_slot(creature_ptr, item);
564     calc_android_exp(creature_ptr);
565     creature_ptr->redraw |= (PR_EQUIPPY);
566 }
567
568 /*!
569  * @brief アイテムを落とすコマンドのメインルーチン / Drop an item
570  * @return なし
571  */
572 void do_cmd_drop(player_type *creature_ptr)
573 {
574     OBJECT_IDX item;
575     int amt = 1;
576
577     object_type *o_ptr;
578
579     concptr q, s;
580
581     if (creature_ptr->special_defense & KATA_MUSOU) {
582         set_action(creature_ptr, ACTION_NONE);
583     }
584
585     q = _("どのアイテムを落としますか? ", "Drop which item? ");
586     s = _("落とせるアイテムを持っていない。", "You have nothing to drop.");
587
588     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | IGNORE_BOTHHAND_SLOT), 0);
589     if (!o_ptr)
590         return;
591
592     /* Hack -- Cannot remove cursed items */
593     if ((item >= INVEN_RARM) && object_is_cursed(o_ptr)) {
594         msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
595         return;
596     }
597
598     if (o_ptr->number > 1) {
599         amt = get_quantity(NULL, o_ptr->number);
600         if (amt <= 0)
601             return;
602     }
603
604     take_turn(creature_ptr, 50);
605
606     /* Drop (some of) the item */
607     drop_from_inventory(creature_ptr, item, amt);
608
609     if (item >= INVEN_RARM) {
610         verify_equip_slot(creature_ptr, item);
611         calc_android_exp(creature_ptr);
612     }
613
614     creature_ptr->redraw |= (PR_EQUIPPY);
615 }
616
617 /*!
618  * @brief アイテムを破壊するコマンドのメインルーチン / Destroy an item
619  * @param creature_ptr プレーヤーへの参照ポインタ
620  * @return なし
621  */
622 void do_cmd_destroy(player_type *creature_ptr)
623 {
624     OBJECT_IDX item;
625     QUANTITY amt = 1;
626     QUANTITY old_number;
627
628     bool force = FALSE;
629
630     object_type *o_ptr;
631     object_type forge;
632     object_type *q_ptr = &forge;
633
634     GAME_TEXT o_name[MAX_NLEN];
635     char out_val[MAX_NLEN + 40];
636
637     concptr q, s;
638
639     if (creature_ptr->special_defense & KATA_MUSOU) {
640         set_action(creature_ptr, ACTION_NONE);
641     }
642
643     /* Hack -- force destruction */
644     if (command_arg > 0)
645         force = TRUE;
646
647     q = _("どのアイテムを壊しますか? ", "Destroy which item? ");
648     s = _("壊せるアイテムを持っていない。", "You have nothing to destroy.");
649
650     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
651     if (!o_ptr)
652         return;
653
654     /* Verify unless quantity given beforehand */
655     if (!force && (confirm_destroy || (object_value(creature_ptr, o_ptr) > 0))) {
656         describe_flavor(creature_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
657
658         /* Make a verification */
659         sprintf(out_val, _("本当に%sを壊しますか? [y/n/Auto]", "Really destroy %s? [y/n/Auto]"), o_name);
660         msg_print(NULL);
661
662         /* HACK : Add the line to message buffer */
663         message_add(out_val);
664         creature_ptr->window |= (PW_MESSAGE);
665         handle_stuff(creature_ptr);
666
667         /* Get an acceptable answer */
668         while (TRUE) {
669             char i;
670
671             /* Prompt */
672             prt(out_val, 0, 0);
673
674             i = inkey();
675
676             /* Erase the prompt */
677             prt("", 0, 0);
678
679             if (i == 'y' || i == 'Y') {
680                 break;
681             }
682             if (i == ESCAPE || i == 'n' || i == 'N') {
683                 /* Cancel */
684                 return;
685             }
686             if (i == 'A') {
687                 /* Add an auto-destroy preference line */
688                 if (autopick_autoregister(creature_ptr, o_ptr)) {
689                     /* Auto-destroy it */
690                     autopick_alter_item(creature_ptr, item, TRUE);
691                 }
692
693                 /* The object is already destroyed. */
694                 return;
695             }
696         } /* while (TRUE) */
697     }
698
699     if (o_ptr->number > 1) {
700         amt = get_quantity(NULL, o_ptr->number);
701         if (amt <= 0)
702             return;
703     }
704
705     old_number = o_ptr->number;
706     o_ptr->number = amt;
707     describe_flavor(creature_ptr, o_name, o_ptr, 0);
708     o_ptr->number = old_number;
709
710     take_turn(creature_ptr, 100);
711
712     /* Artifacts cannot be destroyed */
713     if (!can_player_destroy_object(creature_ptr, o_ptr)) {
714         free_turn(creature_ptr);
715
716         msg_format(_("%sは破壊不可能だ。", "You cannot destroy %s."), o_name);
717         return;
718     }
719
720     object_copy(q_ptr, o_ptr);
721
722     msg_format(_("%sを壊した。", "You destroy %s."), o_name);
723     sound(SOUND_DESTITEM);
724
725     /* Reduce the charges of rods/wands */
726     reduce_charges(o_ptr, amt);
727
728     vary_item(creature_ptr, item, -amt);
729
730     if (item_tester_high_level_book(q_ptr)) {
731         bool gain_expr = FALSE;
732
733         if (creature_ptr->prace == RACE_ANDROID) {
734         } else if ((creature_ptr->pclass == CLASS_WARRIOR) || (creature_ptr->pclass == CLASS_BERSERKER)) {
735             gain_expr = TRUE;
736         } else if (creature_ptr->pclass == CLASS_PALADIN) {
737             if (is_good_realm(creature_ptr->realm1)) {
738                 if (!is_good_realm(tval2realm(q_ptr->tval)))
739                     gain_expr = TRUE;
740             } else {
741                 if (is_good_realm(tval2realm(q_ptr->tval)))
742                     gain_expr = TRUE;
743             }
744         }
745
746         if (gain_expr && (creature_ptr->exp < PY_MAX_EXP)) {
747             s32b tester_exp = creature_ptr->max_exp / 20;
748             if (tester_exp > 10000)
749                 tester_exp = 10000;
750             if (q_ptr->sval < 3)
751                 tester_exp /= 4;
752             if (tester_exp < 1)
753                 tester_exp = 1;
754
755             msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
756             gain_exp(creature_ptr, tester_exp * amt);
757         }
758         if (item_tester_high_level_book(q_ptr) && q_ptr->tval == TV_LIFE_BOOK) {
759             chg_virtue(creature_ptr, V_UNLIFE, 1);
760             chg_virtue(creature_ptr, V_VITALITY, -1);
761         } else if (item_tester_high_level_book(q_ptr) && q_ptr->tval == TV_DEATH_BOOK) {
762             chg_virtue(creature_ptr, V_UNLIFE, -1);
763             chg_virtue(creature_ptr, V_VITALITY, 1);
764         }
765
766         if (q_ptr->to_a || q_ptr->to_h || q_ptr->to_d)
767             chg_virtue(creature_ptr, V_ENCHANT, -1);
768
769         if (object_value_real(creature_ptr, q_ptr) > 30000)
770             chg_virtue(creature_ptr, V_SACRIFICE, 2);
771
772         else if (object_value_real(creature_ptr, q_ptr) > 10000)
773             chg_virtue(creature_ptr, V_SACRIFICE, 1);
774     }
775
776     if (q_ptr->to_a != 0 || q_ptr->to_d != 0 || q_ptr->to_h != 0)
777         chg_virtue(creature_ptr, V_HARMONY, 1);
778
779     if (item >= INVEN_RARM)
780         calc_android_exp(creature_ptr);
781 }
782
783 /*!
784  * @brief アイテムを調査するコマンドのメインルーチン / Observe an item which has been *identify*-ed
785  * @return なし
786  */
787 void do_cmd_observe(player_type *creature_ptr)
788 {
789     OBJECT_IDX item;
790     object_type *o_ptr;
791     GAME_TEXT o_name[MAX_NLEN];
792     concptr q, s;
793
794     q = _("どのアイテムを調べますか? ", "Examine which item? ");
795     s = _("調べられるアイテムがない。", "You have nothing to examine.");
796
797     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
798     if (!o_ptr)
799         return;
800
801     /* Require full knowledge */
802     if (!object_is_fully_known(o_ptr)) {
803         msg_print(_("このアイテムについて特に知っていることはない。", "You have no special knowledge about that item."));
804         return;
805     }
806
807     describe_flavor(creature_ptr, o_name, o_ptr, 0);
808     msg_format(_("%sを調べている...", "Examining %s..."), o_name);
809     if (!screen_object(creature_ptr, o_ptr, SCROBJ_FORCE_DETAIL))
810         msg_print(_("特に変わったところはないようだ。", "You see nothing special."));
811 }
812
813 /*!
814  * @brief アイテムの銘を消すコマンドのメインルーチン
815  * Remove the inscription from an object XXX Mention item (when done)?
816  * @return なし
817  */
818 void do_cmd_uninscribe(player_type *creature_ptr)
819 {
820     OBJECT_IDX item;
821     object_type *o_ptr;
822     concptr q, s;
823
824     q = _("どのアイテムの銘を消しますか? ", "Un-inscribe which item? ");
825     s = _("銘を消せるアイテムがない。", "You have nothing to un-inscribe.");
826
827     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
828     if (!o_ptr)
829         return;
830
831     /* Nothing to remove */
832     if (!o_ptr->inscription) {
833         msg_print(_("このアイテムには消すべき銘がない。", "That item had no inscription to remove."));
834         return;
835     }
836
837     msg_print(_("銘を消した。", "Inscription removed."));
838
839     /* Remove the incription */
840     o_ptr->inscription = 0;
841     creature_ptr->update |= (PU_COMBINE);
842     creature_ptr->window |= (PW_INVEN | PW_EQUIP);
843
844     /* .や$の関係で, 再計算が必要なはず -- henkma */
845     creature_ptr->update |= (PU_BONUS);
846 }
847
848 /*!
849  * @brief アイテムの銘を刻むコマンドのメインルーチン
850  * Inscribe an object with a comment
851  * @return なし
852  */
853 void do_cmd_inscribe(player_type *creature_ptr)
854 {
855     OBJECT_IDX item;
856     object_type *o_ptr;
857     GAME_TEXT o_name[MAX_NLEN];
858     char out_val[80];
859     concptr q, s;
860
861     q = _("どのアイテムに銘を刻みますか? ", "Inscribe which item? ");
862     s = _("銘を刻めるアイテムがない。", "You have nothing to inscribe.");
863
864     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
865     if (!o_ptr)
866         return;
867
868     /* Describe the activity */
869     describe_flavor(creature_ptr, o_name, o_ptr, OD_OMIT_INSCRIPTION);
870
871     msg_format(_("%sに銘を刻む。", "Inscribing %s."), o_name);
872     msg_print(NULL);
873
874     /* Start with nothing */
875     strcpy(out_val, "");
876
877     /* Use old inscription */
878     if (o_ptr->inscription) {
879         /* Start with the old inscription */
880         strcpy(out_val, quark_str(o_ptr->inscription));
881     }
882
883     /* Get a new inscription (possibly empty) */
884     if (get_string(_("銘: ", "Inscription: "), out_val, 80)) {
885         /* Save the inscription */
886         o_ptr->inscription = quark_add(out_val);
887         creature_ptr->update |= (PU_COMBINE);
888         creature_ptr->window |= (PW_INVEN | PW_EQUIP);
889
890         /* .や$の関係で, 再計算が必要なはず -- henkma */
891         creature_ptr->update |= (PU_BONUS);
892     }
893 }
894
895 /*!
896  * @brief ランタンに燃料を加えるコマンドのメインルーチン
897  * Refill the players lamp (from the pack or floor)
898  * @return なし
899  */
900 static void do_cmd_refill_lamp(player_type *user_ptr)
901 {
902     OBJECT_IDX item;
903     object_type *o_ptr;
904     object_type *j_ptr;
905     concptr q, s;
906
907     /* Restrict the choices */
908     item_tester_hook = item_tester_refill_lantern;
909
910     q = _("どの油つぼから注ぎますか? ", "Refill with which flask? ");
911     s = _("油つぼがない。", "You have no flasks of oil.");
912
913     o_ptr = choose_object(user_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
914     if (!o_ptr)
915         return;
916
917     take_turn(user_ptr, 50);
918
919     /* Access the lantern */
920     j_ptr = &user_ptr->inventory_list[INVEN_LITE];
921
922     /* Refuel */
923     j_ptr->xtra4 += o_ptr->xtra4;
924     msg_print(_("ランプに油を注いだ。", "You fuel your lamp."));
925
926     if ((o_ptr->name2 == EGO_LITE_DARKNESS) && (j_ptr->xtra4 > 0)) {
927         j_ptr->xtra4 = 0;
928         msg_print(_("ランプが消えてしまった!", "Your lamp has gone out!"));
929     } else if ((o_ptr->name2 == EGO_LITE_DARKNESS) || (j_ptr->name2 == EGO_LITE_DARKNESS)) {
930         j_ptr->xtra4 = 0;
931         msg_print(_("しかしランプは全く光らない。", "Curiously, your lamp doesn't light."));
932     } else if (j_ptr->xtra4 >= FUEL_LAMP) {
933         j_ptr->xtra4 = FUEL_LAMP;
934         msg_print(_("ランプの油は一杯だ。", "Your lamp is full."));
935     }
936
937     vary_item(user_ptr, item, -1);
938
939     user_ptr->update |= (PU_TORCH);
940 }
941
942 /*!
943  * @brief 松明を束ねるコマンドのメインルーチン
944  * Refuel the players torch (from the pack or floor)
945  * @return なし
946  */
947 static void do_cmd_refill_torch(player_type *creature_ptr)
948 {
949     OBJECT_IDX item;
950
951     object_type *o_ptr;
952     object_type *j_ptr;
953
954     concptr q, s;
955
956     /* Restrict the choices */
957     item_tester_hook = object_can_refill_torch;
958
959     q = _("どの松明で明かりを強めますか? ", "Refuel with which torch? ");
960     s = _("他に松明がない。", "You have no extra torches.");
961
962     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
963     if (!o_ptr)
964         return;
965
966     take_turn(creature_ptr, 50);
967
968     /* Access the primary torch */
969     j_ptr = &creature_ptr->inventory_list[INVEN_LITE];
970
971     /* Refuel */
972     j_ptr->xtra4 += o_ptr->xtra4 + 5;
973
974     msg_print(_("松明を結合した。", "You combine the torches."));
975
976     if ((o_ptr->name2 == EGO_LITE_DARKNESS) && (j_ptr->xtra4 > 0)) {
977         j_ptr->xtra4 = 0;
978         msg_print(_("松明が消えてしまった!", "Your torch has gone out!"));
979     } else if ((o_ptr->name2 == EGO_LITE_DARKNESS) || (j_ptr->name2 == EGO_LITE_DARKNESS)) {
980         j_ptr->xtra4 = 0;
981         msg_print(_("しかし松明は全く光らない。", "Curiously, your torch doesn't light."));
982     }
983     /* Over-fuel message */
984     else if (j_ptr->xtra4 >= FUEL_TORCH) {
985         j_ptr->xtra4 = FUEL_TORCH;
986         msg_print(_("松明の寿命は十分だ。", "Your torch is fully fueled."));
987     }
988
989     /* Refuel message */
990     else {
991         msg_print(_("松明はいっそう明るく輝いた。", "Your torch glows more brightly."));
992     }
993
994     vary_item(creature_ptr, item, -1);
995
996     creature_ptr->update |= (PU_TORCH);
997 }
998
999 /*!
1000  * @brief 燃料を補充するコマンドのメインルーチン
1001  * Refill the players lamp, or restock his torches
1002  * @return なし
1003  */
1004 void do_cmd_refill(player_type *creature_ptr)
1005 {
1006     object_type *o_ptr;
1007
1008     /* Get the light */
1009     o_ptr = &creature_ptr->inventory_list[INVEN_LITE];
1010
1011     if (creature_ptr->special_defense & KATA_MUSOU) {
1012         set_action(creature_ptr, ACTION_NONE);
1013     }
1014
1015     /* It is nothing */
1016     if (o_ptr->tval != TV_LITE) {
1017         msg_print(_("光源を装備していない。", "You are not wielding a light."));
1018     }
1019
1020     /* It's a lamp */
1021     else if (o_ptr->sval == SV_LITE_LANTERN) {
1022         do_cmd_refill_lamp(creature_ptr);
1023     }
1024
1025     /* It's a torch */
1026     else if (o_ptr->sval == SV_LITE_TORCH) {
1027         do_cmd_refill_torch(creature_ptr);
1028     }
1029
1030     /* No torch to refill */
1031     else {
1032         msg_print(_("この光源は寿命を延ばせない。", "Your light cannot be refilled."));
1033     }
1034 }
1035
1036 /*!
1037  * @brief ターゲットを設定するコマンドのメインルーチン
1038  * Target command
1039  * @return なし
1040  */
1041 void do_cmd_target(player_type *creature_ptr)
1042 {
1043     if (creature_ptr->wild_mode)
1044         return;
1045
1046     /* Target set */
1047     if (target_set(creature_ptr, TARGET_KILL)) {
1048         msg_print(_("ターゲット決定。", "Target Selected."));
1049     }
1050
1051     /* Target aborted */
1052     else {
1053         msg_print(_("ターゲット解除。", "Target Aborted."));
1054     }
1055 }
1056
1057 /*!
1058  * @brief 周囲を見渡すコマンドのメインルーチン
1059  * Look command
1060  * @return なし
1061  */
1062 void do_cmd_look(player_type *creature_ptr)
1063 {
1064     creature_ptr->window |= PW_MONSTER_LIST;
1065     handle_stuff(creature_ptr);
1066
1067     /* Look around */
1068     if (target_set(creature_ptr, TARGET_LOOK)) {
1069         msg_print(_("ターゲット決定。", "Target Selected."));
1070     }
1071 }
1072
1073 /*!
1074  * @brief 位置を確認するコマンドのメインルーチン
1075  * Allow the player to examine other sectors on the map
1076  * @return なし
1077  */
1078 void do_cmd_locate(player_type *creature_ptr)
1079 {
1080     DIRECTION dir;
1081     POSITION y1, x1, y2, x2;
1082     GAME_TEXT tmp_val[80];
1083     GAME_TEXT out_val[160];
1084     TERM_LEN wid, hgt;
1085
1086     get_screen_size(&wid, &hgt);
1087
1088     /* Start at current panel */
1089     y2 = y1 = panel_row_min;
1090     x2 = x1 = panel_col_min;
1091
1092     /* Show panels until done */
1093     while (TRUE) {
1094         /* Describe the location */
1095         if ((y2 == y1) && (x2 == x1)) {
1096             strcpy(tmp_val, _("真上", "\0"));
1097         } else {
1098             sprintf(tmp_val, "%s%s", ((y2 < y1) ? _("北", " North") : (y2 > y1) ? _("南", " South") : ""),
1099                 ((x2 < x1) ? _("西", " West") : (x2 > x1) ? _("東", " East") : ""));
1100         }
1101
1102         /* Prepare to ask which way to look */
1103         sprintf(out_val, _("マップ位置 [%d(%02d),%d(%02d)] (プレイヤーの%s)  方向?", "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?"),
1104             y2 / (hgt / 2), y2 % (hgt / 2), x2 / (wid / 2), x2 % (wid / 2), tmp_val);
1105
1106         /* Assume no direction */
1107         dir = 0;
1108
1109         /* Get a direction */
1110         while (!dir) {
1111             char command;
1112
1113             /* Get a command (or Cancel) */
1114             if (!get_com(out_val, &command, TRUE))
1115                 break;
1116
1117             /* Extract the action (if any) */
1118             dir = get_keymap_dir(command);
1119
1120             /* Error */
1121             if (!dir)
1122                 bell();
1123         }
1124
1125         /* No direction */
1126         if (!dir)
1127             break;
1128
1129         /* Apply the motion */
1130         if (change_panel(creature_ptr, ddy[dir], ddx[dir])) {
1131             y2 = panel_row_min;
1132             x2 = panel_col_min;
1133         }
1134     }
1135
1136     /* Recenter the map around the player */
1137     verify_panel(creature_ptr);
1138
1139     creature_ptr->update |= (PU_MONSTERS);
1140     creature_ptr->redraw |= (PR_MAP);
1141     creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1142     handle_stuff(creature_ptr);
1143 }
1144
1145 /*!
1146  * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
1147  * Use an item
1148  * @return なし
1149  * @details
1150  * XXX - Add actions for other item types
1151  */
1152 void do_cmd_use(player_type *creature_ptr)
1153 {
1154     OBJECT_IDX item;
1155     object_type *o_ptr;
1156     concptr q, s;
1157
1158     if (creature_ptr->wild_mode) {
1159         return;
1160     }
1161
1162     if (cmd_limit_arena(creature_ptr))
1163         return;
1164
1165     if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN)) {
1166         set_action(creature_ptr, ACTION_NONE);
1167     }
1168
1169     item_tester_hook = item_tester_hook_use;
1170
1171     q = _("どれを使いますか?", "Use which item? ");
1172     s = _("使えるものがありません。", "You have nothing to use.");
1173
1174     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
1175     if (!o_ptr)
1176         return;
1177
1178     switch (o_ptr->tval) {
1179     case TV_SPIKE:
1180         do_cmd_spike(creature_ptr);
1181         break;
1182
1183     case TV_FOOD:
1184         exe_eat_food(creature_ptr, item);
1185         break;
1186
1187     case TV_WAND:
1188         exe_aim_wand(creature_ptr, item);
1189         break;
1190
1191     case TV_STAFF:
1192         exe_use_staff(creature_ptr, item);
1193         break;
1194
1195     case TV_ROD:
1196         exe_zap_rod(creature_ptr, item);
1197         break;
1198
1199     case TV_POTION:
1200         exe_quaff_potion(creature_ptr, item);
1201         break;
1202
1203     case TV_SCROLL:
1204         if (cmd_limit_blind(creature_ptr))
1205             return;
1206         if (cmd_limit_confused(creature_ptr))
1207             return;
1208         exe_read(creature_ptr, item, TRUE);
1209         break;
1210
1211     case TV_SHOT:
1212     case TV_ARROW:
1213     case TV_BOLT:
1214         exe_fire(creature_ptr, item, &creature_ptr->inventory_list[INVEN_BOW], SP_NONE);
1215         break;
1216
1217     default:
1218         exe_activate(creature_ptr, item);
1219         break;
1220     }
1221 }