OSDN Git Service

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