OSDN Git Service

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