OSDN Git Service

[Refactor] #38824 choose_object()の修正とget_item()の置換。 / Fix choose_object() and replace...
[hengband/hengband.git] / src / cmd-item.c
1 /*!
2  *  @file cmd3.c
3  *  @brief プレイヤーのアイテムに関するコマンドの実装1 / Inventory commands
4  *  @date 2014/01/02
5  *  @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  */
12
13
14 #include "angband.h"
15 #include "selfinfo.h"
16 #include "cmd-activate.h"
17 #include "cmd-eat.h"
18 #include "cmd-quaff.h"
19 #include "cmd-read.h"
20 #include "cmd-usestaff.h"
21 #include "cmd-zaprod.h"
22 #include "cmd-zapwand.h"
23
24 #include "player-item.h"
25 #include "object-hook.h"
26
27
28 /*!
29  * @brief 持ち物一覧を表示するコマンドのメインルーチン / Display inventory
30  * @return なし 
31  */
32 void do_cmd_inven(void)
33 {
34         char out_val[160];
35
36
37         /* Note that we are in "inventory" mode */
38         command_wrk = FALSE;
39
40         /* Note that we are in "inventory" mode */
41         if (easy_floor) command_wrk = (USE_INVEN);
42         screen_save();
43
44         /* Hack -- show empty slots */
45         item_tester_full = TRUE;
46
47         /* Display the inventory */
48         (void)show_inven(0);
49
50         /* Hack -- hide empty slots */
51         item_tester_full = FALSE;
52
53 #ifdef JP
54         sprintf(out_val, "持ち物: 合計 %3d.%1d kg (限界の%ld%%) コマンド: ",
55             (int)lbtokg1(p_ptr->total_weight) , (int)lbtokg2(p_ptr->total_weight) ,
56             (long int)((p_ptr->total_weight * 100) / weight_limit()));
57 #else
58         sprintf(out_val, "Inventory: carrying %d.%d pounds (%ld%% of capacity). Command: ",
59             (int)(p_ptr->total_weight / 10), (int)(p_ptr->total_weight % 10),
60             (p_ptr->total_weight * 100) / weight_limit());
61 #endif
62
63
64         /* Get a command */
65         prt(out_val, 0, 0);
66
67         /* Get a new command */
68         command_new = inkey();
69         screen_load();
70
71
72         /* Process "Escape" */
73         if (command_new == ESCAPE)
74         {
75                 int wid, hgt;
76
77                 Term_get_size(&wid, &hgt);
78
79                 /* Reset stuff */
80                 command_new = 0;
81                 command_gap = wid - 30;
82         }
83
84         /* Process normal keys */
85         else
86         {
87                 /* Hack -- Use "display" mode */
88                 command_see = TRUE;
89         }
90 }
91
92
93 /*!
94  * @brief 装備一覧を表示するコマンドのメインルーチン / Display equipment
95  * @return なし 
96  */
97 void do_cmd_equip(void)
98 {
99         char out_val[160];
100
101
102         /* Note that we are in "equipment" mode */
103         command_wrk = TRUE;
104
105         /* Note that we are in "equipment" mode */
106         if (easy_floor) command_wrk = (USE_EQUIP);
107         screen_save();
108
109         /* Hack -- show empty slots */
110         item_tester_full = TRUE;
111
112         /* Display the equipment */
113         (void)show_equip(0);
114
115         /* Hack -- undo the hack above */
116         item_tester_full = FALSE;
117
118         /* Build a prompt */
119 #ifdef JP
120         sprintf(out_val, "装備: 合計 %3d.%1d kg (限界の%ld%%) コマンド: ",
121             (int)lbtokg1(p_ptr->total_weight) , (int)lbtokg2(p_ptr->total_weight) ,
122             (long int)((p_ptr->total_weight * 100) / weight_limit()));
123 #else
124         sprintf(out_val, "Equipment: carrying %d.%d pounds (%ld%% of capacity). Command: ",
125             (int)(p_ptr->total_weight / 10), (int)(p_ptr->total_weight % 10),
126             (long int)((p_ptr->total_weight * 100) / weight_limit()));
127 #endif
128
129
130         /* Get a command */
131         prt(out_val, 0, 0);
132
133         /* Get a new command */
134         command_new = inkey();
135         screen_load();
136
137
138         /* Process "Escape" */
139         if (command_new == ESCAPE)
140         {
141                 int wid, hgt;
142
143                 Term_get_size(&wid, &hgt);
144
145                 /* Reset stuff */
146                 command_new = 0;
147                 command_gap = wid - 30;
148         }
149
150         /* Process normal keys */
151         else
152         {
153                 /* Enter "display" mode */
154                 command_see = TRUE;
155         }
156 }
157
158
159
160
161 bool select_ring_slot = FALSE;
162
163 /*!
164  * @brief 装備するコマンドのメインルーチン / Wield or wear a single item from the pack or floor
165  * @return なし 
166  */
167 void do_cmd_wield(void)
168 {
169         OBJECT_IDX item, slot;
170         object_type forge;
171         object_type *q_ptr;
172         object_type *o_ptr;
173
174         cptr act;
175         cptr q, s;
176
177         char o_name[MAX_NLEN];
178
179
180         OBJECT_IDX need_switch_wielding = 0;
181
182         if (p_ptr->special_defense & KATA_MUSOU)
183         {
184                 set_action(ACTION_NONE);
185         }
186
187         /* Restrict the choices */
188         item_tester_hook = item_tester_hook_wear;
189
190         q = _("どれを装備しますか? ", "Wear/Wield which item? ");
191         s = _("装備可能なアイテムがない。", "You have nothing you can wear or wield.");
192
193         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
194         if (!o_ptr) return;
195
196         /* Check the slot */
197         slot = wield_slot(o_ptr);
198
199         switch (o_ptr->tval)
200         {
201         /* Shields and some misc. items */
202         case TV_CAPTURE:
203         case TV_SHIELD:
204         case TV_CARD:
205                 /* Dual wielding */
206                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
207                 {
208                         /* Restrict the choices */
209                         item_tester_hook = item_tester_hook_melee_weapon;
210                         item_tester_no_ryoute = TRUE;
211
212                         /* Choose a weapon from the equipment only */
213                         q = _("どちらの武器と取り替えますか?", "Replace which weapon? ");
214                         s = _("おっと。", "Oops.");
215                         if (!get_item(&slot, q, s, (USE_EQUIP))) return;
216                         if (slot == INVEN_RARM) need_switch_wielding = INVEN_LARM;
217                 }
218
219                 else if (buki_motteruka(INVEN_LARM)) slot = INVEN_RARM;
220
221                 /* Both arms are already used by non-weapon */
222                 else if (inventory[INVEN_RARM].k_idx && !object_is_melee_weapon(&inventory[INVEN_RARM]) &&
223                          inventory[INVEN_LARM].k_idx && !object_is_melee_weapon(&inventory[INVEN_LARM]))
224                 {
225                         /* Restrict the choices */
226                         item_tester_hook = item_tester_hook_mochikae;
227
228                         /* Choose a hand */
229                         q = _("どちらの手に装備しますか?", "Equip which hand? ");
230                         s = _("おっと。", "Oops.");
231                         if (!get_item(&slot, q, s, (USE_EQUIP))) return;
232                 }
233                 break;
234
235         /* Melee weapons */
236         case TV_DIGGING:
237         case TV_HAFTED:
238         case TV_POLEARM:
239         case TV_SWORD:
240                 /* Asking for dual wielding */
241                 if (slot == INVEN_LARM)
242                 {
243                         if (!get_check(_("二刀流で戦いますか?", "Dual wielding? "))) slot = INVEN_RARM;
244                 }
245
246                 else if (!inventory[INVEN_RARM].k_idx && buki_motteruka(INVEN_LARM))
247                 {
248                         if (!get_check(_("二刀流で戦いますか?", "Dual wielding? "))) slot = INVEN_LARM;
249                 }
250
251                 /* Both arms are already used */
252                 else if (inventory[INVEN_LARM].k_idx && inventory[INVEN_RARM].k_idx)
253                 {
254                         /* Restrict the choices */
255                         item_tester_hook = item_tester_hook_mochikae;
256
257                         /* Choose a hand */
258                         q = _("どちらの手に装備しますか?", "Equip which hand? ");
259                         s = _("おっと。", "Oops.");
260                         
261                         if (!get_item(&slot, q, s, (USE_EQUIP))) return;
262                         if ((slot == INVEN_LARM) && !buki_motteruka(INVEN_RARM))
263                                 need_switch_wielding = INVEN_RARM;
264                 }
265                 break;
266
267         /* Rings */
268         case TV_RING:
269                 /* Choose a ring slot */
270                 if (inventory[INVEN_LEFT].k_idx && inventory[INVEN_RIGHT].k_idx)
271                 {
272                         q = _("どちらの指輪と取り替えますか?", "Replace which ring? ");
273                 }
274                 else
275                 {
276                         q = _("どちらの手に装備しますか?", "Equip which hand? ");
277                 }
278                 s = _("おっと。", "Oops.");
279
280                 /* Restrict the choices */
281                 select_ring_slot = TRUE;
282                 item_tester_no_ryoute = TRUE;
283
284                 if (!get_item(&slot, q, s, (USE_EQUIP)))
285                 {
286                         select_ring_slot = FALSE;
287                         return;
288                 }
289                 select_ring_slot = FALSE;
290                 break;
291         }
292
293         /* Prevent wielding into a cursed slot */
294         if (object_is_cursed(&inventory[slot]))
295         {
296                 /* Describe it */
297                 object_desc(o_name, &inventory[slot], (OD_OMIT_PREFIX | OD_NAME_ONLY));
298
299 #ifdef JP
300                 msg_format("%s%sは呪われているようだ。",
301                            describe_use(slot) , o_name );
302 #else
303                 msg_format("The %s you are %s appears to be cursed.",
304                            o_name, describe_use(slot));
305 #endif
306
307                 /* Cancel the command */
308                 return;
309         }
310
311         if (confirm_wear &&
312                 ((object_is_cursed(o_ptr) && object_is_known(o_ptr)) ||
313                 ((o_ptr->ident & IDENT_SENSE) &&
314                         (FEEL_BROKEN <= o_ptr->feeling) && (o_ptr->feeling <= FEEL_CURSED))))
315         {
316                 char dummy[MAX_NLEN+80];
317
318                 /* Describe it */
319                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
320                 sprintf(dummy, _("本当に%s{呪われている}を使いますか?", "Really use the %s {cursed}? "), o_name);
321
322                 if (!get_check(dummy)) return;
323         }
324
325         if ((o_ptr->name1 == ART_STONEMASK) && object_is_known(o_ptr) && (p_ptr->prace != RACE_VAMPIRE) && (p_ptr->prace != RACE_ANDROID))
326         {
327                 char dummy[MAX_NLEN+80];
328
329                 /* Describe it */
330                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
331
332 #ifdef JP
333                 sprintf(dummy, "%sを装備すると吸血鬼になります。よろしいですか?", o_name);
334 #else
335                 msg_format("%s will transforms you into a vampire permanently when equiped.", o_name);
336                 sprintf(dummy, "Do you become a vampire?");
337 #endif
338
339                 if (!get_check(dummy)) return;
340         }
341
342         if (need_switch_wielding && !object_is_cursed(&inventory[need_switch_wielding]))
343         {
344                 object_type *slot_o_ptr = &inventory[slot];
345                 object_type *switch_o_ptr = &inventory[need_switch_wielding];
346                 object_type object_tmp;
347                 object_type *otmp_ptr = &object_tmp;
348                 char switch_name[MAX_NLEN];
349
350                 object_desc(switch_name, switch_o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
351
352                 object_copy(otmp_ptr, switch_o_ptr);
353                 object_copy(switch_o_ptr, slot_o_ptr);
354                 object_copy(slot_o_ptr, otmp_ptr);
355                 
356                 msg_format(_("%sを%sに構えなおした。", "You wield %s at %s hand."), switch_name, 
357                                         (slot == INVEN_RARM) ? (left_hander ? _("左手", "left") : _("右手", "right")) : 
358                                                                                    (left_hander ? _("右手", "right") : _("左手", "left")));
359                 slot = need_switch_wielding;
360         }
361
362         check_find_art_quest_completion(o_ptr);
363
364         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
365         {
366                 identify_item(o_ptr);
367
368                 /* Auto-inscription */
369                 autopick_alter_item(item, FALSE);
370         }
371
372         p_ptr->energy_use = 100;
373         q_ptr = &forge;
374
375         /* Obtain local object */
376         object_copy(q_ptr, o_ptr);
377
378         /* Modify quantity */
379         q_ptr->number = 1;
380
381         /* Decrease the item (from the pack) */
382         if (item >= 0)
383         {
384                 inven_item_increase(item, -1);
385                 inven_item_optimize(item);
386         }
387
388         /* Decrease the item (from the floor) */
389         else
390         {
391                 floor_item_increase(0 - item, -1);
392                 floor_item_optimize(0 - item);
393         }
394
395         /* Access the wield slot */
396         o_ptr = &inventory[slot];
397
398         /* Take off existing item */
399         if (o_ptr->k_idx)
400         {
401                 /* Take off existing item */
402                 (void)inven_takeoff(slot, 255);
403         }
404
405         /* Wear the new stuff */
406         object_copy(o_ptr, q_ptr);
407
408         /* Player touches it */
409         o_ptr->marked |= OM_TOUCHED;
410
411         /* Increase the weight */
412         p_ptr->total_weight += q_ptr->weight;
413
414         /* Increment the equip counter by hand */
415         equip_cnt++;
416
417 #ifdef JP
418 #define STR_WIELD_RARM "%s(%c)を右手に装備した。"
419 #define STR_WIELD_LARM "%s(%c)を左手に装備した。"
420 #define STR_WIELD_ARMS "%s(%c)を両手で構えた。"
421 #else
422 #define STR_WIELD_RARM "You are wielding %s (%c) in your right hand."
423 #define STR_WIELD_LARM "You are wielding %s (%c) in your left hand."
424 #define STR_WIELD_ARMS "You are wielding %s (%c) with both hands."
425 #endif
426
427         /* Where is the item now */
428         switch (slot)
429         {
430         case INVEN_RARM:
431                 if (object_allow_two_hands_wielding(o_ptr) && (empty_hands(FALSE) == EMPTY_HAND_LARM) && CAN_TWO_HANDS_WIELDING())
432                         act = STR_WIELD_ARMS;
433                 else
434                         act = (left_hander ? STR_WIELD_LARM : STR_WIELD_RARM);
435                 break;
436
437         case INVEN_LARM:
438                 if (object_allow_two_hands_wielding(o_ptr) && (empty_hands(FALSE) == EMPTY_HAND_RARM) && CAN_TWO_HANDS_WIELDING())
439                         act = STR_WIELD_ARMS;
440                 else
441                         act = (left_hander ? STR_WIELD_RARM : STR_WIELD_LARM);
442                 break;
443
444         case INVEN_BOW:
445                 act = _("%s(%c)を射撃用に装備した。", "You are shooting with %s (%c).");
446                 break;
447
448         case INVEN_LITE:
449                 act = _("%s(%c)を光源にした。", "Your light source is %s (%c).");
450                 break;
451
452         default:
453                 act = _("%s(%c)を装備した。", "You are wearing %s (%c).");
454                 break;
455         }
456
457         /* Describe the result */
458         object_desc(o_name, o_ptr, 0);
459         msg_format(act, o_name, index_to_label(slot));
460
461         /* Cursed! */
462         if (object_is_cursed(o_ptr))
463         {
464                 /* Warn the player */
465                 msg_print(_("うわ! すさまじく冷たい!", "Oops! It feels deathly cold!"));
466                 chg_virtue(V_HARMONY, -1);
467
468                 /* Note the curse */
469                 o_ptr->ident |= (IDENT_SENSE);
470         }
471
472         /* The Stone Mask make the player turn into a vampire! */
473         if ((o_ptr->name1 == ART_STONEMASK) && (p_ptr->prace != RACE_VAMPIRE) && (p_ptr->prace != RACE_ANDROID))
474         {
475                 /* Turn into a vampire */
476                 change_race(RACE_VAMPIRE, "");
477         }
478
479         /* Recalculate bonuses */
480         p_ptr->update |= (PU_BONUS);
481
482         /* Recalculate torch */
483         p_ptr->update |= (PU_TORCH);
484
485         /* Recalculate mana */
486         p_ptr->update |= (PU_MANA);
487
488         p_ptr->redraw |= (PR_EQUIPPY);
489
490         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
491
492         calc_android_exp();
493 }
494
495 /*!
496  * @brief 持ち替え処理
497  * @param item 持ち替えを行いたい装備部位ID
498  * @return なし
499  */
500 void kamaenaoshi(INVENTORY_IDX item)
501 {
502         object_type *o_ptr, *new_o_ptr;
503         char o_name[MAX_NLEN];
504
505         if (item == INVEN_RARM)
506         {
507                 if (buki_motteruka(INVEN_LARM))
508                 {
509                         o_ptr = &inventory[INVEN_LARM];
510                         object_desc(o_name, o_ptr, 0);
511
512                         if (!object_is_cursed(o_ptr))
513                         {
514                                 new_o_ptr = &inventory[INVEN_RARM];
515                                 object_copy(new_o_ptr, o_ptr);
516                                 p_ptr->total_weight += o_ptr->weight;
517                                 inven_item_increase(INVEN_LARM, -((int)o_ptr->number));
518                                 inven_item_optimize(INVEN_LARM);
519                                 if (object_allow_two_hands_wielding(o_ptr) && CAN_TWO_HANDS_WIELDING())
520                                         msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
521                                  else
522                                 msg_format(_("%sを%sで構えた。", "You are wielding %s in your %s hand."), o_name, 
523                                                         (left_hander ? _("左手", "left") : _("右手", "right")));
524                         }
525                         else
526                         {
527                                 if (object_allow_two_hands_wielding(o_ptr) && CAN_TWO_HANDS_WIELDING())
528                                         msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
529                         }
530                 }
531         }
532         else if (item == INVEN_LARM)
533         {
534                 o_ptr = &inventory[INVEN_RARM];
535                 if (o_ptr->k_idx) object_desc(o_name, o_ptr, 0);
536
537                 if (buki_motteruka(INVEN_RARM))
538                 {
539                         if (object_allow_two_hands_wielding(o_ptr) && CAN_TWO_HANDS_WIELDING())
540                                 msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
541                 }
542                 else if (!(empty_hands(FALSE) & EMPTY_HAND_RARM) && !object_is_cursed(o_ptr))
543                 {
544                         new_o_ptr = &inventory[INVEN_LARM];
545                         object_copy(new_o_ptr, o_ptr);
546                         p_ptr->total_weight += o_ptr->weight;
547                         inven_item_increase(INVEN_RARM, -((int)o_ptr->number));
548                         inven_item_optimize(INVEN_RARM);
549                         msg_format(_("%sを持ち替えた。", "You switched hand of %s."), o_name);
550                 }
551         }
552 }
553
554
555 /*!
556  * @brief 装備を外すコマンドのメインルーチン / Take off an item
557  * @return なし
558  */
559 void do_cmd_takeoff(void)
560 {
561         OBJECT_IDX item;
562         object_type *o_ptr;
563         cptr q, s;
564
565         if (p_ptr->special_defense & KATA_MUSOU)
566         {
567                 set_action(ACTION_NONE);
568         }
569
570         item_tester_no_ryoute = TRUE;
571
572         q = _("どれを装備からはずしますか? ", "Take off which item? ");
573         s = _("はずせる装備がない。", "You are not wearing anything to take off.");
574
575         if (!get_item(&item, q, s, (USE_EQUIP))) return;
576
577         /* Get the item (in the pack) */
578         if (item >= 0)
579         {
580                 o_ptr = &inventory[item];
581         }
582
583         /* Get the item (on the floor) */
584         else
585         {
586                 o_ptr = &o_list[0 - item];
587         }
588
589
590         /* Item is cursed */
591         if (object_is_cursed(o_ptr))
592         {
593                 if ((o_ptr->curse_flags & TRC_PERMA_CURSE) || (p_ptr->pclass != CLASS_BERSERKER))
594                 {
595                         msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
596
597                         return;
598                 }
599
600                 if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && one_in_(7)) || one_in_(4))
601                 {
602                         msg_print(_("呪われた装備を力づくで剥がした!", "You teared a cursed equipment off by sheer strength!"));
603
604                         /* Hack -- Assume felt */
605                         o_ptr->ident |= (IDENT_SENSE);
606
607                         o_ptr->curse_flags = 0L;
608
609                         /* Take note */
610                         o_ptr->feeling = FEEL_NONE;
611
612                         /* Recalculate the bonuses */
613                         p_ptr->update |= (PU_BONUS);
614
615                         p_ptr->window |= (PW_EQUIP);
616
617                         msg_print(_("呪いを打ち破った。", "You break the curse."));
618                 }
619                 else
620                 {
621                         msg_print(_("装備を外せなかった。", "You couldn't remove the equipment."));
622                         p_ptr->energy_use = 50;
623                         return;
624                 }
625         }
626
627         /* Take a partial turn */
628         p_ptr->energy_use = 50;
629
630         /* Take off the item */
631         (void)inven_takeoff(item, 255);
632         kamaenaoshi(item);
633         calc_android_exp();
634         p_ptr->redraw |= (PR_EQUIPPY);
635 }
636
637
638 /*!
639  * @brief アイテムを落とすコマンドのメインルーチン / Drop an item
640  * @return なし
641  */
642 void do_cmd_drop(void)
643 {
644         OBJECT_IDX item;
645         int amt = 1;
646
647         object_type *o_ptr;
648
649         cptr q, s;
650
651         if (p_ptr->special_defense & KATA_MUSOU)
652         {
653                 set_action(ACTION_NONE);
654         }
655
656         item_tester_no_ryoute = TRUE;
657         q = _("どのアイテムを落としますか? ", "Drop which item? ");
658         s = _("落とせるアイテムを持っていない。", "You have nothing to drop.");
659
660         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN))) return;
661
662         /* Get the item (in the pack) */
663         if (item >= 0)
664         {
665                 o_ptr = &inventory[item];
666         }
667
668         /* Get the item (on the floor) */
669         else
670         {
671                 o_ptr = &o_list[0 - item];
672         }
673
674
675         /* Hack -- Cannot remove cursed items */
676         if ((item >= INVEN_RARM) && object_is_cursed(o_ptr))
677         {
678                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
679                 return;
680         }
681
682
683         /* See how many items */
684         if (o_ptr->number > 1)
685         {
686                 /* Get a quantity */
687                 amt = get_quantity(NULL, o_ptr->number);
688
689                 /* Allow user abort */
690                 if (amt <= 0) return;
691         }
692
693
694         /* Take a partial turn */
695         p_ptr->energy_use = 50;
696
697         /* Drop (some of) the item */
698         inven_drop(item, amt);
699
700         if (item >= INVEN_RARM)
701         {
702                 kamaenaoshi(item);
703                 calc_android_exp();
704         }
705
706         p_ptr->redraw |= (PR_EQUIPPY);
707 }
708
709 /*!
710  * @brief オブジェクトが高位の魔法書かどうかを判定する
711  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
712  * @return オブジェクトが高位の魔法書ならばTRUEを返す
713  */
714 static bool high_level_book(object_type *o_ptr)
715 {
716         if ((o_ptr->tval == TV_LIFE_BOOK) ||
717             (o_ptr->tval == TV_SORCERY_BOOK) ||
718             (o_ptr->tval == TV_NATURE_BOOK) ||
719             (o_ptr->tval == TV_CHAOS_BOOK) ||
720             (o_ptr->tval == TV_DEATH_BOOK) ||
721             (o_ptr->tval == TV_TRUMP_BOOK) ||
722             (o_ptr->tval == TV_CRAFT_BOOK) ||
723             (o_ptr->tval == TV_DAEMON_BOOK) ||
724             (o_ptr->tval == TV_CRUSADE_BOOK) ||
725             (o_ptr->tval == TV_MUSIC_BOOK) ||
726                 (o_ptr->tval == TV_HEX_BOOK))
727         {
728                 if (o_ptr->sval > 1)
729                         return TRUE;
730                 else
731                         return FALSE;
732         }
733
734         return FALSE;
735 }
736
737
738 /*!
739  * @brief アイテムを破壊するコマンドのメインルーチン / Destroy an item
740  * @return なし
741  */
742 void do_cmd_destroy(void)
743 {
744         OBJECT_IDX item;
745         QUANTITY amt = 1;
746         QUANTITY old_number;
747
748         bool force = FALSE;
749
750         object_type *o_ptr;
751         object_type forge;
752         object_type *q_ptr = &forge;
753
754         char o_name[MAX_NLEN];
755         char out_val[MAX_NLEN+40];
756
757         cptr q, s;
758
759         if (p_ptr->special_defense & KATA_MUSOU)
760         {
761                 set_action(ACTION_NONE);
762         }
763
764         /* Hack -- force destruction */
765         if (command_arg > 0) force = TRUE;
766
767         q = _("どのアイテムを壊しますか? ", "Destroy which item? ");
768         s = _("壊せるアイテムを持っていない。", "You have nothing to destroy.");
769
770         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
771
772         /* Get the item (in the pack) */
773         if (item >= 0)
774         {
775                 o_ptr = &inventory[item];
776         }
777
778         /* Get the item (on the floor) */
779         else
780         {
781                 o_ptr = &o_list[0 - item];
782         }
783
784         /* Verify unless quantity given beforehand */
785         if (!force && (confirm_destroy || (object_value(o_ptr) > 0)))
786         {
787                 object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
788
789                 /* Make a verification */
790                 sprintf(out_val, _("本当に%sを壊しますか? [y/n/Auto]", "Really destroy %s? [y/n/Auto]"), o_name);
791                 msg_print(NULL);
792
793                 /* HACK : Add the line to message buffer */
794                 message_add(out_val);
795                 p_ptr->window |= (PW_MESSAGE);
796                 handle_stuff();
797
798                 /* Get an acceptable answer */
799                 while (TRUE)
800                 {
801                         char i;
802
803                         /* Prompt */
804                         prt(out_val, 0, 0);
805
806                         i = inkey();
807
808                         /* Erase the prompt */
809                         prt("", 0, 0);
810
811
812                         if (i == 'y' || i == 'Y')
813                         {
814                                 break;
815                         }
816                         if (i == ESCAPE || i == 'n' || i == 'N')
817                         {
818                                 /* Cancel */
819                                 return;
820                         }
821                         if (i == 'A')
822                         {
823                                 /* Add an auto-destroy preference line */
824                                 if (autopick_autoregister(o_ptr))
825                                 {
826                                         /* Auto-destroy it */
827                                         autopick_alter_item(item, TRUE);
828                                 }
829
830                                 /* The object is already destroyed. */
831                                 return;
832                         }
833                 } /* while (TRUE) */
834         }
835
836         /* See how many items */
837         if (o_ptr->number > 1)
838         {
839                 /* Get a quantity */
840                 amt = get_quantity(NULL, o_ptr->number);
841
842                 /* Allow user abort */
843                 if (amt <= 0) return;
844         }
845
846
847         old_number = o_ptr->number;
848         o_ptr->number = amt;
849         object_desc(o_name, o_ptr, 0);
850         o_ptr->number = old_number;
851
852         p_ptr->energy_use = 100;
853
854         /* Artifacts cannot be destroyed */
855         if (!can_player_destroy_object(o_ptr))
856         {
857                 p_ptr->energy_use = 0;
858
859                 msg_format(_("%sは破壊不可能だ。", "You cannot destroy %s."), o_name);
860                 return;
861         }
862
863         object_copy(q_ptr, o_ptr);
864
865         msg_format(_("%sを壊した。", "You destroy %s."), o_name);
866         sound(SOUND_DESTITEM);
867
868         /* Reduce the charges of rods/wands */
869         reduce_charges(o_ptr, amt);
870
871         /* Eliminate the item (from the pack) */
872         if (item >= 0)
873         {
874                 inven_item_increase(item, -amt);
875                 inven_item_describe(item);
876                 inven_item_optimize(item);
877         }
878
879         /* Eliminate the item (from the floor) */
880         else
881         {
882                 floor_item_increase(0 - item, -amt);
883                 floor_item_describe(0 - item);
884                 floor_item_optimize(0 - item);
885         }
886
887         if (high_level_book(q_ptr))
888         {
889                 bool gain_expr = FALSE;
890
891                 if (p_ptr->prace == RACE_ANDROID)
892                 {
893                 }
894                 else if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_BERSERKER))
895                 {
896                         gain_expr = TRUE;
897                 }
898                 else if (p_ptr->pclass == CLASS_PALADIN)
899                 {
900                         if (is_good_realm(p_ptr->realm1))
901                         {
902                                 if (!is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE;
903                         }
904                         else
905                         {
906                                 if (is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE;
907                         }
908                 }
909
910                 if (gain_expr && (p_ptr->exp < PY_MAX_EXP))
911                 {
912                         s32b tester_exp = p_ptr->max_exp / 20;
913                         if (tester_exp > 10000) tester_exp = 10000;
914                         if (q_ptr->sval < 3) tester_exp /= 4;
915                         if (tester_exp<1) tester_exp = 1;
916
917                         msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
918                         gain_exp(tester_exp * amt);
919                 }
920                 if (high_level_book(q_ptr) && q_ptr->tval == TV_LIFE_BOOK)
921                 {
922                         chg_virtue(V_UNLIFE, 1);
923                         chg_virtue(V_VITALITY, -1);
924                 }
925                 else if (high_level_book(q_ptr) && q_ptr->tval == TV_DEATH_BOOK)
926                 {
927                         chg_virtue(V_UNLIFE, -1);
928                         chg_virtue(V_VITALITY, 1);
929                 }
930         
931                 if (q_ptr->to_a || q_ptr->to_h || q_ptr->to_d)
932                         chg_virtue(V_ENCHANT, -1);
933         
934                 if (object_value_real(q_ptr) > 30000)
935                         chg_virtue(V_SACRIFICE, 2);
936         
937                 else if (object_value_real(q_ptr) > 10000)
938                         chg_virtue(V_SACRIFICE, 1);
939         }
940
941         if (q_ptr->to_a != 0 || q_ptr->to_d != 0 || q_ptr->to_h != 0)
942                 chg_virtue(V_HARMONY, 1);
943
944         if (item >= INVEN_RARM) calc_android_exp();
945 }
946
947
948 /*!
949  * @brief アイテムを調査するコマンドのメインルーチン / Observe an item which has been *identify*-ed
950  * @return なし
951  */
952 void do_cmd_observe(void)
953 {
954         OBJECT_IDX item;
955         object_type             *o_ptr;
956         char            o_name[MAX_NLEN];
957
958         cptr q, s;
959
960         item_tester_no_ryoute = TRUE;
961
962         q = _("どのアイテムを調べますか? ", "Examine which item? ");
963         s = _("調べられるアイテムがない。", "You have nothing to examine.");
964
965         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
966
967         /* Get the item (in the pack) */
968         if (item >= 0)
969         {
970                 o_ptr = &inventory[item];
971         }
972
973         /* Get the item (on the floor) */
974         else
975         {
976                 o_ptr = &o_list[0 - item];
977         }
978
979
980         /* Require full knowledge */
981         if (!(o_ptr->ident & IDENT_MENTAL))
982         {
983                 msg_print(_("このアイテムについて特に知っていることはない。", "You have no special knowledge about that item."));
984                 return;
985         }
986
987
988         /* Description */
989         object_desc(o_name, o_ptr, 0);
990         msg_format(_("%sを調べている...", "Examining %s..."), o_name);
991         /* Describe it fully */
992         if (!screen_object(o_ptr, SCROBJ_FORCE_DETAIL)) msg_print(_("特に変わったところはないようだ。", "You see nothing special."));
993 }
994
995
996
997 /*!
998  * @brief アイテムの銘を消すコマンドのメインルーチン
999  * Remove the inscription from an object XXX Mention item (when done)?
1000  * @return なし
1001  */
1002 void do_cmd_uninscribe(void)
1003 {
1004         OBJECT_IDX item;
1005         object_type *o_ptr;
1006         cptr q, s;
1007
1008         item_tester_no_ryoute = TRUE;
1009         q = _("どのアイテムの銘を消しますか? ", "Un-inscribe which item? ");
1010         s = _("銘を消せるアイテムがない。", "You have nothing to un-inscribe.");
1011
1012         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1013
1014         /* Get the item (in the pack) */
1015         if (item >= 0)
1016         {
1017                 o_ptr = &inventory[item];
1018         }
1019
1020         /* Get the item (on the floor) */
1021         else
1022         {
1023                 o_ptr = &o_list[0 - item];
1024         }
1025
1026         /* Nothing to remove */
1027         if (!o_ptr->inscription)
1028         {
1029                 msg_print(_("このアイテムには消すべき銘がない。", "That item had no inscription to remove."));
1030                 return;
1031         }
1032
1033         msg_print(_("銘を消した。", "Inscription removed."));
1034
1035         /* Remove the incription */
1036         o_ptr->inscription = 0;
1037
1038         /* Combine the pack */
1039         p_ptr->notice |= (PN_COMBINE);
1040
1041         p_ptr->window |= (PW_INVEN | PW_EQUIP);
1042
1043         /* .や$の関係で, 再計算が必要なはず -- henkma */
1044         p_ptr->update |= (PU_BONUS);
1045
1046 }
1047
1048
1049 /*!
1050  * @brief アイテムの銘を刻むコマンドのメインルーチン
1051  * Inscribe an object with a comment
1052  * @return なし
1053  */
1054 void do_cmd_inscribe(void)
1055 {
1056         OBJECT_IDX item;
1057         object_type             *o_ptr;
1058         char            o_name[MAX_NLEN];
1059         char            out_val[80];
1060         cptr q, s;
1061
1062         item_tester_no_ryoute = TRUE;
1063         q = _("どのアイテムに銘を刻みますか? ", "Inscribe which item? ");
1064         s = _("銘を刻めるアイテムがない。", "You have nothing to inscribe.");
1065
1066         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1067
1068         /* Get the item (in the pack) */
1069         if (item >= 0)
1070         {
1071                 o_ptr = &inventory[item];
1072         }
1073
1074         /* Get the item (on the floor) */
1075         else
1076         {
1077                 o_ptr = &o_list[0 - item];
1078         }
1079
1080         /* Describe the activity */
1081         object_desc(o_name, o_ptr, OD_OMIT_INSCRIPTION);
1082
1083         msg_format(_("%sに銘を刻む。", "Inscribing %s."), o_name);
1084         msg_print(NULL);
1085
1086         /* Start with nothing */
1087         strcpy(out_val, "");
1088
1089         /* Use old inscription */
1090         if (o_ptr->inscription)
1091         {
1092                 /* Start with the old inscription */
1093                 strcpy(out_val, quark_str(o_ptr->inscription));
1094         }
1095
1096         /* Get a new inscription (possibly empty) */
1097         if (get_string(_("銘: ", "Inscription: "), out_val, 80))
1098         {
1099                 /* Save the inscription */
1100                 o_ptr->inscription = quark_add(out_val);
1101
1102                 /* Combine the pack */
1103                 p_ptr->notice |= (PN_COMBINE);
1104
1105                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
1106
1107                 /* .や$の関係で, 再計算が必要なはず -- henkma */
1108                 p_ptr->update |= (PU_BONUS);
1109         }
1110 }
1111
1112
1113
1114 /*!
1115  * @brief オブジェクトがランタンの燃料になるかどうかを判定する
1116  * An "item_tester_hook" for refilling lanterns
1117  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1118  * @return オブジェクトがランタンの燃料になるならばTRUEを返す
1119  */
1120 static bool item_tester_refill_lantern(object_type *o_ptr)
1121 {
1122         /* Flasks of oil are okay */
1123         if (o_ptr->tval == TV_FLASK) return (TRUE);
1124
1125         /* Laterns are okay */
1126         if ((o_ptr->tval == TV_LITE) &&
1127             (o_ptr->sval == SV_LITE_LANTERN)) return (TRUE);
1128
1129         /* Assume not okay */
1130         return (FALSE);
1131 }
1132
1133
1134 /*!
1135  * @brief ランタンに燃料を加えるコマンドのメインルーチン
1136  * Refill the players lamp (from the pack or floor)
1137  * @return なし
1138  */
1139 static void do_cmd_refill_lamp(void)
1140 {
1141         OBJECT_IDX item;
1142
1143         object_type *o_ptr;
1144         object_type *j_ptr;
1145
1146         cptr q, s;
1147
1148
1149         /* Restrict the choices */
1150         item_tester_hook = item_tester_refill_lantern;
1151
1152 #ifdef JP
1153         q = "どの油つぼから注ぎますか? ";
1154         s = "油つぼがない。";
1155 #else
1156         q = "Refill with which flask? ";
1157         s = "You have no flasks of oil.";
1158 #endif
1159
1160         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
1161
1162         /* Get the item (in the pack) */
1163         if (item >= 0)
1164         {
1165                 o_ptr = &inventory[item];
1166         }
1167
1168         /* Get the item (on the floor) */
1169         else
1170         {
1171                 o_ptr = &o_list[0 - item];
1172         }
1173
1174         /* Take a partial turn */
1175         p_ptr->energy_use = 50;
1176
1177         /* Access the lantern */
1178         j_ptr = &inventory[INVEN_LITE];
1179
1180         /* Refuel */
1181         j_ptr->xtra4 += o_ptr->xtra4;
1182         msg_print(_("ランプに油を注いだ。", "You fuel your lamp."));
1183
1184         if ((o_ptr->name2 == EGO_LITE_DARKNESS) && (j_ptr->xtra4 > 0))
1185         {
1186                 j_ptr->xtra4 = 0;
1187                 msg_print(_("ランプが消えてしまった!", "Your lamp has gone out!"));
1188         }
1189         else if ((o_ptr->name2 == EGO_LITE_DARKNESS) || (j_ptr->name2 == EGO_LITE_DARKNESS))
1190         {
1191                 j_ptr->xtra4 = 0;
1192                 msg_print(_("しかしランプは全く光らない。", "Curiously, your lamp doesn't light."));
1193         }
1194         else if (j_ptr->xtra4 >= FUEL_LAMP)
1195         {
1196                 j_ptr->xtra4 = FUEL_LAMP;
1197                 msg_print(_("ランプの油は一杯だ。", "Your lamp is full."));
1198         }
1199
1200         /* Decrease the item (from the pack) */
1201         if (item >= 0)
1202         {
1203                 inven_item_increase(item, -1);
1204                 inven_item_describe(item);
1205                 inven_item_optimize(item);
1206         }
1207
1208         /* Decrease the item (from the floor) */
1209         else
1210         {
1211                 floor_item_increase(0 - item, -1);
1212                 floor_item_describe(0 - item);
1213                 floor_item_optimize(0 - item);
1214         }
1215
1216         /* Recalculate torch */
1217         p_ptr->update |= (PU_TORCH);
1218 }
1219
1220
1221 /*!
1222  * @brief オブジェクトが松明に束ねられるかどうかを判定する
1223  * An "item_tester_hook" for refilling torches
1224  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1225  * @return オブジェクトが松明に束ねられるならばTRUEを返す
1226  */
1227 static bool item_tester_refill_torch(object_type *o_ptr)
1228 {
1229         /* Torches are okay */
1230         if ((o_ptr->tval == TV_LITE) &&
1231             (o_ptr->sval == SV_LITE_TORCH)) return (TRUE);
1232
1233         /* Assume not okay */
1234         return (FALSE);
1235 }
1236
1237
1238 /*!
1239  * @brief 松明を束ねるコマンドのメインルーチン
1240  * Refuel the players torch (from the pack or floor)
1241  * @return なし
1242  */
1243 static void do_cmd_refill_torch(void)
1244 {
1245         OBJECT_IDX item;
1246
1247         object_type *o_ptr;
1248         object_type *j_ptr;
1249
1250         cptr q, s;
1251
1252         /* Restrict the choices */
1253         item_tester_hook = item_tester_refill_torch;
1254
1255         q = _("どの松明で明かりを強めますか? ", "Refuel with which torch? ");
1256         s = _("他に松明がない。", "You have no extra torches.");
1257
1258         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
1259
1260         /* Get the item (in the pack) */
1261         if (item >= 0)
1262         {
1263                 o_ptr = &inventory[item];
1264         }
1265
1266         /* Get the item (on the floor) */
1267         else
1268         {
1269                 o_ptr = &o_list[0 - item];
1270         }
1271
1272
1273         /* Take a partial turn */
1274         p_ptr->energy_use = 50;
1275
1276         /* Access the primary torch */
1277         j_ptr = &inventory[INVEN_LITE];
1278
1279         /* Refuel */
1280         j_ptr->xtra4 += o_ptr->xtra4 + 5;
1281
1282         msg_print(_("松明を結合した。", "You combine the torches."));
1283
1284         if ((o_ptr->name2 == EGO_LITE_DARKNESS) && (j_ptr->xtra4 > 0))
1285         {
1286                 j_ptr->xtra4 = 0;
1287                 msg_print(_("松明が消えてしまった!", "Your torch has gone out!"));
1288         }
1289         else if ((o_ptr->name2 == EGO_LITE_DARKNESS) || (j_ptr->name2 == EGO_LITE_DARKNESS))
1290         {
1291                 j_ptr->xtra4 = 0;
1292                 msg_print(_("しかし松明は全く光らない。", "Curiously, your torche don't light."));
1293         }
1294         /* Over-fuel message */
1295         else if (j_ptr->xtra4 >= FUEL_TORCH)
1296         {
1297                 j_ptr->xtra4 = FUEL_TORCH;
1298                 msg_print(_("松明の寿命は十分だ。", "Your torch is fully fueled."));
1299         }
1300
1301         /* Refuel message */
1302         else
1303         {
1304                 msg_print(_("松明はいっそう明るく輝いた。", "Your torch glows more brightly."));
1305         }
1306
1307         /* Decrease the item (from the pack) */
1308         if (item >= 0)
1309         {
1310                 inven_item_increase(item, -1);
1311                 inven_item_describe(item);
1312                 inven_item_optimize(item);
1313         }
1314
1315         /* Decrease the item (from the floor) */
1316         else
1317         {
1318                 floor_item_increase(0 - item, -1);
1319                 floor_item_describe(0 - item);
1320                 floor_item_optimize(0 - item);
1321         }
1322
1323         /* Recalculate torch */
1324         p_ptr->update |= (PU_TORCH);
1325 }
1326
1327
1328 /*!
1329  * @brief 燃料を補充するコマンドのメインルーチン
1330  * Refill the players lamp, or restock his torches
1331  * @return なし
1332  */
1333 void do_cmd_refill(void)
1334 {
1335         object_type *o_ptr;
1336
1337         /* Get the light */
1338         o_ptr = &inventory[INVEN_LITE];
1339
1340         if (p_ptr->special_defense & KATA_MUSOU)
1341         {
1342                 set_action(ACTION_NONE);
1343         }
1344
1345         /* It is nothing */
1346         if (o_ptr->tval != TV_LITE)
1347         {
1348                 msg_print(_("光源を装備していない。", "You are not wielding a light."));
1349         }
1350
1351         /* It's a lamp */
1352         else if (o_ptr->sval == SV_LITE_LANTERN)
1353         {
1354                 do_cmd_refill_lamp();
1355         }
1356
1357         /* It's a torch */
1358         else if (o_ptr->sval == SV_LITE_TORCH)
1359         {
1360                 do_cmd_refill_torch();
1361         }
1362
1363         /* No torch to refill */
1364         else
1365         {
1366                 msg_print(_("この光源は寿命を延ばせない。", "Your light cannot be refilled."));
1367         }
1368 }
1369
1370
1371 /*!
1372  * @brief ターゲットを設定するコマンドのメインルーチン
1373  * Target command
1374  * @return なし
1375  */
1376 void do_cmd_target(void)
1377 {
1378         /* Target set */
1379         if (target_set(TARGET_KILL))
1380         {
1381                 msg_print(_("ターゲット決定。", "Target Selected."));
1382         }
1383
1384         /* Target aborted */
1385         else
1386         {
1387                 msg_print(_("ターゲット解除。", "Target Aborted."));
1388         }
1389 }
1390
1391
1392
1393 /*!
1394  * @brief 周囲を見渡すコマンドのメインルーチン
1395  * Look command
1396  * @return なし
1397  */
1398 void do_cmd_look(void)
1399 {
1400         p_ptr->window |= PW_MONSTER_LIST;
1401         handle_stuff();
1402
1403         /* Look around */
1404         if (target_set(TARGET_LOOK))
1405         {
1406                 msg_print(_("ターゲット決定。", "Target Selected."));
1407         }
1408 }
1409
1410
1411 /*!
1412  * @brief 位置を確認するコマンドのメインルーチン
1413  * Allow the player to examine other sectors on the map
1414  * @return なし
1415  */
1416 void do_cmd_locate(void)
1417 {
1418         int             dir, y1, x1, y2, x2;
1419
1420         char    tmp_val[80];
1421
1422         char    out_val[160];
1423
1424         int wid, hgt;
1425
1426         get_screen_size(&wid, &hgt);
1427
1428
1429         /* Start at current panel */
1430         y2 = y1 = panel_row_min;
1431         x2 = x1 = panel_col_min;
1432
1433         /* Show panels until done */
1434         while (1)
1435         {
1436                 /* Describe the location */
1437                 if ((y2 == y1) && (x2 == x1))
1438                 {
1439 #ifdef JP
1440                         strcpy(tmp_val, "真上");
1441 #else
1442                         tmp_val[0] = '\0';
1443 #endif
1444
1445                 }
1446                 else
1447                 {
1448 #ifdef JP
1449                         sprintf(tmp_val, "%s%s",
1450                                 ((y2 < y1) ? "北" : (y2 > y1) ? "南" : ""),
1451                                 ((x2 < x1) ? "西" : (x2 > x1) ? "東" : ""));
1452 #else
1453                         sprintf(tmp_val, "%s%s of",
1454                                 ((y2 < y1) ? " North" : (y2 > y1) ? " South" : ""),
1455                                 ((x2 < x1) ? " West" : (x2 > x1) ? " East" : ""));
1456 #endif
1457
1458                 }
1459
1460                 /* Prepare to ask which way to look */
1461                 sprintf(out_val, _("マップ位置 [%d(%02d),%d(%02d)] (プレイヤーの%s)  方向?", 
1462                                                "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?"),
1463                         y2 / (hgt / 2), y2 % (hgt / 2),
1464                         x2 / (wid / 2), x2 % (wid / 2), tmp_val);
1465
1466                 /* Assume no direction */
1467                 dir = 0;
1468
1469                 /* Get a direction */
1470                 while (!dir)
1471                 {
1472                         char command;
1473
1474                         /* Get a command (or Cancel) */
1475                         if (!get_com(out_val, &command, TRUE)) break;
1476
1477                         /* Extract the action (if any) */
1478                         dir = get_keymap_dir(command);
1479
1480                         /* Error */
1481                         if (!dir) bell();
1482                 }
1483
1484                 /* No direction */
1485                 if (!dir) break;
1486
1487                 /* Apply the motion */
1488                 if (change_panel(ddy[dir], ddx[dir]))
1489                 {
1490                         y2 = panel_row_min;
1491                         x2 = panel_col_min;
1492                 }
1493         }
1494
1495
1496         /* Recenter the map around the player */
1497         verify_panel();
1498
1499         p_ptr->update |= (PU_MONSTERS);
1500
1501         p_ptr->redraw |= (PR_MAP);
1502
1503         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1504         handle_stuff();
1505 }
1506
1507
1508
1509 /*!
1510  * @brief モンスター種族情報を特定の基準によりソートするための比較処理
1511  * Sorting hook -- Comp function -- see below
1512  * @param u モンスター種族情報の入れるポインタ
1513  * @param v 条件基準ID
1514  * @param a 比較するモンスター種族のID1
1515  * @param b 比較するモンスター種族のID2
1516  * @return 2の方が大きければTRUEを返す
1517  * We use "u" to point to array of monster indexes,
1518  * and "v" to select the type of sorting to perform on "u".
1519  */
1520 bool ang_sort_comp_hook(vptr u, vptr v, int a, int b)
1521 {
1522         u16b *who = (u16b*)(u);
1523
1524         u16b *why = (u16b*)(v);
1525
1526         int w1 = who[a];
1527         int w2 = who[b];
1528
1529         int z1, z2;
1530
1531         /* Sort by player kills */
1532         if (*why >= 4)
1533         {
1534                 /* Extract player kills */
1535                 z1 = r_info[w1].r_pkills;
1536                 z2 = r_info[w2].r_pkills;
1537
1538                 /* Compare player kills */
1539                 if (z1 < z2) return (TRUE);
1540                 if (z1 > z2) return (FALSE);
1541         }
1542
1543
1544         /* Sort by total kills */
1545         if (*why >= 3)
1546         {
1547                 /* Extract total kills */
1548                 z1 = r_info[w1].r_tkills;
1549                 z2 = r_info[w2].r_tkills;
1550
1551                 /* Compare total kills */
1552                 if (z1 < z2) return (TRUE);
1553                 if (z1 > z2) return (FALSE);
1554         }
1555
1556
1557         /* Sort by monster level */
1558         if (*why >= 2)
1559         {
1560                 /* Extract levels */
1561                 z1 = r_info[w1].level;
1562                 z2 = r_info[w2].level;
1563
1564                 /* Compare levels */
1565                 if (z1 < z2) return (TRUE);
1566                 if (z1 > z2) return (FALSE);
1567         }
1568
1569
1570         /* Sort by monster experience */
1571         if (*why >= 1)
1572         {
1573                 /* Extract experience */
1574                 z1 = r_info[w1].mexp;
1575                 z2 = r_info[w2].mexp;
1576
1577                 /* Compare experience */
1578                 if (z1 < z2) return (TRUE);
1579                 if (z1 > z2) return (FALSE);
1580         }
1581
1582
1583         /* Compare indexes */
1584         return (w1 <= w2);
1585 }
1586
1587
1588 /*!
1589  * @brief モンスター種族情報を特定の基準によりソートするためのスワップ処理
1590  * Sorting hook -- Swap function -- see below
1591  * @param u モンスター種族情報の入れるポインタ
1592  * @param v 未使用
1593  * @param a スワップするモンスター種族のID1
1594  * @param b スワップするモンスター種族のID2
1595  * @return なし
1596  * @details
1597  * We use "u" to point to array of monster indexes,
1598  * and "v" to select the type of sorting to perform.
1599  */
1600 void ang_sort_swap_hook(vptr u, vptr v, int a, int b)
1601 {
1602         u16b *who = (u16b*)(u);
1603
1604         u16b holder;
1605
1606         /* Unused */
1607         (void)v;
1608
1609         /* Swap */
1610         holder = who[a];
1611         who[a] = who[b];
1612         who[b] = holder;
1613 }
1614
1615
1616
1617 /*!
1618  * @brief モンスターの思い出を見るコマンドのメインルーチン
1619  * Identify a character, allow recall of monsters
1620  * @return なし
1621  * @details
1622  * <pre>
1623  * Several "special" responses recall "multiple" monsters:
1624  *   ^A (all monsters)
1625  *   ^U (all unique monsters)
1626  *   ^N (all non-unique monsters)
1627  *
1628  * The responses may be sorted in several ways, see below.
1629  *
1630  * Note that the player ghosts are ignored. 
1631  * </pre>
1632  */
1633 void do_cmd_query_symbol(void)
1634 {
1635         IDX i;
1636         int n;
1637         MONRACE_IDX r_idx;
1638         char    sym, query;
1639         char    buf[128];
1640
1641         bool    all = FALSE;
1642         bool    uniq = FALSE;
1643         bool    norm = FALSE;
1644         bool    ride = FALSE;
1645         char    temp[80] = "";
1646
1647         bool    recall = FALSE;
1648
1649         u16b    why = 0;
1650         IDX     *who;
1651
1652         /* Get a character, or abort */
1653         if (!get_com(_("知りたい文字を入力して下さい(記号 or ^A全,^Uユ,^N非ユ,^R乗馬,^M名前): ", 
1654                                    "Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): "), &sym, FALSE)) return;
1655
1656         /* Find that character info, and describe it */
1657         for (i = 0; ident_info[i]; ++i)
1658         {
1659                 if (sym == ident_info[i][0]) break;
1660         }
1661         if (sym == KTRL('A'))
1662         {
1663                 all = TRUE;
1664                 strcpy(buf, _("全モンスターのリスト", "Full monster list."));
1665         }
1666         else if (sym == KTRL('U'))
1667         {
1668                 all = uniq = TRUE;
1669                 strcpy(buf, _("ユニーク・モンスターのリスト", "Unique monster list."));
1670         }
1671         else if (sym == KTRL('N'))
1672         {
1673                 all = norm = TRUE;
1674                 strcpy(buf, _("ユニーク外モンスターのリスト", "Non-unique monster list."));
1675         }
1676         else if (sym == KTRL('R'))
1677         {
1678                 all = ride = TRUE;
1679                 strcpy(buf, _("乗馬可能モンスターのリスト", "Ridable monster list."));
1680         }
1681         /* XTRA HACK WHATSEARCH */
1682         else if (sym == KTRL('M'))
1683         {
1684                 all = TRUE;
1685                 if (!get_string(_("名前(英語の場合小文字で可)", "Enter name:"),temp, 70))
1686                 {
1687                         temp[0]=0;
1688                         return;
1689                 }
1690                 sprintf(buf, _("名前:%sにマッチ", "Monsters with a name \"%s\""),temp);
1691         }
1692         else if (ident_info[i])
1693         {
1694                 sprintf(buf, "%c - %s.", sym, ident_info[i] + 2);
1695         }
1696         else
1697         {
1698                 sprintf(buf, "%c - %s", sym, _("無効な文字", "Unknown Symbol"));
1699         }
1700
1701         /* Display the result */
1702         prt(buf, 0, 0);
1703
1704         /* Allocate the "who" array */
1705         C_MAKE(who, max_r_idx, IDX);
1706
1707         /* Collect matching monsters */
1708         for (n = 0, i = 1; i < max_r_idx; i++)
1709         {
1710                 monster_race *r_ptr = &r_info[i];
1711
1712                 /* Nothing to recall */
1713                 if (!cheat_know && !r_ptr->r_sights) continue;
1714
1715                 /* Require non-unique monsters if needed */
1716                 if (norm && (r_ptr->flags1 & (RF1_UNIQUE))) continue;
1717
1718                 /* Require unique monsters if needed */
1719                 if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE))) continue;
1720
1721                 /* Require ridable monsters if needed */
1722                 if (ride && !(r_ptr->flags7 & (RF7_RIDING))) continue;
1723
1724                 /* XTRA HACK WHATSEARCH */
1725                 if (temp[0])
1726                 {
1727                         TERM_LEN xx;
1728                         char temp2[80];
1729
1730                         for (xx = 0; temp[xx] && xx < 80; xx++)
1731                         {
1732 #ifdef JP
1733                                 if (iskanji(temp[xx])) { xx++; continue; }
1734 #endif
1735                                 if (isupper(temp[xx])) temp[xx] = (char)tolower(temp[xx]);
1736                         }
1737
1738 #ifdef JP
1739                         strcpy(temp2, r_name + r_ptr->E_name);
1740 #else
1741                         strcpy(temp2, r_name + r_ptr->name);
1742 #endif
1743                         for (xx = 0; temp2[xx] && xx < 80; xx++)
1744                                 if (isupper(temp2[xx])) temp2[xx] = (char)tolower(temp2[xx]);
1745
1746 #ifdef JP
1747                         if (my_strstr(temp2, temp) || my_strstr(r_name + r_ptr->name, temp))
1748 #else
1749                         if (my_strstr(temp2, temp))
1750 #endif
1751                                 who[n++] = i;
1752                 }
1753
1754                 /* Collect "appropriate" monsters */
1755                 else if (all || (r_ptr->d_char == sym)) who[n++] = i;
1756         }
1757
1758         /* Nothing to recall */
1759         if (!n)
1760         {
1761                 /* Free the "who" array */
1762                 C_KILL(who, max_r_idx, IDX);
1763
1764                 return;
1765         }
1766
1767         /* Prompt */
1768         put_str(_("思い出を見ますか? (k:殺害順/y/n): ", "Recall details? (k/y/n): "), 0, _(36, 40));
1769
1770         /* Query */
1771         query = inkey();
1772
1773         /* Restore */
1774         prt(buf, 0, 0);
1775
1776         why = 2;
1777
1778         /* Select the sort method */
1779         ang_sort_comp = ang_sort_comp_hook;
1780         ang_sort_swap = ang_sort_swap_hook;
1781
1782         /* Sort the array */
1783         ang_sort(who, &why, n);
1784
1785         /* Sort by kills (and level) */
1786         if (query == 'k')
1787         {
1788                 why = 4;
1789                 query = 'y';
1790         }
1791
1792         /* Catch "escape" */
1793         if (query != 'y')
1794         {
1795                 /* Free the "who" array */
1796                 C_KILL(who, max_r_idx, IDX);
1797
1798                 return;
1799         }
1800
1801         /* Sort if needed */
1802         if (why == 4)
1803         {
1804                 /* Select the sort method */
1805                 ang_sort_comp = ang_sort_comp_hook;
1806                 ang_sort_swap = ang_sort_swap_hook;
1807
1808                 /* Sort the array */
1809                 ang_sort(who, &why, n);
1810         }
1811
1812
1813         /* Start at the end */
1814         i = n - 1;
1815
1816         /* Scan the monster memory */
1817         while (1)
1818         {
1819                 /* Extract a race */
1820                 r_idx = who[i];
1821
1822                 /* Hack -- Auto-recall */
1823                 monster_race_track(r_idx);
1824                 handle_stuff();
1825
1826                 /* Interact */
1827                 while (1)
1828                 {
1829                         /* Recall */
1830                         if (recall)
1831                         {
1832                                 screen_save();
1833
1834                                 /* Recall on screen */
1835                                 screen_roff(who[i], 0);
1836                         }
1837
1838                         /* Hack -- Begin the prompt */
1839                         roff_top(r_idx);
1840
1841                         /* Hack -- Complete the prompt */
1842                         Term_addstr(-1, TERM_WHITE, _(" ['r'思い出, ESC]", " [(r)ecall, ESC]"));
1843
1844                         /* Command */
1845                         query = inkey();
1846
1847                         /* Unrecall */
1848                         if (recall)
1849                         {
1850                                 /* Restore */
1851                                 screen_load();
1852                         }
1853
1854                         /* Normal commands */
1855                         if (query != 'r') break;
1856
1857                         /* Toggle recall */
1858                         recall = !recall;
1859                 }
1860
1861                 /* Stop scanning */
1862                 if (query == ESCAPE) break;
1863
1864                 /* Move to "prev" monster */
1865                 if (query == '-')
1866                 {
1867                         if (++i == n)
1868                         {
1869                                 i = 0;
1870                                 if (!expand_list) break;
1871                         }
1872                 }
1873
1874                 /* Move to "next" monster */
1875                 else
1876                 {
1877                         if (i-- == 0)
1878                         {
1879                                 i = n - 1;
1880                                 if (!expand_list) break;
1881                         }
1882                 }
1883         }
1884
1885         /* Free the "who" array */
1886         C_KILL(who, max_r_idx, IDX);
1887
1888         /* Re-display the identity */
1889         prt(buf, 0, 0);
1890 }
1891
1892 /*!
1893  * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
1894  * Use an item
1895  * @return なし
1896  * @details
1897  * XXX - Add actions for other item types
1898  */
1899 void do_cmd_use(void)
1900 {
1901         OBJECT_IDX item;
1902         object_type *o_ptr;
1903         cptr        q, s;
1904
1905         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
1906         {
1907                 set_action(ACTION_NONE);
1908         }
1909
1910         item_tester_no_ryoute = TRUE;
1911         item_tester_hook = item_tester_hook_use;
1912
1913         q = _("どれを使いますか?", "Use which item? ");
1914         s = _("使えるものがありません。", "You have nothing to use.");
1915
1916         if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return;
1917
1918         /* Get the item (in the pack) */
1919         if (item >= 0)
1920         {
1921                 o_ptr = &inventory[item];
1922         }
1923         /* Get the item (on the floor) */
1924         else
1925         {
1926                 o_ptr = &o_list[0 - item];
1927         }
1928
1929         switch (o_ptr->tval)
1930         {
1931                 /* Spike a door */
1932                 case TV_SPIKE:
1933                 {
1934                         do_cmd_spike();
1935                         break;
1936                 }
1937
1938                 /* Eat some food */
1939                 case TV_FOOD:
1940                 {
1941                         do_cmd_eat_food_aux(item);
1942                         break;
1943                 }
1944
1945                 /* Aim a wand */
1946                 case TV_WAND:
1947                 {
1948                         do_cmd_aim_wand_aux(item);
1949                         break;
1950                 }
1951
1952                 /* Use a staff */
1953                 case TV_STAFF:
1954                 {
1955                         do_cmd_use_staff_aux(item);
1956                         break;
1957                 }
1958
1959                 /* Zap a rod */
1960                 case TV_ROD:
1961                 {
1962                         do_cmd_zap_rod_aux(item);
1963                         break;
1964                 }
1965
1966                 /* Quaff a potion */
1967                 case TV_POTION:
1968                 {
1969                         do_cmd_quaff_potion_aux(item);
1970                         break;
1971                 }
1972
1973                 /* Read a scroll */
1974                 case TV_SCROLL:
1975                 {
1976                         /* Check some conditions */
1977                         if (p_ptr->blind)
1978                         {
1979                                 msg_print(_("目が見えない。", "You can't see anything."));
1980                                 return;
1981                         }
1982                         if (no_lite())
1983                         {
1984                                 msg_print(_("明かりがないので、暗くて読めない。", "You have no light to read by."));
1985                                 return;
1986                         }
1987                         if (p_ptr->confused)
1988                         {
1989                                 msg_print(_("混乱していて読めない!", "You are too confused!"));
1990                                 return;
1991                         }
1992
1993                   do_cmd_read_scroll_aux(item, TRUE);
1994                   break;
1995                 }
1996
1997                 /* Fire ammo */
1998                 case TV_SHOT:
1999                 case TV_ARROW:
2000                 case TV_BOLT:
2001                 {
2002                         do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
2003                         break;
2004                 }
2005
2006                 /* Activate an artifact */
2007                 default:
2008                 {
2009                         do_cmd_activate_aux(item);
2010                         break;
2011                 }
2012         }
2013 }
2014