OSDN Git Service

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