OSDN Git Service

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