OSDN Git Service

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