OSDN Git Service

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