OSDN Git Service

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