OSDN Git Service

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