OSDN Git Service

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