OSDN Git Service

[Refactor] #37353 歌に関するマクロ定義を realm-song.h へ移動.
[hengband/hengband.git] / src / mspells1.c
1 /*!
2  * @file mspells1.c
3  * @brief モンスター魔法の実装 / Monster spells (attack player)
4  * @date 2014/01/17
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7  * This software may be copied and distributed for educational, research,\n
8  * and not for profit purposes provided that this copyright and statement\n
9  * are included in all such copies.  Other copyrights may also apply.\n
10  * 2014 Deskull rearranged comment for Doxygen.\n
11  * @details
12  * And now for Intelligent monster attacks (including spells).\n
13  *\n
14  * Original idea and code by "DRS" (David Reeves Sward).\n
15  * Major modifications by "BEN" (Ben Harrison).\n
16  *\n
17  * Give monsters more intelligent attack/spell selection based on\n
18  * observations of previous attacks on the player, and/or by allowing\n
19  * the monster to "cheat" and know the player status.\n
20  *\n
21  * Maintain an idea of the player status, and use that information\n
22  * to occasionally eliminate "ineffective" spell attacks.  We could\n
23  * also eliminate ineffective normal attacks, but there is no reason\n
24  * for the monster to do this, since he gains no benefit.\n
25  * Note that MINDLESS monsters are not allowed to use this code.\n
26  * And non-INTELLIGENT monsters only use it partially effectively.\n
27  *\n
28  * Actually learn what the player resists, and use that information\n
29  * to remove attacks or spells before using them.  This will require\n
30  * much less space, if I am not mistaken.  Thus, each monster gets a\n
31  * set of 32 bit flags, "smart", build from the various "SM_*" flags.\n
32  *\n
33  * This has the added advantage that attacks and spells are related.\n
34  * The "smart_learn" option means that the monster "learns" the flags\n
35  * that should be set, and "smart_cheat" means that he "knows" them.\n
36  * So "smart_cheat" means that the "smart" field is always up to date,\n
37  * while "smart_learn" means that the "smart" field is slowly learned.\n
38  * Both of them have the same effect on the "choose spell" routine.\n
39  */
40
41 #include "angband.h"
42 #include "util.h"
43
44 #include "floor.h"
45 #include "dungeon.h"
46 #include "grid.h"
47 #include "object-curse.h"
48 #include "quest.h"
49 #include "realm-hex.h"
50 #include "player-move.h"
51 #include "player-status.h"
52 #include "monster.h"
53 #include "monster-spell.h"
54 #include "spells.h"
55 #include "world.h"
56 #include "realm-song.h"
57
58
59 /*!
60  * @brief モンスターがプレイヤーの弱点をついた選択を取るかどうかの判定 /
61  * Internal probability routine
62  * @param r_ptr モンスター種族の構造体参照ポインタ
63  * @param prob 基本確率(%)
64  * @return 適した選択を取るならばTRUEを返す。
65  */
66 static bool int_outof(monster_race *r_ptr, PERCENTAGE prob)
67 {
68         /* Non-Smart monsters are half as "smart" */
69         if (!(r_ptr->flags2 & RF2_SMART)) prob = prob / 2;
70
71         /* Roll the dice */
72         return (randint0(100) < prob);
73 }
74
75
76 /*!
77  * @brief モンスターの魔法一覧から戦術的に適さない魔法を除外する /
78  * Remove the "bad" spells from a spell list
79  * @param m_idx モンスターの構造体参照ポインタ
80  * @param f4p モンスター魔法のフラグリスト1
81  * @param f5p モンスター魔法のフラグリスト2
82  * @param f6p モンスター魔法のフラグリスト3
83  * @return なし
84  */
85 static void remove_bad_spells(MONSTER_IDX m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
86 {
87         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
88         monster_race *r_ptr = &r_info[m_ptr->r_idx];
89
90         u32b f4 = (*f4p);
91         u32b f5 = (*f5p);
92         u32b f6 = (*f6p);
93
94         u32b smart = 0L;
95
96
97         /* Too stupid to know anything */
98         if (r_ptr->flags2 & RF2_STUPID) return;
99
100
101         /* Must be cheating or learning */
102         if (!smart_cheat && !smart_learn) return;
103
104
105         /* Update acquired knowledge */
106         if (smart_learn)
107         {
108                 /* Hack -- Occasionally forget player status */
109                 /* Only save SM_FRIENDLY, SM_PET or SM_CLONED */
110                 if (m_ptr->smart && (randint0(100) < 1)) m_ptr->smart &= (SM_FRIENDLY | SM_PET | SM_CLONED);
111
112                 /* Use the memorized flags */
113                 smart = m_ptr->smart;
114         }
115
116
117         /* Cheat if requested */
118         if (smart_cheat)
119         {
120                 /* Know basic info */
121                 if (p_ptr->resist_acid) smart |= (SM_RES_ACID);
122                 if (IS_OPPOSE_ACID()) smart |= (SM_OPP_ACID);
123                 if (p_ptr->immune_acid) smart |= (SM_IMM_ACID);
124                 if (p_ptr->resist_elec) smart |= (SM_RES_ELEC);
125                 if (IS_OPPOSE_ELEC()) smart |= (SM_OPP_ELEC);
126                 if (p_ptr->immune_elec) smart |= (SM_IMM_ELEC);
127                 if (p_ptr->resist_fire) smart |= (SM_RES_FIRE);
128                 if (IS_OPPOSE_FIRE()) smart |= (SM_OPP_FIRE);
129                 if (p_ptr->immune_fire) smart |= (SM_IMM_FIRE);
130                 if (p_ptr->resist_cold) smart |= (SM_RES_COLD);
131                 if (IS_OPPOSE_COLD()) smart |= (SM_OPP_COLD);
132                 if (p_ptr->immune_cold) smart |= (SM_IMM_COLD);
133
134                 /* Know poison info */
135                 if (p_ptr->resist_pois) smart |= (SM_RES_POIS);
136                 if (IS_OPPOSE_POIS()) smart |= (SM_OPP_POIS);
137
138                 /* Know special resistances */
139                 if (p_ptr->resist_neth) smart |= (SM_RES_NETH);
140                 if (p_ptr->resist_lite) smart |= (SM_RES_LITE);
141                 if (p_ptr->resist_dark) smart |= (SM_RES_DARK);
142                 if (p_ptr->resist_fear) smart |= (SM_RES_FEAR);
143                 if (p_ptr->resist_conf) smart |= (SM_RES_CONF);
144                 if (p_ptr->resist_chaos) smart |= (SM_RES_CHAOS);
145                 if (p_ptr->resist_disen) smart |= (SM_RES_DISEN);
146                 if (p_ptr->resist_blind) smart |= (SM_RES_BLIND);
147                 if (p_ptr->resist_nexus) smart |= (SM_RES_NEXUS);
148                 if (p_ptr->resist_sound) smart |= (SM_RES_SOUND);
149                 if (p_ptr->resist_shard) smart |= (SM_RES_SHARD);
150                 if (p_ptr->reflect) smart |= (SM_IMM_REFLECT);
151
152                 /* Know bizarre "resistances" */
153                 if (p_ptr->free_act) smart |= (SM_IMM_FREE);
154                 if (!p_ptr->msp) smart |= (SM_IMM_MANA);
155         }
156
157
158         /* Nothing known */
159         if (!smart) return;
160
161
162         if (smart & SM_IMM_ACID)
163         {
164                 f4 &= ~(RF4_BR_ACID);
165                 f5 &= ~(RF5_BA_ACID);
166                 f5 &= ~(RF5_BO_ACID);
167         }
168         else if ((smart & (SM_OPP_ACID)) && (smart & (SM_RES_ACID)))
169         {
170                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_ACID);
171                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_ACID);
172                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ACID);
173         }
174         else if ((smart & (SM_OPP_ACID)) || (smart & (SM_RES_ACID)))
175         {
176                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_ACID);
177                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_ACID);
178                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ACID);
179         }
180
181
182         if (smart & (SM_IMM_ELEC))
183         {
184                 f4 &= ~(RF4_BR_ELEC);
185                 f5 &= ~(RF5_BA_ELEC);
186                 f5 &= ~(RF5_BO_ELEC);
187         }
188         else if ((smart & (SM_OPP_ELEC)) && (smart & (SM_RES_ELEC)))
189         {
190                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_ELEC);
191                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_ELEC);
192                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ELEC);
193         }
194         else if ((smart & (SM_OPP_ELEC)) || (smart & (SM_RES_ELEC)))
195         {
196                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_ELEC);
197                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_ELEC);
198                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ELEC);
199         }
200
201
202         if (smart & (SM_IMM_FIRE))
203         {
204                 f4 &= ~(RF4_BR_FIRE);
205                 f5 &= ~(RF5_BA_FIRE);
206                 f5 &= ~(RF5_BO_FIRE);
207         }
208         else if ((smart & (SM_OPP_FIRE)) && (smart & (SM_RES_FIRE)))
209         {
210                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_FIRE);
211                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_FIRE);
212                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_FIRE);
213         }
214         else if ((smart & (SM_OPP_FIRE)) || (smart & (SM_RES_FIRE)))
215         {
216                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_FIRE);
217                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_FIRE);
218                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_FIRE);
219         }
220
221
222         if (smart & (SM_IMM_COLD))
223         {
224                 f4 &= ~(RF4_BR_COLD);
225                 f5 &= ~(RF5_BA_COLD);
226                 f5 &= ~(RF5_BO_COLD);
227                 f5 &= ~(RF5_BO_ICEE);
228         }
229         else if ((smart & (SM_OPP_COLD)) && (smart & (SM_RES_COLD)))
230         {
231                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_COLD);
232                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_COLD);
233                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_COLD);
234                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ICEE);
235         }
236         else if ((smart & (SM_OPP_COLD)) || (smart & (SM_RES_COLD)))
237         {
238                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_COLD);
239                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_COLD);
240                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_COLD);
241                 if (int_outof(r_ptr, 20)) f5 &= ~(RF5_BO_ICEE);
242         }
243
244
245         if ((smart & (SM_OPP_POIS)) && (smart & (SM_RES_POIS)))
246         {
247                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_POIS);
248                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_POIS);
249                 if (int_outof(r_ptr, 60)) f4 &= ~(RF4_BA_NUKE);
250                 if (int_outof(r_ptr, 60)) f4 &= ~(RF4_BR_NUKE);
251         }
252         else if ((smart & (SM_OPP_POIS)) || (smart & (SM_RES_POIS)))
253         {
254                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_POIS);
255                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_POIS);
256         }
257
258
259         if (smart & (SM_RES_NETH))
260         {
261                 if (prace_is_(RACE_SPECTRE))
262                 {
263                         f4 &= ~(RF4_BR_NETH);
264                         f5 &= ~(RF5_BA_NETH);
265                         f5 &= ~(RF5_BO_NETH);
266                 }
267                 else
268                 {
269                         if (int_outof(r_ptr, 20)) f4 &= ~(RF4_BR_NETH);
270                         if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_NETH);
271                         if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BO_NETH);
272                 }
273         }
274
275         if (smart & (SM_RES_LITE))
276         {
277                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_LITE);
278                 if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_LITE);
279         }
280
281         if (smart & (SM_RES_DARK))
282         {
283                 if (prace_is_(RACE_VAMPIRE))
284                 {
285                         f4 &= ~(RF4_BR_DARK);
286                         f5 &= ~(RF5_BA_DARK);
287                 }
288                 else
289                 {
290                         if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_DARK);
291                         if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_DARK);
292                 }
293         }
294
295         if (smart & (SM_RES_FEAR))
296         {
297                 f5 &= ~(RF5_SCARE);
298         }
299
300         if (smart & (SM_RES_CONF))
301         {
302                 f5 &= ~(RF5_CONF);
303                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CONF);
304         }
305
306         if (smart & (SM_RES_CHAOS))
307         {
308                 if (int_outof(r_ptr, 20)) f4 &= ~(RF4_BR_CHAO);
309                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BA_CHAO);
310         }
311
312         if (smart & (SM_RES_DISEN))
313         {
314                 if (int_outof(r_ptr, 40)) f4 &= ~(RF4_BR_DISE);
315         }
316
317         if (smart & (SM_RES_BLIND))
318         {
319                 f5 &= ~(RF5_BLIND);
320         }
321
322         if (smart & (SM_RES_NEXUS))
323         {
324                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_NEXU);
325                 f6 &= ~(RF6_TELE_LEVEL);
326         }
327
328         if (smart & (SM_RES_SOUND))
329         {
330                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_SOUN);
331         }
332
333         if (smart & (SM_RES_SHARD))
334         {
335                 if (int_outof(r_ptr, 40)) f4 &= ~(RF4_BR_SHAR);
336         }
337
338         if (smart & (SM_IMM_REFLECT))
339         {
340                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_COLD);
341                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_FIRE);
342                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_ACID);
343                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_ELEC);
344                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_NETH);
345                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_WATE);
346                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_MANA);
347                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_PLAS);
348                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_ICEE);
349                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_MISSILE);
350         }
351
352         if (smart & (SM_IMM_FREE))
353         {
354                 f5 &= ~(RF5_HOLD);
355                 f5 &= ~(RF5_SLOW);
356         }
357
358         if (smart & (SM_IMM_MANA))
359         {
360                 f5 &= ~(RF5_DRAIN_MANA);
361         }
362
363         /* No spells left? */
364         /* if (!f4 && !f5 && !f6) ... */
365
366         (*f4p) = f4;
367         (*f5p) = f5;
368         (*f6p) = f6;
369 }
370
371
372 /*!
373  * @brief モンスターにとって所定の地点が召還に相応しい地点かどうかを返す。 /
374  * Determine if there is a space near the player in which a summoned creature can appear
375  * @param y1 判定を行いたいマスのY座標
376  * @param x1 判定を行いたいマスのX座標
377  * @return 召還に相応しいならばTRUEを返す
378  */
379 bool summon_possible(POSITION y1, POSITION x1)
380 {
381         POSITION y, x;
382
383         /* Start at the player's location, and check 2 grids in each dir */
384         for (y = y1 - 2; y <= y1 + 2; y++)
385         {
386                 for (x = x1 - 2; x <= x1 + 2; x++)
387                 {
388                         /* Ignore illegal locations */
389                         if (!in_bounds(y, x)) continue;
390
391                         /* Only check a circular area */
392                         if (distance(y1, x1, y, x)>2) continue;
393
394                         /* ...nor on the Pattern */
395                         if (pattern_tile(y, x)) continue;
396
397                         /* Require empty floor grid in line of projection */
398                         if (cave_empty_bold(y, x) && projectable(y1, x1, y, x) && projectable(y, x, y1, x1)) return (TRUE);
399                 }
400         }
401
402         return FALSE;
403 }
404
405
406 /*!
407  * @brief モンスターにとって死者復活を行うべき状態かどうかを返す /
408  * Determine if there is a space near the player in which a summoned creature can appear
409  * @param m_ptr 判定を行いたいモンスターの構造体参照ポインタ
410  * @return 死者復活が有効な状態ならばTRUEを返す。
411  */
412 bool raise_possible(monster_type *m_ptr)
413 {
414         POSITION xx, yy;
415         POSITION y = m_ptr->fy;
416         POSITION x = m_ptr->fx;
417         OBJECT_IDX this_o_idx, next_o_idx = 0;
418         grid_type *g_ptr;
419
420         for (xx = x - 5; xx <= x + 5; xx++)
421         {
422                 for (yy = y - 5; yy <= y + 5; yy++)
423                 {
424                         if (distance(y, x, yy, xx) > 5) continue;
425                         if (!los(y, x, yy, xx)) continue;
426                         if (!projectable(y, x, yy, xx)) continue;
427
428                         g_ptr = &current_floor_ptr->grid_array[yy][xx];
429                         /* Scan the pile of objects */
430                         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
431                         {
432                                 object_type *o_ptr = &current_floor_ptr->o_list[this_o_idx];
433                                 next_o_idx = o_ptr->next_o_idx;
434
435                                 /* Known to be worthless? */
436                                 if (o_ptr->tval == TV_CORPSE)
437                                 {
438                                         if (!monster_has_hostile_align(m_ptr, 0, 0, &r_info[o_ptr->pval])) return TRUE;
439                                 }
440                         }
441                 }
442         }
443         return FALSE;
444 }
445
446
447
448 /*!
449  * @brief モンスターにとってボルト型魔法が有効な状態かを返す /
450  * Determine if a bolt spell will hit the player.
451  * @param y1 ボルト魔法発射地点のY座標
452  * @param x1 ボルト魔法発射地点のX座標
453  * @param y2 ボルト魔法目標地点のY座標
454  * @param x2 ボルト魔法目標地点のX座標
455  * @param is_friend モンスターがプレイヤーに害意を持たない(ペットか友好的)ならばTRUEをつける
456  * @return ボルト型魔法が有効ならばTRUEを返す。
457  * @details
458  * Originally, it was possible for a friendly to shoot another friendly.\n
459  * Change it so a "clean shot" means no equally friendly monster is\n
460  * between the attacker and target.\n
461  *\n
462  * This is exactly like "projectable", but it will\n
463  * return FALSE if a monster is in the way.\n
464  * no equally friendly monster is\n
465  * between the attacker and target.\n
466  */
467 bool clean_shot(POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_friend)
468 {
469         /* Must be the same as projectable() */
470
471         int i;
472         POSITION y, x;
473
474         int grid_n = 0;
475         u16b grid_g[512];
476
477         /* Check the projection path */
478         grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, 0);
479
480         /* No grid is ever projectable from itself */
481         if (!grid_n) return (FALSE);
482
483         /* Final grid */
484         y = GRID_Y(grid_g[grid_n-1]);
485         x = GRID_X(grid_g[grid_n-1]);
486
487         /* May not end in an unrequested grid */
488         if ((y != y2) || (x != x2)) return (FALSE);
489
490         for (i = 0; i < grid_n; i++)
491         {
492                 y = GRID_Y(grid_g[i]);
493                 x = GRID_X(grid_g[i]);
494
495                 if ((current_floor_ptr->grid_array[y][x].m_idx > 0) && !((y == y2) && (x == x2)))
496                 {
497                         monster_type *m_ptr = &current_floor_ptr->m_list[current_floor_ptr->grid_array[y][x].m_idx];
498                         if (is_friend == is_pet(m_ptr))
499                         {
500                                 return (FALSE);
501                         }
502                 }
503                 /* Pets may not shoot through the character - TNB */
504                 if (player_bold(y, x))
505                 {
506                         if (is_friend) return (FALSE);
507                 }
508         }
509
510         return (TRUE);
511 }
512
513 /*!
514  * @brief モンスターのボルト型魔法処理 /
515  * Cast a bolt at the player Stop if we hit a monster Affect monsters and the player
516  * @param m_idx モンスターのID
517  * @param y 目標のY座標
518  * @param x 目標のX座標
519  * @param typ 効果属性ID
520  * @param dam_hp 威力
521  * @param monspell モンスター魔法のID
522  * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
523  * @return なし
524  */
525 void bolt(MONSTER_IDX m_idx, POSITION y, POSITION x, EFFECT_ID typ, int dam_hp, int monspell, int target_type)
526   {
527     BIT_FLAGS flg = 0;
528     bool learnable = spell_learnable(m_idx);
529
530     switch (target_type)
531     {
532     case MONSTER_TO_MONSTER:
533         flg = PROJECT_STOP | PROJECT_KILL;
534         break;
535     case MONSTER_TO_PLAYER:
536         flg = PROJECT_STOP | PROJECT_KILL | PROJECT_PLAYER;
537         break;
538     }
539         if (typ != GF_ARROW) flg  |= PROJECT_REFLECTABLE;
540
541         /* Target the player with a bolt attack */
542         (void)project(m_idx, 0, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
543 }
544
545 /*!
546  * @brief モンスターのビーム型魔法処理 /
547  * @param m_idx モンスターのID
548  * @param y 目標のY座標
549  * @param x 目標のX座標
550  * @param typ 効果属性ID
551  * @param dam_hp 威力
552  * @param monspell モンスター魔法のID
553  * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
554  * @return なし
555  */
556 void beam(MONSTER_IDX m_idx, POSITION y, POSITION x, EFFECT_ID typ, int dam_hp, int monspell, int target_type)
557 {
558     BIT_FLAGS flg = 0;
559     bool learnable = spell_learnable(m_idx);
560
561     switch (target_type)
562     {
563     case MONSTER_TO_MONSTER:
564         flg = PROJECT_BEAM | PROJECT_KILL | PROJECT_THRU;
565         break;
566     case MONSTER_TO_PLAYER:
567         flg = PROJECT_BEAM | PROJECT_KILL | PROJECT_THRU | PROJECT_PLAYER;
568         break;
569     }
570
571         /* Target the player with a bolt attack */
572         (void)project(m_idx, 0, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
573 }
574
575
576 /*!
577  * @brief モンスターのボール型&ブレス型魔法処理 /
578  * Cast a breath (or ball) attack at the player Pass over any monsters that may be in the way Affect grids, objects, monsters, and the player
579  * @param y 目標地点のY座標
580  * @param x 目標地点のX座標
581  * @param m_idx モンスターのID
582  * @param typ 効果属性ID
583  * @param dam_hp 威力
584  * @param rad 半径
585  * @param breath 
586  * @param monspell モンスター魔法のID
587  * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
588  * @return なし
589  */
590 void breath(POSITION y, POSITION x, MONSTER_IDX m_idx, EFFECT_ID typ, int dam_hp, POSITION rad, bool breath, int monspell, int target_type)
591 {
592     monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
593     monster_race *r_ptr = &r_info[m_ptr->r_idx];
594     bool learnable = spell_learnable(m_idx);
595         BIT_FLAGS flg = 0x00;
596
597     switch (target_type)
598     {
599         case MONSTER_TO_MONSTER:
600             flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
601             break;
602         case MONSTER_TO_PLAYER:
603             flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_PLAYER;
604             break;
605     }
606
607         /* Determine the radius of the blast */
608         if ((rad < 1) && breath) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2;
609
610         /* Handle breath attacks */
611         if (breath) rad = 0 - rad;
612
613         switch (typ)
614         {
615         case GF_ROCKET:
616                 flg |= PROJECT_STOP;
617                 break;
618         case GF_DRAIN_MANA:
619         case GF_MIND_BLAST:
620         case GF_BRAIN_SMASH:
621         case GF_CAUSE_1:
622         case GF_CAUSE_2:
623         case GF_CAUSE_3:
624         case GF_CAUSE_4:
625         case GF_HAND_DOOM:
626                 flg |= (PROJECT_HIDE | PROJECT_AIMED);
627                 break;
628         }
629
630         /* Target the player with a ball attack */
631         (void)project(m_idx, rad, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
632 }
633
634
635
636
637 /*!
638  * @brief ID値が正しいモンスター魔法IDかどうかを返す /
639  * Return TRUE if a spell is good for hurting the player (directly).
640  * @param spell 判定対象のID
641  * @return 正しいIDならばTRUEを返す。
642  */
643 static bool spell_attack(byte spell)
644 {
645         /* All RF4 spells hurt (except for shriek and dispel) */
646         if (spell < 128 && spell > 98) return (TRUE);
647
648         /* Various "ball" spells */
649         if (spell >= 128 && spell <= 128 + 8) return (TRUE);
650
651         /* "Cause wounds" and "bolt" spells */
652         if (spell >= 128 + 12 && spell < 128 + 27) return (TRUE);
653
654         /* Hand of Doom */
655         if (spell == 160 + 1) return (TRUE);
656
657         /* Psycho-Spear */
658         if (spell == 160 + 11) return (TRUE);
659
660         /* Doesn't hurt */
661         return (FALSE);
662 }
663
664
665 /*!
666  * @brief ID値が退避目的に適したモンスター魔法IDかどうかを返す /
667  * Return TRUE if a spell is good for escaping.
668  * @param spell 判定対象のID
669  * @return 適した魔法のIDならばTRUEを返す。
670  */
671 static bool spell_escape(byte spell)
672 {
673         /* Blink or Teleport */
674         if (spell == 160 + 4 || spell == 160 + 5) return (TRUE);
675
676         /* Teleport the player away */
677         if (spell == 160 + 9 || spell == 160 + 10) return (TRUE);
678
679         /* Isn't good for escaping */
680         return (FALSE);
681 }
682
683 /*!
684  * @brief ID値が妨害目的に適したモンスター魔法IDかどうかを返す /
685  * Return TRUE if a spell is good for annoying the player.
686  * @param spell 判定対象のID
687  * @return 適した魔法のIDならばTRUEを返す。
688  */
689 static bool spell_annoy(byte spell)
690 {
691         /* Shriek */
692         if (spell == 96 + 0) return (TRUE);
693
694         /* Brain smash, et al (added curses) */
695         if (spell >= 128 + 9 && spell <= 128 + 14) return (TRUE);
696
697         /* Scare, confuse, blind, slow, paralyze */
698         if (spell >= 128 + 27 && spell <= 128 + 31) return (TRUE);
699
700         /* Teleport to */
701         if (spell == 160 + 8) return (TRUE);
702
703         /* Teleport level */
704         if (spell == 160 + 10) return (TRUE);
705
706         /* Darkness, make traps, cause amnesia */
707         if (spell >= 160 + 12 && spell <= 160 + 14) return (TRUE);
708
709         /* Doesn't annoy */
710         return (FALSE);
711 }
712
713 /*!
714  * @brief ID値が召喚型のモンスター魔法IDかどうかを返す /
715  * Return TRUE if a spell is good for annoying the player.
716  * @param spell 判定対象のID
717  * @return 召喚型魔法のIDならばTRUEを返す。
718  */
719 static bool spell_summon(byte spell)
720 {
721         /* All summon spells */
722         if (spell >= 160 + 16) return (TRUE);
723
724         /* Doesn't summon */
725         return (FALSE);
726 }
727
728
729 /*!
730  * @brief ID値が死者復活処理かどうかを返す /
731  * Return TRUE if a spell is good for annoying the player.
732  * @param spell 判定対象のID
733  * @return 死者復活の処理ならばTRUEを返す。
734  */
735 static bool spell_raise(byte spell)
736 {
737         /* All raise-dead spells */
738         if (spell == 160 + 15) return (TRUE);
739
740         /* Doesn't summon */
741         return (FALSE);
742 }
743
744 /*!
745  * @brief ID値が戦術的なモンスター魔法IDかどうかを返す /
746  * Return TRUE if a spell is good in a tactical situation.
747  * @param spell 判定対象のID
748  * @return 戦術的な魔法のIDならばTRUEを返す。
749  */
750 static bool spell_tactic(byte spell)
751 {
752         /* Blink */
753         if (spell == 160 + 4) return (TRUE);
754
755         /* Not good */
756         return (FALSE);
757 }
758
759 /*!
760  * @brief ID値が無敵化するモンスター魔法IDかどうかを返す /
761  * Return TRUE if a spell makes invulnerable.
762  * @param spell 判定対象のID
763  * @return 召喚型魔法のIDならばTRUEを返す。
764  */
765 static bool spell_invulner(byte spell)
766 {
767         /* Invulnerability */
768         if (spell == 160 + 3) return (TRUE);
769
770         /* No invulnerability */
771         return (FALSE);
772 }
773
774 /*!
775  * @brief ID値が加速するモンスター魔法IDかどうかを返す /
776  * Return TRUE if a spell hastes.
777  * @param spell 判定対象のID
778  * @return 召喚型魔法のIDならばTRUEを返す。
779  */
780 static bool spell_haste(byte spell)
781 {
782         /* Haste self */
783         if (spell == 160 + 0) return (TRUE);
784
785         /* Not a haste spell */
786         return (FALSE);
787 }
788
789
790 /*!
791  * @brief ID値が時間停止を行うモンスター魔法IDかどうかを返す /
792  * Return TRUE if a spell world.
793  * @param spell 判定対象のID
794  * @return 時間停止魔法のIDならばTRUEを返す。
795  */
796 static bool spell_world(byte spell)
797 {
798         if (spell == 160 + 6) return (TRUE);
799         return (FALSE);
800 }
801
802
803 /*!
804  * @brief ID値が特別効果のモンスター魔法IDかどうかを返す /
805  * Return TRUE if a spell special.
806  * @param spell 判定対象のID
807  * @return 特別効果魔法のIDならばTRUEを返す。
808  */
809 static bool spell_special(byte spell)
810 {
811         if (p_ptr->inside_battle) return FALSE;
812         if (spell == 160 + 7) return (TRUE);
813         return (FALSE);
814 }
815
816
817 /*!
818  * @brief ID値が光の剣のモンスター魔法IDかどうかを返す /
819  * Return TRUE if a spell psycho-spear.
820  * @param spell 判定対象のID
821  * @return 光の剣のIDならばTRUEを返す。
822  */
823 static bool spell_psy_spe(byte spell)
824 {
825         /* world */
826         if (spell == 160 + 11) return (TRUE);
827
828         /* Not a haste spell */
829         return (FALSE);
830 }
831
832
833 /*!
834  * @brief ID値が治癒魔法かどうかを返す /
835  * Return TRUE if a spell is good for healing.
836  * @param spell 判定対象のID
837  * @return 治癒魔法のIDならばTRUEを返す。
838  */
839 static bool spell_heal(byte spell)
840 {
841         /* Heal */
842         if (spell == 160 + 2) return (TRUE);
843
844         /* No healing */
845         return (FALSE);
846 }
847
848
849 /*!
850  * @brief ID値が魔力消去かどうかを返す /
851  * Return TRUE if a spell is good for dispel.
852  * @param spell 判定対象のID
853  * @return 魔力消去のIDならばTRUEを返す。
854  */
855 static bool spell_dispel(byte spell)
856 {
857         /* Dispel */
858         if (spell == 96 + 2) return (TRUE);
859
860         /* No dispel */
861         return (FALSE);
862 }
863
864
865 /*!
866  * @brief モンスターがプレイヤーに魔力消去を与えるべきかを判定するルーチン
867  * Check should monster cast dispel spell.
868  * @param m_idx モンスターの構造体配列ID
869  * @return 魔力消去をかけるべきならTRUEを返す。
870  */
871 bool dispel_check(MONSTER_IDX m_idx)
872 {
873         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
874         monster_race *r_ptr = &r_info[m_ptr->r_idx];
875
876         /* Invulnabilty (including the song) */
877         if (IS_INVULN()) return (TRUE);
878
879         /* Wraith form */
880         if (p_ptr->wraith_form) return (TRUE);
881
882         /* Shield */
883         if (p_ptr->shield) return (TRUE);
884
885         /* Magic defence */
886         if (p_ptr->magicdef) return (TRUE);
887
888         /* Multi Shadow */
889         if (p_ptr->multishadow) return (TRUE);
890
891         /* Robe of dust */
892         if (p_ptr->dustrobe) return (TRUE);
893
894         /* Berserk Strength */
895         if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER)) return (TRUE);
896
897         /* Demon Lord */
898         if (p_ptr->mimic_form == MIMIC_DEMON_LORD) return (TRUE);
899
900         /* Elemental resistances */
901         if (r_ptr->flags4 & RF4_BR_ACID)
902         {
903                 if (!p_ptr->immune_acid && (p_ptr->oppose_acid || music_singing(MUSIC_RESIST))) return (TRUE);
904                 if (p_ptr->special_defense & DEFENSE_ACID) return (TRUE);
905         }
906
907         if (r_ptr->flags4 & RF4_BR_FIRE)
908         {
909                 if (!((p_ptr->prace == RACE_DEMON) && p_ptr->lev > 44))
910                 {
911                         if (!p_ptr->immune_fire && (p_ptr->oppose_fire || music_singing(MUSIC_RESIST))) return (TRUE);
912                         if (p_ptr->special_defense & DEFENSE_FIRE) return (TRUE);
913                 }
914         }
915
916         if (r_ptr->flags4 & RF4_BR_ELEC)
917         {
918                 if (!p_ptr->immune_elec && (p_ptr->oppose_elec || music_singing(MUSIC_RESIST))) return (TRUE);
919                 if (p_ptr->special_defense & DEFENSE_ELEC) return (TRUE);
920         }
921
922         if (r_ptr->flags4 & RF4_BR_COLD)
923         {
924                 if (!p_ptr->immune_cold && (p_ptr->oppose_cold || music_singing(MUSIC_RESIST))) return (TRUE);
925                 if (p_ptr->special_defense & DEFENSE_COLD) return (TRUE);
926         }
927
928         if (r_ptr->flags4 & (RF4_BR_POIS | RF4_BR_NUKE))
929         {
930                 if (!((p_ptr->pclass == CLASS_NINJA) && p_ptr->lev > 44))
931                 {
932                         if (p_ptr->oppose_pois || music_singing(MUSIC_RESIST)) return (TRUE);
933                         if (p_ptr->special_defense & DEFENSE_POIS) return (TRUE);
934                 }
935         }
936
937         /* Ultimate resistance */
938         if (p_ptr->ult_res) return (TRUE);
939
940         /* Potion of Neo Tsuyosi special */
941         if (p_ptr->tsuyoshi) return (TRUE);
942
943         /* Elemental Brands */
944         if ((p_ptr->special_attack & ATTACK_ACID) && !(r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)) return (TRUE);
945         if ((p_ptr->special_attack & ATTACK_FIRE) && !(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)) return (TRUE);
946         if ((p_ptr->special_attack & ATTACK_ELEC) && !(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)) return (TRUE);
947         if ((p_ptr->special_attack & ATTACK_COLD) && !(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)) return (TRUE);
948         if ((p_ptr->special_attack & ATTACK_POIS) && !(r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)) return (TRUE);
949
950         if (p_ptr->pspeed < 145)
951         {
952                 if (IS_FAST()) return (TRUE);
953         }
954
955         /* Light speed */
956         if (p_ptr->lightspeed && (m_ptr->mspeed < 136)) return (TRUE);
957
958         if (p_ptr->riding && (current_floor_ptr->m_list[p_ptr->riding].mspeed < 135))
959         {
960                 if (MON_FAST(&current_floor_ptr->m_list[p_ptr->riding])) return (TRUE);
961         }
962
963         /* No need to cast dispel spell */
964         return (FALSE);
965 }
966
967
968 /*!
969  * @brief モンスターの魔法選択ルーチン
970  * Have a monster choose a spell from a list of "useful" spells.
971  * @param m_idx モンスターの構造体配列ID
972  * @param spells 候補魔法IDをまとめた配列
973  * @param num spellsの長さ
974  * @return 選択したモンスター魔法のID
975  * @details
976  * Note that this list does NOT include spells that will just hit\n
977  * other monsters, and the list is restricted when the monster is\n
978  * "desperate".  Should that be the job of this function instead?\n
979  *\n
980  * Stupid monsters will just pick a spell randomly.  Smart monsters\n
981  * will choose more "intelligently".\n
982  *\n
983  * Use the helper functions above to put spells into categories.\n
984  *\n
985  * This function may well be an efficiency bottleneck.\n
986  */
987 static int choose_attack_spell(MONSTER_IDX m_idx, byte spells[], byte num)
988 {
989         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
990         monster_race *r_ptr = &r_info[m_ptr->r_idx];
991
992         byte escape[96], escape_num = 0;
993         byte attack[96], attack_num = 0;
994         byte summon[96], summon_num = 0;
995         byte tactic[96], tactic_num = 0;
996         byte annoy[96], annoy_num = 0;
997         byte invul[96], invul_num = 0;
998         byte haste[96], haste_num = 0;
999         byte world[96], world_num = 0;
1000         byte special[96], special_num = 0;
1001         byte psy_spe[96], psy_spe_num = 0;
1002         byte raise[96], raise_num = 0;
1003         byte heal[96], heal_num = 0;
1004         byte dispel[96], dispel_num = 0;
1005
1006         int i;
1007
1008         /* Stupid monsters choose randomly */
1009         if (r_ptr->flags2 & (RF2_STUPID))
1010         {
1011                 /* Pick at random */
1012                 return (spells[randint0(num)]);
1013         }
1014
1015         /* Categorize spells */
1016         for (i = 0; i < num; i++)
1017         {
1018                 /* Escape spell? */
1019                 if (spell_escape(spells[i])) escape[escape_num++] = spells[i];
1020
1021                 /* Attack spell? */
1022                 if (spell_attack(spells[i])) attack[attack_num++] = spells[i];
1023
1024                 /* Summon spell? */
1025                 if (spell_summon(spells[i])) summon[summon_num++] = spells[i];
1026
1027                 /* Tactical spell? */
1028                 if (spell_tactic(spells[i])) tactic[tactic_num++] = spells[i];
1029
1030                 /* Annoyance spell? */
1031                 if (spell_annoy(spells[i])) annoy[annoy_num++] = spells[i];
1032
1033                 /* Invulnerability spell? */
1034                 if (spell_invulner(spells[i])) invul[invul_num++] = spells[i];
1035
1036                 /* Haste spell? */
1037                 if (spell_haste(spells[i])) haste[haste_num++] = spells[i];
1038
1039                 /* World spell? */
1040                 if (spell_world(spells[i])) world[world_num++] = spells[i];
1041
1042                 /* Special spell? */
1043                 if (spell_special(spells[i])) special[special_num++] = spells[i];
1044
1045                 /* Psycho-spear spell? */
1046                 if (spell_psy_spe(spells[i])) psy_spe[psy_spe_num++] = spells[i];
1047
1048                 /* Raise-dead spell? */
1049                 if (spell_raise(spells[i])) raise[raise_num++] = spells[i];
1050
1051                 /* Heal spell? */
1052                 if (spell_heal(spells[i])) heal[heal_num++] = spells[i];
1053
1054                 /* Dispel spell? */
1055                 if (spell_dispel(spells[i])) dispel[dispel_num++] = spells[i];
1056         }
1057
1058         /*** Try to pick an appropriate spell type ***/
1059
1060         /* world */
1061         if (world_num && (randint0(100) < 15) && !current_world_ptr->timewalk_m_idx)
1062         {
1063                 /* Choose haste spell */
1064                 return (world[randint0(world_num)]);
1065         }
1066
1067         /* special */
1068         if (special_num)
1069         {
1070                 bool success = FALSE;
1071                 switch(m_ptr->r_idx)
1072                 {
1073                         case MON_BANOR:
1074                         case MON_LUPART:
1075                                 if ((m_ptr->hp < m_ptr->maxhp / 2) && r_info[MON_BANOR].max_num && r_info[MON_LUPART].max_num) success = TRUE;
1076                                 break;
1077                         default: break;
1078                 }
1079                 if (success) return (special[randint0(special_num)]);
1080         }
1081
1082         /* Still hurt badly, couldn't flee, attempt to heal */
1083         if (m_ptr->hp < m_ptr->maxhp / 3 && one_in_(2))
1084         {
1085                 /* Choose heal spell if possible */
1086                 if (heal_num) return (heal[randint0(heal_num)]);
1087         }
1088
1089         /* Hurt badly or afraid, attempt to flee */
1090         if (((m_ptr->hp < m_ptr->maxhp / 3) || MON_MONFEAR(m_ptr)) && one_in_(2))
1091         {
1092                 /* Choose escape spell if possible */
1093                 if (escape_num) return (escape[randint0(escape_num)]);
1094         }
1095
1096         /* special */
1097         if (special_num)
1098         {
1099                 bool success = FALSE;
1100                 switch (m_ptr->r_idx)
1101                 {
1102                         case MON_OHMU:
1103                         case MON_BANOR:
1104                         case MON_LUPART:
1105                                 break;
1106                         case MON_BANORLUPART:
1107                                 if (randint0(100) < 70) success = TRUE;
1108                                 break;
1109                         case MON_ROLENTO:
1110                                 if (randint0(100) < 40) success = TRUE;
1111                                 break;
1112                         default:
1113                                 if (randint0(100) < 50) success = TRUE;
1114                                 break;
1115                 }
1116                 if (success) return (special[randint0(special_num)]);
1117         }
1118
1119         /* Player is close and we have attack spells, blink away */
1120         if ((distance(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx) < 4) && (attack_num || (r_ptr->a_ability_flags2 & RF6_TRAPS)) && (randint0(100) < 75) && !current_world_ptr->timewalk_m_idx)
1121         {
1122                 /* Choose tactical spell */
1123                 if (tactic_num) return (tactic[randint0(tactic_num)]);
1124         }
1125
1126         /* Summon if possible (sometimes) */
1127         if (summon_num && (randint0(100) < 40))
1128         {
1129                 /* Choose summon spell */
1130                 return (summon[randint0(summon_num)]);
1131         }
1132
1133         /* dispel */
1134         if (dispel_num && one_in_(2))
1135         {
1136                 /* Choose dispel spell if possible */
1137                 if (dispel_check(m_idx))
1138                 {
1139                         return (dispel[randint0(dispel_num)]);
1140                 }
1141         }
1142
1143         /* Raise-dead if possible (sometimes) */
1144         if (raise_num && (randint0(100) < 40))
1145         {
1146                 /* Choose raise-dead spell */
1147                 return (raise[randint0(raise_num)]);
1148         }
1149
1150         /* Attack spell (most of the time) */
1151         if (IS_INVULN())
1152         {
1153                 if (psy_spe_num && (randint0(100) < 50))
1154                 {
1155                         /* Choose attack spell */
1156                         return (psy_spe[randint0(psy_spe_num)]);
1157                 }
1158                 else if (attack_num && (randint0(100) < 40))
1159                 {
1160                         /* Choose attack spell */
1161                         return (attack[randint0(attack_num)]);
1162                 }
1163         }
1164         else if (attack_num && (randint0(100) < 85))
1165         {
1166                 /* Choose attack spell */
1167                 return (attack[randint0(attack_num)]);
1168         }
1169
1170         /* Try another tactical spell (sometimes) */
1171         if (tactic_num && (randint0(100) < 50) && !current_world_ptr->timewalk_m_idx)
1172         {
1173                 /* Choose tactic spell */
1174                 return (tactic[randint0(tactic_num)]);
1175         }
1176
1177         /* Cast globe of invulnerability if not already in effect */
1178         if (invul_num && !m_ptr->mtimed[MTIMED_INVULNER] && (randint0(100) < 50))
1179         {
1180                 /* Choose Globe of Invulnerability */
1181                 return (invul[randint0(invul_num)]);
1182         }
1183
1184         /* We're hurt (not badly), try to heal */
1185         if ((m_ptr->hp < m_ptr->maxhp * 3 / 4) && (randint0(100) < 25))
1186         {
1187                 /* Choose heal spell if possible */
1188                 if (heal_num) return (heal[randint0(heal_num)]);
1189         }
1190
1191         /* Haste self if we aren't already somewhat hasted (rarely) */
1192         if (haste_num && (randint0(100) < 20) && !MON_FAST(m_ptr))
1193         {
1194                 /* Choose haste spell */
1195                 return (haste[randint0(haste_num)]);
1196         }
1197
1198         /* Annoy player (most of the time) */
1199         if (annoy_num && (randint0(100) < 80))
1200         {
1201                 /* Choose annoyance spell */
1202                 return (annoy[randint0(annoy_num)]);
1203         }
1204
1205         /* Choose no spell */
1206         return (0);
1207 }
1208
1209
1210 /*!
1211  * @brief ID値が非魔術的な特殊技能かどうかを返す /
1212  * Return TRUE if a spell is inate spell.
1213  * @param spell 判定対象のID
1214  * @return 非魔術的な特殊技能ならばTRUEを返す。
1215  */
1216 bool spell_is_inate(SPELL_IDX spell)
1217 {
1218         if (spell < 32 * 4) /* Set RF4 */
1219         {
1220                 if ((1L << (spell - 32 * 3)) & RF4_NOMAGIC_MASK) return TRUE;
1221         }
1222         else if (spell < 32 * 5) /* Set RF5 */
1223         {
1224                 if ((1L << (spell - 32 * 4)) & RF5_NOMAGIC_MASK) return TRUE;
1225         }
1226         else if (spell < 32 * 6) /* Set RF6 */
1227         {
1228                 if ((1L << (spell - 32 * 5)) & RF6_NOMAGIC_MASK) return TRUE;
1229         }
1230
1231         /* This spell is not "inate" */
1232         return FALSE;
1233 }
1234
1235
1236 /*!
1237  * @brief モンスターがプレイヤーにダメージを与えるための最適な座標を算出する /
1238  * @param m_ptr 技能を使用するモンスター構造体の参照ポインタ
1239  * @param yp 最適な目標地点のY座標を返す参照ポインタ
1240  * @param xp 最適な目標地点のX座標を返す参照ポインタ
1241  * @param f_flag 射線に入れるのを避ける地形の所持フラグ
1242  * @param path_check 射線を判定するための関数ポインタ
1243  * @return 有効な座標があった場合TRUEを返す
1244  */
1245 static bool adjacent_grid_check(monster_type *m_ptr, POSITION *yp, POSITION *xp,
1246         int f_flag, bool (*path_check)(POSITION, POSITION, POSITION, POSITION))
1247 {
1248         int i;
1249         int tonari;
1250         static int tonari_y[4][8] = {{-1, -1, -1,  0,  0,  1,  1,  1},
1251                                              {-1, -1, -1,  0,  0,  1,  1,  1},
1252                                              { 1,  1,  1,  0,  0, -1, -1, -1},
1253                                              { 1,  1,  1,  0,  0, -1, -1, -1}};
1254         static int tonari_x[4][8] = {{-1,  0,  1, -1,  1, -1,  0,  1},
1255                                              { 1,  0, -1,  1, -1,  1,  0, -1},
1256                                              {-1,  0,  1, -1,  1, -1,  0,  1},
1257                                              { 1,  0, -1,  1, -1,  1,  0, -1}};
1258
1259         if (m_ptr->fy < p_ptr->y && m_ptr->fx < p_ptr->x) tonari = 0;
1260         else if (m_ptr->fy < p_ptr->y) tonari = 1;
1261         else if (m_ptr->fx < p_ptr->x) tonari = 2;
1262         else tonari = 3;
1263
1264         for (i = 0; i < 8; i++)
1265         {
1266                 int next_x = *xp + tonari_x[tonari][i];
1267                 int next_y = *yp + tonari_y[tonari][i];
1268                 grid_type *g_ptr;
1269
1270                 /* Access the next grid */
1271                 g_ptr = &current_floor_ptr->grid_array[next_y][next_x];
1272
1273                 /* Skip this feature */
1274                 if (!cave_have_flag_grid(g_ptr, f_flag)) continue;
1275
1276                 if (path_check(m_ptr->fy, m_ptr->fx, next_y, next_x))
1277                 {
1278                         *yp = next_y;
1279                         *xp = next_x;
1280                         return TRUE;
1281                 }
1282         }
1283
1284         return FALSE;
1285 }
1286
1287 #define DO_SPELL_NONE    0
1288 #define DO_SPELL_BR_LITE 1
1289 #define DO_SPELL_BR_DISI 2
1290 #define DO_SPELL_BA_LITE 3
1291
1292 /*!
1293  * @brief モンスターの特殊技能メインルーチン /
1294  * Creatures can cast spells, shoot missiles, and breathe.
1295  * @param m_idx モンスター構造体配列のID
1296  * @return 実際に特殊技能を利用したらTRUEを返す
1297  * @details
1298  * Returns "TRUE" if a spell (or whatever) was (successfully) cast.\n
1299  *\n
1300  * This function could use some work, but remember to\n
1301  * keep it as optimized as possible, while retaining generic code.\n
1302  *\n
1303  * Verify the various "blind-ness" checks in the code.\n
1304  *\n
1305  * Note that several effects should really not be "seen"\n
1306  * if the player is blind.  See also "effects.c" for other "mistakes".\n
1307  *\n
1308  * Perhaps monsters should breathe at locations *near* the player,\n
1309  * since this would allow them to inflict "partial" damage.\n
1310  *\n
1311  * Perhaps smart monsters should decline to use "bolt" spells if\n
1312  * there is a monster in the way, unless they wish to kill it.\n
1313  *\n
1314  * Note that, to allow the use of the "track_target" option at some\n
1315  * later time, certain non-optimal things are done in the code below,\n
1316  * including explicit checks against the "direct" variable, which is\n
1317  * currently always true by the time it is checked, but which should\n
1318  * really be set according to an explicit "projectable()" test, and\n
1319  * the use of generic "x,y" locations instead of the player location,\n
1320  * with those values being initialized with the player location.\n
1321  *\n
1322  * It will not be possible to "correctly" handle the case in which a\n
1323  * monster attempts to attack a location which is thought to contain\n
1324  * the player, but which in fact is nowhere near the player, since this\n
1325  * might induce all sorts of messages about the attack itself, and about\n
1326  * the effects of the attack, which the player might or might not be in\n
1327  * a position to observe.  Thus, for simplicity, it is probably best to\n
1328  * only allow "faulty" attacks by a monster if one of the important grids\n
1329  * (probably the initial or final grid) is in fact in view of the player.\n
1330  * It may be necessary to actually prevent spell attacks except when the\n
1331  * monster actually has line of sight to the player.  Note that a monster\n
1332  * could be left in a bizarre situation after the player ducked behind a\n
1333  * pillar and then teleported away, for example.\n
1334  *\n
1335  * @note
1336  * that certain spell attacks do not use the "project()" function\n
1337  * but "simulate" it via the "direct" variable, which is always at least\n
1338  * as restrictive as the "project()" function.  This is necessary to\n
1339  * prevent "blindness" attacks and such from bending around walls, etc,\n
1340  * and to allow the use of the "track_target" option in the future.\n
1341  *\n
1342  * Note that this function attempts to optimize the use of spells for the\n
1343  * cases in which the monster has no spells, or has spells but cannot use\n
1344  * them, or has spells but they will have no "useful" effect.  Note that\n
1345  * this function has been an efficiency bottleneck in the past.\n
1346  *\n
1347  * Note the special "MFLAG_NICE" flag, which prevents a monster from using\n
1348  * any spell attacks until the player has had a single chance to move.\n
1349  */
1350 bool make_attack_spell(MONSTER_IDX m_idx)
1351 {
1352         int k;
1353         SPELL_IDX thrown_spell = 0;
1354         DEPTH rlev;
1355         PERCENTAGE failrate;
1356         byte spell[96], num = 0;
1357         BIT_FLAGS f4, f5, f6;
1358         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
1359         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1360         GAME_TEXT m_name[MAX_NLEN];
1361 #ifndef JP
1362         char m_poss[80];
1363 #endif
1364         bool            no_inate = FALSE;
1365         bool            do_spell = DO_SPELL_NONE;
1366         int             dam = 0;
1367
1368         POSITION x = p_ptr->x;
1369         POSITION y = p_ptr->y;
1370
1371         /* Target location for lite breath */
1372         POSITION x_br_lite = 0;
1373         POSITION y_br_lite = 0;
1374
1375         /* Extract the "see-able-ness" */
1376     bool seen = (!p_ptr->blind && m_ptr->ml);
1377         bool maneable = player_has_los_bold(m_ptr->fy, m_ptr->fx);
1378
1379         /* Check "projectable" */
1380         bool direct;
1381
1382         bool in_no_magic_dungeon = (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC) && current_floor_ptr->dun_level
1383                 && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest));
1384
1385         bool can_use_lite_area = FALSE;
1386
1387         bool can_remember;
1388
1389         /* Cannot cast spells when confused */
1390         if (MON_CONFUSED(m_ptr))
1391         {
1392                 reset_target(m_ptr);
1393                 return (FALSE);
1394         }
1395
1396         /* Cannot cast spells when nice */
1397         if (m_ptr->mflag & MFLAG_NICE) return (FALSE);
1398         if (!is_hostile(m_ptr)) return (FALSE);
1399
1400
1401         /* Sometimes forbid inate attacks (breaths) */
1402         if (randint0(100) >= (r_ptr->freq_spell * 2)) no_inate = TRUE;
1403
1404         /* Handle "track_target" option (?) */
1405
1406
1407         /* Extract the racial spell flags */
1408         f4 = r_ptr->flags4;
1409         f5 = r_ptr->a_ability_flags1;
1410         f6 = r_ptr->a_ability_flags2;
1411
1412         /*** require projectable player ***/
1413
1414         /* Check range */
1415         if ((m_ptr->cdis > MAX_RANGE) && !m_ptr->target_y) return (FALSE);
1416
1417         /* Check path for lite breath */
1418         if (f4 & RF4_BR_LITE)
1419         {
1420                 y_br_lite = y;
1421                 x_br_lite = x;
1422
1423                 if (los(m_ptr->fy, m_ptr->fx, y_br_lite, x_br_lite))
1424                 {
1425                         feature_type *f_ptr = &f_info[current_floor_ptr->grid_array[y_br_lite][x_br_lite].feat];
1426
1427                         if (!have_flag(f_ptr->flags, FF_LOS))
1428                         {
1429                                 if (have_flag(f_ptr->flags, FF_PROJECT) && one_in_(2)) f4 &= ~(RF4_BR_LITE);
1430                         }
1431                 }
1432
1433                 /* Check path to next grid */
1434                 else if (!adjacent_grid_check(m_ptr, &y_br_lite, &x_br_lite, FF_LOS, los)) f4 &= ~(RF4_BR_LITE);
1435
1436                 /* Don't breath lite to the wall if impossible */
1437                 if (!(f4 & RF4_BR_LITE))
1438                 {
1439                         y_br_lite = 0;
1440                         x_br_lite = 0;
1441                 }
1442         }
1443
1444         /* Check path */
1445         if (projectable(m_ptr->fy, m_ptr->fx, y, x))
1446         {
1447                 feature_type *f_ptr = &f_info[current_floor_ptr->grid_array[y][x].feat];
1448
1449                 if (!have_flag(f_ptr->flags, FF_PROJECT))
1450                 {
1451                         /* Breath disintegration to the wall if possible */
1452                         if ((f4 & RF4_BR_DISI) && have_flag(f_ptr->flags, FF_HURT_DISI) && one_in_(2)) do_spell = DO_SPELL_BR_DISI;
1453
1454                         /* Breath lite to the transparent wall if possible */
1455                         else if ((f4 & RF4_BR_LITE) && have_flag(f_ptr->flags, FF_LOS) && one_in_(2)) do_spell = DO_SPELL_BR_LITE;
1456                 }
1457         }
1458
1459         /* Check path to next grid */
1460         else
1461         {
1462                 bool success = FALSE;
1463
1464                 if ((f4 & RF4_BR_DISI) && (m_ptr->cdis < MAX_RANGE/2) &&
1465                     in_disintegration_range(m_ptr->fy, m_ptr->fx, y, x) &&
1466                     (one_in_(10) || (projectable(y, x, m_ptr->fy, m_ptr->fx) && one_in_(2))))
1467                 {
1468                         do_spell = DO_SPELL_BR_DISI;
1469                         success = TRUE;
1470                 }
1471                 else if ((f4 & RF4_BR_LITE) && (m_ptr->cdis < MAX_RANGE/2) &&
1472                     los(m_ptr->fy, m_ptr->fx, y, x) && one_in_(5))
1473                 {
1474                         do_spell = DO_SPELL_BR_LITE;
1475                         success = TRUE;
1476                 }
1477                 else if ((f5 & RF5_BA_LITE) && (m_ptr->cdis <= MAX_RANGE))
1478                 {
1479                         POSITION by = y, bx = x;
1480                         get_project_point(m_ptr->fy, m_ptr->fx, &by, &bx, 0L);
1481                         if ((distance(by, bx, y, x) <= 3) && los(by, bx, y, x) && one_in_(5))
1482                         {
1483                                 do_spell = DO_SPELL_BA_LITE;
1484                                 success = TRUE;
1485                         }
1486                 }
1487
1488                 if (!success) success = adjacent_grid_check(m_ptr, &y, &x, FF_PROJECT, projectable);
1489
1490                 if (!success)
1491                 {
1492                         if (m_ptr->target_y && m_ptr->target_x)
1493                         {
1494                                 y = m_ptr->target_y;
1495                                 x = m_ptr->target_x;
1496                                 f4 &= (RF4_INDIRECT_MASK);
1497                                 f5 &= (RF5_INDIRECT_MASK);
1498                                 f6 &= (RF6_INDIRECT_MASK);
1499                                 success = TRUE;
1500                         }
1501
1502                         if (y_br_lite && x_br_lite && (m_ptr->cdis < MAX_RANGE/2) && one_in_(5))
1503                         {
1504                                 if (!success)
1505                                 {
1506                                         y = y_br_lite;
1507                                         x = x_br_lite;
1508                                         do_spell = DO_SPELL_BR_LITE;
1509                                         success = TRUE;
1510                                 }
1511                                 else f4 |= (RF4_BR_LITE);
1512                         }
1513                 }
1514
1515                 /* No spells */
1516                 if (!success) return FALSE;
1517         }
1518
1519         reset_target(m_ptr);
1520
1521         rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1522
1523         /* Forbid inate attacks sometimes */
1524         if (no_inate)
1525         {
1526                 f4 &= ~(RF4_NOMAGIC_MASK);
1527                 f5 &= ~(RF5_NOMAGIC_MASK);
1528                 f6 &= ~(RF6_NOMAGIC_MASK);
1529         }
1530
1531         if (f6 & RF6_DARKNESS)
1532         {
1533                 if ((p_ptr->pclass == CLASS_NINJA) &&
1534                     !(r_ptr->flags3 & (RF3_UNDEAD | RF3_HURT_LITE)) &&
1535                     !(r_ptr->flags7 & RF7_DARK_MASK))
1536                         can_use_lite_area = TRUE;
1537
1538                 if (!(r_ptr->flags2 & RF2_STUPID))
1539                 {
1540                         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) f6 &= ~(RF6_DARKNESS);
1541                         else if ((p_ptr->pclass == CLASS_NINJA) && !can_use_lite_area) f6 &= ~(RF6_DARKNESS);
1542                 }
1543         }
1544
1545         if (in_no_magic_dungeon && !(r_ptr->flags2 & RF2_STUPID))
1546         {
1547                 f4 &= (RF4_NOMAGIC_MASK);
1548                 f5 &= (RF5_NOMAGIC_MASK);
1549                 f6 &= (RF6_NOMAGIC_MASK);
1550         }
1551
1552         if (r_ptr->flags2 & RF2_SMART)
1553         {
1554                 /* Hack -- allow "desperate" spells */
1555                 if ((m_ptr->hp < m_ptr->maxhp / 10) &&
1556                         (randint0(100) < 50))
1557                 {
1558                         /* Require intelligent spells */
1559                         f4 &= (RF4_INT_MASK);
1560                         f5 &= (RF5_INT_MASK);
1561                         f6 &= (RF6_INT_MASK);
1562                 }
1563
1564                 /* Hack -- decline "teleport level" in some case */
1565                 if ((f6 & RF6_TELE_LEVEL) && TELE_LEVEL_IS_INEFF(0))
1566                 {
1567                         f6 &= ~(RF6_TELE_LEVEL);
1568                 }
1569         }
1570
1571         /* No spells left */
1572         if (!f4 && !f5 && !f6) return (FALSE);
1573
1574         /* Remove the "ineffective" spells */
1575         remove_bad_spells(m_idx, &f4, &f5, &f6);
1576
1577         if (p_ptr->inside_arena || p_ptr->inside_battle)
1578         {
1579                 f4 &= ~(RF4_SUMMON_MASK);
1580                 f5 &= ~(RF5_SUMMON_MASK);
1581                 f6 &= ~(RF6_SUMMON_MASK | RF6_TELE_LEVEL);
1582
1583                 if (m_ptr->r_idx == MON_ROLENTO) f6 &= ~(RF6_SPECIAL);
1584         }
1585
1586         /* No spells left */
1587         if (!f4 && !f5 && !f6) return (FALSE);
1588
1589         if (!(r_ptr->flags2 & RF2_STUPID))
1590         {
1591                 if (!p_ptr->csp) f5 &= ~(RF5_DRAIN_MANA);
1592
1593                 /* Check for a clean bolt shot */
1594                 if (((f4 & RF4_BOLT_MASK) ||
1595                      (f5 & RF5_BOLT_MASK) ||
1596                      (f6 & RF6_BOLT_MASK)) &&
1597                     !clean_shot(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x, FALSE))
1598                 {
1599                         /* Remove spells that will only hurt friends */
1600                         f4 &= ~(RF4_BOLT_MASK);
1601                         f5 &= ~(RF5_BOLT_MASK);
1602                         f6 &= ~(RF6_BOLT_MASK);
1603                 }
1604
1605                 /* Check for a possible summon */
1606                 if (((f4 & RF4_SUMMON_MASK) ||
1607                      (f5 & RF5_SUMMON_MASK) ||
1608                      (f6 & RF6_SUMMON_MASK)) &&
1609                     !(summon_possible(y, x)))
1610                 {
1611                         /* Remove summoning spells */
1612                         f4 &= ~(RF4_SUMMON_MASK);
1613                         f5 &= ~(RF5_SUMMON_MASK);
1614                         f6 &= ~(RF6_SUMMON_MASK);
1615                 }
1616
1617                 /* Check for a possible raise dead */
1618                 if ((f6 & RF6_RAISE_DEAD) && !raise_possible(m_ptr))
1619                 {
1620                         /* Remove raise dead spell */
1621                         f6 &= ~(RF6_RAISE_DEAD);
1622                 }
1623
1624                 /* Special moves restriction */
1625                 if (f6 & RF6_SPECIAL)
1626                 {
1627                         if ((m_ptr->r_idx == MON_ROLENTO) && !summon_possible(y, x))
1628                         {
1629                                 f6 &= ~(RF6_SPECIAL);
1630                         }
1631                 }
1632
1633                 /* No spells left */
1634                 if (!f4 && !f5 && !f6) return (FALSE);
1635         }
1636
1637         /* Extract the "inate" spells */
1638         for (k = 0; k < 32; k++)
1639         {
1640         if (f4 & (1L << k)) spell[num++] = k + RF4_SPELL_START;
1641         }
1642
1643         /* Extract the "normal" spells */
1644         for (k = 0; k < 32; k++)
1645         {
1646         if (f5 & (1L << k)) spell[num++] = k + RF5_SPELL_START;
1647         }
1648
1649         /* Extract the "bizarre" spells */
1650         for (k = 0; k < 32; k++)
1651         {
1652         if (f6 & (1L << k)) spell[num++] = k + RF6_SPELL_START;
1653         }
1654
1655         /* No spells left */
1656         if (!num) return (FALSE);
1657
1658         /* Stop if player is dead or gone */
1659         if (!p_ptr->playing || p_ptr->is_dead) return (FALSE);
1660
1661         /* Stop if player is leaving */
1662         if (p_ptr->leaving) return (FALSE);
1663
1664         /* Get the monster name (or "it") */
1665         monster_desc(m_name, m_ptr, 0x00);
1666
1667 #ifndef JP
1668         /* Get the monster possessive ("his"/"her"/"its") */
1669         monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
1670 #endif
1671
1672         switch (do_spell)
1673         {
1674         case DO_SPELL_NONE:
1675                 {
1676                         int attempt = 10;
1677                         while (attempt--)
1678                         {
1679                                 thrown_spell = choose_attack_spell(m_idx, spell, num);
1680                                 if (thrown_spell) break;
1681                         }
1682                 }
1683                 break;
1684
1685         case DO_SPELL_BR_LITE:
1686                 thrown_spell = 96+14; /* RF4_BR_LITE */
1687                 break;
1688
1689         case DO_SPELL_BR_DISI:
1690                 thrown_spell = 96+31; /* RF4_BR_DISI */
1691                 break;
1692
1693         case DO_SPELL_BA_LITE:
1694                 thrown_spell = 128+20; /* RF5_BA_LITE */
1695                 break;
1696
1697         default:
1698                 return FALSE;
1699         }
1700
1701         /* Abort if no spell was chosen */
1702         if (!thrown_spell) return (FALSE);
1703
1704         /* Calculate spell failure rate */
1705         failrate = 25 - (rlev + 3) / 4;
1706
1707         /* Hack -- Stupid monsters will never fail (for jellies and such) */
1708         if (r_ptr->flags2 & RF2_STUPID) failrate = 0;
1709
1710         /* Check for spell failure (inate attacks never fail) */
1711         if (!spell_is_inate(thrown_spell)
1712             && (in_no_magic_dungeon || (MON_STUNNED(m_ptr) && one_in_(2)) || (randint0(100) < failrate)))
1713         {
1714                 disturb(TRUE, TRUE);
1715                 msg_format(_("%^sは呪文を唱えようとしたが失敗した。", "%^s tries to cast a spell, but fails."), m_name);
1716
1717                 return (TRUE);
1718         }
1719
1720         /* Hex: Anti Magic Barrier */
1721         if (!spell_is_inate(thrown_spell) && magic_barrier(m_idx))
1722         {
1723                 msg_format(_("反魔法バリアが%^sの呪文をかき消した。", "Anti magic barrier cancels the spell which %^s casts."), m_name);
1724                 return (TRUE);
1725         }
1726
1727         /* Projectable? */
1728         direct = player_bold(y, x);
1729
1730         can_remember = is_original_ap_and_seen(m_ptr);
1731
1732     if (!direct)
1733     {
1734         switch (thrown_spell)
1735         {
1736             case 96 + 2:    /* RF4_DISPEL */
1737             case 96 + 4:    /* RF4_SHOOT */
1738             case 128 + 9:   /* RF5_DRAIN_MANA */
1739             case 128 + 10:  /* RF5_MIND_BLAST */
1740             case 128 + 11:  /* RF5_BRAIN_SMASH */
1741             case 128 + 12:  /* RF5_CAUSE_1 */
1742             case 128 + 13:  /* RF5_CAUSE_2 */
1743             case 128 + 14:  /* RF5_CAUSE_3 */
1744             case 128 + 15:  /* RF5_CAUSE_4 */
1745             case 128 + 16:  /* RF5_BO_ACID */
1746             case 128 + 17:  /* RF5_BO_ELEC */
1747             case 128 + 18:  /* RF5_BO_FIRE */
1748             case 128 + 19:  /* RF5_BO_COLD */
1749             case 128 + 21:  /* RF5_BO_NETH */
1750             case 128 + 22:  /* RF5_BO_WATE */
1751             case 128 + 23:  /* RF5_BO_MANA */
1752             case 128 + 24:  /* RF5_BO_PLAS */
1753             case 128 + 25:  /* RF5_BO_ICEE */
1754             case 128 + 26:  /* RF5_MISSILE */
1755             case 128 + 27:  /* RF5_SCARE */
1756             case 128 + 28:  /* RF5_BLIND */
1757             case 128 + 29:  /* RF5_CONF */
1758             case 128 + 30:  /* RF5_SLOW */
1759             case 128 + 31:  /* RF5_HOLD */
1760             case 160 + 1:   /* RF6_HAND_DOOM */
1761             case 160 + 8:   /* RF6_TELE_TO */
1762             case 160 + 9:   /* RF6_TELE_AWAY */
1763             case 160 + 10:  /* RF6_TELE_LEVEL */
1764             case 160 + 11:  /* RF6_PSY_SPEAR */
1765             case 160 + 12:  /* RF6_DARKNESS */
1766             case 160 + 14:  /* RF6_FORGET */
1767                 return (FALSE);
1768         }
1769     }
1770
1771     /* Cast the spell. */
1772     dam = monspell_to_player(thrown_spell, y, x, m_idx);
1773     if (dam < 0) return FALSE;
1774
1775         if ((p_ptr->action == ACTION_LEARN) && thrown_spell > 175)
1776         {
1777                 learn_spell(thrown_spell - 96);
1778         }
1779
1780         if (seen && maneable && !current_world_ptr->timewalk_m_idx && (p_ptr->pclass == CLASS_IMITATOR))
1781         {
1782                 if (thrown_spell != 167) /* Not RF6_SPECIAL */
1783                 {
1784                         if (p_ptr->mane_num == MAX_MANE)
1785                         {
1786                                 int i;
1787                                 p_ptr->mane_num--;
1788                                 for (i = 0;i < p_ptr->mane_num;i++)
1789                                 {
1790                                         p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
1791                                         p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
1792                                 }
1793                         }
1794                         p_ptr->mane_spell[p_ptr->mane_num] = thrown_spell - 96;
1795                         p_ptr->mane_dam[p_ptr->mane_num] = dam;
1796                         p_ptr->mane_num++;
1797                         new_mane = TRUE;
1798
1799                         p_ptr->redraw |= (PR_IMITATION);
1800                 }
1801         }
1802
1803         /* Remember what the monster did to us */
1804         if (can_remember)
1805         {
1806                 /* Inate spell */
1807                 if (thrown_spell < 32 * 4)
1808                 {
1809                         r_ptr->r_flags4 |= (1L << (thrown_spell - 32 * 3));
1810                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
1811                 }
1812
1813                 /* Bolt or Ball */
1814                 else if (thrown_spell < 32 * 5)
1815                 {
1816                         r_ptr->r_flags5 |= (1L << (thrown_spell - 32 * 4));
1817                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
1818                 }
1819
1820                 /* Special spell */
1821                 else if (thrown_spell < 32 * 6)
1822                 {
1823                         r_ptr->r_flags6 |= (1L << (thrown_spell - 32 * 5));
1824                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
1825                 }
1826         }
1827
1828
1829         /* Always take note of monsters that kill you */
1830         if (p_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !p_ptr->inside_arena)
1831         {
1832                 r_ptr->r_deaths++; /* Ignore appearance difference */
1833         }
1834
1835         /* A spell was cast */
1836         return (TRUE);
1837 }