OSDN Git Service

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