OSDN Git Service

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