OSDN Git Service

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