OSDN Git Service

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