OSDN Git Service

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