OSDN Git Service

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