OSDN Git Service

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