OSDN Git Service

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