OSDN Git Service

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