OSDN Git Service

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