OSDN Git Service

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