OSDN Git Service

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