OSDN Git Service

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