OSDN Git Service

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