OSDN Git Service

Merge branch 'develop' into feature/Remove-Dependency-Player-Status
[hengbandforosx/hengbandosx.git] / src / cmd-action / cmd-mane.cpp
1 /*!
2  * @brief ものまねの処理実装 / Imitation code
3  * @date 2014/01/14
4  * @author
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
6  * This software may be copied and distributed for educational, research,\n
7  * and not for profit purposes provided that this copyright and statement\n
8  * are included in all such copies.  Other copyrights may also apply.\n
9  * 2014 Deskull rearranged comment for Doxygen.\n
10  */
11
12 #include "action/action-limited.h"
13 #include "cmd-action/cmd-spell.h"
14 #include "core/asking-player.h"
15 #include "core/player-redraw-types.h"
16 #include "core/stuff-handler.h"
17 #include "core/window-redrawer.h"
18 #include "floor/cave.h"
19 #include "floor/floor-object.h"
20 #include "game-option/disturbance-options.h"
21 #include "game-option/text-display-options.h"
22 #include "grid/grid.h"
23 #include "hpmp/hp-mp-processor.h"
24 #include "main/sound-definitions-table.h"
25 #include "main/sound-of-music.h"
26 #include "mind/mind-mage.h"
27 #include "monster-floor/monster-summon.h"
28 #include "monster-floor/place-monster-types.h"
29 #include "monster-race/monster-race.h"
30 #include "monster-race/race-ability-flags.h"
31 #include "monster-race/race-flags-resistance.h"
32 #include "monster-race/race-flags1.h"
33 #include "monster/monster-describer.h"
34 #include "monster/monster-info.h"
35 #include "monster/monster-processor.h"
36 #include "monster/monster-status.h"
37 #include "mspell/monster-power-table.h"
38 #include "player/player-status-table.h"
39 #include "player/player-status.h"
40 #include "spell-kind/spells-launcher.h"
41 #include "spell-kind/spells-lite.h"
42 #include "spell-kind/spells-neighbor.h"
43 #include "spell-kind/spells-sight.h"
44 #include "spell-kind/spells-teleport.h"
45 #include "spell-kind/spells-world.h"
46 #include "spell/spell-types.h"
47 #include "spell/spells-status.h"
48 #include "spell/spells-summon.h"
49 #include "spell/summon-types.h"
50 #include "status/bad-status-setter.h"
51 #include "status/body-improvement.h"
52 #include "status/buff-setter.h"
53 #include "system/floor-type-definition.h"
54 #include "system/monster-race-definition.h"
55 #include "system/monster-type-definition.h"
56 #include "system/player-type-definition.h"
57 #include "target/projection-path-calculator.h"
58 #include "target/target-checker.h"
59 #include "target/target-getter.h"
60 #include "target/target-setter.h"
61 #include "target/target-types.h"
62 #include "term/screen-processor.h"
63 #include "util/int-char-converter.h"
64 #include "view/display-messages.h"
65
66 static int damage;
67
68 /*!
69  * @brief 受け取ったパラメータに応じてものまねの効果情報をまとめたフォーマットを返す
70  * @param p 情報を返す文字列参照ポインタ
71  * @param power ものまねの効力の種類
72  * @param dam ものまねの威力
73  * @return なし
74  */
75 static void mane_info(player_type *caster_ptr, char *p, RF_ABILITY power, HIT_POINT dam)
76 {
77     PLAYER_LEVEL plev = caster_ptr->lev;
78
79     strcpy(p, "");
80
81     const auto power_int = static_cast<int>(power);
82
83     if ((power_int > 2 && power_int < 41) || (power_int > 41 && power_int < 59) || (power == RF_ABILITY::PSY_SPEAR))
84         sprintf(p, " %s%d", KWD_DAM, (int)dam);
85     else {
86         switch (power) {
87         case RF_ABILITY::DRAIN_MANA:
88             sprintf(p, " %sd%d+%d", KWD_HEAL, plev * 3, plev);
89             break;
90         case RF_ABILITY::HASTE:
91             sprintf(p, " %sd%d+%d", KWD_DURATION, 20 + plev, plev);
92             break;
93         case RF_ABILITY::HEAL:
94             sprintf(p, " %s%d", KWD_HEAL, plev * 6);
95             break;
96         case RF_ABILITY::INVULNER:
97             sprintf(p, " %sd7+7", KWD_DURATION);
98             break;
99         case RF_ABILITY::BLINK:
100             sprintf(p, " %s10", KWD_SPHERE);
101             break;
102         case RF_ABILITY::TPORT:
103             sprintf(p, " %s%d", KWD_SPHERE, plev * 5);
104             break;
105         case RF_ABILITY::RAISE_DEAD:
106             sprintf(p, " %s5", KWD_SPHERE);
107             break;
108         default:
109             break;
110         }
111     }
112 }
113
114 /*!
115  * @brief どのものまねを発動するか選択する処理 /
116  * Allow user to choose a imitation.
117  * @param sn 実行したものまねのIDを返す参照ポインタ(キャンセルなどの場合-1を返す)
118  * @param baigaesi TRUEならば倍返し上の処理として行う
119  * @return 処理を実行したらTRUE、キャンセルした場合FALSEを返す。
120  * @details
121  * If a valid spell is chosen, saves it in '*sn' and returns TRUE
122  * If the user hits escape, returns FALSE, and set '*sn' to -1
123  * If there are no legal choices, returns FALSE, and sets '*sn' to -2
124  *
125  * The "prompt" should be "cast", "recite", or "study"
126  * The "known" should be TRUE for cast/pray, FALSE for study
127  *
128  * nb: This function has a (trivial) display bug which will be obvious
129  * when you run it. It's probably easy to fix but I haven't tried,
130  * sorry.
131  */
132 static int get_mane_power(player_type *caster_ptr, int *sn, bool baigaesi)
133 {
134     int i = 0;
135     int num = 0;
136     TERM_LEN y = 1;
137     TERM_LEN x = 18;
138     PERCENTAGE minfail = 0;
139     PLAYER_LEVEL plev = caster_ptr->lev;
140     PERCENTAGE chance = 0;
141     int ask;
142     char choice;
143     char out_val[MAX_MONSTER_NAME];
144     char comment[80];
145     concptr p = _("能力", "power");
146
147     monster_power spell;
148     bool flag, redraw;
149
150     /* Assume cancelled */
151     *sn = (-1);
152
153     flag = FALSE;
154     redraw = FALSE;
155
156     num = caster_ptr->mane_num;
157
158     /* Build a prompt (accept all spells) */
159     (void)strnfmt(out_val, 78, _("(%c-%c, '*'で一覧, ESC) どの%sをまねますか?", "(%c-%c, *=List, ESC=exit) Use which %s? "), I2A(0), I2A(num - 1), p);
160
161     choice = always_show_list ? ESCAPE : 1;
162     while (!flag) {
163         if (choice == ESCAPE)
164             choice = ' ';
165         else if (!get_com(out_val, &choice, TRUE))
166             break;
167
168         /* Request redraw */
169         if ((choice == ' ') || (choice == '*') || (choice == '?')) {
170             /* Show the list */
171             if (!redraw) {
172                 char psi_desc[160];
173                 redraw = TRUE;
174                 screen_save();
175
176                 /* Display a list of spells */
177                 prt("", y, x);
178                 put_str(_("名前", "Name"), y, x + 5);
179                 put_str(_("失率 効果", "Fail Info"), y, x + 36);
180
181                 /* Dump the spells */
182                 for (i = 0; i < num; i++) {
183                     /* Access the spell */
184                     spell = monster_powers[static_cast<size_t>(caster_ptr->mane_spell[i])];
185
186                     chance = spell.manefail;
187
188                     /* Reduce failure rate by "effective" level adjustment */
189                     if (plev > spell.level)
190                         chance -= 3 * (plev - spell.level);
191
192                     /* Reduce failure rate by INT/WIS adjustment */
193                     chance -= 3 * (adj_mag_stat[caster_ptr->stat_index[spell.use_stat]] + adj_mag_stat[caster_ptr->stat_index[A_DEX]] - 2) / 2;
194
195                     if (spell.manedam)
196                         chance = chance * (baigaesi ? caster_ptr->mane_dam[i] * 2 : caster_ptr->mane_dam[i]) / spell.manedam;
197
198                     chance += caster_ptr->to_m_chance;
199
200                     /* Extract the minimum failure rate */
201                     minfail = adj_mag_fail[caster_ptr->stat_index[spell.use_stat]];
202
203                     /* Minimum failure rate */
204                     if (chance < minfail)
205                         chance = minfail;
206
207                     /* Stunning makes spells harder */
208                     if (caster_ptr->stun > 50)
209                         chance += 25;
210                     else if (caster_ptr->stun)
211                         chance += 15;
212
213                     /* Always a 5 percent chance of working */
214                     if (chance > 95)
215                         chance = 95;
216
217                     /* Get info */
218                     mane_info(caster_ptr, comment, caster_ptr->mane_spell[i], (baigaesi ? caster_ptr->mane_dam[i] * 2 : caster_ptr->mane_dam[i]));
219
220                     /* Dump the spell --(-- */
221                     sprintf(psi_desc, "  %c) %-30s %3d%%%s", I2A(i), spell.name, chance, comment);
222                     prt(psi_desc, y + i + 1, x);
223                 }
224
225                 /* Clear the bottom line */
226                 prt("", y + i + 1, x);
227             }
228
229             /* Hide the list */
230             else {
231                 /* Hide list */
232                 redraw = FALSE;
233                 screen_load();
234             }
235
236             /* Redo asking */
237             continue;
238         }
239
240         /* Note verify */
241         ask = isupper(choice);
242
243         /* Lowercase */
244         if (ask)
245             choice = (char)tolower(choice);
246
247         /* Extract request */
248         i = (islower(choice) ? A2I(choice) : -1);
249
250         /* Totally Illegal */
251         if ((i < 0) || (i >= num)) {
252             bell();
253             continue;
254         }
255
256         /* Save the spell index */
257         spell = monster_powers[static_cast<int>(caster_ptr->mane_spell[i])];
258
259         /* Verify it */
260         if (ask) {
261             char tmp_val[160];
262
263             /* Prompt */
264             (void)strnfmt(tmp_val, 78, _("%sをまねますか?", "Use %s? "), spell.name);
265
266             /* Belay that order */
267             if (!get_check(tmp_val))
268                 continue;
269         }
270
271         /* Stop the loop */
272         flag = TRUE;
273     }
274     if (redraw)
275         screen_load();
276
277     caster_ptr->window_flags |= (PW_SPELL);
278     handle_stuff(caster_ptr);
279
280     /* Abort if needed */
281     if (!flag)
282         return FALSE;
283
284     /* Save the choice */
285     (*sn) = i;
286
287     damage = (baigaesi ? caster_ptr->mane_dam[i] * 2 : caster_ptr->mane_dam[i]);
288
289     /* Success */
290     return TRUE;
291 }
292
293 /*!
294  * @brief ものまね処理の発動 /
295  * do_cmd_cast calls this function if the player's class is 'imitator'.
296  * @param caster_ptr プレーヤーへの参照ポインタ
297  * @param spell 発動するモンスター攻撃のID
298  * @return 処理を実行したらTRUE、キャンセルした場合FALSEを返す。
299  */
300 static bool use_mane(player_type *caster_ptr, RF_ABILITY spell)
301 {
302     DIRECTION dir;
303     PLAYER_LEVEL plev = caster_ptr->lev;
304     BIT_FLAGS mode = (PM_ALLOW_GROUP | PM_FORCE_PET);
305     BIT_FLAGS u_mode = 0L;
306
307     if (randint1(50 + plev) < plev / 10)
308         u_mode = PM_ALLOW_UNIQUE;
309
310     /* spell code */
311     switch (spell) {
312     case RF_ABILITY::SHRIEK:
313         msg_print(_("かん高い金切り声をあげた。", "You make a high pitched shriek."));
314         aggravate_monsters(caster_ptr, 0);
315         break;
316
317     case RF_ABILITY::XXX1:
318         break;
319
320     case RF_ABILITY::DISPEL: {
321         MONSTER_IDX m_idx;
322
323         if (!target_set(caster_ptr, TARGET_KILL))
324             return FALSE;
325         m_idx = caster_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx;
326         if (!m_idx)
327             break;
328         if (!player_has_los_bold(caster_ptr, target_row, target_col))
329             break;
330         if (!projectable(caster_ptr, caster_ptr->y, caster_ptr->x, target_row, target_col))
331             break;
332         dispel_monster_status(caster_ptr, m_idx);
333         break;
334     }
335
336     case RF_ABILITY::ROCKET:
337         if (!get_aim_dir(caster_ptr, &dir))
338             return FALSE;
339         else
340             msg_print(_("ロケットを発射した。", "You fire a rocket."));
341         fire_rocket(caster_ptr, GF_ROCKET, dir, damage, 2);
342         break;
343
344     case RF_ABILITY::SHOOT:
345         if (!get_aim_dir(caster_ptr, &dir))
346             return FALSE;
347         else
348             msg_print(_("矢を放った。", "You fire an arrow."));
349         fire_bolt(caster_ptr, GF_ARROW, dir, damage);
350         break;
351
352     case RF_ABILITY::XXX2:
353         break;
354
355     case RF_ABILITY::XXX3:
356         break;
357
358     case RF_ABILITY::XXX4:
359         break;
360
361     case RF_ABILITY::BR_ACID:
362         if (!get_aim_dir(caster_ptr, &dir))
363             return FALSE;
364         else
365             msg_print(_("酸のブレスを吐いた。", "You breathe acid."));
366         fire_breath(caster_ptr, GF_ACID, dir, damage, (plev > 35 ? 3 : 2));
367         break;
368
369     case RF_ABILITY::BR_ELEC:
370         if (!get_aim_dir(caster_ptr, &dir))
371             return FALSE;
372         else
373             msg_print(_("稲妻のブレスを吐いた。", "You breathe lightning."));
374         fire_breath(caster_ptr, GF_ELEC, dir, damage, (plev > 35 ? 3 : 2));
375         break;
376
377     case RF_ABILITY::BR_FIRE:
378         if (!get_aim_dir(caster_ptr, &dir))
379             return FALSE;
380         else
381             msg_print(_("火炎のブレスを吐いた。", "You breathe fire."));
382         fire_breath(caster_ptr, GF_FIRE, dir, damage, (plev > 35 ? 3 : 2));
383         break;
384
385     case RF_ABILITY::BR_COLD:
386         if (!get_aim_dir(caster_ptr, &dir))
387             return FALSE;
388         else
389             msg_print(_("冷気のブレスを吐いた。", "You breathe frost."));
390         fire_breath(caster_ptr, GF_COLD, dir, damage, (plev > 35 ? 3 : 2));
391         break;
392
393     case RF_ABILITY::BR_POIS:
394         if (!get_aim_dir(caster_ptr, &dir))
395             return FALSE;
396         else
397             msg_print(_("ガスのブレスを吐いた。", "You breathe gas."));
398         fire_breath(caster_ptr, GF_POIS, dir, damage, (plev > 35 ? 3 : 2));
399         break;
400
401     case RF_ABILITY::BR_NETH:
402         if (!get_aim_dir(caster_ptr, &dir))
403             return FALSE;
404         else
405             msg_print(_("地獄のブレスを吐いた。", "You breathe nether."));
406         fire_breath(caster_ptr, GF_NETHER, dir, damage, (plev > 35 ? 3 : 2));
407         break;
408
409     case RF_ABILITY::BR_LITE:
410         if (!get_aim_dir(caster_ptr, &dir))
411             return FALSE;
412         else
413             msg_print(_("閃光のブレスを吐いた。", "You breathe light."));
414         fire_breath(caster_ptr, GF_LITE, dir, damage, (plev > 35 ? 3 : 2));
415         break;
416
417     case RF_ABILITY::BR_DARK:
418         if (!get_aim_dir(caster_ptr, &dir))
419             return FALSE;
420         else
421             msg_print(_("暗黒のブレスを吐いた。", "You breathe darkness."));
422         fire_breath(caster_ptr, GF_DARK, dir, damage, (plev > 35 ? 3 : 2));
423         break;
424
425     case RF_ABILITY::BR_CONF:
426         if (!get_aim_dir(caster_ptr, &dir))
427             return FALSE;
428         else
429             msg_print(_("混乱のブレスを吐いた。", "You breathe confusion."));
430         fire_breath(caster_ptr, GF_CONFUSION, dir, damage, (plev > 35 ? 3 : 2));
431         break;
432
433     case RF_ABILITY::BR_SOUN:
434         if (!get_aim_dir(caster_ptr, &dir))
435             return FALSE;
436         else
437             msg_print(_("轟音のブレスを吐いた。", "You breathe sound."));
438         fire_breath(caster_ptr, GF_SOUND, dir, damage, (plev > 35 ? 3 : 2));
439         break;
440
441     case RF_ABILITY::BR_CHAO:
442         if (!get_aim_dir(caster_ptr, &dir))
443             return FALSE;
444         else
445             msg_print(_("カオスのブレスを吐いた。", "You breathe chaos."));
446         fire_breath(caster_ptr, GF_CHAOS, dir, damage, (plev > 35 ? 3 : 2));
447         break;
448
449     case RF_ABILITY::BR_DISE:
450         if (!get_aim_dir(caster_ptr, &dir))
451             return FALSE;
452         else
453             msg_print(_("劣化のブレスを吐いた。", "You breathe disenchantment."));
454         fire_breath(caster_ptr, GF_DISENCHANT, dir, damage, (plev > 35 ? 3 : 2));
455         break;
456
457     case RF_ABILITY::BR_NEXU:
458         if (!get_aim_dir(caster_ptr, &dir))
459             return FALSE;
460         else
461             msg_print(_("因果混乱のブレスを吐いた。", "You breathe nexus."));
462         fire_breath(caster_ptr, GF_NEXUS, dir, damage, (plev > 35 ? 3 : 2));
463         break;
464
465     case RF_ABILITY::BR_TIME:
466         if (!get_aim_dir(caster_ptr, &dir))
467             return FALSE;
468         else
469             msg_print(_("時間逆転のブレスを吐いた。", "You breathe time."));
470         fire_breath(caster_ptr, GF_TIME, dir, damage, (plev > 35 ? 3 : 2));
471         break;
472
473     case RF_ABILITY::BR_INER:
474         if (!get_aim_dir(caster_ptr, &dir))
475             return FALSE;
476         else
477             msg_print(_("遅鈍のブレスを吐いた。", "You breathe inertia."));
478         fire_breath(caster_ptr, GF_INERTIAL, dir, damage, (plev > 35 ? 3 : 2));
479         break;
480
481     case RF_ABILITY::BR_GRAV:
482         if (!get_aim_dir(caster_ptr, &dir))
483             return FALSE;
484         else
485             msg_print(_("重力のブレスを吐いた。", "You breathe gravity."));
486         fire_breath(caster_ptr, GF_GRAVITY, dir, damage, (plev > 35 ? 3 : 2));
487         break;
488
489     case RF_ABILITY::BR_SHAR:
490         if (!get_aim_dir(caster_ptr, &dir))
491             return FALSE;
492         else
493             msg_print(_("破片のブレスを吐いた。", "You breathe shards."));
494         fire_breath(caster_ptr, GF_SHARDS, dir, damage, (plev > 35 ? 3 : 2));
495         break;
496
497     case RF_ABILITY::BR_PLAS:
498         if (!get_aim_dir(caster_ptr, &dir))
499             return FALSE;
500         else
501             msg_print(_("プラズマのブレスを吐いた。", "You breathe plasma."));
502
503         fire_breath(caster_ptr, GF_PLASMA, dir, damage, (plev > 35 ? 3 : 2));
504         break;
505
506     case RF_ABILITY::BR_FORC:
507         if (!get_aim_dir(caster_ptr, &dir))
508             return FALSE;
509         else
510             msg_print(_("フォースのブレスを吐いた。", "You breathe force."));
511
512         fire_breath(caster_ptr, GF_FORCE, dir, damage, (plev > 35 ? 3 : 2));
513         break;
514
515     case RF_ABILITY::BR_MANA:
516         if (!get_aim_dir(caster_ptr, &dir))
517             return FALSE;
518         else
519             msg_print(_("魔力のブレスを吐いた。", "You breathe mana."));
520
521         fire_breath(caster_ptr, GF_MANA, dir, damage, (plev > 35 ? 3 : 2));
522         break;
523
524     case RF_ABILITY::BA_NUKE:
525         if (!get_aim_dir(caster_ptr, &dir))
526             return FALSE;
527         else
528             msg_print(_("放射能球を放った。", "You cast a ball of radiation."));
529
530         fire_ball(caster_ptr, GF_NUKE, dir, damage, 2);
531         break;
532
533     case RF_ABILITY::BR_NUKE:
534         if (!get_aim_dir(caster_ptr, &dir))
535             return FALSE;
536         else
537             msg_print(_("放射性廃棄物のブレスを吐いた。", "You breathe toxic waste."));
538
539         fire_breath(caster_ptr, GF_NUKE, dir, damage, (plev > 35 ? 3 : 2));
540         break;
541
542     case RF_ABILITY::BA_CHAO:
543         if (!get_aim_dir(caster_ptr, &dir))
544             return FALSE;
545         else
546             msg_print(_("純ログルスを放った。", "You invoke a raw Logrus."));
547
548         fire_ball(caster_ptr, GF_CHAOS, dir, damage, 4);
549         break;
550     case RF_ABILITY::BR_DISI:
551         if (!get_aim_dir(caster_ptr, &dir))
552             return FALSE;
553         else
554             msg_print(_("分解のブレスを吐いた。", "You breathe disintegration."));
555
556         fire_breath(caster_ptr, GF_DISINTEGRATE, dir, damage, (plev > 35 ? 3 : 2));
557         break;
558     case RF_ABILITY::BA_ACID:
559         if (!get_aim_dir(caster_ptr, &dir))
560             return FALSE;
561         else
562             msg_print(_("アシッド・ボールの呪文を唱えた。", "You cast an acid ball."));
563
564         fire_ball(caster_ptr, GF_ACID, dir, damage, 2);
565         break;
566     case RF_ABILITY::BA_ELEC:
567         if (!get_aim_dir(caster_ptr, &dir))
568             return FALSE;
569         else
570             msg_print(_("サンダー・ボールの呪文を唱えた。", "You cast a lightning ball."));
571
572         fire_ball(caster_ptr, GF_ELEC, dir, damage, 2);
573         break;
574     case RF_ABILITY::BA_FIRE:
575         if (!get_aim_dir(caster_ptr, &dir))
576             return FALSE;
577         else
578             msg_print(_("ファイア・ボールの呪文を唱えた。", "You cast a fire ball."));
579
580         fire_ball(caster_ptr, GF_FIRE, dir, damage, 2);
581         break;
582     case RF_ABILITY::BA_COLD:
583         if (!get_aim_dir(caster_ptr, &dir))
584             return FALSE;
585         else
586             msg_print(_("アイス・ボールの呪文を唱えた。", "You cast a frost ball."));
587
588         fire_ball(caster_ptr, GF_COLD, dir, damage, 2);
589         break;
590     case RF_ABILITY::BA_POIS:
591         if (!get_aim_dir(caster_ptr, &dir))
592             return FALSE;
593         else
594             msg_print(_("悪臭雲の呪文を唱えた。", "You cast a stinking cloud."));
595
596         fire_ball(caster_ptr, GF_POIS, dir, damage, 2);
597         break;
598     case RF_ABILITY::BA_NETH:
599         if (!get_aim_dir(caster_ptr, &dir))
600             return FALSE;
601         else
602             msg_print(_("地獄球の呪文を唱えた。", "You cast a nether ball."));
603
604         fire_ball(caster_ptr, GF_NETHER, dir, damage, 2);
605         break;
606     case RF_ABILITY::BA_WATE:
607         if (!get_aim_dir(caster_ptr, &dir))
608             return FALSE;
609         else
610             msg_print(_("流れるような身振りをした。", "You gesture fluidly."));
611
612         fire_ball(caster_ptr, GF_WATER, dir, damage, 4);
613         break;
614     case RF_ABILITY::BA_MANA:
615         if (!get_aim_dir(caster_ptr, &dir))
616             return FALSE;
617         else
618             msg_print(_("魔力の嵐の呪文を念じた。", "You invoke a mana storm."));
619
620         fire_ball(caster_ptr, GF_MANA, dir, damage, 4);
621         break;
622     case RF_ABILITY::BA_DARK:
623         if (!get_aim_dir(caster_ptr, &dir))
624             return FALSE;
625         else
626             msg_print(_("暗黒の嵐の呪文を念じた。", "You invoke a darkness storm."));
627
628         fire_ball(caster_ptr, GF_DARK, dir, damage, 4);
629         break;
630     case RF_ABILITY::DRAIN_MANA:
631         if (!get_aim_dir(caster_ptr, &dir))
632             return FALSE;
633         fire_ball_hide(caster_ptr, GF_DRAIN_MANA, dir, randint1(plev * 3) + plev, 0);
634         break;
635     case RF_ABILITY::MIND_BLAST:
636         if (!get_aim_dir(caster_ptr, &dir))
637             return FALSE;
638         fire_ball_hide(caster_ptr, GF_MIND_BLAST, dir, damage, 0);
639         break;
640     case RF_ABILITY::BRAIN_SMASH:
641         if (!get_aim_dir(caster_ptr, &dir))
642             return FALSE;
643         fire_ball_hide(caster_ptr, GF_BRAIN_SMASH, dir, damage, 0);
644         break;
645     case RF_ABILITY::CAUSE_1:
646         if (!get_aim_dir(caster_ptr, &dir))
647             return FALSE;
648         fire_ball_hide(caster_ptr, GF_CAUSE_1, dir, damage, 0);
649         break;
650     case RF_ABILITY::CAUSE_2:
651         if (!get_aim_dir(caster_ptr, &dir))
652             return FALSE;
653         fire_ball_hide(caster_ptr, GF_CAUSE_2, dir, damage, 0);
654         break;
655     case RF_ABILITY::CAUSE_3:
656         if (!get_aim_dir(caster_ptr, &dir))
657             return FALSE;
658         fire_ball_hide(caster_ptr, GF_CAUSE_3, dir, damage, 0);
659         break;
660     case RF_ABILITY::CAUSE_4:
661         if (!get_aim_dir(caster_ptr, &dir))
662             return FALSE;
663         fire_ball_hide(caster_ptr, GF_CAUSE_4, dir, damage, 0);
664         break;
665     case RF_ABILITY::BO_ACID:
666         if (!get_aim_dir(caster_ptr, &dir))
667             return FALSE;
668         else
669             msg_print(_("アシッド・ボルトの呪文を唱えた。", "You cast an acid bolt."));
670
671         fire_bolt(caster_ptr, GF_ACID, dir, damage);
672         break;
673     case RF_ABILITY::BO_ELEC:
674         if (!get_aim_dir(caster_ptr, &dir))
675             return FALSE;
676         else
677             msg_print(_("サンダー・ボルトの呪文を唱えた。", "You cast a lightning bolt."));
678
679         fire_bolt(caster_ptr, GF_ELEC, dir, damage);
680         break;
681     case RF_ABILITY::BO_FIRE:
682         if (!get_aim_dir(caster_ptr, &dir))
683             return FALSE;
684         else
685             msg_print(_("ファイア・ボルトの呪文を唱えた。", "You cast a fire bolt."));
686
687         fire_bolt(caster_ptr, GF_FIRE, dir, damage);
688         break;
689     case RF_ABILITY::BO_COLD:
690         if (!get_aim_dir(caster_ptr, &dir))
691             return FALSE;
692         else
693             msg_print(_("アイス・ボルトの呪文を唱えた。", "You cast a frost bolt."));
694
695         fire_bolt(caster_ptr, GF_COLD, dir, damage);
696         break;
697     case RF_ABILITY::BA_LITE:
698         if (!get_aim_dir(caster_ptr, &dir))
699             return FALSE;
700         else
701             msg_print(_("スターバーストの呪文を念じた。", "You invoke a starburst."));
702
703         fire_ball(caster_ptr, GF_LITE, dir, damage, 4);
704         break;
705     case RF_ABILITY::BO_NETH:
706         if (!get_aim_dir(caster_ptr, &dir))
707             return FALSE;
708         else
709             msg_print(_("地獄の矢の呪文を唱えた。", "You cast a nether bolt."));
710
711         fire_bolt(caster_ptr, GF_NETHER, dir, damage);
712         break;
713     case RF_ABILITY::BO_WATE:
714         if (!get_aim_dir(caster_ptr, &dir))
715             return FALSE;
716         else
717             msg_print(_("ウォーター・ボルトの呪文を唱えた。", "You cast a water bolt."));
718
719         fire_bolt(caster_ptr, GF_WATER, dir, damage);
720         break;
721     case RF_ABILITY::BO_MANA:
722         if (!get_aim_dir(caster_ptr, &dir))
723             return FALSE;
724         else
725             msg_print(_("魔力の矢の呪文を唱えた。", "You cast a mana bolt."));
726
727         fire_bolt(caster_ptr, GF_MANA, dir, damage);
728         break;
729     case RF_ABILITY::BO_PLAS:
730         if (!get_aim_dir(caster_ptr, &dir))
731             return FALSE;
732         else
733             msg_print(_("プラズマ・ボルトの呪文を唱えた。", "You cast a plasma bolt."));
734
735         fire_bolt(caster_ptr, GF_PLASMA, dir, damage);
736         break;
737     case RF_ABILITY::BO_ICEE:
738         if (!get_aim_dir(caster_ptr, &dir))
739             return FALSE;
740         else
741             msg_print(_("極寒の矢の呪文を唱えた。", "You cast a ice bolt."));
742
743         fire_bolt(caster_ptr, GF_ICE, dir, damage);
744         break;
745     case RF_ABILITY::MISSILE:
746         if (!get_aim_dir(caster_ptr, &dir))
747             return FALSE;
748         else
749             msg_print(_("マジック・ミサイルの呪文を唱えた。", "You cast a magic missile."));
750
751         fire_bolt(caster_ptr, GF_MISSILE, dir, damage);
752         break;
753     case RF_ABILITY::SCARE:
754         if (!get_aim_dir(caster_ptr, &dir))
755             return FALSE;
756         else
757             msg_print(_("恐ろしげな幻覚を作り出した。", "You cast a fearful illusion."));
758
759         fear_monster(caster_ptr, dir, plev + 10);
760         break;
761     case RF_ABILITY::BLIND:
762         if (!get_aim_dir(caster_ptr, &dir))
763             return FALSE;
764         confuse_monster(caster_ptr, dir, plev * 2);
765         break;
766     case RF_ABILITY::CONF:
767         if (!get_aim_dir(caster_ptr, &dir))
768             return FALSE;
769         else
770             msg_print(_("誘惑的な幻覚をつくり出した。", "You cast a mesmerizing illusion."));
771
772         confuse_monster(caster_ptr, dir, plev * 2);
773         break;
774     case RF_ABILITY::SLOW:
775         if (!get_aim_dir(caster_ptr, &dir))
776             return FALSE;
777         slow_monster(caster_ptr, dir, plev);
778         break;
779     case RF_ABILITY::HOLD:
780         if (!get_aim_dir(caster_ptr, &dir))
781             return FALSE;
782         sleep_monster(caster_ptr, dir, plev);
783         break;
784     case RF_ABILITY::HASTE:
785         (void)set_fast(caster_ptr, randint1(20 + plev) + plev, FALSE);
786         break;
787     case RF_ABILITY::HAND_DOOM: {
788         if (!get_aim_dir(caster_ptr, &dir))
789             return FALSE;
790         else
791             msg_print(_("<破滅の手>を放った!", "You invoke the Hand of Doom!"));
792
793         fire_ball_hide(caster_ptr, GF_HAND_DOOM, dir, 200, 0);
794         break;
795     }
796     case RF_ABILITY::HEAL:
797         msg_print(_("自分の傷に念を集中した。", "You concentrate on your wounds!"));
798         (void)hp_player(caster_ptr, plev * 6);
799         (void)set_stun(caster_ptr, 0);
800         (void)set_cut(caster_ptr, 0);
801         break;
802     case RF_ABILITY::INVULNER:
803         msg_print(_("無傷の球の呪文を唱えた。", "You cast a Globe of Invulnerability."));
804         (void)set_invuln(caster_ptr, randint1(7) + 7, FALSE);
805         break;
806     case RF_ABILITY::BLINK:
807         teleport_player(caster_ptr, 10, TELEPORT_SPONTANEOUS);
808         break;
809     case RF_ABILITY::TPORT:
810         teleport_player(caster_ptr, plev * 5, TELEPORT_SPONTANEOUS);
811         break;
812     case RF_ABILITY::WORLD:
813         (void)time_walk(caster_ptr);
814         break;
815     case RF_ABILITY::SPECIAL:
816         break;
817     case RF_ABILITY::TELE_TO: {
818         monster_type *m_ptr;
819         monster_race *r_ptr;
820         GAME_TEXT m_name[MAX_NLEN];
821
822         if (!target_set(caster_ptr, TARGET_KILL))
823             return FALSE;
824         if (!caster_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx)
825             break;
826         if (!player_has_los_bold(caster_ptr, target_row, target_col))
827             break;
828         if (!projectable(caster_ptr, caster_ptr->y, caster_ptr->x, target_row, target_col))
829             break;
830         m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx];
831         r_ptr = &r_info[m_ptr->r_idx];
832         monster_desc(caster_ptr, m_name, m_ptr, 0);
833         if (r_ptr->flagsr & RFR_RES_TELE) {
834             if ((r_ptr->flags1 & (RF1_UNIQUE)) || (r_ptr->flagsr & RFR_RES_ALL)) {
835                 if (is_original_ap_and_seen(caster_ptr, m_ptr))
836                     r_ptr->r_flagsr |= RFR_RES_TELE;
837                 msg_format(_("%sには効果がなかった!", "%s is unaffected!"), m_name);
838
839                 break;
840             } else if (r_ptr->level > randint1(100)) {
841                 if (is_original_ap_and_seen(caster_ptr, m_ptr))
842                     r_ptr->r_flagsr |= RFR_RES_TELE;
843                 msg_format(_("%sには耐性がある!", "%s resists!"), m_name);
844
845                 break;
846             }
847         }
848         msg_format(_("%sを引き戻した。", "You command %s to return."), m_name);
849
850         teleport_monster_to(
851             caster_ptr, caster_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx, caster_ptr->y, caster_ptr->x, 100, TELEPORT_PASSIVE);
852         break;
853     }
854     case RF_ABILITY::TELE_AWAY:
855         if (!get_aim_dir(caster_ptr, &dir))
856             return FALSE;
857
858         (void)fire_beam(caster_ptr, GF_AWAY_ALL, dir, plev);
859         break;
860
861     case RF_ABILITY::TELE_LEVEL:
862         return teleport_level_other(caster_ptr);
863         break;
864
865     case RF_ABILITY::PSY_SPEAR:
866         if (!get_aim_dir(caster_ptr, &dir))
867             return FALSE;
868         else
869             msg_print(_("光の剣を放った。", "You throw a psycho-spear."));
870         (void)fire_beam(caster_ptr, GF_PSY_SPEAR, dir, damage);
871         break;
872
873     case RF_ABILITY::DARKNESS:
874         msg_print(_("暗闇の中で手を振った。", "You gesture in shadow."));
875         (void)unlite_area(caster_ptr, 10, 3);
876         break;
877
878     case RF_ABILITY::TRAPS:
879         if (!target_set(caster_ptr, TARGET_KILL))
880             return FALSE;
881         msg_print(_("呪文を唱えて邪悪に微笑んだ。", "You cast a spell and cackle evilly."));
882         trap_creation(caster_ptr, target_row, target_col);
883         break;
884     case RF_ABILITY::FORGET:
885         msg_print(_("しかし何も起きなかった。", "Nothing happens."));
886         break;
887     case RF_ABILITY::RAISE_DEAD:
888         msg_print(_("死者復活の呪文を唱えた。", "You animate the dead."));
889         (void)animate_dead(caster_ptr, 0, caster_ptr->y, caster_ptr->x);
890         break;
891     case RF_ABILITY::S_KIN: {
892         int k;
893         if (!target_set(caster_ptr, TARGET_KILL))
894             return FALSE;
895
896         msg_print(_("援軍を召喚した。", "You summon minions."));
897         for (k = 0; k < 4; k++) {
898             (void)summon_kin_player(caster_ptr, plev, target_row, target_col, (PM_FORCE_PET | PM_ALLOW_GROUP));
899         }
900         break;
901     }
902     case RF_ABILITY::S_CYBER: {
903         int k;
904         int max_cyber = (caster_ptr->current_floor_ptr->dun_level / 50) + randint1(3);
905         if (!target_set(caster_ptr, TARGET_KILL))
906             return FALSE;
907         msg_print(_("サイバーデーモンを召喚した!", "You summon Cyberdemons!"));
908         if (max_cyber > 4)
909             max_cyber = 4;
910         for (k = 0; k < max_cyber; k++)
911             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_CYBER, mode);
912         break;
913     }
914     case RF_ABILITY::S_MONSTER: {
915         int k;
916         if (!target_set(caster_ptr, TARGET_KILL))
917             return FALSE;
918         msg_print(_("仲間を召喚した。", "You summon help."));
919         for (k = 0; k < 1; k++)
920             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_NONE, (mode | u_mode));
921         break;
922     }
923     case RF_ABILITY::S_MONSTERS: {
924         int k;
925         if (!target_set(caster_ptr, TARGET_KILL))
926             return FALSE;
927         msg_print(_("モンスターを召喚した!", "You summon monsters!"));
928         for (k = 0; k < 6; k++)
929             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_NONE, (mode | u_mode));
930         break;
931     }
932     case RF_ABILITY::S_ANT: {
933         int k;
934         if (!target_set(caster_ptr, TARGET_KILL))
935             return FALSE;
936         msg_print(_("アリを召喚した。", "You summon ants."));
937         for (k = 0; k < 6; k++)
938             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_ANT, mode);
939         break;
940     }
941     case RF_ABILITY::S_SPIDER: {
942         int k;
943         if (!target_set(caster_ptr, TARGET_KILL))
944             return FALSE;
945         msg_print(_("蜘蛛を召喚した。", "You summon spiders."));
946         for (k = 0; k < 6; k++)
947             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_SPIDER, mode);
948         break;
949     }
950     case RF_ABILITY::S_HOUND: {
951         int k;
952         if (!target_set(caster_ptr, TARGET_KILL))
953             return FALSE;
954         msg_print(_("ハウンドを召喚した。", "You summon hounds."));
955         for (k = 0; k < 4; k++)
956             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_HOUND, mode);
957         break;
958     }
959     case RF_ABILITY::S_HYDRA: {
960         int k;
961         if (!target_set(caster_ptr, TARGET_KILL))
962             return FALSE;
963         msg_print(_("ヒドラを召喚した。", "You summon hydras."));
964         for (k = 0; k < 4; k++)
965             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_HYDRA, mode);
966         break;
967     }
968     case RF_ABILITY::S_ANGEL: {
969         int k;
970         if (!target_set(caster_ptr, TARGET_KILL))
971             return FALSE;
972         msg_print(_("天使を召喚した!", "You summon an angel!"));
973         for (k = 0; k < 1; k++)
974             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_ANGEL, mode);
975         break;
976     }
977     case RF_ABILITY::S_DEMON: {
978         int k;
979         if (!target_set(caster_ptr, TARGET_KILL))
980             return FALSE;
981         msg_print(_("混沌の宮廷から悪魔を召喚した!", "You summon a demon from the Courts of Chaos!"));
982         for (k = 0; k < 1; k++)
983             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_DEMON, (mode | u_mode));
984         break;
985     }
986     case RF_ABILITY::S_UNDEAD: {
987         int k;
988         if (!target_set(caster_ptr, TARGET_KILL))
989             return FALSE;
990         msg_print(_("アンデッドの強敵を召喚した!", "You summon an undead adversary!"));
991         for (k = 0; k < 1; k++)
992             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_UNDEAD, (mode | u_mode));
993         break;
994     }
995     case RF_ABILITY::S_DRAGON: {
996         int k;
997         if (!target_set(caster_ptr, TARGET_KILL))
998             return FALSE;
999         msg_print(_("ドラゴンを召喚した!", "You summon a dragon!"));
1000         for (k = 0; k < 1; k++)
1001             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_DRAGON, (mode | u_mode));
1002         break;
1003     }
1004     case RF_ABILITY::S_HI_UNDEAD: {
1005         int k;
1006         if (!target_set(caster_ptr, TARGET_KILL))
1007             return FALSE;
1008         msg_print(_("強力なアンデッドを召喚した!", "You summon greater undead!"));
1009         for (k = 0; k < 6; k++)
1010             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_HI_UNDEAD, (mode | u_mode));
1011         break;
1012     }
1013     case RF_ABILITY::S_HI_DRAGON: {
1014         int k;
1015         if (!target_set(caster_ptr, TARGET_KILL))
1016             return FALSE;
1017         msg_print(_("古代ドラゴンを召喚した!", "You summon ancient dragons!"));
1018         for (k = 0; k < 4; k++)
1019             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_HI_DRAGON, (mode | u_mode));
1020         break;
1021     }
1022     case RF_ABILITY::S_AMBERITES: {
1023         int k;
1024         if (!target_set(caster_ptr, TARGET_KILL))
1025             return FALSE;
1026         msg_print(_("アンバーの王族を召喚した!", "You summon Lords of Amber!"));
1027         for (k = 0; k < 4; k++)
1028             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_AMBERITES, (mode | PM_ALLOW_UNIQUE));
1029         break;
1030     }
1031     case RF_ABILITY::S_UNIQUE: {
1032         int k, count = 0;
1033         if (!target_set(caster_ptr, TARGET_KILL))
1034             return FALSE;
1035         msg_print(_("特別な強敵を召喚した!", "You summon special opponents!"));
1036         for (k = 0; k < 4; k++)
1037             if (summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_UNIQUE, (mode | PM_ALLOW_UNIQUE)))
1038                 count++;
1039         for (k = count; k < 4; k++)
1040             summon_specific(caster_ptr, -1, target_row, target_col, plev, SUMMON_HI_UNDEAD, (mode | u_mode));
1041         break;
1042     }
1043     default:
1044         msg_print("hoge?");
1045     }
1046
1047     return TRUE;
1048 }
1049
1050 /*!
1051  * @brief ものまねコマンドのメインルーチン /
1052  * do_cmd_cast calls this function if the player's class is 'imitator'.
1053  * @param baigaesi TRUEならば倍返し上の処理として行う
1054  * @return 処理を実行したらTRUE、キャンセルした場合FALSEを返す。
1055  * @details
1056  * If a valid spell is chosen, saves it in '*sn' and returns TRUE
1057  * If the user hits escape, returns FALSE, and set '*sn' to -1
1058  * If there are no legal choices, returns FALSE, and sets '*sn' to -2
1059  *
1060  * The "prompt" should be "cast", "recite", or "study"
1061  * The "known" should be TRUE for cast/pray, FALSE for study
1062  *
1063  * nb: This function has a (trivial) display bug which will be obvious
1064  * when you run it. It's probably easy to fix but I haven't tried,
1065  * sorry.
1066  */
1067 bool do_cmd_mane(player_type *creature_ptr, bool baigaesi)
1068 {
1069     int n = 0, j;
1070     PERCENTAGE chance;
1071     PERCENTAGE minfail = 0;
1072     PLAYER_LEVEL plev = creature_ptr->lev;
1073     monster_power spell;
1074     bool cast;
1075
1076     if (cmd_limit_confused(creature_ptr))
1077         return FALSE;
1078
1079     if (!creature_ptr->mane_num) {
1080         msg_print(_("まねられるものが何もない!", "You don't remember any action!"));
1081         return FALSE;
1082     }
1083
1084     if (!get_mane_power(creature_ptr, &n, baigaesi))
1085         return FALSE;
1086
1087     spell = monster_powers[static_cast<int>(creature_ptr->mane_spell[n])];
1088
1089     /* Spell failure chance */
1090     chance = spell.manefail;
1091
1092     /* Reduce failure rate by "effective" level adjustment */
1093     if (plev > spell.level)
1094         chance -= 3 * (plev - spell.level);
1095
1096     /* Reduce failure rate by 1 stat and DEX adjustment */
1097     chance -= 3 * (adj_mag_stat[creature_ptr->stat_index[spell.use_stat]] + adj_mag_stat[creature_ptr->stat_index[A_DEX]] - 2) / 2;
1098
1099     if (spell.manedam)
1100         chance = chance * damage / spell.manedam;
1101
1102     chance += creature_ptr->to_m_chance;
1103
1104     /* Extract the minimum failure rate */
1105     minfail = adj_mag_fail[creature_ptr->stat_index[spell.use_stat]];
1106
1107     /* Minimum failure rate */
1108     if (chance < minfail)
1109         chance = minfail;
1110
1111     /* Stunning makes spells harder */
1112     if (creature_ptr->stun > 50)
1113         chance += 25;
1114     else if (creature_ptr->stun)
1115         chance += 15;
1116
1117     /* Always a 5 percent chance of working */
1118     if (chance > 95)
1119         chance = 95;
1120
1121     /* Failed spell */
1122     if (randint0(100) < chance) {
1123         if (flush_failure)
1124             flush();
1125         msg_print(_("ものまねに失敗した!", "You failed to concentrate hard enough!"));
1126         sound(SOUND_FAIL);
1127     } else {
1128         sound(SOUND_ZAP);
1129         cast = use_mane(creature_ptr, creature_ptr->mane_spell[n]);
1130         if (!cast)
1131             return FALSE;
1132     }
1133
1134     creature_ptr->mane_num--;
1135     for (j = n; j < creature_ptr->mane_num; j++) {
1136         creature_ptr->mane_spell[j] = creature_ptr->mane_spell[j + 1];
1137         creature_ptr->mane_dam[j] = creature_ptr->mane_dam[j + 1];
1138     }
1139
1140     take_turn(creature_ptr, 100);
1141
1142     creature_ptr->redraw |= (PR_IMITATION);
1143     creature_ptr->window_flags |= (PW_PLAYER);
1144     creature_ptr->window_flags |= (PW_SPELL);
1145
1146     return TRUE;
1147 }