OSDN Git Service

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