OSDN Git Service

1be1d7ee7455c09e78cd3c0d9de4ea722de4da0f
[hengband/hengband.git] / src / cmd6.c
1 /*!
2  * @file cmd6.c
3  * @brief プレイヤーのアイテムに関するコマンドの実装2 / Spell/Prayer commands
4  * @date 2014/01/27
5  * @author
6  * <pre>
7  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
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  * 2014 Deskull rearranged comment for Doxygen.\n
12  * </pre>
13  * @details
14  * <pre>
15  * This file includes code for eating food, drinking potions,
16  * reading scrolls, aiming wands, using staffs, zapping rods,
17  * and activating artifacts.
18  *
19  * In all cases, if the player becomes "aware" of the item's use
20  * by testing it, mark it as "aware" and reward some experience
21  * based on the object's level, always rounding up.  If the player
22  * remains "unaware", mark that object "kind" as "tried".
23  *
24  * This code now correctly handles the unstacking of wands, staffs,
25  * and rods.  Note the overly paranoid warning about potential pack
26  * overflow, which allows the player to use and drop a stacked item.
27  *
28  * In all "unstacking" scenarios, the "used" object is "carried" as if
29  * the player had just picked it up.  In particular, this means that if
30  * the use of an item induces pack overflow, that item will be dropped.
31  *
32  * For simplicity, these routines induce a full "pack reorganization"
33  * which not only combines similar items, but also reorganizes various
34  * items to obey the current "sorting" method.  This may require about
35  * 400 item comparisons, but only occasionally.
36  *
37  * There may be a BIG problem with any "effect" that can cause "changes"
38  * to the inventory.  For example, a "scroll of recharging" can cause
39  * a wand/staff to "disappear", moving the inventory up.  Luckily, the
40  * scrolls all appear BEFORE the staffs/wands, so this is not a problem.
41  * But, for example, a "staff of recharging" could cause MAJOR problems.
42  * In such a case, it will be best to either (1) "postpone" the effect
43  * until the end of the function, or (2) "change" the effect, say, into
44  * giving a staff "negative" charges, or "turning a staff into a stick".
45  * It seems as though a "rod of recharging" might in fact cause problems.
46  * The basic problem is that the act of recharging (and destroying) an
47  * item causes the inducer of that action to "move", causing "o_ptr" to
48  * no longer point at the correct item, with horrifying results.
49  *
50  * Note that food/potions/scrolls no longer use bit-flags for effects,
51  * but instead use the "sval" (which is also used to sort the objects).
52  * </pre>
53  */
54
55 #include "angband.h"
56
57
58 /*!
59  * @brief 食料を食べるコマンドのサブルーチン
60  * @param item 食べるオブジェクトの所持品ID
61  * @return なし
62  */
63 static void do_cmd_eat_food_aux(int item)
64 {
65         int ident, lev;
66         object_type *o_ptr;
67
68         if (music_singing_any()) stop_singing();
69         if (hex_spelling_any()) stop_hex_spell_all();
70
71         /* Get the item (in the pack) */
72         if (item >= 0)
73         {
74                 o_ptr = &inventory[item];
75         }
76
77         /* Get the item (on the floor) */
78         else
79         {
80                 o_ptr = &o_list[0 - item];
81         }
82
83         /* Sound */
84         sound(SOUND_EAT);
85
86         /* Take a turn */
87         p_ptr->energy_use = 100;
88
89         /* Identity not known yet */
90         ident = FALSE;
91
92         /* Object level */
93         lev = k_info[o_ptr->k_idx].level;
94
95         if (o_ptr->tval == TV_FOOD)
96         {
97                 /* Analyze the food */
98                 switch (o_ptr->sval)
99                 {
100                         case SV_FOOD_POISON:
101                         {
102                                 if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))
103                                 {
104                                         if (set_poisoned(p_ptr->poisoned + randint0(10) + 10))
105                                         {
106                                                 ident = TRUE;
107                                         }
108                                 }
109                                 break;
110                         }
111
112                         case SV_FOOD_BLINDNESS:
113                         {
114                                 if (!p_ptr->resist_blind)
115                                 {
116                                         if (set_blind(p_ptr->blind + randint0(200) + 200))
117                                         {
118                                                 ident = TRUE;
119                                         }
120                                 }
121                                 break;
122                         }
123
124                         case SV_FOOD_PARANOIA:
125                         {
126                                 if (!p_ptr->resist_fear)
127                                 {
128                                         if (set_afraid(p_ptr->afraid + randint0(10) + 10))
129                                         {
130                                                 ident = TRUE;
131                                         }
132                                 }
133                                 break;
134                         }
135
136                         case SV_FOOD_CONFUSION:
137                         {
138                                 if (!p_ptr->resist_conf)
139                                 {
140                                         if (set_confused(p_ptr->confused + randint0(10) + 10))
141                                         {
142                                                 ident = TRUE;
143                                         }
144                                 }
145                                 break;
146                         }
147
148                         case SV_FOOD_HALLUCINATION:
149                         {
150                                 if (!p_ptr->resist_chaos)
151                                 {
152                                         if (set_image(p_ptr->image + randint0(250) + 250))
153                                         {
154                                                 ident = TRUE;
155                                         }
156                                 }
157                                 break;
158                         }
159
160                         case SV_FOOD_PARALYSIS:
161                         {
162                                 if (!p_ptr->free_act)
163                                 {
164                                         if (set_paralyzed(p_ptr->paralyzed + randint0(10) + 10))
165                                         {
166                                                 ident = TRUE;
167                                         }
168                                 }
169                                 break;
170                         }
171
172                         case SV_FOOD_WEAKNESS:
173                         {
174                                 take_hit(DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"), -1);
175                                 (void)do_dec_stat(A_STR);
176                                 ident = TRUE;
177                                 break;
178                         }
179
180                         case SV_FOOD_SICKNESS:
181                         {
182                                 take_hit(DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"), -1);
183                                 (void)do_dec_stat(A_CON);
184                                 ident = TRUE;
185                                 break;
186                         }
187
188                         case SV_FOOD_STUPIDITY:
189                         {
190                                 take_hit(DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"), -1);
191                                 (void)do_dec_stat(A_INT);
192                                 ident = TRUE;
193                                 break;
194                         }
195
196                         case SV_FOOD_NAIVETY:
197                         {
198                                 take_hit(DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"), -1);
199                                 (void)do_dec_stat(A_WIS);
200                                 ident = TRUE;
201                                 break;
202                         }
203
204                         case SV_FOOD_UNHEALTH:
205                         {
206                                 take_hit(DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"), -1);
207                                 (void)do_dec_stat(A_CON);
208                                 ident = TRUE;
209                                 break;
210                         }
211
212                         case SV_FOOD_DISEASE:
213                         {
214                                 take_hit(DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"), -1);
215                                 (void)do_dec_stat(A_STR);
216                                 ident = TRUE;
217                                 break;
218                         }
219
220                         case SV_FOOD_CURE_POISON:
221                         {
222                                 if (set_poisoned(0)) ident = TRUE;
223                                 break;
224                         }
225
226                         case SV_FOOD_CURE_BLINDNESS:
227                         {
228                                 if (set_blind(0)) ident = TRUE;
229                                 break;
230                         }
231
232                         case SV_FOOD_CURE_PARANOIA:
233                         {
234                                 if (set_afraid(0)) ident = TRUE;
235                                 break;
236                         }
237
238                         case SV_FOOD_CURE_CONFUSION:
239                         {
240                                 if (set_confused(0)) ident = TRUE;
241                                 break;
242                         }
243
244                         case SV_FOOD_CURE_SERIOUS:
245                         {
246                                 if (hp_player(damroll(4, 8))) ident = TRUE;
247                                 break;
248                         }
249
250                         case SV_FOOD_RESTORE_STR:
251                         {
252                                 if (do_res_stat(A_STR)) ident = TRUE;
253                                 break;
254                         }
255
256                         case SV_FOOD_RESTORE_CON:
257                         {
258                                 if (do_res_stat(A_CON)) ident = TRUE;
259                                 break;
260                         }
261
262                         case SV_FOOD_RESTORING:
263                         {
264                                 if (do_res_stat(A_STR)) ident = TRUE;
265                                 if (do_res_stat(A_INT)) ident = TRUE;
266                                 if (do_res_stat(A_WIS)) ident = TRUE;
267                                 if (do_res_stat(A_DEX)) ident = TRUE;
268                                 if (do_res_stat(A_CON)) ident = TRUE;
269                                 if (do_res_stat(A_CHR)) ident = TRUE;
270                                 break;
271                         }
272
273
274 #ifdef JP
275                         /* それぞれの食べ物の感想をオリジナルより細かく表現 */
276                         case SV_FOOD_BISCUIT:
277                         {
278                                 msg_print("甘くてサクサクしてとてもおいしい。");
279                                 ident = TRUE;
280                                 break;
281                         }
282
283                         case SV_FOOD_JERKY:
284                         {
285                                 msg_print("歯ごたえがあっておいしい。");
286                                 ident = TRUE;
287                                 break;
288                         }
289
290                         case SV_FOOD_SLIME_MOLD:
291                         {
292                                 msg_print("これはなんとも形容しがたい味だ。");
293                                 ident = TRUE;
294                                 break;
295                         }
296
297                         case SV_FOOD_RATION:
298                         {
299                                 msg_print("これはおいしい。");
300                                 ident = TRUE;
301                                 break;
302                         }
303 #else
304                         case SV_FOOD_RATION:
305                         case SV_FOOD_BISCUIT:
306                         case SV_FOOD_JERKY:
307                         case SV_FOOD_SLIME_MOLD:
308                         {
309                                 msg_print("That tastes good.");
310                                 ident = TRUE;
311                                 break;
312                         }
313 #endif
314
315
316                         case SV_FOOD_WAYBREAD:
317                         {
318                                 msg_print(_("これはひじょうに美味だ。", "That tastes good."));
319                                 (void)set_poisoned(0);
320                                 (void)hp_player(damroll(4, 8));
321                                 ident = TRUE;
322                                 break;
323                         }
324
325 #ifdef JP
326                         case SV_FOOD_PINT_OF_ALE:
327                         {
328                                 msg_print("のどごし爽やかだ。");
329                                 ident = TRUE;
330                                 break;
331                         }
332
333                         case SV_FOOD_PINT_OF_WINE:
334                         {
335                                 msg_print("That tastes good.");
336                                 ident = TRUE;
337                                 break;
338                         }
339 #else
340                         case SV_FOOD_PINT_OF_ALE:
341                         case SV_FOOD_PINT_OF_WINE:
342                         {
343                                 msg_print("That tastes good.");
344                                 ident = TRUE;
345                                 break;
346                         }
347 #endif
348
349                 }
350         }
351
352         /* Combine / Reorder the pack (later) */
353         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
354
355         if (!(object_is_aware(o_ptr)))
356         {
357                 chg_virtue(V_KNOWLEDGE, -1);
358                 chg_virtue(V_PATIENCE, -1);
359                 chg_virtue(V_CHANCE, 1);
360         }
361
362         /* We have tried it */
363         if (o_ptr->tval == TV_FOOD) object_tried(o_ptr);
364
365         /* The player is now aware of the object */
366         if (ident && !object_is_aware(o_ptr))
367         {
368                 object_aware(o_ptr);
369                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
370         }
371
372         /* Window stuff */
373         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
374
375
376         /* Food can feed the player */
377         if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE))
378         {
379                 /* Reduced nutritional benefit */
380                 (void)set_food(p_ptr->food + (o_ptr->pval / 10));
381                 msg_print(_("あなたのような者にとって食糧など僅かな栄養にしかならない。", 
382                                         "Mere victuals hold scant sustenance for a being such as yourself."));
383
384                 if (p_ptr->food < PY_FOOD_ALERT)   /* Hungry */
385                 msg_print(_("あなたの飢えは新鮮な血によってのみ満たされる!", 
386                                         "Your hunger can only be satisfied with fresh blood!"));
387         }
388         else if ((prace_is_(RACE_SKELETON) ||
389                   prace_is_(RACE_GOLEM) ||
390                   prace_is_(RACE_ZOMBIE) ||
391                   prace_is_(RACE_SPECTRE)) &&
392                  (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND))
393         {
394                 cptr staff;
395
396                 if (o_ptr->tval == TV_STAFF &&
397                     (item < 0) && (o_ptr->number > 1))
398                 {
399                         msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
400                         return;
401                 }
402                 staff = (o_ptr->tval == TV_STAFF) ? _("杖", "staff") : _("魔法棒", "wand");
403
404                 /* "Eat" charges */
405                 if (o_ptr->pval == 0)
406                 {
407                         msg_format(_("この%sにはもう魔力が残っていない。", "The %s has no charges left."), staff);
408                         o_ptr->ident |= (IDENT_EMPTY);
409
410                         /* Combine / Reorder the pack (later) */
411                         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
412                         p_ptr->window |= (PW_INVEN);
413
414                         return;
415                 }
416                 msg_format(_("あなたは%sの魔力をエネルギー源として吸収した。", "You absorb mana of the %s as your energy."), staff);
417
418                 /* Use a single charge */
419                 o_ptr->pval--;
420
421                 /* Eat a charge */
422                 set_food(p_ptr->food + 5000);
423
424                 /* XXX Hack -- unstack if necessary */
425                 if (o_ptr->tval == TV_STAFF &&
426                     (item >= 0) && (o_ptr->number > 1))
427                 {
428                         object_type forge;
429                         object_type *q_ptr;
430
431                         /* Get local object */
432                         q_ptr = &forge;
433
434                         /* Obtain a local object */
435                         object_copy(q_ptr, o_ptr);
436
437                         /* Modify quantity */
438                         q_ptr->number = 1;
439
440                         /* Restore the charges */
441                         o_ptr->pval++;
442
443                         /* Unstack the used item */
444                         o_ptr->number--;
445                         p_ptr->total_weight -= q_ptr->weight;
446                         item = inven_carry(q_ptr);
447
448                         /* Message */
449                         msg_format(_("杖をまとめなおした。", "You unstack your staff."));
450                 }
451
452                 /* Describe charges in the pack */
453                 if (item >= 0)
454                 {
455                         inven_item_charges(item);
456                 }
457
458                 /* Describe charges on the floor */
459                 else
460                 {
461                         floor_item_charges(0 - item);
462                 }
463
464                 /* Window stuff */
465                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
466
467                 /* Don't eat a staff/wand itself */
468                 return;
469         }
470         else if ((prace_is_(RACE_DEMON) ||
471                  (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) &&
472                  (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_CORPSE &&
473                   my_strchr("pht", r_info[o_ptr->pval].d_char)))
474         {
475                 /* Drain vitality of humanoids */
476                 char o_name[MAX_NLEN];
477                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
478                 msg_format(_("%sは燃え上り灰になった。精力を吸収した気がする。", "%^s is burnt to ashes.  You absorb its vitality!"), o_name);
479                 (void)set_food(PY_FOOD_MAX - 1);
480         }
481         else if (prace_is_(RACE_SKELETON))
482         {
483 #if 0
484                 if (o_ptr->tval == TV_SKELETON ||
485                     (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
486                 {
487                         msg_print(_("あなたは骨で自分の体を補った。", "Your body absorbs the bone."));
488                         set_food(p_ptr->food + 5000);
489                 }
490                 else 
491 #endif
492
493                 if (!((o_ptr->sval == SV_FOOD_WAYBREAD) ||
494                       (o_ptr->sval < SV_FOOD_BISCUIT)))
495                 {
496                         object_type forge;
497                         object_type *q_ptr = &forge;
498                         
499                         msg_print(_("食べ物がアゴを素通りして落ちた!", "The food falls through your jaws!"));
500
501                         /* Create the item */
502                         object_prep(q_ptr, lookup_kind(o_ptr->tval, o_ptr->sval));
503
504                         /* Drop the object from heaven */
505                         (void)drop_near(q_ptr, -1, p_ptr->y, p_ptr->x);
506                 }
507                 else
508                 {
509                         msg_print(_("食べ物がアゴを素通りして落ち、消えた!", "The food falls through your jaws and vanishes!"));
510                 }
511         }
512         else if (prace_is_(RACE_GOLEM) ||
513                  prace_is_(RACE_ZOMBIE) ||
514                  prace_is_(RACE_ENT) ||
515                  prace_is_(RACE_DEMON) ||
516                  prace_is_(RACE_ANDROID) ||
517                  prace_is_(RACE_SPECTRE) ||
518                  (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING))
519         {
520                 msg_print(_("生者の食物はあなたにとってほとんど栄養にならない。", "The food of mortals is poor sustenance for you."));
521                 set_food(p_ptr->food + ((o_ptr->pval) / 20));
522         }
523         else if (o_ptr->tval == TV_FOOD && o_ptr->sval == SV_FOOD_WAYBREAD)
524         {
525                 /* Waybread is always fully satisfying. */
526                 set_food(MAX(p_ptr->food, PY_FOOD_MAX - 1));
527         }
528         else
529         {
530                 /* Food can feed the player */
531                 (void)set_food(p_ptr->food + o_ptr->pval);
532         }
533
534         /* Destroy a food in the pack */
535         if (item >= 0)
536         {
537                 inven_item_increase(item, -1);
538                 inven_item_describe(item);
539                 inven_item_optimize(item);
540         }
541
542         /* Destroy a food on the floor */
543         else
544         {
545                 floor_item_increase(0 - item, -1);
546                 floor_item_describe(0 - item);
547                 floor_item_optimize(0 - item);
548         }
549 }
550
551
552 /*!
553  * @brief オブジェクトをプレイヤーが食べることができるかを判定する /
554  * Hook to determine if an object is eatable
555  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
556  * @return 食べることが可能ならばTRUEを返す
557  */
558 static bool item_tester_hook_eatable(object_type *o_ptr)
559 {
560         if (o_ptr->tval==TV_FOOD) return TRUE;
561
562 #if 0
563         if (prace_is_(RACE_SKELETON))
564         {
565                 if (o_ptr->tval == TV_SKELETON ||
566                     (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
567                         return TRUE;
568         }
569         else 
570 #endif
571
572         if (prace_is_(RACE_SKELETON) ||
573             prace_is_(RACE_GOLEM) ||
574             prace_is_(RACE_ZOMBIE) ||
575             prace_is_(RACE_SPECTRE))
576         {
577                 if (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND)
578                         return TRUE;
579         }
580         else if (prace_is_(RACE_DEMON) ||
581                  (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON))
582         {
583                 if (o_ptr->tval == TV_CORPSE &&
584                     o_ptr->sval == SV_CORPSE &&
585                     my_strchr("pht", r_info[o_ptr->pval].d_char))
586                         return TRUE;
587         }
588
589         /* Assume not */
590         return (FALSE);
591 }
592
593
594 /*!
595  * @brief 食料を食べるコマンドのメインルーチン /
596  * Eat some food (from the pack or floor)
597  * @return なし
598  */
599 void do_cmd_eat_food(void)
600 {
601         OBJECT_IDX item;
602         cptr        q, s;
603
604
605         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
606         {
607                 set_action(ACTION_NONE);
608         }
609
610         /* Restrict choices to food */
611         item_tester_hook = item_tester_hook_eatable;
612
613         /* Get an item */
614         q = _("どれを食べますか? ", "Eat which item? ");
615         s = _("食べ物がない。", "You have nothing to eat.");
616
617         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
618
619         /* Eat the object */
620         do_cmd_eat_food_aux(item);
621 }
622
623
624 /*!
625  * @brief 薬を飲むコマンドのサブルーチン /
626  * Quaff a potion (from the pack or the floor)
627  * @param item 飲む薬オブジェクトの所持品ID
628  * @return なし
629  */
630 static void do_cmd_quaff_potion_aux(int item)
631 {
632         int         ident, lev;
633         object_type *o_ptr;
634         object_type forge;
635         object_type *q_ptr;
636
637
638         /* Take a turn */
639         p_ptr->energy_use = 100;
640
641         if (world_player)
642         {
643                 if (flush_failure) flush();
644                 msg_print(_("瓶から水が流れ出てこない!", "The potion doesn't flow out from a bottle."));
645
646                 sound(SOUND_FAIL);
647                 return;
648         }
649
650         if (music_singing_any()) stop_singing();
651         if (hex_spelling_any())
652         {
653                 if (!hex_spelling(HEX_INHAIL)) stop_hex_spell_all();
654         }
655
656         /* Get the item (in the pack) */
657         if (item >= 0)
658         {
659                 o_ptr = &inventory[item];
660         }
661
662         /* Get the item (on the floor) */
663         else
664         {
665                 o_ptr = &o_list[0 - item];
666         }
667
668         /* Get local object */
669         q_ptr = &forge;
670
671         /* Obtain a local object */
672         object_copy(q_ptr, o_ptr);
673
674         /* Single object */
675         q_ptr->number = 1;
676
677         /* Reduce and describe inventory */
678         if (item >= 0)
679         {
680                 inven_item_increase(item, -1);
681                 inven_item_describe(item);
682                 inven_item_optimize(item);
683         }
684
685         /* Reduce and describe floor item */
686         else
687         {
688                 floor_item_increase(0 - item, -1);
689                 floor_item_describe(0 - item);
690                 floor_item_optimize(0 - item);
691         }
692
693         /* Sound */
694         sound(SOUND_QUAFF);
695
696
697         /* Not identified yet */
698         ident = FALSE;
699
700         /* Object level */
701         lev = k_info[q_ptr->k_idx].level;
702
703         /* Analyze the potion */
704         if (q_ptr->tval == TV_POTION)
705         {
706                 switch (q_ptr->sval)
707                 {
708                         /* 飲みごたえをオリジナルより細かく表現 */
709                 case SV_POTION_WATER:
710                         msg_print(_("口の中がさっぱりした。", ""));
711                         msg_print(_("のどの渇きが少しおさまった。", "You feel less thirsty."));
712                         ident = TRUE;
713                         break;
714
715                 case SV_POTION_APPLE_JUICE:
716                         msg_print(_("甘くてサッパリとしていて、とてもおいしい。", ""));
717                         msg_print(_("のどの渇きが少しおさまった。", "You feel less thirsty."));
718                         ident = TRUE;
719                         break;
720
721                 case SV_POTION_SLIME_MOLD:
722                         msg_print(_("なんとも不気味な味だ。", ""));
723                         msg_print(_("のどの渇きが少しおさまった。", "You feel less thirsty."));
724                         ident = TRUE;
725                         break;
726
727                 case SV_POTION_SLOWNESS:
728                         if (set_slow(randint1(25) + 15, FALSE)) ident = TRUE;
729                         break;
730
731                 case SV_POTION_SALT_WATER:
732                         msg_print(_("うぇ!思わず吐いてしまった。", "The potion makes you vomit!"));
733
734                         if (!(prace_is_(RACE_GOLEM) ||
735                               prace_is_(RACE_ZOMBIE) ||
736                               prace_is_(RACE_DEMON) ||
737                               prace_is_(RACE_ANDROID) ||
738                               prace_is_(RACE_SPECTRE) ||
739                               (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)))
740                         {
741                                 /* Only living creatures get thirsty */
742                                 (void)set_food(PY_FOOD_STARVE - 1);
743                         }
744
745                         (void)set_poisoned(0);
746                         (void)set_paralyzed(p_ptr->paralyzed + 4);
747                         ident = TRUE;
748                         break;
749
750                 case SV_POTION_POISON:
751                         if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))
752                         {
753                                 if (set_poisoned(p_ptr->poisoned + randint0(15) + 10))
754                                 {
755                                         ident = TRUE;
756                                 }
757                         }
758                         break;
759
760                 case SV_POTION_BLINDNESS:
761                         if (!p_ptr->resist_blind)
762                         {
763                                 if (set_blind(p_ptr->blind + randint0(100) + 100))
764                                 {
765                                         ident = TRUE;
766                                 }
767                         }
768                         break;
769
770                 case SV_POTION_CONFUSION: /* Booze */
771                         if (p_ptr->pclass != CLASS_MONK) chg_virtue(V_HARMONY, -1);
772                         else if (!p_ptr->resist_conf) p_ptr->special_attack |= ATTACK_SUIKEN;
773                         if (!p_ptr->resist_conf)
774                         {
775                                 if (set_confused(randint0(20) + 15))
776                                 {
777                                         ident = TRUE;
778                                 }
779                         }
780
781                         if (!p_ptr->resist_chaos)
782                         {
783                                 if (one_in_(2))
784                                 {
785                                         if (set_image(p_ptr->image + randint0(150) + 150))
786                                         {
787                                                 ident = TRUE;
788                                         }
789                                 }
790                                 if (one_in_(13) && (p_ptr->pclass != CLASS_MONK))
791                                 {
792                                         ident = TRUE;
793                                         if (one_in_(3)) lose_all_info();
794                                         else wiz_dark();
795                                         (void)teleport_player_aux(100, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
796                                         wiz_dark();
797                                         msg_print(_("知らない場所で目が醒めた。頭痛がする。", "You wake up somewhere with a sore head..."));
798                                         msg_print(_("何も思い出せない。どうやってここへ来たのかも分からない!", "You can't remember a thing, or how you got here!"));
799                                 }
800                         }
801                         break;
802
803                 case SV_POTION_SLEEP:
804                         if (!p_ptr->free_act)
805                         {
806                                 msg_print(_("あなたは眠ってしまった。", "You fall asleep."));
807
808                                 if (ironman_nightmare)
809                                 {
810                                         msg_print(_("恐ろしい光景が頭に浮かんできた。", "A horrible vision enters your mind."));
811
812                                         /* Have some nightmares */
813                                         sanity_blast(NULL, FALSE);
814                                 }
815                                 if (set_paralyzed(p_ptr->paralyzed + randint0(4) + 4))
816                                 {
817                                         ident = TRUE;
818                                 }
819                         }
820                         break;
821
822                 case SV_POTION_LOSE_MEMORIES:
823                         if (!p_ptr->hold_exp && (p_ptr->exp > 0))
824                         {
825                                 msg_print(_("過去の記憶が薄れていく気がする。", "You feel your memories fade."));
826                                 chg_virtue(V_KNOWLEDGE, -5);
827
828                                 lose_exp(p_ptr->exp / 4);
829                                 ident = TRUE;
830                         }
831                         break;
832
833                 case SV_POTION_RUINATION:
834                         msg_print(_("身も心も弱ってきて、精気が抜けていくようだ。", "Your nerves and muscles feel weak and lifeless!"));
835                         take_hit(DAMAGE_LOSELIFE, damroll(10, 10), _("破滅の薬", "a potion of Ruination"), -1);
836
837                         (void)dec_stat(A_DEX, 25, TRUE);
838                         (void)dec_stat(A_WIS, 25, TRUE);
839                         (void)dec_stat(A_CON, 25, TRUE);
840                         (void)dec_stat(A_STR, 25, TRUE);
841                         (void)dec_stat(A_CHR, 25, TRUE);
842                         (void)dec_stat(A_INT, 25, TRUE);
843                         ident = TRUE;
844                         break;
845
846                 case SV_POTION_DEC_STR:
847                         if (do_dec_stat(A_STR)) ident = TRUE;
848                         break;
849
850                 case SV_POTION_DEC_INT:
851                         if (do_dec_stat(A_INT)) ident = TRUE;
852                         break;
853
854                 case SV_POTION_DEC_WIS:
855                         if (do_dec_stat(A_WIS)) ident = TRUE;
856                         break;
857
858                 case SV_POTION_DEC_DEX:
859                         if (do_dec_stat(A_DEX)) ident = TRUE;
860                         break;
861
862                 case SV_POTION_DEC_CON:
863                         if (do_dec_stat(A_CON)) ident = TRUE;
864                         break;
865
866                 case SV_POTION_DEC_CHR:
867                         if (do_dec_stat(A_CHR)) ident = TRUE;
868                         break;
869
870                 case SV_POTION_DETONATIONS:
871                         msg_print(_("体の中で激しい爆発が起きた!", "Massive explosions rupture your body!"));
872                         take_hit(DAMAGE_NOESCAPE, damroll(50, 20), _("爆発の薬", "a potion of Detonation"), -1);
873
874                         (void)set_stun(p_ptr->stun + 75);
875                         (void)set_cut(p_ptr->cut + 5000);
876                         ident = TRUE;
877                         break;
878
879                 case SV_POTION_DEATH:
880                         chg_virtue(V_VITALITY, -1);
881                         chg_virtue(V_UNLIFE, 5);
882                         msg_print(_("死の予感が体中を駆けめぐった。", "A feeling of Death flows through your body."));
883                         take_hit(DAMAGE_LOSELIFE, 5000, _("死の薬", "a potion of Death"), -1);
884                         ident = TRUE;
885                         break;
886
887                 case SV_POTION_INFRAVISION:
888                         if (set_tim_infra(p_ptr->tim_infra + 100 + randint1(100), FALSE))
889                         {
890                                 ident = TRUE;
891                         }
892                         break;
893
894                 case SV_POTION_DETECT_INVIS:
895                         if (set_tim_invis(p_ptr->tim_invis + 12 + randint1(12), FALSE))
896                         {
897                                 ident = TRUE;
898                         }
899                         break;
900
901                 case SV_POTION_SLOW_POISON:
902                         if (set_poisoned(p_ptr->poisoned / 2)) ident = TRUE;
903                         break;
904
905                 case SV_POTION_CURE_POISON:
906                         if (set_poisoned(0)) ident = TRUE;
907                         break;
908
909                 case SV_POTION_BOLDNESS:
910                         if (set_afraid(0)) ident = TRUE;
911                         break;
912
913                 case SV_POTION_SPEED:
914                         if (!p_ptr->fast)
915                         {
916                                 if (set_fast(randint1(25) + 15, FALSE)) ident = TRUE;
917                         }
918                         else
919                         {
920                                 (void)set_fast(p_ptr->fast + 5, FALSE);
921                         }
922                         break;
923
924                 case SV_POTION_RESIST_HEAT:
925                         if (set_oppose_fire(p_ptr->oppose_fire + randint1(10) + 10, FALSE))
926                         {
927                                 ident = TRUE;
928                         }
929                         break;
930
931                 case SV_POTION_RESIST_COLD:
932                         if (set_oppose_cold(p_ptr->oppose_cold + randint1(10) + 10, FALSE))
933                         {
934                                 ident = TRUE;
935                         }
936                         break;
937
938                 case SV_POTION_HEROISM:
939                         if (set_afraid(0)) ident = TRUE;
940                         if (set_hero(p_ptr->hero + randint1(25) + 25, FALSE)) ident = TRUE;
941                         if (hp_player(10)) ident = TRUE;
942                         break;
943
944                 case SV_POTION_BESERK_STRENGTH:
945                         if (set_afraid(0)) ident = TRUE;
946                         if (set_shero(p_ptr->shero + randint1(25) + 25, FALSE)) ident = TRUE;
947                         if (hp_player(30)) ident = TRUE;
948                         break;
949
950                 case SV_POTION_CURE_LIGHT:
951                         if (hp_player(damroll(2, 8))) ident = TRUE;
952                         if (set_blind(0)) ident = TRUE;
953                         if (set_cut(p_ptr->cut - 10)) ident = TRUE;
954                         if (set_shero(0,TRUE)) ident = TRUE;
955                         break;
956
957                 case SV_POTION_CURE_SERIOUS:
958                         if (hp_player(damroll(4, 8))) ident = TRUE;
959                         if (set_blind(0)) ident = TRUE;
960                         if (set_confused(0)) ident = TRUE;
961                         if (set_cut((p_ptr->cut / 2) - 50)) ident = TRUE;
962                         if (set_shero(0,TRUE)) ident = TRUE;
963                         break;
964
965                 case SV_POTION_CURE_CRITICAL:
966                         if (hp_player(damroll(6, 8))) ident = TRUE;
967                         if (set_blind(0)) ident = TRUE;
968                         if (set_confused(0)) ident = TRUE;
969                         if (set_poisoned(0)) ident = TRUE;
970                         if (set_stun(0)) ident = TRUE;
971                         if (set_cut(0)) ident = TRUE;
972                         if (set_shero(0,TRUE)) ident = TRUE;
973                         break;
974
975                 case SV_POTION_HEALING:
976                         if (hp_player(300)) ident = TRUE;
977                         if (set_blind(0)) ident = TRUE;
978                         if (set_confused(0)) ident = TRUE;
979                         if (set_poisoned(0)) ident = TRUE;
980                         if (set_stun(0)) ident = TRUE;
981                         if (set_cut(0)) ident = TRUE;
982                         if (set_shero(0,TRUE)) ident = TRUE;
983                         break;
984
985                 case SV_POTION_STAR_HEALING:
986                         if (hp_player(1200)) ident = TRUE;
987                         if (set_blind(0)) ident = TRUE;
988                         if (set_confused(0)) ident = TRUE;
989                         if (set_poisoned(0)) ident = TRUE;
990                         if (set_stun(0)) ident = TRUE;
991                         if (set_cut(0)) ident = TRUE;
992                         if (set_shero(0,TRUE)) ident = TRUE;
993                         break;
994
995                 case SV_POTION_LIFE:
996                         chg_virtue(V_VITALITY, 1);
997                         chg_virtue(V_UNLIFE, -5);
998                         msg_print(_("体中に生命力が満ちあふれてきた!", "You feel life flow through your body!"));
999                         restore_level();
1000                         (void)set_poisoned(0);
1001                         (void)set_blind(0);
1002                         (void)set_confused(0);
1003                         (void)set_image(0);
1004                         (void)set_stun(0);
1005                         (void)set_cut(0);
1006                         (void)do_res_stat(A_STR);
1007                         (void)do_res_stat(A_CON);
1008                         (void)do_res_stat(A_DEX);
1009                         (void)do_res_stat(A_WIS);
1010                         (void)do_res_stat(A_INT);
1011                         (void)do_res_stat(A_CHR);
1012                         (void)set_shero(0,TRUE);
1013                         update_stuff();
1014                         hp_player(5000);
1015                         ident = TRUE;
1016                         break;
1017
1018                 case SV_POTION_RESTORE_MANA:
1019                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
1020                         {
1021                                 int i;
1022                                 for (i = 0; i < EATER_EXT*2; i++)
1023                                 {
1024                                         p_ptr->magic_num1[i] += (p_ptr->magic_num2[i] < 10) ? EATER_CHARGE * 3 : p_ptr->magic_num2[i]*EATER_CHARGE/3;
1025                                         if (p_ptr->magic_num1[i] > p_ptr->magic_num2[i]*EATER_CHARGE) p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*EATER_CHARGE;
1026                                 }
1027                                 for (; i < EATER_EXT*3; i++)
1028                                 {
1029                                         KIND_OBJECT_IDX k_idx = lookup_kind(TV_ROD, i-EATER_EXT*2);
1030                                         p_ptr->magic_num1[i] -= ((p_ptr->magic_num2[i] < 10) ? EATER_ROD_CHARGE*3 : p_ptr->magic_num2[i]*EATER_ROD_CHARGE/3)*k_info[k_idx].pval;
1031                                         if (p_ptr->magic_num1[i] < 0) p_ptr->magic_num1[i] = 0;
1032                                 }
1033                                 msg_print(_("頭がハッキリとした。", "You feel your head clear."));
1034                                 p_ptr->window |= (PW_PLAYER);
1035                                 ident = TRUE;
1036                         }
1037                         else if (p_ptr->csp < p_ptr->msp)
1038                         {
1039                                 p_ptr->csp = p_ptr->msp;
1040                                 p_ptr->csp_frac = 0;
1041                                 msg_print(_("頭がハッキリとした。", "You feel your head clear."));
1042
1043                                 p_ptr->redraw |= (PR_MANA);
1044                                 p_ptr->window |= (PW_PLAYER);
1045                                 p_ptr->window |= (PW_SPELL);
1046                                 ident = TRUE;
1047                         }
1048                         if (set_shero(0,TRUE)) ident = TRUE;
1049                         break;
1050
1051                 case SV_POTION_RESTORE_EXP:
1052                         if (restore_level()) ident = TRUE;
1053                         break;
1054
1055                 case SV_POTION_RES_STR:
1056                         if (do_res_stat(A_STR)) ident = TRUE;
1057                         break;
1058
1059                 case SV_POTION_RES_INT:
1060                         if (do_res_stat(A_INT)) ident = TRUE;
1061                         break;
1062
1063                 case SV_POTION_RES_WIS:
1064                         if (do_res_stat(A_WIS)) ident = TRUE;
1065                         break;
1066
1067                 case SV_POTION_RES_DEX:
1068                         if (do_res_stat(A_DEX)) ident = TRUE;
1069                         break;
1070
1071                 case SV_POTION_RES_CON:
1072                         if (do_res_stat(A_CON)) ident = TRUE;
1073                         break;
1074
1075                 case SV_POTION_RES_CHR:
1076                         if (do_res_stat(A_CHR)) ident = TRUE;
1077                         break;
1078
1079                 case SV_POTION_INC_STR:
1080                         if (do_inc_stat(A_STR)) ident = TRUE;
1081                         break;
1082
1083                 case SV_POTION_INC_INT:
1084                         if (do_inc_stat(A_INT)) ident = TRUE;
1085                         break;
1086
1087                 case SV_POTION_INC_WIS:
1088                         if (do_inc_stat(A_WIS)) ident = TRUE;
1089                         break;
1090
1091                 case SV_POTION_INC_DEX:
1092                         if (do_inc_stat(A_DEX)) ident = TRUE;
1093                         break;
1094
1095                 case SV_POTION_INC_CON:
1096                         if (do_inc_stat(A_CON)) ident = TRUE;
1097                         break;
1098
1099                 case SV_POTION_INC_CHR:
1100                         if (do_inc_stat(A_CHR)) ident = TRUE;
1101                         break;
1102
1103                 case SV_POTION_AUGMENTATION:
1104                         if (do_inc_stat(A_STR)) ident = TRUE;
1105                         if (do_inc_stat(A_INT)) ident = TRUE;
1106                         if (do_inc_stat(A_WIS)) ident = TRUE;
1107                         if (do_inc_stat(A_DEX)) ident = TRUE;
1108                         if (do_inc_stat(A_CON)) ident = TRUE;
1109                         if (do_inc_stat(A_CHR)) ident = TRUE;
1110                         break;
1111
1112                 case SV_POTION_ENLIGHTENMENT:
1113                         msg_print(_("自分の置かれている状況が脳裏に浮かんできた...", "An image of your surroundings forms in your mind..."));
1114                         chg_virtue(V_KNOWLEDGE, 1);
1115                         chg_virtue(V_ENLIGHTEN, 1);
1116                         wiz_lite(FALSE);
1117                         ident = TRUE;
1118                         break;
1119
1120                 case SV_POTION_STAR_ENLIGHTENMENT:
1121                         msg_print(_("更なる啓蒙を感じた...", "You begin to feel more enlightened..."));
1122                         chg_virtue(V_KNOWLEDGE, 1);
1123                         chg_virtue(V_ENLIGHTEN, 2);
1124                         msg_print(NULL);
1125                         wiz_lite(FALSE);
1126                         (void)do_inc_stat(A_INT);
1127                         (void)do_inc_stat(A_WIS);
1128                         (void)detect_traps(DETECT_RAD_DEFAULT, TRUE);
1129                         (void)detect_doors(DETECT_RAD_DEFAULT);
1130                         (void)detect_stairs(DETECT_RAD_DEFAULT);
1131                         (void)detect_treasure(DETECT_RAD_DEFAULT);
1132                         (void)detect_objects_gold(DETECT_RAD_DEFAULT);
1133                         (void)detect_objects_normal(DETECT_RAD_DEFAULT);
1134                         identify_pack();
1135                         self_knowledge();
1136                         ident = TRUE;
1137                         break;
1138
1139                 case SV_POTION_SELF_KNOWLEDGE:
1140                         msg_print(_("自分自身のことが少しは分かった気がする...", "You begin to know yourself a little better..."));
1141                         msg_print(NULL);
1142                         self_knowledge();
1143                         ident = TRUE;
1144                         break;
1145
1146                 case SV_POTION_EXPERIENCE:
1147                         if (p_ptr->prace == RACE_ANDROID) break;
1148                         chg_virtue(V_ENLIGHTEN, 1);
1149                         if (p_ptr->exp < PY_MAX_EXP)
1150                         {
1151                                 s32b ee = (p_ptr->exp / 2) + 10;
1152                                 if (ee > 100000L) ee = 100000L;
1153                                 msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
1154                                 gain_exp(ee);
1155                                 ident = TRUE;
1156                         }
1157                         break;
1158
1159                 case SV_POTION_RESISTANCE:
1160                         (void)set_oppose_acid(p_ptr->oppose_acid + randint1(20) + 20, FALSE);
1161                         (void)set_oppose_elec(p_ptr->oppose_elec + randint1(20) + 20, FALSE);
1162                         (void)set_oppose_fire(p_ptr->oppose_fire + randint1(20) + 20, FALSE);
1163                         (void)set_oppose_cold(p_ptr->oppose_cold + randint1(20) + 20, FALSE);
1164                         (void)set_oppose_pois(p_ptr->oppose_pois + randint1(20) + 20, FALSE);
1165                         ident = TRUE;
1166                         break;
1167
1168                 case SV_POTION_CURING:
1169                         if (hp_player(50)) ident = TRUE;
1170                         if (set_blind(0)) ident = TRUE;
1171                         if (set_poisoned(0)) ident = TRUE;
1172                         if (set_confused(0)) ident = TRUE;
1173                         if (set_stun(0)) ident = TRUE;
1174                         if (set_cut(0)) ident = TRUE;
1175                         if (set_image(0)) ident = TRUE;
1176                         break;
1177
1178                 case SV_POTION_INVULNERABILITY:
1179                         (void)set_invuln(p_ptr->invuln + randint1(4) + 4, FALSE);
1180                         ident = TRUE;
1181                         break;
1182
1183                 case SV_POTION_NEW_LIFE:
1184                         do_cmd_rerate(FALSE);
1185                         get_max_stats();
1186                         p_ptr->update |= PU_BONUS;
1187                         lose_all_mutations();
1188                         ident = TRUE;
1189                         break;
1190
1191                 case SV_POTION_NEO_TSUYOSHI:
1192                         (void)set_image(0);
1193                         (void)set_tsuyoshi(p_ptr->tsuyoshi + randint1(100) + 100, FALSE);
1194                         ident = TRUE;
1195                         break;
1196
1197                 case SV_POTION_TSUYOSHI:
1198                         msg_print(_("「オクレ兄さん!」", "Brother OKURE!"));
1199                         msg_print(NULL);
1200                         p_ptr->tsuyoshi = 1;
1201                         (void)set_tsuyoshi(0, TRUE);
1202                         if (!p_ptr->resist_chaos)
1203                         {
1204                                 (void)set_image(50 + randint1(50));
1205                         }
1206                         ident = TRUE;
1207                         break;
1208                 
1209                 case SV_POTION_POLYMORPH:
1210                         if ((p_ptr->muta1 || p_ptr->muta2 || p_ptr->muta3) && one_in_(23))
1211                         {
1212                                 lose_all_mutations();
1213                         }
1214                         else
1215                         {
1216                                 do
1217                                 {
1218                                         if (one_in_(2))
1219                                         {
1220                                                 if(gain_random_mutation(0)) ident = TRUE;
1221                                         }
1222                                         else if (lose_mutation(0)) ident = TRUE;
1223                                 } while(!ident || one_in_(2));
1224                         }
1225                         break;
1226                 }
1227         }
1228
1229         if (prace_is_(RACE_SKELETON))
1230         {
1231                 msg_print(_("液体の一部はあなたのアゴを素通りして落ちた!", "Some of the fluid falls through your jaws!"));
1232                 (void)potion_smash_effect(0, p_ptr->y, p_ptr->x, q_ptr->k_idx);
1233         }
1234
1235         /* Combine / Reorder the pack (later) */
1236         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1237
1238         if (!(object_is_aware(q_ptr)))
1239         {
1240                 chg_virtue(V_PATIENCE, -1);
1241                 chg_virtue(V_CHANCE, 1);
1242                 chg_virtue(V_KNOWLEDGE, -1);
1243         }
1244
1245         /* The item has been tried */
1246         object_tried(q_ptr);
1247
1248         /* An identification was made */
1249         if (ident && !object_is_aware(q_ptr))
1250         {
1251                 object_aware(q_ptr);
1252                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
1253         }
1254
1255         /* Window stuff */
1256         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1257
1258         /* Potions can feed the player */
1259         switch (p_ptr->mimic_form)
1260         {
1261         case MIMIC_NONE:
1262                 switch (p_ptr->prace)
1263                 {
1264                         case RACE_VAMPIRE:
1265                                 (void)set_food(p_ptr->food + (q_ptr->pval / 10));
1266                                 break;
1267                         case RACE_SKELETON:
1268                                 /* Do nothing */
1269                                 break;
1270                         case RACE_GOLEM:
1271                         case RACE_ZOMBIE:
1272                         case RACE_DEMON:
1273                         case RACE_SPECTRE:
1274                                 set_food(p_ptr->food + ((q_ptr->pval) / 20));
1275                                 break;
1276                         case RACE_ANDROID:
1277                                 if (q_ptr->tval == TV_FLASK)
1278                                 {
1279                                         msg_print(_("オイルを補給した。", "You replenish yourself with the oil."));
1280                                         set_food(p_ptr->food + 5000);
1281                                 }
1282                                 else
1283                                 {
1284                                         set_food(p_ptr->food + ((q_ptr->pval) / 20));
1285                                 }
1286                                 break;
1287                         case RACE_ENT:
1288                                 msg_print(_("水分を取り込んだ。", "You are moistened."));
1289                                 set_food(MIN(p_ptr->food + q_ptr->pval + MAX(0, q_ptr->pval * 10) + 2000, PY_FOOD_MAX - 1));
1290                                 break;
1291                         default:
1292                                 (void)set_food(p_ptr->food + q_ptr->pval);
1293                                 break;
1294                 }
1295                 break;
1296         case MIMIC_DEMON:
1297         case MIMIC_DEMON_LORD:
1298                 set_food(p_ptr->food + ((q_ptr->pval) / 20));
1299                 break;
1300         case MIMIC_VAMPIRE:
1301                 (void)set_food(p_ptr->food + (q_ptr->pval / 10));
1302                 break;
1303         default:
1304                 (void)set_food(p_ptr->food + q_ptr->pval);
1305                 break;
1306         }
1307 }
1308
1309
1310 /*!
1311  * @brief オブジェクトをプレイヤーが飲むことができるかを判定する /
1312  * Hook to determine if an object can be quaffed
1313  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1314  * @return 飲むことが可能ならばTRUEを返す
1315  */
1316 static bool item_tester_hook_quaff(object_type *o_ptr)
1317 {
1318         if (o_ptr->tval == TV_POTION) return TRUE;
1319
1320         if (prace_is_(RACE_ANDROID))
1321         {
1322                 if (o_ptr->tval == TV_FLASK && o_ptr->sval == SV_FLASK_OIL)
1323                         return TRUE;
1324         }
1325         return FALSE;
1326 }
1327
1328
1329 /*!
1330  * @brief 薬を飲むコマンドのメインルーチン /
1331  * Quaff some potion (from the pack or floor)
1332  * @return なし
1333  */
1334 void do_cmd_quaff_potion(void)
1335 {
1336         OBJECT_IDX item;
1337         cptr q, s;
1338
1339         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
1340         {
1341                 set_action(ACTION_NONE);
1342         }
1343
1344         /* Restrict choices to potions */
1345         item_tester_hook = item_tester_hook_quaff;
1346
1347         /* Get an item */
1348         q = _("どの薬を飲みますか? ", "Quaff which potion? ");
1349         s = _("飲める薬がない。", "You have no potions to quaff.");
1350
1351         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
1352
1353         /* Quaff the potion */
1354         do_cmd_quaff_potion_aux(item);
1355 }
1356
1357
1358 /*!
1359  * @brief 巻物を読むコマンドのサブルーチン
1360  * Read a scroll (from the pack or floor).
1361  * @param item 読むオブジェクトの所持品ID
1362  * @param known 判明済ならばTRUE
1363  * @return なし
1364  * @details
1365  * <pre>
1366  * Certain scrolls can be "aborted" without losing the scroll.  These
1367  * include scrolls with no effects but recharge or identify, which are
1368  * cancelled before use.  XXX Reading them still takes a turn, though.
1369  * </pre>
1370  */
1371 static void do_cmd_read_scroll_aux(int item, bool known)
1372 {
1373         int         k, used_up, ident, lev;
1374         object_type *o_ptr;
1375
1376
1377         /* Get the item (in the pack) */
1378         if (item >= 0)
1379         {
1380                 o_ptr = &inventory[item];
1381         }
1382
1383         /* Get the item (on the floor) */
1384         else
1385         {
1386                 o_ptr = &o_list[0 - item];
1387         }
1388
1389
1390         /* Take a turn */
1391         p_ptr->energy_use = 100;
1392
1393         if (world_player)
1394         {
1395                 if (flush_failure) flush();
1396                 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen."));
1397                 sound(SOUND_FAIL);
1398                 return;
1399         }
1400
1401         if (p_ptr->pclass == CLASS_BERSERKER)
1402         {
1403                 msg_print(_("巻物なんて読めない。", "You cannot read."));
1404                 return;
1405         }
1406
1407         if (music_singing_any()) stop_singing();
1408
1409         /* Hex */
1410         if (hex_spelling_any() && ((p_ptr->lev < 35) || hex_spell_fully())) stop_hex_spell_all();
1411
1412         /* Not identified yet */
1413         ident = FALSE;
1414
1415         /* Object level */
1416         lev = k_info[o_ptr->k_idx].level;
1417
1418         /* Assume the scroll will get used up */
1419         used_up = TRUE;
1420
1421         if (o_ptr->tval == TV_SCROLL)
1422         {
1423         /* Analyze the scroll */
1424         switch (o_ptr->sval)
1425         {
1426                 case SV_SCROLL_DARKNESS:
1427                 {
1428                         if (!(p_ptr->resist_blind) && !(p_ptr->resist_dark))
1429                         {
1430                                 (void)set_blind(p_ptr->blind + 3 + randint1(5));
1431                         }
1432                         if (unlite_area(10, 3)) ident = TRUE;
1433                         break;
1434                 }
1435
1436                 case SV_SCROLL_AGGRAVATE_MONSTER:
1437                 {
1438                         msg_print(_("カン高くうなる様な音が辺りを覆った。", "There is a high pitched humming noise."));
1439                         aggravate_monsters(0);
1440                         ident = TRUE;
1441                         break;
1442                 }
1443
1444                 case SV_SCROLL_CURSE_ARMOR:
1445                 {
1446                         if (curse_armor()) ident = TRUE;
1447                         break;
1448                 }
1449
1450                 case SV_SCROLL_CURSE_WEAPON:
1451                 {
1452                         k = 0;
1453                         if (buki_motteruka(INVEN_RARM))
1454                         {
1455                                 k = INVEN_RARM;
1456                                 if (buki_motteruka(INVEN_LARM) && one_in_(2)) k = INVEN_LARM;
1457                         }
1458                         else if (buki_motteruka(INVEN_LARM)) k = INVEN_LARM;
1459                         if (k && curse_weapon(FALSE, k)) ident = TRUE;
1460                         break;
1461                 }
1462
1463                 case SV_SCROLL_SUMMON_MONSTER:
1464                 {
1465                         for (k = 0; k < randint1(3); k++)
1466                         {
1467                                 if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
1468                                 {
1469                                         ident = TRUE;
1470                                 }
1471                         }
1472                         break;
1473                 }
1474
1475                 case SV_SCROLL_SUMMON_UNDEAD:
1476                 {
1477                         for (k = 0; k < randint1(3); k++)
1478                         {
1479                                 if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_UNDEAD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
1480                                 {
1481                                         ident = TRUE;
1482                                 }
1483                         }
1484                         break;
1485                 }
1486
1487                 case SV_SCROLL_SUMMON_PET:
1488                 {
1489                         if (summon_specific(-1, p_ptr->y, p_ptr->x, dun_level, 0, (PM_ALLOW_GROUP | PM_FORCE_PET)))
1490                         {
1491                                 ident = TRUE;
1492                         }
1493                         break;
1494                 }
1495
1496                 case SV_SCROLL_SUMMON_KIN:
1497                 {
1498                         if (summon_kin_player(p_ptr->lev, p_ptr->y, p_ptr->x, (PM_FORCE_PET | PM_ALLOW_GROUP)))
1499                         {
1500                                 ident = TRUE;
1501                         }
1502                         break;
1503                 }
1504
1505                 case SV_SCROLL_TRAP_CREATION:
1506                 {
1507                         if (trap_creation(p_ptr->y, p_ptr->x)) ident = TRUE;
1508                         break;
1509                 }
1510
1511                 case SV_SCROLL_PHASE_DOOR:
1512                 {
1513                         teleport_player(10, 0L);
1514                         ident = TRUE;
1515                         break;
1516                 }
1517
1518                 case SV_SCROLL_TELEPORT:
1519                 {
1520                         teleport_player(100, 0L);
1521                         ident = TRUE;
1522                         break;
1523                 }
1524
1525                 case SV_SCROLL_TELEPORT_LEVEL:
1526                 {
1527                         (void)teleport_level(0);
1528                         ident = TRUE;
1529                         break;
1530                 }
1531
1532                 case SV_SCROLL_WORD_OF_RECALL:
1533                 {
1534                         if (!word_of_recall()) used_up = FALSE;
1535                         ident = TRUE;
1536                         break;
1537                 }
1538
1539                 case SV_SCROLL_IDENTIFY:
1540                 {
1541                         if (!ident_spell(FALSE)) used_up = FALSE;
1542                         ident = TRUE;
1543                         break;
1544                 }
1545
1546                 case SV_SCROLL_STAR_IDENTIFY:
1547                 {
1548                         if (!identify_fully(FALSE)) used_up = FALSE;
1549                         ident = TRUE;
1550                         break;
1551                 }
1552
1553                 case SV_SCROLL_REMOVE_CURSE:
1554                 {
1555                         if (remove_curse())
1556                         {
1557                                 msg_print(_("誰かに見守られているような気がする。", "You feel as if someone is watching over you."));
1558                                 ident = TRUE;
1559                         }
1560                         break;
1561                 }
1562
1563                 case SV_SCROLL_STAR_REMOVE_CURSE:
1564                 {
1565                         if (remove_all_curse())
1566                         {
1567                                 msg_print(_("誰かに見守られているような気がする。", "You feel as if someone is watching over you."));
1568                         }
1569                         ident = TRUE;
1570                         break;
1571                 }
1572
1573                 case SV_SCROLL_ENCHANT_ARMOR:
1574                 {
1575                         ident = TRUE;
1576                         if (!enchant_spell(0, 0, 1)) used_up = FALSE;
1577                         break;
1578                 }
1579
1580                 case SV_SCROLL_ENCHANT_WEAPON_TO_HIT:
1581                 {
1582                         if (!enchant_spell(1, 0, 0)) used_up = FALSE;
1583                         ident = TRUE;
1584                         break;
1585                 }
1586
1587                 case SV_SCROLL_ENCHANT_WEAPON_TO_DAM:
1588                 {
1589                         if (!enchant_spell(0, 1, 0)) used_up = FALSE;
1590                         ident = TRUE;
1591                         break;
1592                 }
1593
1594                 case SV_SCROLL_STAR_ENCHANT_ARMOR:
1595                 {
1596                         if (!enchant_spell(0, 0, randint1(3) + 2)) used_up = FALSE;
1597                         ident = TRUE;
1598                         break;
1599                 }
1600
1601                 case SV_SCROLL_STAR_ENCHANT_WEAPON:
1602                 {
1603                         if (!enchant_spell(randint1(3), randint1(3), 0)) used_up = FALSE;
1604                         ident = TRUE;
1605                         break;
1606                 }
1607
1608                 case SV_SCROLL_RECHARGING:
1609                 {
1610                         if (!recharge(130)) used_up = FALSE;
1611                         ident = TRUE;
1612                         break;
1613                 }
1614
1615                 case SV_SCROLL_MUNDANITY:
1616                 {
1617                         ident = TRUE;
1618                         if (!mundane_spell(FALSE)) used_up = FALSE;
1619                         break;
1620                 }
1621
1622                 case SV_SCROLL_LIGHT:
1623                 {
1624                         if (lite_area(damroll(2, 8), 2)) ident = TRUE;
1625                         break;
1626                 }
1627
1628                 case SV_SCROLL_MAPPING:
1629                 {
1630                         map_area(DETECT_RAD_MAP);
1631                         ident = TRUE;
1632                         break;
1633                 }
1634
1635                 case SV_SCROLL_DETECT_GOLD:
1636                 {
1637                         if (detect_treasure(DETECT_RAD_DEFAULT)) ident = TRUE;
1638                         if (detect_objects_gold(DETECT_RAD_DEFAULT)) ident = TRUE;
1639                         break;
1640                 }
1641
1642                 case SV_SCROLL_DETECT_ITEM:
1643                 {
1644                         if (detect_objects_normal(DETECT_RAD_DEFAULT)) ident = TRUE;
1645                         break;
1646                 }
1647
1648                 case SV_SCROLL_DETECT_TRAP:
1649                 {
1650                         if (detect_traps(DETECT_RAD_DEFAULT, known)) ident = TRUE;
1651                         break;
1652                 }
1653
1654                 case SV_SCROLL_DETECT_DOOR:
1655                 {
1656                         if (detect_doors(DETECT_RAD_DEFAULT)) ident = TRUE;
1657                         if (detect_stairs(DETECT_RAD_DEFAULT)) ident = TRUE;
1658                         break;
1659                 }
1660
1661                 case SV_SCROLL_DETECT_INVIS:
1662                 {
1663                         if (detect_monsters_invis(DETECT_RAD_DEFAULT)) ident = TRUE;
1664                         break;
1665                 }
1666
1667                 case SV_SCROLL_SATISFY_HUNGER:
1668                 {
1669                         if (set_food(PY_FOOD_MAX - 1)) ident = TRUE;
1670                         break;
1671                 }
1672
1673                 case SV_SCROLL_BLESSING:
1674                 {
1675                         if (set_blessed(p_ptr->blessed + randint1(12) + 6, FALSE)) ident = TRUE;
1676                         break;
1677                 }
1678
1679                 case SV_SCROLL_HOLY_CHANT:
1680                 {
1681                         if (set_blessed(p_ptr->blessed + randint1(24) + 12, FALSE)) ident = TRUE;
1682                         break;
1683                 }
1684
1685                 case SV_SCROLL_HOLY_PRAYER:
1686                 {
1687                         if (set_blessed(p_ptr->blessed + randint1(48) + 24, FALSE)) ident = TRUE;
1688                         break;
1689                 }
1690
1691                 case SV_SCROLL_MONSTER_CONFUSION:
1692                 {
1693                         if (!(p_ptr->special_attack & ATTACK_CONFUSE))
1694                         {
1695                                 msg_print(_("手が輝き始めた。", "Your hands begin to glow."));
1696                                 p_ptr->special_attack |= ATTACK_CONFUSE;
1697                                 p_ptr->redraw |= (PR_STATUS);
1698                                 ident = TRUE;
1699                         }
1700                         break;
1701                 }
1702
1703                 case SV_SCROLL_PROTECTION_FROM_EVIL:
1704                 {
1705                         k = 3 * p_ptr->lev;
1706                         if (set_protevil(p_ptr->protevil + randint1(25) + k, FALSE)) ident = TRUE;
1707                         break;
1708                 }
1709
1710                 case SV_SCROLL_RUNE_OF_PROTECTION:
1711                 {
1712                         warding_glyph();
1713                         ident = TRUE;
1714                         break;
1715                 }
1716
1717                 case SV_SCROLL_TRAP_DOOR_DESTRUCTION:
1718                 {
1719                         if (destroy_doors_touch()) ident = TRUE;
1720                         break;
1721                 }
1722
1723                 case SV_SCROLL_STAR_DESTRUCTION:
1724                 {
1725                         if (destroy_area(p_ptr->y, p_ptr->x, 13 + randint0(5), FALSE))
1726                                 ident = TRUE;
1727                         else
1728                                 msg_print(_("ダンジョンが揺れた...", "The dungeon trembles..."));
1729
1730                         break;
1731                 }
1732
1733                 case SV_SCROLL_DISPEL_UNDEAD:
1734                 {
1735                         if (dispel_undead(80)) ident = TRUE;
1736                         break;
1737                 }
1738
1739                 case SV_SCROLL_SPELL:
1740                 {
1741                         if ((p_ptr->pclass == CLASS_WARRIOR) ||
1742                                 (p_ptr->pclass == CLASS_IMITATOR) ||
1743                                 (p_ptr->pclass == CLASS_MINDCRAFTER) ||
1744                                 (p_ptr->pclass == CLASS_SORCERER) ||
1745                                 (p_ptr->pclass == CLASS_ARCHER) ||
1746                                 (p_ptr->pclass == CLASS_MAGIC_EATER) ||
1747                                 (p_ptr->pclass == CLASS_RED_MAGE) ||
1748                                 (p_ptr->pclass == CLASS_SAMURAI) ||
1749                                 (p_ptr->pclass == CLASS_BLUE_MAGE) ||
1750                                 (p_ptr->pclass == CLASS_CAVALRY) ||
1751                                 (p_ptr->pclass == CLASS_BERSERKER) ||
1752                                 (p_ptr->pclass == CLASS_SMITH) ||
1753                                 (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
1754                                 (p_ptr->pclass == CLASS_NINJA) ||
1755                                 (p_ptr->pclass == CLASS_SNIPER)) break;
1756                         p_ptr->add_spells++;
1757                         p_ptr->update |= (PU_SPELLS);
1758                         ident = TRUE;
1759                         break;
1760                 }
1761
1762                 case SV_SCROLL_GENOCIDE:
1763                 {
1764                         (void)symbol_genocide(300, TRUE);
1765                         ident = TRUE;
1766                         break;
1767                 }
1768
1769                 case SV_SCROLL_MASS_GENOCIDE:
1770                 {
1771                         (void)mass_genocide(300, TRUE);
1772                         ident = TRUE;
1773                         break;
1774                 }
1775
1776                 case SV_SCROLL_ACQUIREMENT:
1777                 {
1778                         acquirement(p_ptr->y, p_ptr->x, 1, TRUE, FALSE, FALSE);
1779                         ident = TRUE;
1780                         break;
1781                 }
1782
1783                 case SV_SCROLL_STAR_ACQUIREMENT:
1784                 {
1785                         acquirement(p_ptr->y, p_ptr->x, randint1(2) + 1, TRUE, FALSE, FALSE);
1786                         ident = TRUE;
1787                         break;
1788                 }
1789
1790                 /* New Hengband scrolls */
1791                 case SV_SCROLL_FIRE:
1792                 {
1793                         fire_ball(GF_FIRE, 0, 666, 4);
1794                         /* Note: "Double" damage since it is centered on the player ... */
1795                         if (!(IS_OPPOSE_FIRE() || p_ptr->resist_fire || p_ptr->immune_fire))
1796                                 take_hit(DAMAGE_NOESCAPE, 50+randint1(50), _("炎の巻物", "a Scroll of Fire"), -1);
1797
1798                         ident = TRUE;
1799                         break;
1800                 }
1801
1802
1803                 case SV_SCROLL_ICE:
1804                 {
1805                         fire_ball(GF_ICE, 0, 777, 4);
1806                         if (!(IS_OPPOSE_COLD() || p_ptr->resist_cold || p_ptr->immune_cold))
1807                                 take_hit(DAMAGE_NOESCAPE, 100+randint1(100), _("氷の巻物", "a Scroll of Ice"), -1);
1808
1809                         ident = TRUE;
1810                         break;
1811                 }
1812
1813                 case SV_SCROLL_CHAOS:
1814                 {
1815                         fire_ball(GF_CHAOS, 0, 1000, 4);
1816                         if (!p_ptr->resist_chaos)
1817                                 take_hit(DAMAGE_NOESCAPE, 111+randint1(111), _("ログルスの巻物", "a Scroll of Logrus"), -1);
1818
1819                         ident = TRUE;
1820                         break;
1821                 }
1822
1823                 case SV_SCROLL_RUMOR:
1824                 {
1825                         msg_print(_("巻物にはメッセージが書かれている:", "There is message on the scroll. It says:"));
1826                         msg_print(NULL);
1827                         display_rumor(TRUE);
1828                         msg_print(NULL);
1829                         msg_print(_("巻物は煙を立てて消え去った!", "The scroll disappears in a puff of smoke!"));
1830
1831                         ident = TRUE;
1832                         break;
1833                 }
1834
1835                 case SV_SCROLL_ARTIFACT:
1836                 {
1837                         ident = TRUE;
1838                         if (!artifact_scroll()) used_up = FALSE;
1839                         break;
1840                 }
1841
1842                 case SV_SCROLL_RESET_RECALL:
1843                 {
1844                         ident = TRUE;
1845                         if (!reset_recall()) used_up = FALSE;
1846                         break;
1847                 }
1848
1849                 case SV_SCROLL_AMUSEMENT:
1850                 {
1851                         ident = TRUE;
1852                         amusement(p_ptr->y, p_ptr->x, 1, FALSE);
1853                         break;
1854                 }
1855
1856                 case SV_SCROLL_STAR_AMUSEMENT:
1857                 {
1858                         ident = TRUE;
1859                         amusement(p_ptr->y, p_ptr->x,  randint1(2) + 1, FALSE);
1860                         break;
1861                 }
1862         }
1863         }
1864         else if (o_ptr->name1 == ART_GHB)
1865         {
1866                 msg_print(_("私は苦労して『グレーター・ヘル=ビースト』を倒した。", "I had a very hard time to kill the Greater hell-beast, "));
1867                 msg_print(_("しかし手に入ったのはこのきたないTシャツだけだった。", "but all I got was this lousy t-shirt!"));
1868                 used_up = FALSE;
1869         }
1870         else if (o_ptr->name1 == ART_POWER)
1871         {
1872                 msg_print(_("「一つの指輪は全てを統べ、", "'One Ring to rule them all, "));
1873                 msg_print(NULL);
1874                 msg_print(_("一つの指輪は全てを見つけ、", "One Ring to find them, "));
1875                 msg_print(NULL);
1876                 msg_print(_("一つの指輪は全てを捕らえて", "One Ring to bring them all "));
1877                 msg_print(NULL);
1878                 msg_print(_("暗闇の中に繋ぎとめる。」", "and in the darkness bind them.'"));
1879                 used_up = FALSE;
1880         }
1881         else if (o_ptr->tval==TV_PARCHMENT)
1882         {
1883                 cptr q;
1884                 char o_name[MAX_NLEN];
1885                 char buf[1024];
1886
1887                 /* Save screen */
1888                 screen_save();
1889
1890                 q=format("book-%d_jp.txt",o_ptr->sval);
1891
1892                 /* Display object description */
1893                 object_desc(o_name, o_ptr, OD_NAME_ONLY);
1894
1895                 /* Build the filename */
1896                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, q);
1897
1898                 /* Peruse the help file */
1899                 (void)show_file(TRUE, buf, o_name, 0, 0);
1900
1901                 /* Load screen */
1902                 screen_load();
1903
1904                 used_up=FALSE;
1905         }
1906
1907
1908         /* Combine / Reorder the pack (later) */
1909         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1910
1911         if (!(object_is_aware(o_ptr)))
1912         {
1913                 chg_virtue(V_PATIENCE, -1);
1914                 chg_virtue(V_CHANCE, 1);
1915                 chg_virtue(V_KNOWLEDGE, -1);
1916         }
1917
1918         /* The item was tried */
1919         object_tried(o_ptr);
1920
1921         /* An identification was made */
1922         if (ident && !object_is_aware(o_ptr))
1923         {
1924                 object_aware(o_ptr);
1925                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
1926         }
1927
1928         /* Window stuff */
1929         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1930
1931
1932         /* Hack -- allow certain scrolls to be "preserved" */
1933         if (!used_up)
1934         {
1935                 return;
1936         }
1937
1938         sound(SOUND_SCROLL);
1939
1940         /* Destroy a scroll in the pack */
1941         if (item >= 0)
1942         {
1943                 inven_item_increase(item, -1);
1944                 inven_item_describe(item);
1945                 inven_item_optimize(item);
1946         }
1947
1948         /* Destroy a scroll on the floor */
1949         else
1950         {
1951                 floor_item_increase(0 - item, -1);
1952                 floor_item_describe(0 - item);
1953                 floor_item_optimize(0 - item);
1954         }
1955 }
1956
1957 /*!
1958  * @brief オブジェクトをプレイヤーが読むことができるかを判定する /
1959  * Hook to determine if an object is readable
1960  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1961  * @return 読むことが可能ならばTRUEを返す
1962  */
1963 static bool item_tester_hook_readable(object_type *o_ptr)
1964 {
1965         if ((o_ptr->tval==TV_SCROLL) || (o_ptr->tval==TV_PARCHMENT) || (o_ptr->name1 == ART_GHB) || (o_ptr->name1 == ART_POWER)) return (TRUE);
1966
1967         /* Assume not */
1968         return (FALSE);
1969 }
1970
1971 /*!
1972  * @brief 読むコマンドのメインルーチン /
1973  * Eat some food (from the pack or floor)
1974  * @return なし
1975  */
1976 void do_cmd_read_scroll(void)
1977 {
1978         object_type *o_ptr;
1979         OBJECT_IDX item;
1980         cptr q, s;
1981
1982         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
1983         {
1984                 set_action(ACTION_NONE);
1985         }
1986
1987         /* Check some conditions */
1988         if (p_ptr->blind)
1989         {
1990                 msg_print(_("目が見えない。", "You can't see anything."));
1991                 return;
1992         }
1993         if (no_lite())
1994         {
1995                 msg_print(_("明かりがないので、暗くて読めない。", "You have no light to read by."));
1996                 return;
1997         }
1998         if (p_ptr->confused)
1999         {
2000                 msg_print(_("混乱していて読めない。", "You are too confused!"));
2001                 return;
2002         }
2003
2004
2005         /* Restrict choices to scrolls */
2006         item_tester_hook = item_tester_hook_readable;
2007
2008         /* Get an item */
2009         q = _("どの巻物を読みますか? ", "Read which scroll? ");
2010         s = _("読める巻物がない。", "You have no scrolls to read.");
2011
2012         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
2013
2014         /* Get the item (in the pack) */
2015         if (item >= 0)
2016         {
2017                 o_ptr = &inventory[item];
2018         }
2019
2020         /* Get the item (on the floor) */
2021         else
2022         {
2023                 o_ptr = &o_list[0 - item];
2024         }
2025
2026         /* Read the scroll */
2027         do_cmd_read_scroll_aux(item, object_is_aware(o_ptr));
2028 }
2029
2030 /*!
2031  * @brief 杖の効果を発動する
2032  * @param sval オブジェクトのsval
2033  * @param use_charge 使用回数を消費したかどうかを返す参照ポインタ
2034  * @param powerful 強力発動上の処理ならばTRUE
2035  * @param magic 魔道具術上の処理ならばTRUE
2036  * @param known 判明済ならばTRUE
2037  * @return 発動により効果内容が確定したならばTRUEを返す
2038  */
2039 static int staff_effect(OBJECT_SUBTYPE_VALUE sval, bool *use_charge, bool powerful, bool magic, bool known)
2040 {
2041         int k;
2042         int ident = FALSE;
2043         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
2044         int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
2045
2046         /* Analyze the staff */
2047         switch (sval)
2048         {
2049                 case SV_STAFF_DARKNESS:
2050                 {
2051                         if (!(p_ptr->resist_blind) && !(p_ptr->resist_dark))
2052                         {
2053                                 if (set_blind(p_ptr->blind + 3 + randint1(5))) ident = TRUE;
2054                         }
2055                         if (unlite_area(10, (powerful ? 6 : 3))) ident = TRUE;
2056                         break;
2057                 }
2058
2059                 case SV_STAFF_SLOWNESS:
2060                 {
2061                         if (set_slow(p_ptr->slow + randint1(30) + 15, FALSE)) ident = TRUE;
2062                         break;
2063                 }
2064
2065                 case SV_STAFF_HASTE_MONSTERS:
2066                 {
2067                         if (speed_monsters()) ident = TRUE;
2068                         break;
2069                 }
2070
2071                 case SV_STAFF_SUMMONING:
2072                 {
2073                         const int times = randint1(powerful ? 8 : 4);
2074                         for (k = 0; k < times; k++)
2075                         {
2076                                 if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
2077                                 {
2078                                         ident = TRUE;
2079                                 }
2080                         }
2081                         break;
2082                 }
2083
2084                 case SV_STAFF_TELEPORTATION:
2085                 {
2086                         teleport_player((powerful ? 150 : 100), 0L);
2087                         ident = TRUE;
2088                         break;
2089                 }
2090
2091                 case SV_STAFF_IDENTIFY:
2092                 {
2093                         if (powerful) {
2094                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
2095                         } else {
2096                                 if (!ident_spell(FALSE)) *use_charge = FALSE;
2097                         }
2098                         ident = TRUE;
2099                         break;
2100                 }
2101
2102                 case SV_STAFF_REMOVE_CURSE:
2103                 {
2104                         bool result = powerful ? remove_all_curse() : remove_curse();
2105                         if (result)
2106                         {
2107                                 if (magic)
2108                                 {
2109                                         msg_print(_("誰かに見守られているような気がする。", "You feel as if someone is watching over you."));
2110                                 }
2111                                 else if (!p_ptr->blind)
2112                                 {
2113                                         msg_print(_("杖は一瞬ブルーに輝いた...", "The staff glows blue for a moment..."));
2114
2115                                 }
2116                                 ident = TRUE;
2117                         }
2118                         break;
2119                 }
2120
2121                 case SV_STAFF_STARLITE:
2122                 {
2123                         HIT_POINT num = damroll(5, 3);
2124                         POSITION y = 0, x = 0;
2125                         int attempts;
2126
2127                         if (!p_ptr->blind && !magic)
2128                         {
2129                                 msg_print(_("杖の先が明るく輝いた...", "The end of the staff glows brightly..."));
2130                         }
2131                         for (k = 0; k < num; k++)
2132                         {
2133                                 attempts = 1000;
2134
2135                                 while (attempts--)
2136                                 {
2137                                         scatter(&y, &x, p_ptr->y, p_ptr->x, 4, 0);
2138
2139                                         if (!cave_have_flag_bold(y, x, FF_PROJECT)) continue;
2140
2141                                         if (!player_bold(y, x)) break;
2142                                 }
2143
2144                                 project(0, 0, y, x, damroll(6 + lev / 8, 10), GF_LITE_WEAK,
2145                                                   (PROJECT_BEAM | PROJECT_THRU | PROJECT_GRID | PROJECT_KILL), -1);
2146                         }
2147                         ident = TRUE;
2148                         break;
2149                 }
2150
2151                 case SV_STAFF_LITE:
2152                 {
2153                         if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
2154                         break;
2155                 }
2156
2157                 case SV_STAFF_MAPPING:
2158                 {
2159                         map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
2160                         ident = TRUE;
2161                         break;
2162                 }
2163
2164                 case SV_STAFF_DETECT_GOLD:
2165                 {
2166                         if (detect_treasure(detect_rad)) ident = TRUE;
2167                         if (detect_objects_gold(detect_rad)) ident = TRUE;
2168                         break;
2169                 }
2170
2171                 case SV_STAFF_DETECT_ITEM:
2172                 {
2173                         if (detect_objects_normal(detect_rad)) ident = TRUE;
2174                         break;
2175                 }
2176
2177                 case SV_STAFF_DETECT_TRAP:
2178                 {
2179                         if (detect_traps(detect_rad, known)) ident = TRUE;
2180                         break;
2181                 }
2182
2183                 case SV_STAFF_DETECT_DOOR:
2184                 {
2185                         if (detect_doors(detect_rad)) ident = TRUE;
2186                         if (detect_stairs(detect_rad)) ident = TRUE;
2187                         break;
2188                 }
2189
2190                 case SV_STAFF_DETECT_INVIS:
2191                 {
2192                         if (detect_monsters_invis(detect_rad)) ident = TRUE;
2193                         break;
2194                 }
2195
2196                 case SV_STAFF_DETECT_EVIL:
2197                 {
2198                         if (detect_monsters_evil(detect_rad)) ident = TRUE;
2199                         break;
2200                 }
2201
2202                 case SV_STAFF_CURE_LIGHT:
2203                 {
2204                         if (hp_player(damroll((powerful ? 4 : 2), 8))) ident = TRUE;
2205                         if (powerful) {
2206                                 if (set_blind(0)) ident = TRUE;
2207                                 if (set_poisoned(0)) ident = TRUE;
2208                                 if (set_cut(p_ptr->cut - 10)) ident = TRUE;
2209                         }
2210                         if (set_shero(0,TRUE)) ident = TRUE;
2211                         break;
2212                 }
2213
2214                 case SV_STAFF_CURING:
2215                 {
2216                         if (set_blind(0)) ident = TRUE;
2217                         if (set_poisoned(0)) ident = TRUE;
2218                         if (set_confused(0)) ident = TRUE;
2219                         if (set_stun(0)) ident = TRUE;
2220                         if (set_cut(0)) ident = TRUE;
2221                         if (set_image(0)) ident = TRUE;
2222                         if (set_shero(0,TRUE)) ident = TRUE;
2223                         break;
2224                 }
2225
2226                 case SV_STAFF_HEALING:
2227                 {
2228                         if (hp_player(powerful ? 500 : 300)) ident = TRUE;
2229                         if (set_stun(0)) ident = TRUE;
2230                         if (set_cut(0)) ident = TRUE;
2231                         if (set_shero(0,TRUE)) ident = TRUE;
2232                         break;
2233                 }
2234
2235                 case SV_STAFF_THE_MAGI:
2236                 {
2237                         if (do_res_stat(A_INT)) ident = TRUE;
2238                         if (p_ptr->csp < p_ptr->msp)
2239                         {
2240                                 p_ptr->csp = p_ptr->msp;
2241                                 p_ptr->csp_frac = 0;
2242                                 ident = TRUE;
2243                                 msg_print(_("頭がハッキリとした。", "You feel your head clear."));
2244
2245                                 p_ptr->redraw |= (PR_MANA);
2246                                 p_ptr->window |= (PW_PLAYER);
2247                                 p_ptr->window |= (PW_SPELL);
2248                         }
2249                         if (set_shero(0,TRUE)) ident = TRUE;
2250                         break;
2251                 }
2252
2253                 case SV_STAFF_SLEEP_MONSTERS:
2254                 {
2255                         if (sleep_monsters(lev)) ident = TRUE;
2256                         break;
2257                 }
2258
2259                 case SV_STAFF_SLOW_MONSTERS:
2260                 {
2261                         if (slow_monsters(lev)) ident = TRUE;
2262                         break;
2263                 }
2264
2265                 case SV_STAFF_SPEED:
2266                 {
2267                         if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
2268                         break;
2269                 }
2270
2271                 case SV_STAFF_PROBING:
2272                 {
2273                         probing();
2274                         ident = TRUE;
2275                         break;
2276                 }
2277
2278                 case SV_STAFF_DISPEL_EVIL:
2279                 {
2280                         if (dispel_evil(powerful ? 120 : 80)) ident = TRUE;
2281                         break;
2282                 }
2283
2284                 case SV_STAFF_POWER:
2285                 {
2286                         if (dispel_monsters(powerful ? 225 : 150)) ident = TRUE;
2287                         break;
2288                 }
2289
2290                 case SV_STAFF_HOLINESS:
2291                 {
2292                         if (dispel_evil(powerful ? 225 : 150)) ident = TRUE;
2293                         k = 3 * lev;
2294                         if (set_protevil((magic ? 0 : p_ptr->protevil) + randint1(25) + k, FALSE)) ident = TRUE;
2295                         if (set_poisoned(0)) ident = TRUE;
2296                         if (set_afraid(0)) ident = TRUE;
2297                         if (hp_player(50)) ident = TRUE;
2298                         if (set_stun(0)) ident = TRUE;
2299                         if (set_cut(0)) ident = TRUE;
2300                         break;
2301                 }
2302
2303                 case SV_STAFF_GENOCIDE:
2304                 {
2305                         (void)symbol_genocide((magic ? lev + 50 : 200), TRUE);
2306                         ident = TRUE;
2307                         break;
2308                 }
2309
2310                 case SV_STAFF_EARTHQUAKES:
2311                 {
2312                         if (earthquake(p_ptr->y, p_ptr->x, (powerful ? 15 : 10)))
2313                                 ident = TRUE;
2314                         else
2315                                 msg_print(_("ダンジョンが揺れた。", "The dungeon trembles."));
2316
2317                         break;
2318                 }
2319
2320                 case SV_STAFF_DESTRUCTION:
2321                 {
2322                         if (destroy_area(p_ptr->y, p_ptr->x, (powerful ? 18 : 13) + randint0(5), FALSE))
2323                                 ident = TRUE;
2324
2325                         break;
2326                 }
2327
2328                 case SV_STAFF_ANIMATE_DEAD:
2329                 {
2330                         if (animate_dead(0, p_ptr->y, p_ptr->x))
2331                                 ident = TRUE;
2332
2333                         break;
2334                 }
2335
2336                 case SV_STAFF_MSTORM:
2337                 {
2338                         msg_print(_("強力な魔力が敵を引き裂いた!", "Mighty magics rend your enemies!"));
2339                         project(0, (powerful ? 7 : 5), p_ptr->y, p_ptr->x,
2340                                 (randint1(200) + (powerful ? 500 : 300)) * 2, GF_MANA, PROJECT_KILL | PROJECT_ITEM | PROJECT_GRID, -1);
2341                         if ((p_ptr->pclass != CLASS_MAGE) && (p_ptr->pclass != CLASS_HIGH_MAGE) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_MAGIC_EATER) && (p_ptr->pclass != CLASS_BLUE_MAGE))
2342                         {
2343                                 (void)take_hit(DAMAGE_NOESCAPE, 50, _("コントロールし難い強力な魔力の解放", "unleashing magics too mighty to control"), -1);
2344                         }
2345                         ident = TRUE;
2346
2347                         break;
2348                 }
2349
2350                 case SV_STAFF_NOTHING:
2351                 {
2352                         msg_print(_("何も起らなかった。", "Nothing happen."));
2353                         if (prace_is_(RACE_SKELETON) || prace_is_(RACE_GOLEM) ||
2354                                 prace_is_(RACE_ZOMBIE) || prace_is_(RACE_SPECTRE))
2355                                 msg_print(_("もったいない事をしたような気がする。食べ物は大切にしなくては。", "What a waste.  It's your food!"));
2356                         break;
2357                 }
2358         }
2359         return ident;
2360 }
2361
2362 /*!
2363  * @brief 杖を使うコマンドのサブルーチン / 
2364  * Use a staff.                 -RAK-
2365  * @param item 使うオブジェクトの所持品ID
2366  * @return なし
2367  * @details
2368  * One charge of one staff disappears.
2369  * Hack -- staffs of identify can be "cancelled".
2370  */
2371 static void do_cmd_use_staff_aux(int item)
2372 {
2373         int         ident, chance, lev;
2374         object_type *o_ptr;
2375
2376
2377         /* Hack -- let staffs of identify get aborted */
2378         bool use_charge = TRUE;
2379
2380
2381         /* Get the item (in the pack) */
2382         if (item >= 0)
2383         {
2384                 o_ptr = &inventory[item];
2385         }
2386
2387         /* Get the item (on the floor) */
2388         else
2389         {
2390                 o_ptr = &o_list[0 - item];
2391         }
2392
2393
2394         /* Mega-Hack -- refuse to use a pile from the ground */
2395         if ((item < 0) && (o_ptr->number > 1))
2396         {
2397                 msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
2398                 return;
2399         }
2400
2401
2402         /* Take a turn */
2403         p_ptr->energy_use = 100;
2404
2405         /* Extract the item level */
2406         lev = k_info[o_ptr->k_idx].level;
2407         if (lev > 50) lev = 50 + (lev - 50)/2;
2408
2409         /* Base chance of success */
2410         chance = p_ptr->skill_dev;
2411
2412         /* Confusion hurts skill */
2413         if (p_ptr->confused) chance = chance / 2;
2414
2415         /* Hight level objects are harder */
2416         chance = chance - lev;
2417
2418         /* Give everyone a (slight) chance */
2419         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
2420         {
2421                 chance = USE_DEVICE;
2422         }
2423
2424         if (world_player)
2425         {
2426                 if (flush_failure) flush();
2427                 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen. Maybe this staff is freezing too."));
2428                 sound(SOUND_FAIL);
2429                 return;
2430         }
2431
2432         /* Roll for usage */
2433         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
2434         {
2435                 if (flush_failure) flush();
2436                 msg_print(_("杖をうまく使えなかった。", "You failed to use the staff properly."));
2437                 sound(SOUND_FAIL);
2438                 return;
2439         }
2440
2441         /* Notice empty staffs */
2442         if (o_ptr->pval <= 0)
2443         {
2444                 if (flush_failure) flush();
2445                 msg_print(_("この杖にはもう魔力が残っていない。", "The staff has no charges left."));
2446                 o_ptr->ident |= (IDENT_EMPTY);
2447
2448                 /* Combine / Reorder the pack (later) */
2449                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2450                 p_ptr->window |= (PW_INVEN);
2451
2452                 return;
2453         }
2454
2455
2456         /* Sound */
2457         sound(SOUND_ZAP);
2458
2459         ident = staff_effect(o_ptr->sval, &use_charge, FALSE, FALSE, object_is_aware(o_ptr));
2460
2461         if (!(object_is_aware(o_ptr)))
2462         {
2463                 chg_virtue(V_PATIENCE, -1);
2464                 chg_virtue(V_CHANCE, 1);
2465                 chg_virtue(V_KNOWLEDGE, -1);
2466         }
2467
2468         /* Combine / Reorder the pack (later) */
2469         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2470
2471         /* Tried the item */
2472         object_tried(o_ptr);
2473
2474         /* An identification was made */
2475         if (ident && !object_is_aware(o_ptr))
2476         {
2477                 object_aware(o_ptr);
2478                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
2479         }
2480
2481         /* Window stuff */
2482         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2483
2484
2485         /* Hack -- some uses are "free" */
2486         if (!use_charge) return;
2487
2488
2489         /* Use a single charge */
2490         o_ptr->pval--;
2491
2492         /* XXX Hack -- unstack if necessary */
2493         if ((item >= 0) && (o_ptr->number > 1))
2494         {
2495                 object_type forge;
2496                 object_type *q_ptr;
2497
2498                 /* Get local object */
2499                 q_ptr = &forge;
2500
2501                 /* Obtain a local object */
2502                 object_copy(q_ptr, o_ptr);
2503
2504                 /* Modify quantity */
2505                 q_ptr->number = 1;
2506
2507                 /* Restore the charges */
2508                 o_ptr->pval++;
2509
2510                 /* Unstack the used item */
2511                 o_ptr->number--;
2512                 p_ptr->total_weight -= q_ptr->weight;
2513                 item = inven_carry(q_ptr);
2514
2515                 /* Message */
2516                 msg_print(_("杖をまとめなおした。", "You unstack your staff."));
2517         }
2518
2519         /* Describe charges in the pack */
2520         if (item >= 0)
2521         {
2522                 inven_item_charges(item);
2523         }
2524
2525         /* Describe charges on the floor */
2526         else
2527         {
2528                 floor_item_charges(0 - item);
2529         }
2530 }
2531
2532 /*!
2533  * @brief 杖を使うコマンドのメインルーチン /
2534  * @return なし
2535  */
2536 void do_cmd_use_staff(void)
2537 {
2538         OBJECT_IDX item;
2539         cptr q, s;
2540
2541         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
2542         {
2543                 set_action(ACTION_NONE);
2544         }
2545
2546         /* Restrict choices to wands */
2547         item_tester_tval = TV_STAFF;
2548
2549         /* Get an item */
2550         q = _("どの杖を使いますか? ", "Use which staff? ");
2551         s = _("使える杖がない。", "You have no staff to use.");
2552
2553         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
2554
2555         do_cmd_use_staff_aux(item);
2556 }
2557
2558 /*!
2559  * @brief 魔法棒の効果を発動する
2560  * @param sval オブジェクトのsval
2561  * @param dir 発動の方向ID
2562  * @param powerful 強力発動上の処理ならばTRUE
2563  * @param magic 魔道具術上の処理ならばTRUE
2564  * @return 発動により効果内容が確定したならばTRUEを返す
2565  */
2566 static int wand_effect(OBJECT_SUBTYPE_VALUE sval, int dir, bool powerful, bool magic)
2567 {
2568         int ident = FALSE;
2569         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
2570         int rad = powerful ? 3 : 2;
2571
2572         /* XXX Hack -- Wand of wonder can do anything before it */
2573         if (sval == SV_WAND_WONDER)
2574         {
2575                 int vir = virtue_number(V_CHANCE);
2576                 sval = (OBJECT_SUBTYPE_VALUE)randint0(SV_WAND_WONDER);
2577
2578                 if (vir)
2579                 {
2580                         if (p_ptr->virtues[vir - 1] > 0)
2581                         {
2582                                 while (randint1(300) < p_ptr->virtues[vir - 1]) sval++;
2583                                 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
2584                         }
2585                         else
2586                         {
2587                                 while (randint1(300) < (0-p_ptr->virtues[vir - 1])) sval--;
2588                                 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
2589                         }
2590                 }
2591                 if (sval < SV_WAND_TELEPORT_AWAY)
2592                         chg_virtue(V_CHANCE, 1);
2593         }
2594
2595         /* Analyze the wand */
2596         switch (sval)
2597         {
2598                 case SV_WAND_HEAL_MONSTER:
2599                 {
2600                         HIT_POINT dam = damroll((powerful ? 20 : 10), 10);
2601                         if (heal_monster(dir, dam)) ident = TRUE;
2602                         break;
2603                 }
2604
2605                 case SV_WAND_HASTE_MONSTER:
2606                 {
2607                         if (speed_monster(dir, lev)) ident = TRUE;
2608                         break;
2609                 }
2610
2611                 case SV_WAND_CLONE_MONSTER:
2612                 {
2613                         if (clone_monster(dir)) ident = TRUE;
2614                         break;
2615                 }
2616
2617                 case SV_WAND_TELEPORT_AWAY:
2618                 {
2619                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
2620                         if (teleport_monster(dir, distance)) ident = TRUE;
2621                         break;
2622                 }
2623
2624                 case SV_WAND_DISARMING:
2625                 {
2626                         if (disarm_trap(dir)) ident = TRUE;
2627                         if (powerful && disarm_traps_touch()) ident = TRUE;
2628                         break;
2629                 }
2630
2631                 case SV_WAND_TRAP_DOOR_DEST:
2632                 {
2633                         if (destroy_door(dir)) ident = TRUE;
2634                         if (powerful && destroy_doors_touch()) ident = TRUE;
2635                         break;
2636                 }
2637
2638                 case SV_WAND_STONE_TO_MUD:
2639                 {
2640                         HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
2641                         if (wall_to_mud(dir, dam)) ident = TRUE;
2642                         break;
2643                 }
2644
2645                 case SV_WAND_LITE:
2646                 {
2647                         HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
2648                         msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
2649                         (void)lite_line(dir, dam);
2650                         ident = TRUE;
2651                         break;
2652                 }
2653
2654                 case SV_WAND_SLEEP_MONSTER:
2655                 {
2656                         if (sleep_monster(dir, lev)) ident = TRUE;
2657                         break;
2658                 }
2659
2660                 case SV_WAND_SLOW_MONSTER:
2661                 {
2662                         if (slow_monster(dir, lev)) ident = TRUE;
2663                         break;
2664                 }
2665
2666                 case SV_WAND_CONFUSE_MONSTER:
2667                 {
2668                         if (confuse_monster(dir, lev)) ident = TRUE;
2669                         break;
2670                 }
2671
2672                 case SV_WAND_FEAR_MONSTER:
2673                 {
2674                         if (fear_monster(dir, lev)) ident = TRUE;
2675                         break;
2676                 }
2677
2678                 case SV_WAND_HYPODYNAMIA:
2679                 {
2680                         if (hypodynamic_bolt(dir, 80 + lev)) ident = TRUE;
2681                         break;
2682                 }
2683
2684                 case SV_WAND_POLYMORPH:
2685                 {
2686                         if (poly_monster(dir, lev)) ident = TRUE;
2687                         break;
2688                 }
2689
2690                 case SV_WAND_STINKING_CLOUD:
2691                 {
2692                         fire_ball(GF_POIS, dir, 12 + lev / 4, rad);
2693                         ident = TRUE;
2694                         break;
2695                 }
2696
2697                 case SV_WAND_MAGIC_MISSILE:
2698                 {
2699                         fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
2700                         ident = TRUE;
2701                         break;
2702                 }
2703
2704                 case SV_WAND_ACID_BOLT:
2705                 {
2706                         fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
2707                         ident = TRUE;
2708                         break;
2709                 }
2710
2711                 case SV_WAND_CHARM_MONSTER:
2712                 {
2713                         if (charm_monster(dir, MAX(20, lev)))
2714                         ident = TRUE;
2715                         break;
2716                 }
2717
2718                 case SV_WAND_FIRE_BOLT:
2719                 {
2720                         fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
2721                         ident = TRUE;
2722                         break;
2723                 }
2724
2725                 case SV_WAND_COLD_BOLT:
2726                 {
2727                         fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
2728                         ident = TRUE;
2729                         break;
2730                 }
2731
2732                 case SV_WAND_ACID_BALL:
2733                 {
2734                         fire_ball(GF_ACID, dir, 60 + 3 * lev / 4, rad);
2735                         ident = TRUE;
2736                         break;
2737                 }
2738
2739                 case SV_WAND_ELEC_BALL:
2740                 {
2741                         fire_ball(GF_ELEC, dir, 40 + 3 * lev / 4, rad);
2742                         ident = TRUE;
2743                         break;
2744                 }
2745
2746                 case SV_WAND_FIRE_BALL:
2747                 {
2748                         fire_ball(GF_FIRE, dir, 70 + 3 * lev / 4, rad);
2749                         ident = TRUE;
2750                         break;
2751                 }
2752
2753                 case SV_WAND_COLD_BALL:
2754                 {
2755                         fire_ball(GF_COLD, dir, 50 + 3 * lev / 4, rad);
2756                         ident = TRUE;
2757                         break;
2758                 }
2759
2760                 case SV_WAND_WONDER:
2761                 {
2762                         msg_print(_("おっと、謎の魔法棒を始動させた。", "Oops.  Wand of wonder activated."));
2763                         break;
2764                 }
2765
2766                 case SV_WAND_DRAGON_FIRE:
2767                 {
2768                         fire_ball(GF_FIRE, dir, (powerful ? 300 : 200), -3);
2769                         ident = TRUE;
2770                         break;
2771                 }
2772
2773                 case SV_WAND_DRAGON_COLD:
2774                 {
2775                         fire_ball(GF_COLD, dir, (powerful ? 270 : 180), -3);
2776                         ident = TRUE;
2777                         break;
2778                 }
2779
2780                 case SV_WAND_DRAGON_BREATH:
2781                 {
2782                         HIT_POINT dam;
2783                         int typ;
2784
2785                         switch (randint1(5))
2786                         {
2787                                 case 1:
2788                                         dam = 240;
2789                                         typ = GF_ACID;
2790                                         break;
2791                                 case 2:
2792                                         dam = 210;
2793                                         typ = GF_ELEC;
2794                                         break;
2795                                 case 3:
2796                                         dam = 240;
2797                                         typ = GF_FIRE;
2798                                         break;
2799                                 case 4:
2800                                         dam = 210;
2801                                         typ = GF_COLD;
2802                                         break;
2803                                 default:
2804                                         dam = 180;
2805                                         typ = GF_POIS;
2806                                         break;
2807                         }
2808
2809                         if (powerful) dam = (dam * 3) / 2;
2810
2811                         fire_ball(typ, dir, dam, -3);
2812
2813                         ident = TRUE;
2814                         break;
2815                 }
2816
2817                 case SV_WAND_DISINTEGRATE:
2818                 {
2819                         fire_ball(GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
2820                         ident = TRUE;
2821                         break;
2822                 }
2823
2824                 case SV_WAND_ROCKETS:
2825                 {
2826                         msg_print(_("ロケットを発射した!", "You launch a rocket!"));
2827                         fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
2828                         ident = TRUE;
2829                         break;
2830                 }
2831
2832                 case SV_WAND_STRIKING:
2833                 {
2834                         fire_bolt(GF_METEOR, dir, damroll(15 + lev / 3, 13));
2835                         ident = TRUE;
2836                         break;
2837                 }
2838
2839                 case SV_WAND_GENOCIDE:
2840                 {
2841                         fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
2842                         ident = TRUE;
2843                         break;
2844                 }
2845         }
2846         return ident;
2847 }
2848
2849 /*!
2850  * @brief 魔法棒を使うコマンドのサブルーチン / 
2851  * Aim a wand (from the pack or floor).
2852  * @param item 使うオブジェクトの所持品ID
2853  * @return なし
2854  * @details
2855  * <pre>
2856  * Use a single charge from a single item.
2857  * Handle "unstacking" in a logical manner.
2858  * For simplicity, you cannot use a stack of items from the
2859  * ground.  This would require too much nasty code.
2860  * There are no wands which can "destroy" themselves, in the inventory
2861  * or on the ground, so we can ignore this possibility.  Note that this
2862  * required giving "wand of wonder" the ability to ignore destruction
2863  * by electric balls.
2864  * All wands can be "cancelled" at the "Direction?" prompt for free.
2865  * Note that the basic "bolt" wands do slightly less damage than the
2866  * basic "bolt" rods, but the basic "ball" wands do the same damage
2867  * as the basic "ball" rods.
2868  * </pre>
2869  */
2870 static void do_cmd_aim_wand_aux(int item)
2871 {
2872         int         lev, ident, chance, dir;
2873         object_type *o_ptr;
2874         bool old_target_pet = target_pet;
2875
2876         /* Get the item (in the pack) */
2877         if (item >= 0)
2878         {
2879                 o_ptr = &inventory[item];
2880         }
2881
2882         /* Get the item (on the floor) */
2883         else
2884         {
2885                 o_ptr = &o_list[0 - item];
2886         }
2887
2888         /* Mega-Hack -- refuse to aim a pile from the ground */
2889         if ((item < 0) && (o_ptr->number > 1))
2890         {
2891                 msg_print(_("まずは魔法棒を拾わなければ。", "You must first pick up the wands."));
2892                 return;
2893         }
2894
2895
2896         /* Allow direction to be cancelled for free */
2897         if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
2898                                       || o_ptr->sval == SV_WAND_HASTE_MONSTER))
2899                         target_pet = TRUE;
2900         if (!get_aim_dir(&dir))
2901         {
2902                 target_pet = old_target_pet;
2903                 return;
2904         }
2905         target_pet = old_target_pet;
2906
2907         /* Take a turn */
2908         p_ptr->energy_use = 100;
2909
2910         /* Get the level */
2911         lev = k_info[o_ptr->k_idx].level;
2912         if (lev > 50) lev = 50 + (lev - 50)/2;
2913
2914         /* Base chance of success */
2915         chance = p_ptr->skill_dev;
2916
2917         /* Confusion hurts skill */
2918         if (p_ptr->confused) chance = chance / 2;
2919
2920         /* Hight level objects are harder */
2921         chance = chance - lev;
2922
2923         /* Give everyone a (slight) chance */
2924         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
2925         {
2926                 chance = USE_DEVICE;
2927         }
2928
2929         if (world_player)
2930         {
2931                 if (flush_failure) flush();
2932                 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen. Maybe this wand is freezing too."));
2933                 sound(SOUND_FAIL);
2934                 return;
2935         }
2936
2937         /* Roll for usage */
2938         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
2939         {
2940                 if (flush_failure) flush();
2941                 msg_print(_("魔法棒をうまく使えなかった。", "You failed to use the wand properly."));
2942                 sound(SOUND_FAIL);
2943                 return;
2944         }
2945
2946         /* The wand is already empty! */
2947         if (o_ptr->pval <= 0)
2948         {
2949                 if (flush_failure) flush();
2950                 msg_print(_("この魔法棒にはもう魔力が残っていない。", "The wand has no charges left."));
2951                 o_ptr->ident |= (IDENT_EMPTY);
2952
2953                 /* Combine / Reorder the pack (later) */
2954                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2955                 p_ptr->window |= (PW_INVEN);
2956
2957                 return;
2958         }
2959
2960         /* Sound */
2961         sound(SOUND_ZAP);
2962
2963         ident = wand_effect(o_ptr->sval, dir, FALSE, FALSE);
2964
2965         /* Combine / Reorder the pack (later) */
2966         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2967
2968         if (!(object_is_aware(o_ptr)))
2969         {
2970                 chg_virtue(V_PATIENCE, -1);
2971                 chg_virtue(V_CHANCE, 1);
2972                 chg_virtue(V_KNOWLEDGE, -1);
2973         }
2974
2975         /* Mark it as tried */
2976         object_tried(o_ptr);
2977
2978         /* Apply identification */
2979         if (ident && !object_is_aware(o_ptr))
2980         {
2981                 object_aware(o_ptr);
2982                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
2983         }
2984
2985         /* Window stuff */
2986         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2987
2988
2989         /* Use a single charge */
2990         o_ptr->pval--;
2991
2992         /* Describe the charges in the pack */
2993         if (item >= 0)
2994         {
2995                 inven_item_charges(item);
2996         }
2997
2998         /* Describe the charges on the floor */
2999         else
3000         {
3001                 floor_item_charges(0 - item);
3002         }
3003 }
3004
3005 /*!
3006  * @brief 魔法棒を使うコマンドのメインルーチン /
3007  * @return なし
3008  */
3009 void do_cmd_aim_wand(void)
3010 {
3011         OBJECT_IDX item;
3012         cptr    q, s;
3013
3014         /* Restrict choices to wands */
3015         item_tester_tval = TV_WAND;
3016
3017         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
3018         {
3019                 set_action(ACTION_NONE);
3020         }
3021
3022         /* Get an item */
3023         q = _("どの魔法棒で狙いますか? ", "Aim which wand? ");
3024         s = _("使える魔法棒がない。", "You have no wand to aim.");
3025         
3026         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
3027
3028         /* Aim the wand */
3029         do_cmd_aim_wand_aux(item);
3030 }
3031
3032 /*!
3033  * @brief ロッドの効果を発動する
3034  * @param sval オブジェクトのsval
3035  * @param dir 発動目標の方向ID
3036  * @param use_charge チャージを消費したかどうかを返す参照ポインタ
3037  * @param powerful 強力発動上の処理ならばTRUE
3038  * @param magic 魔道具術上の処理ならばTRUE
3039  * @return 発動により効果内容が確定したならばTRUEを返す
3040  */
3041 static int rod_effect(OBJECT_SUBTYPE_VALUE sval, int dir, bool *use_charge, bool powerful, bool magic)
3042 {
3043         int ident = FALSE;
3044         int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
3045         int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
3046         int rad = powerful ? 3 : 2;
3047
3048         /* Unused */
3049         (void)magic;
3050
3051         /* Analyze the rod */
3052         switch (sval)
3053         {
3054                 case SV_ROD_DETECT_TRAP:
3055                 {
3056                         if (detect_traps(detect_rad, (bool)(dir ? FALSE : TRUE))) ident = TRUE;
3057                         break;
3058                 }
3059
3060                 case SV_ROD_DETECT_DOOR:
3061                 {
3062                         if (detect_doors(detect_rad)) ident = TRUE;
3063                         if (detect_stairs(detect_rad)) ident = TRUE;
3064                         break;
3065                 }
3066
3067                 case SV_ROD_IDENTIFY:
3068                 {
3069                         if (powerful) {
3070                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
3071                         } else {
3072                                 if (!ident_spell(FALSE)) *use_charge = FALSE;
3073                         }
3074                         ident = TRUE;
3075                         break;
3076                 }
3077
3078                 case SV_ROD_RECALL:
3079                 {
3080                         if (!word_of_recall()) *use_charge = FALSE;
3081                         ident = TRUE;
3082                         break;
3083                 }
3084
3085                 case SV_ROD_ILLUMINATION:
3086                 {
3087                         if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
3088                         break;
3089                 }
3090
3091                 case SV_ROD_MAPPING:
3092                 {
3093                         map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
3094                         ident = TRUE;
3095                         break;
3096                 }
3097
3098                 case SV_ROD_DETECTION:
3099                 {
3100                         detect_all(detect_rad);
3101                         ident = TRUE;
3102                         break;
3103                 }
3104
3105                 case SV_ROD_PROBING:
3106                 {
3107                         probing();
3108                         ident = TRUE;
3109                         break;
3110                 }
3111
3112                 case SV_ROD_CURING:
3113                 {
3114                         if (set_blind(0)) ident = TRUE;
3115                         if (set_poisoned(0)) ident = TRUE;
3116                         if (set_confused(0)) ident = TRUE;
3117                         if (set_stun(0)) ident = TRUE;
3118                         if (set_cut(0)) ident = TRUE;
3119                         if (set_image(0)) ident = TRUE;
3120                         if (set_shero(0,TRUE)) ident = TRUE;
3121                         break;
3122                 }
3123
3124                 case SV_ROD_HEALING:
3125                 {
3126                         if (hp_player(powerful ? 750 : 500)) ident = TRUE;
3127                         if (set_stun(0)) ident = TRUE;
3128                         if (set_cut(0)) ident = TRUE;
3129                         if (set_shero(0,TRUE)) ident = TRUE;
3130                         break;
3131                 }
3132
3133                 case SV_ROD_RESTORATION:
3134                 {
3135                         if (restore_level()) ident = TRUE;
3136                         if (do_res_stat(A_STR)) ident = TRUE;
3137                         if (do_res_stat(A_INT)) ident = TRUE;
3138                         if (do_res_stat(A_WIS)) ident = TRUE;
3139                         if (do_res_stat(A_DEX)) ident = TRUE;
3140                         if (do_res_stat(A_CON)) ident = TRUE;
3141                         if (do_res_stat(A_CHR)) ident = TRUE;
3142                         break;
3143                 }
3144
3145                 case SV_ROD_SPEED:
3146                 {
3147                         if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
3148                         break;
3149                 }
3150
3151                 case SV_ROD_PESTICIDE:
3152                 {
3153                         if (dispel_monsters(powerful ? 8 : 4)) ident = TRUE;
3154                         break;
3155                 }
3156
3157                 case SV_ROD_TELEPORT_AWAY:
3158                 {
3159                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
3160                         if (teleport_monster(dir, distance)) ident = TRUE;
3161                         break;
3162                 }
3163
3164                 case SV_ROD_DISARMING:
3165                 {
3166                         if (disarm_trap(dir)) ident = TRUE;
3167                         if (powerful && disarm_traps_touch()) ident = TRUE;
3168                         break;
3169                 }
3170
3171                 case SV_ROD_LITE:
3172                 {
3173                         HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
3174                         msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
3175                         (void)lite_line(dir, dam);
3176                         ident = TRUE;
3177                         break;
3178                 }
3179
3180                 case SV_ROD_SLEEP_MONSTER:
3181                 {
3182                         if (sleep_monster(dir, lev)) ident = TRUE;
3183                         break;
3184                 }
3185
3186                 case SV_ROD_SLOW_MONSTER:
3187                 {
3188                         if (slow_monster(dir, lev)) ident = TRUE;
3189                         break;
3190                 }
3191
3192                 case SV_ROD_HYPODYNAMIA:
3193                 {
3194                         if (hypodynamic_bolt(dir, 70 + 3 * lev / 2)) ident = TRUE;
3195                         break;
3196                 }
3197
3198                 case SV_ROD_POLYMORPH:
3199                 {
3200                         if (poly_monster(dir, lev)) ident = TRUE;
3201                         break;
3202                 }
3203
3204                 case SV_ROD_ACID_BOLT:
3205                 {
3206                         fire_bolt_or_beam(10, GF_ACID, dir, damroll(6 + lev / 7, 8));
3207                         ident = TRUE;
3208                         break;
3209                 }
3210
3211                 case SV_ROD_ELEC_BOLT:
3212                 {
3213                         fire_bolt_or_beam(10, GF_ELEC, dir, damroll(4 + lev / 9, 8));
3214                         ident = TRUE;
3215                         break;
3216                 }
3217
3218                 case SV_ROD_FIRE_BOLT:
3219                 {
3220                         fire_bolt_or_beam(10, GF_FIRE, dir, damroll(7 + lev / 6, 8));
3221                         ident = TRUE;
3222                         break;
3223                 }
3224
3225                 case SV_ROD_COLD_BOLT:
3226                 {
3227                         fire_bolt_or_beam(10, GF_COLD, dir, damroll(5 + lev / 8, 8));
3228                         ident = TRUE;
3229                         break;
3230                 }
3231
3232                 case SV_ROD_ACID_BALL:
3233                 {
3234                         fire_ball(GF_ACID, dir, 60 + lev, rad);
3235                         ident = TRUE;
3236                         break;
3237                 }
3238
3239                 case SV_ROD_ELEC_BALL:
3240                 {
3241                         fire_ball(GF_ELEC, dir, 40 + lev, rad);
3242                         ident = TRUE;
3243                         break;
3244                 }
3245
3246                 case SV_ROD_FIRE_BALL:
3247                 {
3248                         fire_ball(GF_FIRE, dir, 70 + lev, rad);
3249                         ident = TRUE;
3250                         break;
3251                 }
3252
3253                 case SV_ROD_COLD_BALL:
3254                 {
3255                         fire_ball(GF_COLD, dir, 50 + lev, rad);
3256                         ident = TRUE;
3257                         break;
3258                 }
3259
3260                 case SV_ROD_HAVOC:
3261                 {
3262                         call_chaos();
3263                         ident = TRUE;
3264                         break;
3265                 }
3266
3267                 case SV_ROD_STONE_TO_MUD:
3268                 {
3269                         HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
3270                         if (wall_to_mud(dir, dam)) ident = TRUE;
3271                         break;
3272                 }
3273
3274                 case SV_ROD_AGGRAVATE:
3275                 {
3276                         aggravate_monsters(0);
3277                         ident = TRUE;
3278                         break;
3279                 }
3280         }
3281         return ident;
3282 }
3283
3284 /*!
3285  * @brief 魔法棒を使うコマンドのサブルーチン / 
3286  * Activate (zap) a Rod
3287  * @param item 使うオブジェクトの所持品ID
3288  * @return なし
3289  * @details
3290  * <pre>
3291  * Unstack fully charged rods as needed.
3292  * Hack -- rods of perception/genocide can be "cancelled"
3293  * All rods can be cancelled at the "Direction?" prompt
3294  * pvals are defined for each rod in k_info. -LM-
3295  * </pre>
3296  */
3297 static void do_cmd_zap_rod_aux(int item)
3298 {
3299         int ident, chance, lev, fail;
3300         int dir = 0;
3301         object_type *o_ptr;
3302         bool success;
3303
3304         /* Hack -- let perception get aborted */
3305         bool use_charge = TRUE;
3306
3307         object_kind *k_ptr;
3308
3309         /* Get the item (in the pack) */
3310         if (item >= 0)
3311         {
3312                 o_ptr = &inventory[item];
3313         }
3314
3315         /* Get the item (on the floor) */
3316         else
3317         {
3318                 o_ptr = &o_list[0 - item];
3319         }
3320
3321
3322         /* Mega-Hack -- refuse to zap a pile from the ground */
3323         if ((item < 0) && (o_ptr->number > 1))
3324         {
3325                 msg_print(_("まずはロッドを拾わなければ。", "You must first pick up the rods."));
3326                 return;
3327         }
3328
3329
3330         /* Get a direction (unless KNOWN not to need it) */
3331         if (((o_ptr->sval >= SV_ROD_MIN_DIRECTION) && (o_ptr->sval != SV_ROD_HAVOC) && (o_ptr->sval != SV_ROD_AGGRAVATE) && (o_ptr->sval != SV_ROD_PESTICIDE)) ||
3332              !object_is_aware(o_ptr))
3333         {
3334                 /* Get a direction, allow cancel */
3335                 if (!get_aim_dir(&dir)) return;
3336         }
3337
3338
3339         /* Take a turn */
3340         p_ptr->energy_use = 100;
3341
3342         /* Extract the item level */
3343         lev = k_info[o_ptr->k_idx].level;
3344
3345         /* Base chance of success */
3346         chance = p_ptr->skill_dev;
3347
3348         /* Confusion hurts skill */
3349         if (p_ptr->confused) chance = chance / 2;
3350
3351         fail = lev+5;
3352         if (chance > fail) fail -= (chance - fail)*2;
3353         else chance -= (fail - chance)*2;
3354         if (fail < USE_DEVICE) fail = USE_DEVICE;
3355         if (chance < USE_DEVICE) chance = USE_DEVICE;
3356
3357         if (world_player)
3358         {
3359                 if (flush_failure) flush();
3360                 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen. Maybe this rod is freezing too."));
3361                 sound(SOUND_FAIL);
3362                 return;
3363         }
3364
3365         if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
3366         else if (chance > fail)
3367         {
3368                 if (randint0(chance*2) < fail) success = FALSE;
3369                 else success = TRUE;
3370         }
3371         else
3372         {
3373                 if (randint0(fail*2) < chance) success = TRUE;
3374                 else success = FALSE;
3375         }
3376
3377         /* Roll for usage */
3378         if (!success)
3379         {
3380                 if (flush_failure) flush();
3381                 msg_print(_("うまくロッドを使えなかった。", "You failed to use the rod properly."));
3382                 sound(SOUND_FAIL);
3383                 return;
3384         }
3385
3386         k_ptr = &k_info[o_ptr->k_idx];
3387
3388         /* A single rod is still charging */
3389         if ((o_ptr->number == 1) && (o_ptr->timeout))
3390         {
3391                 if (flush_failure) flush();
3392                 msg_print(_("このロッドはまだ魔力を充填している最中だ。", "The rod is still charging."));
3393                 return;
3394         }
3395         /* A stack of rods lacks enough energy. */
3396         else if ((o_ptr->number > 1) && (o_ptr->timeout > k_ptr->pval * (o_ptr->number - 1)))
3397         {
3398                 if (flush_failure) flush();
3399                 msg_print(_("そのロッドはまだ充填中です。", "The rods are all still charging."));
3400                 return;
3401         }
3402
3403         /* Sound */
3404         sound(SOUND_ZAP);
3405
3406         ident = rod_effect(o_ptr->sval, dir, &use_charge, FALSE, FALSE);
3407
3408         /* Increase the timeout by the rod kind's pval. -LM- */
3409         if (use_charge) o_ptr->timeout += k_ptr->pval;
3410
3411         /* Combine / Reorder the pack (later) */
3412         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3413
3414         if (!(object_is_aware(o_ptr)))
3415         {
3416                 chg_virtue(V_PATIENCE, -1);
3417                 chg_virtue(V_CHANCE, 1);
3418                 chg_virtue(V_KNOWLEDGE, -1);
3419         }
3420
3421         /* Tried the object */
3422         object_tried(o_ptr);
3423
3424         /* Successfully determined the object function */
3425         if (ident && !object_is_aware(o_ptr))
3426         {
3427                 object_aware(o_ptr);
3428                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
3429         }
3430
3431         /* Window stuff */
3432         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
3433 }
3434
3435 /*!
3436  * @brief ロッドを使うコマンドのメインルーチン /
3437  * @return なし
3438  */
3439 void do_cmd_zap_rod(void)
3440 {
3441         OBJECT_IDX item;
3442         cptr q, s;
3443
3444         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
3445         {
3446                 set_action(ACTION_NONE);
3447         }
3448
3449         /* Restrict choices to rods */
3450         item_tester_tval = TV_ROD;
3451
3452         /* Get an item */
3453         q = _("どのロッドを振りますか? ", "Zap which rod? ");
3454         s = _("使えるロッドがない。", "You have no rod to zap.");
3455
3456         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
3457
3458         /* Zap the rod */
3459         do_cmd_zap_rod_aux(item);
3460 }
3461
3462 /*!
3463  * @brief オブジェクトをプレイヤーが魔道具として発動できるかを判定する /
3464  * Hook to determine if an object is activatable
3465  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
3466  * @return 魔道具として発動可能ならばTRUEを返す
3467  */
3468 static bool item_tester_hook_activate(object_type *o_ptr)
3469 {
3470         u32b flgs[TR_FLAG_SIZE];
3471
3472         /* Not known */
3473         if (!object_is_known(o_ptr)) return (FALSE);
3474
3475         /* Extract the flags */
3476         object_flags(o_ptr, flgs);
3477
3478         /* Check activation flag */
3479         if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
3480
3481         /* Assume not */
3482         return (FALSE);
3483 }
3484
3485 /*!
3486  * @brief 『一つの指輪』の効果処理 /
3487  * Hack -- activate the ring of power
3488  * @param dir 発動の方向ID
3489  * @return なし
3490  */
3491 void ring_of_power(int dir)
3492 {
3493         /* Pick a random effect */
3494         switch (randint1(10))
3495         {
3496                 case 1:
3497                 case 2:
3498                 {
3499                         /* Message */
3500                         msg_print(_("あなたは悪性のオーラに包み込まれた。", "You are surrounded by a malignant aura."));
3501                         sound(SOUND_EVIL);
3502
3503                         /* Decrease all stats (permanently) */
3504                         (void)dec_stat(A_STR, 50, TRUE);
3505                         (void)dec_stat(A_INT, 50, TRUE);
3506                         (void)dec_stat(A_WIS, 50, TRUE);
3507                         (void)dec_stat(A_DEX, 50, TRUE);
3508                         (void)dec_stat(A_CON, 50, TRUE);
3509                         (void)dec_stat(A_CHR, 50, TRUE);
3510
3511                         /* Lose some experience (permanently) */
3512                         p_ptr->exp -= (p_ptr->exp / 4);
3513                         p_ptr->max_exp -= (p_ptr->exp / 4);
3514                         check_experience();
3515
3516                         break;
3517                 }
3518
3519                 case 3:
3520                 {
3521                         /* Message */
3522                         msg_print(_("あなたは強力なオーラに包み込まれた。", "You are surrounded by a powerful aura."));
3523
3524                         /* Dispel monsters */
3525                         dispel_monsters(1000);
3526
3527                         break;
3528                 }
3529
3530                 case 4:
3531                 case 5:
3532                 case 6:
3533                 {
3534                         /* Mana Ball */
3535                         fire_ball(GF_MANA, dir, 600, 3);
3536
3537                         break;
3538                 }
3539
3540                 case 7:
3541                 case 8:
3542                 case 9:
3543                 case 10:
3544                 {
3545                         /* Mana Bolt */
3546                         fire_bolt(GF_MANA, dir, 500);
3547
3548                         break;
3549                 }
3550         }
3551 }
3552
3553 /*!
3554  * @brief ペット入りモンスターボールをソートするための比較関数
3555  * @param u 所持品配列の参照ポインタ
3556  * @param v 未使用
3557  * @param a 所持品ID1
3558  * @param b 所持品ID2
3559  * @return 1の方が大であればTRUE
3560  */
3561 static bool ang_sort_comp_pet(vptr u, vptr v, int a, int b)
3562 {
3563         u16b *who = (u16b*)(u);
3564
3565         int w1 = who[a];
3566         int w2 = who[b];
3567
3568         monster_type *m_ptr1 = &m_list[w1];
3569         monster_type *m_ptr2 = &m_list[w2];
3570         monster_race *r_ptr1 = &r_info[m_ptr1->r_idx];
3571         monster_race *r_ptr2 = &r_info[m_ptr2->r_idx];
3572
3573         /* Unused */
3574         (void)v;
3575
3576         if (m_ptr1->nickname && !m_ptr2->nickname) return TRUE;
3577         if (m_ptr2->nickname && !m_ptr1->nickname) return FALSE;
3578
3579         if ((r_ptr1->flags1 & RF1_UNIQUE) && !(r_ptr2->flags1 & RF1_UNIQUE)) return TRUE;
3580         if ((r_ptr2->flags1 & RF1_UNIQUE) && !(r_ptr1->flags1 & RF1_UNIQUE)) return FALSE;
3581
3582         if (r_ptr1->level > r_ptr2->level) return TRUE;
3583         if (r_ptr2->level > r_ptr1->level) return FALSE;
3584
3585         if (m_ptr1->hp > m_ptr2->hp) return TRUE;
3586         if (m_ptr2->hp > m_ptr1->hp) return FALSE;
3587         
3588         return w1 <= w2;
3589 }
3590
3591
3592 /*!
3593  * @brief 装備を発動するコマンドのサブルーチン /
3594  * Activate a wielded object.  Wielded objects never stack.
3595  * And even if they did, activatable objects never stack.
3596  * @param item 発動するオブジェクトの所持品ID
3597  * @return なし
3598  * @details
3599  * <pre>
3600  * Currently, only (some) artifacts, and Dragon Scale Mail, can be activated.
3601  * But one could, for example, easily make an activatable "Ring of Plasma".
3602  * Note that it always takes a turn to activate an artifact, even if
3603  * the user hits "escape" at the "direction" prompt.
3604  * </pre>
3605  */
3606 static void do_cmd_activate_aux(int item)
3607 {
3608         int         dir, lev, chance, fail;
3609         object_type *o_ptr;
3610         bool success;
3611
3612
3613         /* Get the item (in the pack) */
3614         if (item >= 0)
3615         {
3616                 o_ptr = &inventory[item];
3617         }
3618
3619         /* Get the item (on the floor) */
3620         else
3621         {
3622                 o_ptr = &o_list[0 - item];
3623         }
3624
3625         /* Take a turn */
3626         p_ptr->energy_use = 100;
3627
3628         /* Extract the item level */
3629         lev = k_info[o_ptr->k_idx].level;
3630
3631         /* Hack -- use artifact level instead */
3632         if (object_is_fixed_artifact(o_ptr)) lev = a_info[o_ptr->name1].level;
3633         else if (object_is_random_artifact(o_ptr))
3634         {
3635                 const activation_type* const act_ptr = find_activation_info(o_ptr);
3636                 if (act_ptr) {
3637                         lev = act_ptr->level;
3638                 }
3639         }
3640         else if (((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) && o_ptr->name2) lev = e_info[o_ptr->name2].level;
3641
3642         /* Base chance of success */
3643         chance = p_ptr->skill_dev;
3644
3645         /* Confusion hurts skill */
3646         if (p_ptr->confused) chance = chance / 2;
3647
3648         fail = lev+5;
3649         if (chance > fail) fail -= (chance - fail)*2;
3650         else chance -= (fail - chance)*2;
3651         if (fail < USE_DEVICE) fail = USE_DEVICE;
3652         if (chance < USE_DEVICE) chance = USE_DEVICE;
3653
3654         if (world_player)
3655         {
3656                 if (flush_failure) flush();
3657                 msg_print(_("止まった時の中ではうまく働かないようだ。", "It shows no reaction."));
3658                 sound(SOUND_FAIL);
3659                 return;
3660         }
3661
3662         if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
3663         else if (chance > fail)
3664         {
3665                 if (randint0(chance*2) < fail) success = FALSE;
3666                 else success = TRUE;
3667         }
3668         else
3669         {
3670                 if (randint0(fail*2) < chance) success = TRUE;
3671                 else success = FALSE;
3672         }
3673
3674         /* Roll for usage */
3675         if (!success)
3676         {
3677                 if (flush_failure) flush();
3678                 msg_print(_("うまく始動させることができなかった。", "You failed to activate it properly."));
3679                 sound(SOUND_FAIL);
3680                 return;
3681         }
3682
3683         /* Check the recharge */
3684         if (o_ptr->timeout)
3685         {
3686                 msg_print(_("それは微かに音を立て、輝き、消えた...", "It whines, glows and fades..."));
3687                 return;
3688         }
3689
3690         /* Some lights need enough fuel for activation */
3691         if (!o_ptr->xtra4 && (o_ptr->tval == TV_FLASK) &&
3692                 ((o_ptr->sval == SV_LITE_TORCH) || (o_ptr->sval == SV_LITE_LANTERN)))
3693         {
3694                 msg_print(_("燃料がない。", "It has no fuel."));
3695                 p_ptr->energy_use = 0;
3696                 return;
3697         }
3698
3699         /* Activate the artifact */
3700         msg_print(_("始動させた...", "You activate it..."));
3701
3702         /* Sound */
3703         sound(SOUND_ZAP);
3704
3705         /* Activate object */
3706         if (activation_index(o_ptr))
3707         {
3708                 (void)activate_random_artifact(o_ptr);
3709
3710                 /* Window stuff */
3711                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
3712
3713                 /* Success */
3714                 return;
3715         }
3716
3717         /* Special items */
3718         else if (o_ptr->tval == TV_WHISTLE)
3719         {
3720                 if (music_singing_any()) stop_singing();
3721                 if (hex_spelling_any()) stop_hex_spell_all();
3722
3723 #if 0
3724                 if (object_is_cursed(o_ptr))
3725                 {
3726                         msg_print(_("カン高い音が響き渡った。", "You produce a shrill whistling sound."));
3727                         aggravate_monsters(0);
3728                 }
3729                 else
3730 #endif
3731                 {
3732                         IDX pet_ctr, i;
3733                         IDX *who;
3734                         int max_pet = 0;
3735                         u16b dummy_why;
3736
3737                         /* Allocate the "who" array */
3738                         C_MAKE(who, max_m_idx, IDX);
3739
3740                         /* Process the monsters (backwards) */
3741                         for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
3742                         {
3743                                 if (is_pet(&m_list[pet_ctr]) && (p_ptr->riding != pet_ctr))
3744                                   who[max_pet++] = pet_ctr;
3745                         }
3746
3747                         /* Select the sort method */
3748                         ang_sort_comp = ang_sort_comp_pet;
3749                         ang_sort_swap = ang_sort_swap_hook;
3750
3751                         ang_sort(who, &dummy_why, max_pet);
3752
3753                         /* Process the monsters (backwards) */
3754                         for (i = 0; i < max_pet; i++)
3755                         {
3756                                 pet_ctr = who[i];
3757                                 teleport_monster_to(pet_ctr, p_ptr->y, p_ptr->x, 100, TELEPORT_PASSIVE);
3758                         }
3759
3760                         /* Free the "who" array */
3761                         C_KILL(who, max_m_idx, IDX);
3762                 }
3763                 o_ptr->timeout = 100+randint1(100);
3764                 return;
3765         }
3766         else if (o_ptr->tval == TV_CAPTURE)
3767         {
3768                 if(!o_ptr->pval)
3769                 {
3770                         bool old_target_pet = target_pet;
3771                         target_pet = TRUE;
3772                         if (!get_aim_dir(&dir))
3773                         {
3774                                 target_pet = old_target_pet;
3775                                 return;
3776                         }
3777                         target_pet = old_target_pet;
3778
3779                         if(fire_ball(GF_CAPTURE, dir, 0, 0))
3780                         {
3781                                 o_ptr->pval = (PARAMETER_VALUE)cap_mon;
3782                                 o_ptr->xtra3 = (XTRA8)cap_mspeed;
3783                                 o_ptr->xtra4 = (XTRA16)cap_hp;
3784                                 o_ptr->xtra5 = (XTRA16)cap_maxhp;
3785                                 if (cap_nickname)
3786                                 {
3787                                         cptr t;
3788                                         char *s;
3789                                         char buf[80] = "";
3790
3791                                         if (o_ptr->inscription)
3792                                                 strcpy(buf, quark_str(o_ptr->inscription));
3793                                         s = buf;
3794                                         for (s = buf;*s && (*s != '#'); s++)
3795                                         {
3796 #ifdef JP
3797                                                 if (iskanji(*s)) s++;
3798 #endif
3799                                         }
3800                                         *s = '#';
3801                                         s++;
3802 #ifdef JP
3803  /*nothing*/
3804 #else
3805                                         *s++ = '\'';
3806 #endif
3807                                         t = quark_str(cap_nickname);
3808                                         while (*t)
3809                                         {
3810                                                 *s = *t;
3811                                                 s++;
3812                                                 t++;
3813                                         }
3814 #ifdef JP
3815  /*nothing*/
3816 #else
3817                                         *s++ = '\'';
3818 #endif
3819                                         *s = '\0';
3820                                         o_ptr->inscription = quark_add(buf);
3821                                 }
3822                         }
3823                 }
3824                 else
3825                 {
3826                         success = FALSE;
3827                         if (!get_rep_dir2(&dir)) return;
3828                         if (monster_can_enter(p_ptr->y + ddy[dir], p_ptr->x + ddx[dir], &r_info[o_ptr->pval], 0))
3829                         {
3830                                 if (place_monster_aux(0, p_ptr->y + ddy[dir], p_ptr->x + ddx[dir], o_ptr->pval, (PM_FORCE_PET | PM_NO_KAGE)))
3831                                 {
3832                                         if (o_ptr->xtra3) m_list[hack_m_idx_ii].mspeed = o_ptr->xtra3;
3833                                         if (o_ptr->xtra5) m_list[hack_m_idx_ii].max_maxhp = o_ptr->xtra5;
3834                                         if (o_ptr->xtra4) m_list[hack_m_idx_ii].hp = o_ptr->xtra4;
3835                                         m_list[hack_m_idx_ii].maxhp = m_list[hack_m_idx_ii].max_maxhp;
3836                                         if (o_ptr->inscription)
3837                                         {
3838                                                 char buf[80];
3839                                                 cptr t;
3840 #ifndef JP
3841                                                 bool quote = FALSE;
3842 #endif
3843
3844                                                 t = quark_str(o_ptr->inscription);
3845                                                 for (t = quark_str(o_ptr->inscription);*t && (*t != '#'); t++)
3846                                                 {
3847 #ifdef JP
3848                                                         if (iskanji(*t)) t++;
3849 #endif
3850                                                 }
3851                                                 if (*t)
3852                                                 {
3853                                                         char *s = buf;
3854                                                         t++;
3855 #ifdef JP
3856                                                         /* nothing */
3857 #else
3858                                                         if (*t =='\'')
3859                                                         {
3860                                                                 t++;
3861                                                                 quote = TRUE;
3862                                                         }
3863 #endif
3864                                                         while(*t)
3865                                                         {
3866                                                                 *s = *t;
3867                                                                 t++;
3868                                                                 s++;
3869                                                         }
3870 #ifdef JP
3871                                                         /* nothing */
3872 #else
3873                                                         if (quote && *(s-1) =='\'')
3874                                                                 s--;
3875 #endif
3876                                                         *s = '\0';
3877                                                         m_list[hack_m_idx_ii].nickname = quark_add(buf);
3878                                                         t = quark_str(o_ptr->inscription);
3879                                                         s = buf;
3880                                                         while(*t && (*t != '#'))
3881                                                         {
3882                                                                 *s = *t;
3883                                                                 t++;
3884                                                                 s++;
3885                                                         }
3886                                                         *s = '\0';
3887                                                         o_ptr->inscription = quark_add(buf);
3888                                                 }
3889                                         }
3890                                         o_ptr->pval = 0;
3891                                         o_ptr->xtra3 = 0;
3892                                         o_ptr->xtra4 = 0;
3893                                         o_ptr->xtra5 = 0;
3894                                         success = TRUE;
3895                                 }
3896                         }
3897                         if (!success)
3898                                 msg_print(_("おっと、解放に失敗した。", "Oops.  You failed to release your pet."));
3899                 }
3900                 calc_android_exp();
3901                 return;
3902         }
3903
3904         /* Mistake */
3905         msg_print(_("おっと、このアイテムは始動できない。", "Oops.  That object cannot be activated."));
3906 }
3907
3908 /*!
3909  * @brief 装備を発動するコマンドのメインルーチン /
3910  * @return なし
3911  */
3912 void do_cmd_activate(void)
3913 {
3914         OBJECT_IDX item;
3915         cptr    q, s;
3916
3917
3918         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
3919         {
3920                 set_action(ACTION_NONE);
3921         }
3922
3923         item_tester_no_ryoute = TRUE;
3924         /* Prepare the hook */
3925         item_tester_hook = item_tester_hook_activate;
3926
3927         /* Get an item */
3928         q = _("どのアイテムを始動させますか? ", "Activate which item? ");
3929         s = _("始動できるアイテムを装備していない。", "You have nothing to activate.");
3930
3931         if (!get_item(&item, q, s, (USE_EQUIP))) return;
3932
3933         /* Activate the item */
3934         do_cmd_activate_aux(item);
3935 }
3936
3937
3938 /*!
3939  * @brief オブジェクトをプレイヤーが簡易使用コマンドで利用できるかを判定する /
3940  * Hook to determine if an object is useable
3941  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
3942  * @return 利用可能ならばTRUEを返す
3943  */
3944 static bool item_tester_hook_use(object_type *o_ptr)
3945 {
3946         u32b flgs[TR_FLAG_SIZE];
3947
3948         /* Ammo */
3949         if (o_ptr->tval == p_ptr->tval_ammo)
3950                 return (TRUE);
3951
3952         /* Useable object */
3953         switch (o_ptr->tval)
3954         {
3955                 case TV_SPIKE:
3956                 case TV_STAFF:
3957                 case TV_WAND:
3958                 case TV_ROD:
3959                 case TV_SCROLL:
3960                 case TV_POTION:
3961                 case TV_FOOD:
3962                 {
3963                         return (TRUE);
3964                 }
3965
3966                 default:
3967                 {
3968                         int i;
3969
3970                         /* Not known */
3971                         if (!object_is_known(o_ptr)) return (FALSE);
3972
3973                         /* HACK - only items from the equipment can be activated */
3974                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
3975                         {
3976                                 if (&inventory[i] == o_ptr)
3977                                 {
3978                                         /* Extract the flags */
3979                                         object_flags(o_ptr, flgs);
3980
3981                                         /* Check activation flag */
3982                                         if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
3983                                 }
3984                         }
3985                 }
3986         }
3987
3988         /* Assume not */
3989         return (FALSE);
3990 }
3991
3992
3993 /*!
3994  * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
3995  * Use an item
3996  * @return なし
3997  * @details
3998  * XXX - Add actions for other item types
3999  */
4000 void do_cmd_use(void)
4001 {
4002         OBJECT_IDX item;
4003         object_type *o_ptr;
4004         cptr        q, s;
4005
4006         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
4007         {
4008                 set_action(ACTION_NONE);
4009         }
4010
4011         item_tester_no_ryoute = TRUE;
4012         /* Prepare the hook */
4013         item_tester_hook = item_tester_hook_use;
4014
4015         /* Get an item */
4016         q = _("どれを使いますか?", "Use which item? ");
4017         s = _("使えるものがありません。", "You have nothing to use.");
4018
4019         if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return;
4020
4021         /* Get the item (in the pack) */
4022         if (item >= 0)
4023         {
4024                 o_ptr = &inventory[item];
4025         }
4026         /* Get the item (on the floor) */
4027         else
4028         {
4029                 o_ptr = &o_list[0 - item];
4030         }
4031
4032         switch (o_ptr->tval)
4033         {
4034                 /* Spike a door */
4035                 case TV_SPIKE:
4036                 {
4037                         do_cmd_spike();
4038                         break;
4039                 }
4040
4041                 /* Eat some food */
4042                 case TV_FOOD:
4043                 {
4044                         do_cmd_eat_food_aux(item);
4045                         break;
4046                 }
4047
4048                 /* Aim a wand */
4049                 case TV_WAND:
4050                 {
4051                         do_cmd_aim_wand_aux(item);
4052                         break;
4053                 }
4054
4055                 /* Use a staff */
4056                 case TV_STAFF:
4057                 {
4058                         do_cmd_use_staff_aux(item);
4059                         break;
4060                 }
4061
4062                 /* Zap a rod */
4063                 case TV_ROD:
4064                 {
4065                         do_cmd_zap_rod_aux(item);
4066                         break;
4067                 }
4068
4069                 /* Quaff a potion */
4070                 case TV_POTION:
4071                 {
4072                         do_cmd_quaff_potion_aux(item);
4073                         break;
4074                 }
4075
4076                 /* Read a scroll */
4077                 case TV_SCROLL:
4078                 {
4079                         /* Check some conditions */
4080                         if (p_ptr->blind)
4081                         {
4082                                 msg_print(_("目が見えない。", "You can't see anything."));
4083                                 return;
4084                         }
4085                         if (no_lite())
4086                         {
4087                                 msg_print(_("明かりがないので、暗くて読めない。", "You have no light to read by."));
4088                                 return;
4089                         }
4090                         if (p_ptr->confused)
4091                         {
4092                                 msg_print(_("混乱していて読めない!", "You are too confused!"));
4093                                 return;
4094                         }
4095
4096                   do_cmd_read_scroll_aux(item, TRUE);
4097                   break;
4098                 }
4099
4100                 /* Fire ammo */
4101                 case TV_SHOT:
4102                 case TV_ARROW:
4103                 case TV_BOLT:
4104                 {
4105                         do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
4106                         break;
4107                 }
4108
4109                 /* Activate an artifact */
4110                 default:
4111                 {
4112                         do_cmd_activate_aux(item);
4113                         break;
4114                 }
4115         }
4116 }
4117
4118 /*!
4119  * @brief 魔道具術師の取り込んだ魔力一覧から選択/閲覧する /
4120  * @param only_browse 閲覧するだけならばTRUE
4121  * @return 選択した魔力のID、キャンセルならば-1を返す
4122  */
4123 static OBJECT_SUBTYPE_VALUE select_magic_eater(bool only_browse)
4124 {
4125         OBJECT_SUBTYPE_VALUE ext = 0;
4126         char choice;
4127         bool flag, request_list;
4128         OBJECT_TYPE_VALUE tval = 0;
4129         int             ask = TRUE;
4130         OBJECT_SUBTYPE_VALUE i = 0;
4131         char            out_val[160];
4132
4133         int menu_line = (use_menu ? 1 : 0);
4134
4135 #ifdef ALLOW_REPEAT
4136         COMMAND_CODE sn;
4137         if (repeat_pull(&sn))
4138         {
4139                 /* Verify the spell */
4140                 if (sn >= EATER_EXT*2 && !(p_ptr->magic_num1[sn] > k_info[lookup_kind(TV_ROD, sn-EATER_EXT*2)].pval * (p_ptr->magic_num2[sn] - 1) * EATER_ROD_CHARGE))
4141                         return sn;
4142                 else if (sn < EATER_EXT*2 && !(p_ptr->magic_num1[sn] < EATER_CHARGE))
4143                         return sn;
4144         }
4145         
4146 #endif /* ALLOW_REPEAT */
4147
4148         for (i = 0; i < 108; i++)
4149         {
4150                 if (p_ptr->magic_num2[i]) break;
4151         }
4152         if (i == 108)
4153         {
4154                 msg_print(_("魔法を覚えていない!", "You don't have any magic!"));
4155                 return -1;
4156         }
4157
4158         if (use_menu)
4159         {
4160                 screen_save();
4161
4162                 while(!tval)
4163                 {
4164 #ifdef JP
4165                         prt(format(" %s 杖", (menu_line == 1) ? "》" : "  "), 2, 14);
4166                         prt(format(" %s 魔法棒", (menu_line == 2) ? "》" : "  "), 3, 14);
4167                         prt(format(" %s ロッド", (menu_line == 3) ? "》" : "  "), 4, 14);
4168 #else
4169                         prt(format(" %s staff", (menu_line == 1) ? "> " : "  "), 2, 14);
4170                         prt(format(" %s wand", (menu_line == 2) ? "> " : "  "), 3, 14);
4171                         prt(format(" %s rod", (menu_line == 3) ? "> " : "  "), 4, 14);
4172 #endif
4173
4174                         if (only_browse) prt(_("どの種類の魔法を見ますか?", "Which type of magic do you browse?"), 0, 0);
4175                         else prt(_("どの種類の魔法を使いますか?", "Which type of magic do you use?"), 0, 0);
4176
4177                         choice = inkey();
4178                         switch(choice)
4179                         {
4180                         case ESCAPE:
4181                         case 'z':
4182                         case 'Z':
4183                                 screen_load();
4184                                 return -1;
4185                         case '2':
4186                         case 'j':
4187                         case 'J':
4188                                 menu_line++;
4189                                 break;
4190                         case '8':
4191                         case 'k':
4192                         case 'K':
4193                                 menu_line+= 2;
4194                                 break;
4195                         case '\r':
4196                         case 'x':
4197                         case 'X':
4198                                 ext = (menu_line-1)*EATER_EXT;
4199                                 if (menu_line == 1) tval = TV_STAFF;
4200                                 else if (menu_line == 2) tval = TV_WAND;
4201                                 else tval = TV_ROD;
4202                                 break;
4203                         }
4204                         if (menu_line > 3) menu_line -= 3;
4205                 }
4206                 screen_load();
4207         }
4208         else
4209         {
4210         while (TRUE)
4211         {
4212                 if (!get_com(_("[A] 杖, [B] 魔法棒, [C] ロッド:", "[A] staff, [B] wand, [C] rod:"), &choice, TRUE))
4213                 {
4214                         return -1;
4215                 }
4216                 if (choice == 'A' || choice == 'a')
4217                 {
4218                         ext = 0;
4219                         tval = TV_STAFF;
4220                         break;
4221                 }
4222                 if (choice == 'B' || choice == 'b')
4223                 {
4224                         ext = EATER_EXT;
4225                         tval = TV_WAND;
4226                         break;
4227                 }
4228                 if (choice == 'C' || choice == 'c')
4229                 {
4230                         ext = EATER_EXT*2;
4231                         tval = TV_ROD;
4232                         break;
4233                 }
4234         }
4235         }
4236         for (i = ext; i < ext + EATER_EXT; i++)
4237         {
4238                 if (p_ptr->magic_num2[i])
4239                 {
4240                         if (use_menu) menu_line = i-ext+1;
4241                         break;
4242                 }
4243         }
4244         if (i == ext+EATER_EXT)
4245         {
4246                 msg_print(_("その種類の魔法は覚えていない!", "You don't have that type of magic!"));
4247                 return -1;
4248         }
4249
4250         /* Nothing chosen yet */
4251         flag = FALSE;
4252
4253         /* Build a prompt */
4254         if (only_browse) strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を見ますか?",
4255                                                                                         "(*=List, ESC=exit) Browse which power? "));
4256         else strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を使いますか?",
4257                                                                 "(*=List, ESC=exit) Use which power? "));
4258         
4259         /* Save the screen */
4260         screen_save();
4261
4262         request_list = always_show_list;
4263
4264         /* Get a spell from the user */
4265         while (!flag)
4266         {
4267                 /* Show the list */
4268                 if (request_list || use_menu)
4269                 {
4270                         byte y, x = 0;
4271                         OBJECT_SUBTYPE_VALUE ctr;
4272                         PERCENTAGE chance;
4273                         IDX k_idx;
4274                         char dummy[80];
4275                         POSITION x1, y1;
4276                         int level;
4277                         byte col;
4278
4279                         strcpy(dummy, "");
4280
4281                         for (y = 1; y < 20; y++)
4282                                 prt("", y, x);
4283
4284                         y = 1;
4285
4286                         /* Print header(s) */
4287 #ifdef JP
4288                         prt(format("                           %s 失率                           %s 失率", (tval == TV_ROD ? "  状態  " : "使用回数"), (tval == TV_ROD ? "  状態  " : "使用回数")), y++, x);
4289 #else
4290                         prt(format("                           %s Fail                           %s Fail", (tval == TV_ROD ? "  Stat  " : " Charges"), (tval == TV_ROD ? "  Stat  " : " Charges")), y++, x);
4291 #endif
4292
4293                         /* Print list */
4294                         for (ctr = 0; ctr < EATER_EXT; ctr++)
4295                         {
4296                                 if (!p_ptr->magic_num2[ctr+ext]) continue;
4297
4298                                 k_idx = lookup_kind(tval, ctr);
4299
4300                                 if (use_menu)
4301                                 {
4302                                         if (ctr == (menu_line-1))
4303                                                 strcpy(dummy, _("》", "> "));
4304                                         else
4305                                                 strcpy(dummy, "  ");
4306                                 }
4307                                 /* letter/number for power selection */
4308                                 else
4309                                 {
4310                                         char letter;
4311                                         if (ctr < 26)
4312                                                 letter = I2A(ctr);
4313                                         else
4314                                                 letter = '0' + ctr - 26;
4315                                         sprintf(dummy, "%c)",letter);
4316                                 }
4317                                 x1 = ((ctr < EATER_EXT/2) ? x : x + 40);
4318                                 y1 = ((ctr < EATER_EXT/2) ? y + ctr : y + ctr - EATER_EXT/2);
4319                                 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
4320                                 chance = level * 4 / 5 + 20;
4321                                 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
4322                                 level /= 2;
4323                                 if (p_ptr->lev > level)
4324                                 {
4325                                         chance -= 3 * (p_ptr->lev - level);
4326                                 }
4327                                 chance = mod_spell_chance_1(chance);
4328                                 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
4329                                 /* Stunning makes spells harder */
4330                                 if (p_ptr->stun > 50) chance += 25;
4331                                 else if (p_ptr->stun) chance += 15;
4332
4333                                 if (chance > 95) chance = 95;
4334
4335                                 chance = mod_spell_chance_2(chance);
4336
4337                                 col = TERM_WHITE;
4338
4339                                 if (k_idx)
4340                                 {
4341                                         if (tval == TV_ROD)
4342                                         {
4343                                                 strcat(dummy, format(
4344                                                                _(" %-22.22s 充填:%2d/%2d%3d%%", " %-22.22s   (%2d/%2d) %3d%%"),
4345                                                                k_name + k_info[k_idx].name, 
4346                                                                p_ptr->magic_num1[ctr+ext] ? 
4347                                                                (p_ptr->magic_num1[ctr+ext] - 1) / (EATER_ROD_CHARGE * k_info[k_idx].pval) +1 : 0, 
4348                                                                p_ptr->magic_num2[ctr+ext], chance));
4349                                                 if (p_ptr->magic_num1[ctr+ext] > k_info[k_idx].pval * (p_ptr->magic_num2[ctr+ext]-1) * EATER_ROD_CHARGE) col = TERM_RED;
4350                                         }
4351                                         else
4352                                         {
4353                                                 strcat(dummy, format(" %-22.22s    %2d/%2d %3d%%", k_name + k_info[k_idx].name, (s16b)(p_ptr->magic_num1[ctr+ext]/EATER_CHARGE), p_ptr->magic_num2[ctr+ext], chance));
4354                                                 if (p_ptr->magic_num1[ctr+ext] < EATER_CHARGE) col = TERM_RED;
4355                                         }
4356                                 }
4357                                 else
4358                                         strcpy(dummy, "");
4359                                 c_prt(col, dummy, y1, x1);
4360                         }
4361                 }
4362
4363                 if (!get_com(out_val, &choice, FALSE)) break;
4364
4365                 if (use_menu && choice != ' ')
4366                 {
4367                         switch (choice)
4368                         {
4369                                 case '0':
4370                                 {
4371                                         screen_load();
4372                                         return 0;
4373                                 }
4374
4375                                 case '8':
4376                                 case 'k':
4377                                 case 'K':
4378                                 {
4379                                         do
4380                                         {
4381                                                 menu_line += EATER_EXT - 1;
4382                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
4383                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
4384                                         break;
4385                                 }
4386
4387                                 case '2':
4388                                 case 'j':
4389                                 case 'J':
4390                                 {
4391                                         do
4392                                         {
4393                                                 menu_line++;
4394                                                 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
4395                                         } while(!p_ptr->magic_num2[menu_line+ext-1]);
4396                                         break;
4397                                 }
4398
4399                                 case '4':
4400                                 case 'h':
4401                                 case 'H':
4402                                 case '6':
4403                                 case 'l':
4404                                 case 'L':
4405                                 {
4406                                         bool reverse = FALSE;
4407                                         if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
4408                                         if (menu_line > EATER_EXT/2)
4409                                         {
4410                                                 menu_line -= EATER_EXT/2;
4411                                                 reverse = TRUE;
4412                                         }
4413                                         else menu_line+=EATER_EXT/2;
4414                                         while(!p_ptr->magic_num2[menu_line+ext-1])
4415                                         {
4416                                                 if (reverse)
4417                                                 {
4418                                                         menu_line--;
4419                                                         if (menu_line < 2) reverse = FALSE;
4420                                                 }
4421                                                 else
4422                                                 {
4423                                                         menu_line++;
4424                                                         if (menu_line > EATER_EXT-1) reverse = TRUE;
4425                                                 }
4426                                         }
4427                                         break;
4428                                 }
4429
4430                                 case 'x':
4431                                 case 'X':
4432                                 case '\r':
4433                                 {
4434                                         i = menu_line - 1;
4435                                         ask = FALSE;
4436                                         break;
4437                                 }
4438                         }
4439                 }
4440
4441                 /* Request redraw */
4442                 if (use_menu && ask) continue;
4443
4444                 /* Request redraw */
4445                 if (!use_menu && ((choice == ' ') || (choice == '*') || (choice == '?')))
4446                 {
4447                         /* Hide the list */
4448                         if (request_list)
4449                         {
4450                                 /* Hide list */
4451                                 request_list = FALSE;
4452                                 
4453                                 /* Restore the screen */
4454                                 screen_load();
4455                                 screen_save();
4456                         }
4457                         else
4458                                 request_list = TRUE;
4459
4460                         /* Redo asking */
4461                         continue;
4462                 }
4463
4464                 if (!use_menu)
4465                 {
4466                         if (isalpha(choice))
4467                         {
4468                                 /* Note verify */
4469                                 ask = (isupper(choice));
4470
4471                                 /* Lowercase */
4472                                 if (ask) choice = (char)tolower(choice);
4473
4474                                 /* Extract request */
4475                                 i = (islower(choice) ? A2I(choice) : -1);
4476                         }
4477                         else
4478                         {
4479                                 ask = FALSE; /* Can't uppercase digits */
4480
4481                                 i = choice - '0' + 26;
4482                         }
4483                 }
4484
4485                 /* Totally Illegal */
4486                 if ((i < 0) || (i > EATER_EXT) || !p_ptr->magic_num2[i+ext])
4487                 {
4488                         bell();
4489                         continue;
4490                 }
4491
4492                 if (!only_browse)
4493                 {
4494                         /* Verify it */
4495                         if (ask)
4496                         {
4497                                 char tmp_val[160];
4498
4499                                 /* Prompt */
4500                                 (void) strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s?"), k_name + k_info[lookup_kind(tval ,i)].name);
4501
4502                                 /* Belay that order */
4503                                 if (!get_check(tmp_val)) continue;
4504                         }
4505                         if (tval == TV_ROD)
4506                         {
4507                                 if (p_ptr->magic_num1[ext+i]  > k_info[lookup_kind(tval, i)].pval * (p_ptr->magic_num2[ext+i] - 1) * EATER_ROD_CHARGE)
4508                                 {
4509                                         msg_print(_("その魔法はまだ充填している最中だ。", "The magic are still charging."));
4510                                         msg_print(NULL);
4511                                         if (use_menu) ask = TRUE;
4512                                         continue;
4513                                 }
4514                         }
4515                         else
4516                         {
4517                                 if (p_ptr->magic_num1[ext+i] < EATER_CHARGE)
4518                                 {
4519                                         msg_print(_("その魔法は使用回数が切れている。", "The magic has no charges left."));
4520                                         msg_print(NULL);
4521                                         if (use_menu) ask = TRUE;
4522                                         continue;
4523                                 }
4524                         }
4525                 }
4526
4527                 /* Browse */
4528                 else
4529                 {
4530                         int line, j;
4531                         char temp[70 * 20];
4532
4533                         /* Clear lines, position cursor  (really should use strlen here) */
4534                         Term_erase(7, 23, 255);
4535                         Term_erase(7, 22, 255);
4536                         Term_erase(7, 21, 255);
4537                         Term_erase(7, 20, 255);
4538
4539                         roff_to_buf(k_text + k_info[lookup_kind(tval, i)].text, 62, temp, sizeof(temp));
4540                         for (j = 0, line = 21; temp[j]; j += 1 + strlen(&temp[j]))
4541                         {
4542                                 prt(&temp[j], line, 10);
4543                                 line++;
4544                         }
4545
4546                         continue;
4547                 }
4548
4549                 /* Stop the loop */
4550                 flag = TRUE;
4551         }
4552
4553         /* Restore the screen */
4554         screen_load();
4555
4556         if (!flag) return -1;
4557
4558 #ifdef ALLOW_REPEAT
4559         repeat_push(ext+i);
4560 #endif /* ALLOW_REPEAT */
4561         return ext+i;
4562 }
4563
4564
4565 /*!
4566  * @brief 取り込んだ魔力を利用するコマンドのメインルーチン /
4567  * Use eaten rod, wand or staff
4568  * @param only_browse 閲覧するだけならばTRUE
4569  * @param powerful 強力発動中の処理ならばTRUE
4570  * @return 実際にコマンドを実行したならばTRUEを返す。
4571  */
4572 bool do_cmd_magic_eater(bool only_browse, bool powerful)
4573 {
4574         OBJECT_SUBTYPE_VALUE item;
4575         PERCENTAGE chance;
4576         DEPTH level;
4577         IDX k_idx;
4578         OBJECT_TYPE_VALUE tval;
4579         OBJECT_SUBTYPE_VALUE sval;
4580         bool use_charge = TRUE;
4581
4582         /* Not when confused */
4583         if (!only_browse && p_ptr->confused)
4584         {
4585                 msg_print(_("混乱していて唱えられない!", "You are too confused!"));
4586                 return FALSE;
4587         }
4588
4589         item = select_magic_eater(only_browse);
4590         if (item == -1)
4591         {
4592                 p_ptr->energy_use = 0;
4593                 return FALSE;
4594         }
4595         if (item >= EATER_EXT*2) {tval = TV_ROD;sval = item - EATER_EXT*2;}
4596         else if (item >= EATER_EXT) {tval = TV_WAND;sval = item - EATER_EXT;}
4597         else {tval = TV_STAFF; sval = item;}
4598         k_idx = lookup_kind(tval, sval);
4599
4600         level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
4601         chance = level * 4 / 5 + 20;
4602         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
4603         level /= 2;
4604         if (p_ptr->lev > level)
4605         {
4606                 chance -= 3 * (p_ptr->lev - level);
4607         }
4608         chance = mod_spell_chance_1(chance);
4609         chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
4610         /* Stunning makes spells harder */
4611         if (p_ptr->stun > 50) chance += 25;
4612         else if (p_ptr->stun) chance += 15;
4613
4614         if (chance > 95) chance = 95;
4615
4616         chance = mod_spell_chance_2(chance);
4617
4618         if (randint0(100) < chance)
4619         {
4620                 if (flush_failure) flush();
4621                 
4622                 msg_print(_("呪文をうまく唱えられなかった!", "You failed to get the magic off!"));
4623                 sound(SOUND_FAIL);
4624                 if (randint1(100) >= chance)
4625                         chg_virtue(V_CHANCE,-1);
4626                 p_ptr->energy_use = 100;
4627
4628                 return TRUE;
4629         }
4630         else
4631         {
4632                 int dir = 0;
4633
4634                 if (tval == TV_ROD)
4635                 {
4636                         if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE))
4637                                 if (!get_aim_dir(&dir)) return FALSE;
4638                         rod_effect(sval, dir, &use_charge, powerful, TRUE);
4639                         if (!use_charge) return FALSE;
4640                 }
4641                 else if (tval == TV_WAND)
4642                 {
4643                         if (!get_aim_dir(&dir)) return FALSE;
4644                         wand_effect(sval, dir, powerful, TRUE);
4645                 }
4646                 else
4647                 {
4648                         staff_effect(sval, &use_charge, powerful, TRUE, TRUE);
4649                         if (!use_charge) return FALSE;
4650                 }
4651                 if (randint1(100) < chance)
4652                         chg_virtue(V_CHANCE,1);
4653         }
4654         p_ptr->energy_use = 100;
4655         if (tval == TV_ROD) p_ptr->magic_num1[item] += k_info[k_idx].pval * EATER_ROD_CHARGE;
4656         else p_ptr->magic_num1[item] -= EATER_CHARGE;
4657
4658         return TRUE;
4659 }