OSDN Git Service

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