OSDN Git Service

refactor: integrate monst_breath_monst() into breath
[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
43
44 /*!
45  * @brief ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤Î¼åÅÀ¤ò¤Ä¤¤¤¿ÁªÂò¤ò¼è¤ë¤«¤É¤¦¤«¤ÎȽÄê /
46  * Internal probability routine
47  * @param r_ptr ¥â¥ó¥¹¥¿¡¼¼ï²¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
48  * @param prob ´ðËܳÎΨ(%)
49  * @return Å¬¤·¤¿ÁªÂò¤ò¼è¤ë¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
50  */
51 static bool int_outof(monster_race *r_ptr, int prob)
52 {
53         /* Non-Smart monsters are half as "smart" */
54         if (!(r_ptr->flags2 & RF2_SMART)) prob = prob / 2;
55
56         /* Roll the dice */
57         return (randint0(100) < prob);
58 }
59
60
61 /*!
62  * @brief ¥â¥ó¥¹¥¿¡¼¤ÎËâË¡°ìÍ÷¤«¤éÀï½ÑŪ¤ËŬ¤µ¤Ê¤¤ËâË¡¤ò½ü³°¤¹¤ë /
63  * Remove the "bad" spells from a spell list
64  * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
65  * @param f4p ¥â¥ó¥¹¥¿¡¼ËâË¡¤Î¥Õ¥é¥°¥ê¥¹¥È1
66  * @param f5p ¥â¥ó¥¹¥¿¡¼ËâË¡¤Î¥Õ¥é¥°¥ê¥¹¥È2
67  * @param f6p ¥â¥ó¥¹¥¿¡¼ËâË¡¤Î¥Õ¥é¥°¥ê¥¹¥È3
68  * @return ¤Ê¤·
69  */
70 static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
71 {
72         monster_type *m_ptr = &m_list[m_idx];
73         monster_race *r_ptr = &r_info[m_ptr->r_idx];
74
75         u32b f4 = (*f4p);
76         u32b f5 = (*f5p);
77         u32b f6 = (*f6p);
78
79         u32b smart = 0L;
80
81
82         /* Too stupid to know anything */
83         if (r_ptr->flags2 & RF2_STUPID) return;
84
85
86         /* Must be cheating or learning */
87         if (!smart_cheat && !smart_learn) return;
88
89
90         /* Update acquired knowledge */
91         if (smart_learn)
92         {
93                 /* Hack -- Occasionally forget player status */
94                 /* Only save SM_FRIENDLY, SM_PET or SM_CLONED */
95                 if (m_ptr->smart && (randint0(100) < 1)) m_ptr->smart &= (SM_FRIENDLY | SM_PET | SM_CLONED);
96
97                 /* Use the memorized flags */
98                 smart = m_ptr->smart;
99         }
100
101
102         /* Cheat if requested */
103         if (smart_cheat)
104         {
105                 /* Know basic info */
106                 if (p_ptr->resist_acid) smart |= (SM_RES_ACID);
107                 if (IS_OPPOSE_ACID()) smart |= (SM_OPP_ACID);
108                 if (p_ptr->immune_acid) smart |= (SM_IMM_ACID);
109                 if (p_ptr->resist_elec) smart |= (SM_RES_ELEC);
110                 if (IS_OPPOSE_ELEC()) smart |= (SM_OPP_ELEC);
111                 if (p_ptr->immune_elec) smart |= (SM_IMM_ELEC);
112                 if (p_ptr->resist_fire) smart |= (SM_RES_FIRE);
113                 if (IS_OPPOSE_FIRE()) smart |= (SM_OPP_FIRE);
114                 if (p_ptr->immune_fire) smart |= (SM_IMM_FIRE);
115                 if (p_ptr->resist_cold) smart |= (SM_RES_COLD);
116                 if (IS_OPPOSE_COLD()) smart |= (SM_OPP_COLD);
117                 if (p_ptr->immune_cold) smart |= (SM_IMM_COLD);
118
119                 /* Know poison info */
120                 if (p_ptr->resist_pois) smart |= (SM_RES_POIS);
121                 if (IS_OPPOSE_POIS()) smart |= (SM_OPP_POIS);
122
123                 /* Know special resistances */
124                 if (p_ptr->resist_neth) smart |= (SM_RES_NETH);
125                 if (p_ptr->resist_lite) smart |= (SM_RES_LITE);
126                 if (p_ptr->resist_dark) smart |= (SM_RES_DARK);
127                 if (p_ptr->resist_fear) smart |= (SM_RES_FEAR);
128                 if (p_ptr->resist_conf) smart |= (SM_RES_CONF);
129                 if (p_ptr->resist_chaos) smart |= (SM_RES_CHAOS);
130                 if (p_ptr->resist_disen) smart |= (SM_RES_DISEN);
131                 if (p_ptr->resist_blind) smart |= (SM_RES_BLIND);
132                 if (p_ptr->resist_nexus) smart |= (SM_RES_NEXUS);
133                 if (p_ptr->resist_sound) smart |= (SM_RES_SOUND);
134                 if (p_ptr->resist_shard) smart |= (SM_RES_SHARD);
135                 if (p_ptr->reflect) smart |= (SM_IMM_REFLECT);
136
137                 /* Know bizarre "resistances" */
138                 if (p_ptr->free_act) smart |= (SM_IMM_FREE);
139                 if (!p_ptr->msp) smart |= (SM_IMM_MANA);
140         }
141
142
143         /* Nothing known */
144         if (!smart) return;
145
146
147         if (smart & SM_IMM_ACID)
148         {
149                 f4 &= ~(RF4_BR_ACID);
150                 f5 &= ~(RF5_BA_ACID);
151                 f5 &= ~(RF5_BO_ACID);
152         }
153         else if ((smart & (SM_OPP_ACID)) && (smart & (SM_RES_ACID)))
154         {
155                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_ACID);
156                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_ACID);
157                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ACID);
158         }
159         else if ((smart & (SM_OPP_ACID)) || (smart & (SM_RES_ACID)))
160         {
161                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_ACID);
162                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_ACID);
163                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ACID);
164         }
165
166
167         if (smart & (SM_IMM_ELEC))
168         {
169                 f4 &= ~(RF4_BR_ELEC);
170                 f5 &= ~(RF5_BA_ELEC);
171                 f5 &= ~(RF5_BO_ELEC);
172         }
173         else if ((smart & (SM_OPP_ELEC)) && (smart & (SM_RES_ELEC)))
174         {
175                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_ELEC);
176                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_ELEC);
177                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ELEC);
178         }
179         else if ((smart & (SM_OPP_ELEC)) || (smart & (SM_RES_ELEC)))
180         {
181                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_ELEC);
182                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_ELEC);
183                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ELEC);
184         }
185
186
187         if (smart & (SM_IMM_FIRE))
188         {
189                 f4 &= ~(RF4_BR_FIRE);
190                 f5 &= ~(RF5_BA_FIRE);
191                 f5 &= ~(RF5_BO_FIRE);
192         }
193         else if ((smart & (SM_OPP_FIRE)) && (smart & (SM_RES_FIRE)))
194         {
195                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_FIRE);
196                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_FIRE);
197                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_FIRE);
198         }
199         else if ((smart & (SM_OPP_FIRE)) || (smart & (SM_RES_FIRE)))
200         {
201                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_FIRE);
202                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_FIRE);
203                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_FIRE);
204         }
205
206
207         if (smart & (SM_IMM_COLD))
208         {
209                 f4 &= ~(RF4_BR_COLD);
210                 f5 &= ~(RF5_BA_COLD);
211                 f5 &= ~(RF5_BO_COLD);
212                 f5 &= ~(RF5_BO_ICEE);
213         }
214         else if ((smart & (SM_OPP_COLD)) && (smart & (SM_RES_COLD)))
215         {
216                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_COLD);
217                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_COLD);
218                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_COLD);
219                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ICEE);
220         }
221         else if ((smart & (SM_OPP_COLD)) || (smart & (SM_RES_COLD)))
222         {
223                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_COLD);
224                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_COLD);
225                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_COLD);
226                 if (int_outof(r_ptr, 20)) f5 &= ~(RF5_BO_ICEE);
227         }
228
229
230         if ((smart & (SM_OPP_POIS)) && (smart & (SM_RES_POIS)))
231         {
232                 if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_POIS);
233                 if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_POIS);
234                 if (int_outof(r_ptr, 60)) f4 &= ~(RF4_BA_NUKE);
235                 if (int_outof(r_ptr, 60)) f4 &= ~(RF4_BR_NUKE);
236         }
237         else if ((smart & (SM_OPP_POIS)) || (smart & (SM_RES_POIS)))
238         {
239                 if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_POIS);
240                 if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_POIS);
241         }
242
243
244         if (smart & (SM_RES_NETH))
245         {
246                 if (prace_is_(RACE_SPECTRE))
247                 {
248                         f4 &= ~(RF4_BR_NETH);
249                         f5 &= ~(RF5_BA_NETH);
250                         f5 &= ~(RF5_BO_NETH);
251                 }
252                 else
253                 {
254                         if (int_outof(r_ptr, 20)) f4 &= ~(RF4_BR_NETH);
255                         if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_NETH);
256                         if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BO_NETH);
257                 }
258         }
259
260         if (smart & (SM_RES_LITE))
261         {
262                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_LITE);
263                 if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_LITE);
264         }
265
266         if (smart & (SM_RES_DARK))
267         {
268                 if (prace_is_(RACE_VAMPIRE))
269                 {
270                         f4 &= ~(RF4_BR_DARK);
271                         f5 &= ~(RF5_BA_DARK);
272                 }
273                 else
274                 {
275                         if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_DARK);
276                         if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_DARK);
277                 }
278         }
279
280         if (smart & (SM_RES_FEAR))
281         {
282                 f5 &= ~(RF5_SCARE);
283         }
284
285         if (smart & (SM_RES_CONF))
286         {
287                 f5 &= ~(RF5_CONF);
288                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CONF);
289         }
290
291         if (smart & (SM_RES_CHAOS))
292         {
293                 if (int_outof(r_ptr, 20)) f4 &= ~(RF4_BR_CHAO);
294                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BA_CHAO);
295         }
296
297         if (smart & (SM_RES_DISEN))
298         {
299                 if (int_outof(r_ptr, 40)) f4 &= ~(RF4_BR_DISE);
300         }
301
302         if (smart & (SM_RES_BLIND))
303         {
304                 f5 &= ~(RF5_BLIND);
305         }
306
307         if (smart & (SM_RES_NEXUS))
308         {
309                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_NEXU);
310                 f6 &= ~(RF6_TELE_LEVEL);
311         }
312
313         if (smart & (SM_RES_SOUND))
314         {
315                 if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_SOUN);
316         }
317
318         if (smart & (SM_RES_SHARD))
319         {
320                 if (int_outof(r_ptr, 40)) f4 &= ~(RF4_BR_SHAR);
321         }
322
323         if (smart & (SM_IMM_REFLECT))
324         {
325                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_COLD);
326                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_FIRE);
327                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_ACID);
328                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_ELEC);
329                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_NETH);
330                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_WATE);
331                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_MANA);
332                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_PLAS);
333                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_ICEE);
334                 if (int_outof(r_ptr, 150)) f5 &= ~(RF5_MISSILE);
335                 if (int_outof(r_ptr, 150)) f4 &= ~(RF4_SHOOT);
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         /* XXX XXX XXX 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(int y1, int x1)
366 {
367         int 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         int xx, yy;
401         int y = m_ptr->fy;
402         int x = m_ptr->fx;
403         s16b 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                                 /* Acquire object */
419                                 object_type *o_ptr = &o_list[this_o_idx];
420
421                                 /* Acquire next object */
422                                 next_o_idx = o_ptr->next_o_idx;
423
424                                 /* Known to be worthless? */
425                                 if (o_ptr->tval == TV_CORPSE)
426                                 {
427                                         if (!monster_has_hostile_align(m_ptr, 0, 0, &r_info[o_ptr->pval])) return TRUE;
428                                 }
429                         }
430                 }
431         }
432         return FALSE;
433 }
434
435
436
437 /*!
438  * @brief ¥â¥ó¥¹¥¿¡¼¤Ë¤È¤Ã¤Æ¥Ü¥ë¥È·¿ËâË¡¤¬Í­¸ú¤Ê¾õÂÖ¤«¤òÊÖ¤¹ /
439  * Determine if a bolt spell will hit the player.
440  * @param y1 ¥Ü¥ë¥ÈËâˡȯ¼ÍÃÏÅÀ¤ÎYºÂɸ
441  * @param x1 ¥Ü¥ë¥ÈËâˡȯ¼ÍÃÏÅÀ¤ÎXºÂɸ
442  * @param y2 ¥Ü¥ë¥ÈËâË¡ÌÜɸÃÏÅÀ¤ÎYºÂɸ
443  * @param x2 ¥Ü¥ë¥ÈËâË¡ÌÜɸÃÏÅÀ¤ÎXºÂɸ
444  * @param is_friend ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤Ë³²°Õ¤ò»ý¤¿¤Ê¤¤(¥Ú¥Ã¥È¤«Í§¹¥Åª)¤Ê¤é¤ÐTRUE¤ò¤Ä¤±¤ë
445  * @return ¥Ü¥ë¥È·¿ËâË¡¤¬Í­¸ú¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
446  * @details
447  * Originally, it was possible for a friendly to shoot another friendly.\n
448  * Change it so a "clean shot" means no equally friendly monster is\n
449  * between the attacker and target.\n
450  *\n
451  * This is exactly like "projectable", but it will\n
452  * return FALSE if a monster is in the way.\n
453  * no equally friendly monster is\n
454  * between the attacker and target.\n
455  */
456 bool clean_shot(int y1, int x1, int y2, int x2, bool is_friend)
457 {
458         /* Must be the same as projectable() */
459
460         int i, 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 typ ¸ú²Ì°À­ID
506  * @param dam_hp °ÒÎÏ
507  * @param monspell ¥â¥ó¥¹¥¿¡¼ËâË¡¤ÎID
508  * @param learnable ¥é¡¼¥Ë¥ó¥°²Äǽ¤«Èݤ«
509  * @return ¤Ê¤·
510  */
511 void bolt(int m_idx, int typ, int dam_hp, int monspell)
512 {
513     int flg = PROJECT_STOP | PROJECT_KILL | PROJECT_PLAYER;
514     bool learnable = spell_learnable(m_idx);
515         if (typ != GF_ARROW) flg  |= PROJECT_REFLECTABLE;
516
517         /* Target the player with a bolt attack */
518         (void)project(m_idx, 0, py, px, dam_hp, typ, flg, (learnable ? monspell : -1));
519 }
520
521 /*!
522  * @brief ¥â¥ó¥¹¥¿¡¼¤Î¥Ó¡¼¥à·¿ËâË¡½èÍý /
523  * @param m_idx ¥â¥ó¥¹¥¿¡¼¤ÎID
524  * @param typ ¸ú²Ì°À­ID
525  * @param dam_hp °ÒÎÏ
526  * @param monspell ¥â¥ó¥¹¥¿¡¼ËâË¡¤ÎID
527  * @return ¤Ê¤·
528  */
529 void beam(int m_idx, int typ, int dam_hp, int monspell)
530 {
531     int flg = PROJECT_BEAM | PROJECT_KILL | PROJECT_THRU | PROJECT_PLAYER;
532     bool learnable = spell_learnable(m_idx);
533
534         /* Target the player with a bolt attack */
535         (void)project(m_idx, 0, py, px, dam_hp, typ, flg, (learnable ? monspell : -1));
536 }
537
538
539 /*!
540  * @brief ¥â¥ó¥¹¥¿¡¼¤Î¥Ü¡¼¥ë·¿¡õ¥Ö¥ì¥¹·¿ËâË¡½èÍý /
541  * 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
542  * @param y ÌÜɸÃÏÅÀ¤ÎYºÂɸ
543  * @param x ÌÜɸÃÏÅÀ¤ÎXºÂɸ
544  * @param m_idx ¥â¥ó¥¹¥¿¡¼¤ÎID
545  * @param typ ¸ú²Ì°À­ID
546  * @param dam_hp °ÒÎÏ
547  * @param rad È¾·Â
548  * @param breath TRUE¤Ê¤é¤Ð¥Ö¥ì¥¹½èÍý¡¢FALSE¤Ê¤é¤Ð¥Ü¡¼¥ë½èÍý
549  * @param monspell ¥â¥ó¥¹¥¿¡¼ËâË¡¤ÎID
550  * @param spell_type ¥â¥ó¥¹¥¿¡¼¤«¤é¥â¥ó¥¹¥¿¡¼¤Ø·â¤Ä¤Ê¤éSPELL_MON_TO_MON¡¢¥â¥ó¥¹¥¿¡¼¤«¤é¥×¥ì¥¤¥ä¡¼¤Ê¤éSPELL_MON_TO_PLAYER
551  * @return ¤Ê¤·
552  */
553 void breath(int y, int x, int m_idx, int typ, int dam_hp, int rad, bool breath, int monspell, int spell_type)
554 {
555     monster_type *m_ptr = &m_list[m_idx];
556     monster_race *r_ptr = &r_info[m_ptr->r_idx];
557     bool learnable = spell_learnable(m_idx);
558         int flg;
559
560     switch (spell_type)
561     {
562         case SPELL_MON_TO_MON:
563             flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
564             break;
565         case SPELL_MON_TO_PLAYER:
566             flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_PLAYER;
567             break;
568     }
569
570         /* Determine the radius of the blast */
571         if ((rad < 1) && breath) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2;
572
573         /* Handle breath attacks */
574         if (breath) rad = 0 - rad;
575
576         switch (typ)
577         {
578         case GF_ROCKET:
579                 flg |= PROJECT_STOP;
580                 break;
581         case GF_DRAIN_MANA:
582         case GF_MIND_BLAST:
583         case GF_BRAIN_SMASH:
584         case GF_CAUSE_1:
585         case GF_CAUSE_2:
586         case GF_CAUSE_3:
587         case GF_CAUSE_4:
588         case GF_HAND_DOOM:
589                 flg |= (PROJECT_HIDE | PROJECT_AIMED);
590                 break;
591         }
592
593         /* Target the player with a ball attack */
594         (void)project(m_idx, rad, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
595 }
596
597 /*!
598  * @brief ¥â¥ó¥¹¥¿¡¼¤Î¥Ü¡¼¥ë·¿¡õ¥Ö¥ì¥¹·¿ËâË¡½èÍý /
599  * @param power ¼ö¤¤¤ÎÃʳ¬
600  * @param o_ptr ¼ö¤¤¤ò¤«¤±¤é¤ì¤ëÁõÈ÷¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
601  * @return Í¿¤¨¤ë¼ö¤¤¤ÎID
602  */
603 u32b get_curse(int power, object_type *o_ptr)
604 {
605         u32b new_curse;
606
607         while(1)
608         {
609                 new_curse = (1 << (randint0(MAX_CURSE)+4));
610                 if (power == 2)
611                 {
612                         if (!(new_curse & TRC_HEAVY_MASK)) continue;
613                 }
614                 else if (power == 1)
615                 {
616                         if (new_curse & TRC_SPECIAL_MASK) continue;
617                 }
618                 else if (power == 0)
619                 {
620                         if (new_curse & TRC_HEAVY_MASK) continue;
621                 }
622                 if (new_curse == TRC_LOW_MELEE && !object_is_weapon(o_ptr)) continue;
623                 if (new_curse == TRC_LOW_AC && !object_is_armour(o_ptr)) continue;
624                 break;
625         }
626         return new_curse;
627 }
628
629 /*!
630  * @brief ÁõÈ÷¤Ø¤Î¼ö¤¤ÉÕ²ÃȽÄê¤ÈÉղýèÍý /
631  * @param chance ¼ö¤¤¤Î´ðËܳÎΨ
632  * @param heavy_chance ½Å¤¤¼ö¤¤¤òÁªÂò»è¤ËÆþ¤ì¤ë¤«Èݤ«¡£
633  * @return ¤Ê¤·
634  */
635 void curse_equipment(int chance, int heavy_chance)
636 {
637         bool        changed = FALSE;
638         int         curse_power = 0;
639         u32b        new_curse;
640         u32b oflgs[TR_FLAG_SIZE];
641         object_type *o_ptr = &inventory[INVEN_RARM + randint0(12)];
642         char o_name[MAX_NLEN];
643
644         if (randint1(100) > chance) return;
645
646         if (!o_ptr->k_idx) return;
647
648         object_flags(o_ptr, oflgs);
649
650         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
651
652         /* Extra, biased saving throw for blessed items */
653         if (have_flag(oflgs, TR_BLESSED) && (randint1(888) > chance))
654         {
655 #ifdef JP
656 msg_format("%s¤Ï¼ö¤¤¤òÄ·¤ÍÊÖ¤·¤¿¡ª", o_name,
657 #else
658                 msg_format("Your %s resist%s cursing!", o_name,
659 #endif
660
661                         ((o_ptr->number > 1) ? "" : "s"));
662                 /* Hmmm -- can we wear multiple items? If not, this is unnecessary */
663                 return;
664         }
665
666         if ((randint1(100) <= heavy_chance) &&
667             (object_is_artifact(o_ptr) || object_is_ego(o_ptr)))
668         {
669                 if (!(o_ptr->curse_flags & TRC_HEAVY_CURSE))
670                         changed = TRUE;
671                 o_ptr->curse_flags |= TRC_HEAVY_CURSE;
672                 o_ptr->curse_flags |= TRC_CURSED;
673                 curse_power++;
674         }
675         else
676         {
677                 if (!object_is_cursed(o_ptr))
678                         changed = TRUE;
679                 o_ptr->curse_flags |= TRC_CURSED;
680         }
681         if (heavy_chance >= 50) curse_power++;
682
683         new_curse = get_curse(curse_power, o_ptr);
684         if (!(o_ptr->curse_flags & new_curse))
685         {
686                 changed = TRUE;
687                 o_ptr->curse_flags |= new_curse;
688         }
689
690         if (changed)
691         {
692 #ifdef JP
693 msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
694 #else
695                 msg_format("There is a malignant black aura surrounding %s...", o_name);
696 #endif
697
698                 o_ptr->feeling = FEEL_NONE;
699         }
700         p_ptr->update |= (PU_BONUS);
701 }
702
703
704 /*!
705  * @brief IDÃͤ¬Àµ¤·¤¤¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
706  * Return TRUE if a spell is good for hurting the player (directly).
707  * @param spell È½ÄêÂоݤÎID
708  * @return Àµ¤·¤¤ID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
709  */
710 static bool spell_attack(byte spell)
711 {
712         /* All RF4 spells hurt (except for shriek and dispel) */
713         if (spell < 128 && spell > 98) return (TRUE);
714
715         /* Various "ball" spells */
716         if (spell >= 128 && spell <= 128 + 8) return (TRUE);
717
718         /* "Cause wounds" and "bolt" spells */
719         if (spell >= 128 + 12 && spell < 128 + 27) return (TRUE);
720
721         /* Hand of Doom */
722         if (spell == 160 + 1) return (TRUE);
723
724         /* Psycho-Spear */
725         if (spell == 160 + 11) return (TRUE);
726
727         /* Doesn't hurt */
728         return (FALSE);
729 }
730
731
732 /*!
733  * @brief IDÃͤ¬ÂàÈòÌÜŪ¤ËŬ¤·¤¿¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
734  * Return TRUE if a spell is good for escaping.
735  * @param spell È½ÄêÂоݤÎID
736  * @return Å¬¤·¤¿ËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
737  */
738 static bool spell_escape(byte spell)
739 {
740         /* Blink or Teleport */
741         if (spell == 160 + 4 || spell == 160 + 5) return (TRUE);
742
743         /* Teleport the player away */
744         if (spell == 160 + 9 || spell == 160 + 10) return (TRUE);
745
746         /* Isn't good for escaping */
747         return (FALSE);
748 }
749
750 /*!
751  * @brief IDÃͤ¬Ë¸³²ÌÜŪ¤ËŬ¤·¤¿¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
752  * Return TRUE if a spell is good for annoying the player.
753  * @param spell È½ÄêÂоݤÎID
754  * @return Å¬¤·¤¿ËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
755  */
756 static bool spell_annoy(byte spell)
757 {
758         /* Shriek */
759         if (spell == 96 + 0) return (TRUE);
760
761         /* Brain smash, et al (added curses) */
762         if (spell >= 128 + 9 && spell <= 128 + 14) return (TRUE);
763
764         /* Scare, confuse, blind, slow, paralyze */
765         if (spell >= 128 + 27 && spell <= 128 + 31) return (TRUE);
766
767         /* Teleport to */
768         if (spell == 160 + 8) return (TRUE);
769
770         /* Teleport level */
771         if (spell == 160 + 10) return (TRUE);
772
773         /* Darkness, make traps, cause amnesia */
774         if (spell >= 160 + 12 && spell <= 160 + 14) return (TRUE);
775
776         /* Doesn't annoy */
777         return (FALSE);
778 }
779
780 /*!
781  * @brief IDÃͤ¬¾¤´­·¿¤Î¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
782  * Return TRUE if a spell is good for annoying the player.
783  * @param spell È½ÄêÂоݤÎID
784  * @return ¾¤´­·¿ËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
785  */
786 static bool spell_summon(byte spell)
787 {
788         /* All summon spells */
789         if (spell >= 160 + 16) return (TRUE);
790
791         /* Doesn't summon */
792         return (FALSE);
793 }
794
795
796 /*!
797  * @brief IDÃͤ¬»à¼ÔÉü³è½èÍý¤«¤É¤¦¤«¤òÊÖ¤¹ /
798  * Return TRUE if a spell is good for annoying the player.
799  * @param spell È½ÄêÂоݤÎID
800  * @return »à¼ÔÉü³è¤Î½èÍý¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
801  */
802 static bool spell_raise(byte spell)
803 {
804         /* All raise-dead spells */
805         if (spell == 160 + 15) return (TRUE);
806
807         /* Doesn't summon */
808         return (FALSE);
809 }
810
811 /*!
812  * @brief IDÃͤ¬Àï½ÑŪ¤Ê¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
813  * Return TRUE if a spell is good in a tactical situation.
814  * @param spell È½ÄêÂоݤÎID
815  * @return Àï½ÑŪ¤ÊËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
816  */
817 static bool spell_tactic(byte spell)
818 {
819         /* Blink */
820         if (spell == 160 + 4) return (TRUE);
821
822         /* Not good */
823         return (FALSE);
824 }
825
826 /*!
827  * @brief IDÃͤ¬ÌµÅ¨²½¤¹¤ë¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
828  * Return TRUE if a spell makes invulnerable.
829  * @param spell È½ÄêÂоݤÎID
830  * @return ¾¤´­·¿ËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
831  */
832 static bool spell_invulner(byte spell)
833 {
834         /* Invulnerability */
835         if (spell == 160 + 3) return (TRUE);
836
837         /* No invulnerability */
838         return (FALSE);
839 }
840
841 /*!
842  * @brief IDÃͤ¬²Ã®¤¹¤ë¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
843  * Return TRUE if a spell hastes.
844  * @param spell È½ÄêÂоݤÎID
845  * @return ¾¤´­·¿ËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
846  */
847 static bool spell_haste(byte spell)
848 {
849         /* Haste self */
850         if (spell == 160 + 0) return (TRUE);
851
852         /* Not a haste spell */
853         return (FALSE);
854 }
855
856
857 /*!
858  * @brief IDÃͤ¬»þ´ÖÄä»ß¤ò¹Ô¤¦¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
859  * Return TRUE if a spell world.
860  * @param spell È½ÄêÂоݤÎID
861  * @return »þ´ÖÄä»ßËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
862  */
863 static bool spell_world(byte spell)
864 {
865         if (spell == 160 + 6) return (TRUE);
866         return (FALSE);
867 }
868
869
870 /*!
871  * @brief IDÃͤ¬ÆÃÊ̸ú²Ì¤Î¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
872  * Return TRUE if a spell special.
873  * @param spell È½ÄêÂоݤÎID
874  * @return ÆÃÊ̸ú²ÌËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
875  */
876 static bool spell_special(byte spell)
877 {
878         if (p_ptr->inside_battle) return FALSE;
879         if (spell == 160 + 7) return (TRUE);
880         return (FALSE);
881 }
882
883
884 /*!
885  * @brief IDÃͤ¬¸÷¤Î·õ¤Î¥â¥ó¥¹¥¿¡¼ËâË¡ID¤«¤É¤¦¤«¤òÊÖ¤¹ /
886  * Return TRUE if a spell psycho-spear.
887  * @param spell È½ÄêÂоݤÎID
888  * @return ¸÷¤Î·õ¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
889  */
890 static bool spell_psy_spe(byte spell)
891 {
892         /* world */
893         if (spell == 160 + 11) return (TRUE);
894
895         /* Not a haste spell */
896         return (FALSE);
897 }
898
899
900 /*!
901  * @brief IDÃͤ¬¼£ÌþËâË¡¤«¤É¤¦¤«¤òÊÖ¤¹ /
902  * Return TRUE if a spell is good for healing.
903  * @param spell È½ÄêÂоݤÎID
904  * @return ¼£ÌþËâË¡¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
905  */
906 static bool spell_heal(byte spell)
907 {
908         /* Heal */
909         if (spell == 160 + 2) return (TRUE);
910
911         /* No healing */
912         return (FALSE);
913 }
914
915
916 /*!
917  * @brief IDÃͤ¬ËâÎϾõ¤É¤¦¤«¤òÊÖ¤¹ /
918  * Return TRUE if a spell is good for dispel.
919  * @param spell È½ÄêÂоݤÎID
920  * @return ËâÎϾõî¤ÎID¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
921  */
922 static bool spell_dispel(byte spell)
923 {
924         /* Dispel */
925         if (spell == 96 + 2) return (TRUE);
926
927         /* No dispel */
928         return (FALSE);
929 }
930
931
932 /*!
933  * @brief ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤ËËâÎϾõî¤òÍ¿¤¨¤ë¤Ù¤­¤«¤òȽÄꤹ¤ë¥ë¡¼¥Á¥ó
934  * Check should monster cast dispel spell.
935  * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î¹½Â¤ÂÎÇÛÎóID
936  * @return ËâÎϾõî¤ò¤«¤±¤ë¤Ù¤­¤Ê¤éTRUE¤òÊÖ¤¹¡£
937  */
938 bool dispel_check(int m_idx)
939 {
940         monster_type *m_ptr = &m_list[m_idx];
941         monster_race *r_ptr = &r_info[m_ptr->r_idx];
942
943         /* Invulnabilty (including the song) */
944         if (IS_INVULN()) return (TRUE);
945
946         /* Wraith form */
947         if (p_ptr->wraith_form) return (TRUE);
948
949         /* Shield */
950         if (p_ptr->shield) return (TRUE);
951
952         /* Magic defence */
953         if (p_ptr->magicdef) return (TRUE);
954
955         /* Multi Shadow */
956         if (p_ptr->multishadow) return (TRUE);
957
958         /* Robe of dust */
959         if (p_ptr->dustrobe) return (TRUE);
960
961         /* Berserk Strength */
962         if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER)) return (TRUE);
963
964         /* Demon Lord */
965         if (p_ptr->mimic_form == MIMIC_DEMON_LORD) return (TRUE);
966
967         /* Elemental resistances */
968         if (r_ptr->flags4 & RF4_BR_ACID)
969         {
970                 if (!p_ptr->immune_acid && (p_ptr->oppose_acid || music_singing(MUSIC_RESIST))) return (TRUE);
971                 if (p_ptr->special_defense & DEFENSE_ACID) return (TRUE);
972         }
973
974         if (r_ptr->flags4 & RF4_BR_FIRE)
975         {
976                 if (!((p_ptr->prace == RACE_DEMON) && p_ptr->lev > 44))
977                 {
978                         if (!p_ptr->immune_fire && (p_ptr->oppose_fire || music_singing(MUSIC_RESIST))) return (TRUE);
979                         if (p_ptr->special_defense & DEFENSE_FIRE) return (TRUE);
980                 }
981         }
982
983         if (r_ptr->flags4 & RF4_BR_ELEC)
984         {
985                 if (!p_ptr->immune_elec && (p_ptr->oppose_elec || music_singing(MUSIC_RESIST))) return (TRUE);
986                 if (p_ptr->special_defense & DEFENSE_ELEC) return (TRUE);
987         }
988
989         if (r_ptr->flags4 & RF4_BR_COLD)
990         {
991                 if (!p_ptr->immune_cold && (p_ptr->oppose_cold || music_singing(MUSIC_RESIST))) return (TRUE);
992                 if (p_ptr->special_defense & DEFENSE_COLD) return (TRUE);
993         }
994
995         if (r_ptr->flags4 & (RF4_BR_POIS | RF4_BR_NUKE))
996         {
997                 if (!((p_ptr->pclass == CLASS_NINJA) && p_ptr->lev > 44))
998                 {
999                         if (p_ptr->oppose_pois || music_singing(MUSIC_RESIST)) return (TRUE);
1000                         if (p_ptr->special_defense & DEFENSE_POIS) return (TRUE);
1001                 }
1002         }
1003
1004         /* Ultimate resistance */
1005         if (p_ptr->ult_res) return (TRUE);
1006
1007         /* Potion of Neo Tsuyosi special */
1008         if (p_ptr->tsuyoshi) return (TRUE);
1009
1010         /* Elemental Brands */
1011         if ((p_ptr->special_attack & ATTACK_ACID) && !(r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)) return (TRUE);
1012         if ((p_ptr->special_attack & ATTACK_FIRE) && !(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)) return (TRUE);
1013         if ((p_ptr->special_attack & ATTACK_ELEC) && !(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)) return (TRUE);
1014         if ((p_ptr->special_attack & ATTACK_COLD) && !(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)) return (TRUE);
1015         if ((p_ptr->special_attack & ATTACK_POIS) && !(r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)) return (TRUE);
1016
1017         /* Speed */
1018         if (p_ptr->pspeed < 145)
1019         {
1020                 if (IS_FAST()) return (TRUE);
1021         }
1022
1023         /* Light speed */
1024         if (p_ptr->lightspeed && (m_ptr->mspeed < 136)) return (TRUE);
1025
1026         if (p_ptr->riding && (m_list[p_ptr->riding].mspeed < 135))
1027         {
1028                 if (MON_FAST(&m_list[p_ptr->riding])) return (TRUE);
1029         }
1030
1031         /* No need to cast dispel spell */
1032         return (FALSE);
1033 }
1034
1035
1036 /*!
1037  * @brief ¥â¥ó¥¹¥¿¡¼¤ÎËâË¡ÁªÂò¥ë¡¼¥Á¥ó
1038  * Have a monster choose a spell from a list of "useful" spells.
1039  * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î¹½Â¤ÂÎÇÛÎóID
1040  * @param spells ¸õÊäËâË¡ID¤ò¤Þ¤È¤á¤¿ÇÛÎó
1041  * @param num spells¤ÎŤµ
1042  * @return ÁªÂò¤·¤¿¥â¥ó¥¹¥¿¡¼ËâË¡¤ÎID
1043  * @details
1044  * Note that this list does NOT include spells that will just hit\n
1045  * other monsters, and the list is restricted when the monster is\n
1046  * "desperate".  Should that be the job of this function instead?\n
1047  *\n
1048  * Stupid monsters will just pick a spell randomly.  Smart monsters\n
1049  * will choose more "intelligently".\n
1050  *\n
1051  * Use the helper functions above to put spells into categories.\n
1052  *\n
1053  * This function may well be an efficiency bottleneck.\n
1054  */
1055 static int choose_attack_spell(int m_idx, byte spells[], byte num)
1056 {
1057         monster_type *m_ptr = &m_list[m_idx];
1058         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1059
1060         byte escape[96], escape_num = 0;
1061         byte attack[96], attack_num = 0;
1062         byte summon[96], summon_num = 0;
1063         byte tactic[96], tactic_num = 0;
1064         byte annoy[96], annoy_num = 0;
1065         byte invul[96], invul_num = 0;
1066         byte haste[96], haste_num = 0;
1067         byte world[96], world_num = 0;
1068         byte special[96], special_num = 0;
1069         byte psy_spe[96], psy_spe_num = 0;
1070         byte raise[96], raise_num = 0;
1071         byte heal[96], heal_num = 0;
1072         byte dispel[96], dispel_num = 0;
1073
1074         int i;
1075
1076         /* Stupid monsters choose randomly */
1077         if (r_ptr->flags2 & (RF2_STUPID))
1078         {
1079                 /* Pick at random */
1080                 return (spells[randint0(num)]);
1081         }
1082
1083         /* Categorize spells */
1084         for (i = 0; i < num; i++)
1085         {
1086                 /* Escape spell? */
1087                 if (spell_escape(spells[i])) escape[escape_num++] = spells[i];
1088
1089                 /* Attack spell? */
1090                 if (spell_attack(spells[i])) attack[attack_num++] = spells[i];
1091
1092                 /* Summon spell? */
1093                 if (spell_summon(spells[i])) summon[summon_num++] = spells[i];
1094
1095                 /* Tactical spell? */
1096                 if (spell_tactic(spells[i])) tactic[tactic_num++] = spells[i];
1097
1098                 /* Annoyance spell? */
1099                 if (spell_annoy(spells[i])) annoy[annoy_num++] = spells[i];
1100
1101                 /* Invulnerability spell? */
1102                 if (spell_invulner(spells[i])) invul[invul_num++] = spells[i];
1103
1104                 /* Haste spell? */
1105                 if (spell_haste(spells[i])) haste[haste_num++] = spells[i];
1106
1107                 /* World spell? */
1108                 if (spell_world(spells[i])) world[world_num++] = spells[i];
1109
1110                 /* Special spell? */
1111                 if (spell_special(spells[i])) special[special_num++] = spells[i];
1112
1113                 /* Psycho-spear spell? */
1114                 if (spell_psy_spe(spells[i])) psy_spe[psy_spe_num++] = spells[i];
1115
1116                 /* Raise-dead spell? */
1117                 if (spell_raise(spells[i])) raise[raise_num++] = spells[i];
1118
1119                 /* Heal spell? */
1120                 if (spell_heal(spells[i])) heal[heal_num++] = spells[i];
1121
1122                 /* Dispel spell? */
1123                 if (spell_dispel(spells[i])) dispel[dispel_num++] = spells[i];
1124         }
1125
1126         /*** Try to pick an appropriate spell type ***/
1127
1128         /* world */
1129         if (world_num && (randint0(100) < 15) && !world_monster)
1130         {
1131                 /* Choose haste spell */
1132                 return (world[randint0(world_num)]);
1133         }
1134
1135         /* special */
1136         if (special_num)
1137         {
1138                 bool success = FALSE;
1139                 switch(m_ptr->r_idx)
1140                 {
1141                         case MON_BANOR:
1142                         case MON_LUPART:
1143                                 if ((m_ptr->hp < m_ptr->maxhp / 2) && r_info[MON_BANOR].max_num && r_info[MON_LUPART].max_num) success = TRUE;
1144                                 break;
1145                         default: break;
1146                 }
1147                 if (success) return (special[randint0(special_num)]);
1148         }
1149
1150         /* Still hurt badly, couldn't flee, attempt to heal */
1151         if (m_ptr->hp < m_ptr->maxhp / 3 && one_in_(2))
1152         {
1153                 /* Choose heal spell if possible */
1154                 if (heal_num) return (heal[randint0(heal_num)]);
1155         }
1156
1157         /* Hurt badly or afraid, attempt to flee */
1158         if (((m_ptr->hp < m_ptr->maxhp / 3) || MON_MONFEAR(m_ptr)) && one_in_(2))
1159         {
1160                 /* Choose escape spell if possible */
1161                 if (escape_num) return (escape[randint0(escape_num)]);
1162         }
1163
1164         /* special */
1165         if (special_num)
1166         {
1167                 bool success = FALSE;
1168                 switch (m_ptr->r_idx)
1169                 {
1170                         case MON_OHMU:
1171                         case MON_BANOR:
1172                         case MON_LUPART:
1173                                 break;
1174                         case MON_BANORLUPART:
1175                                 if (randint0(100) < 70) success = TRUE;
1176                                 break;
1177                         case MON_ROLENTO:
1178                                 if (randint0(100) < 40) success = TRUE;
1179                                 break;
1180                         default:
1181                                 if (randint0(100) < 50) success = TRUE;
1182                                 break;
1183                 }
1184                 if (success) return (special[randint0(special_num)]);
1185         }
1186
1187         /* Player is close and we have attack spells, blink away */
1188         if ((distance(py, px, m_ptr->fy, m_ptr->fx) < 4) && (attack_num || (r_ptr->flags6 & RF6_TRAPS)) && (randint0(100) < 75) && !world_monster)
1189         {
1190                 /* Choose tactical spell */
1191                 if (tactic_num) return (tactic[randint0(tactic_num)]);
1192         }
1193
1194         /* Summon if possible (sometimes) */
1195         if (summon_num && (randint0(100) < 40))
1196         {
1197                 /* Choose summon spell */
1198                 return (summon[randint0(summon_num)]);
1199         }
1200
1201         /* dispel */
1202         if (dispel_num && one_in_(2))
1203         {
1204                 /* Choose dispel spell if possible */
1205                 if (dispel_check(m_idx))
1206                 {
1207                         return (dispel[randint0(dispel_num)]);
1208                 }
1209         }
1210
1211         /* Raise-dead if possible (sometimes) */
1212         if (raise_num && (randint0(100) < 40))
1213         {
1214                 /* Choose raise-dead spell */
1215                 return (raise[randint0(raise_num)]);
1216         }
1217
1218         /* Attack spell (most of the time) */
1219         if (IS_INVULN())
1220         {
1221                 if (psy_spe_num && (randint0(100) < 50))
1222                 {
1223                         /* Choose attack spell */
1224                         return (psy_spe[randint0(psy_spe_num)]);
1225                 }
1226                 else if (attack_num && (randint0(100) < 40))
1227                 {
1228                         /* Choose attack spell */
1229                         return (attack[randint0(attack_num)]);
1230                 }
1231         }
1232         else if (attack_num && (randint0(100) < 85))
1233         {
1234                 /* Choose attack spell */
1235                 return (attack[randint0(attack_num)]);
1236         }
1237
1238         /* Try another tactical spell (sometimes) */
1239         if (tactic_num && (randint0(100) < 50) && !world_monster)
1240         {
1241                 /* Choose tactic spell */
1242                 return (tactic[randint0(tactic_num)]);
1243         }
1244
1245         /* Cast globe of invulnerability if not already in effect */
1246         if (invul_num && !m_ptr->mtimed[MTIMED_INVULNER] && (randint0(100) < 50))
1247         {
1248                 /* Choose Globe of Invulnerability */
1249                 return (invul[randint0(invul_num)]);
1250         }
1251
1252         /* We're hurt (not badly), try to heal */
1253         if ((m_ptr->hp < m_ptr->maxhp * 3 / 4) && (randint0(100) < 25))
1254         {
1255                 /* Choose heal spell if possible */
1256                 if (heal_num) return (heal[randint0(heal_num)]);
1257         }
1258
1259         /* Haste self if we aren't already somewhat hasted (rarely) */
1260         if (haste_num && (randint0(100) < 20) && !MON_FAST(m_ptr))
1261         {
1262                 /* Choose haste spell */
1263                 return (haste[randint0(haste_num)]);
1264         }
1265
1266         /* Annoy player (most of the time) */
1267         if (annoy_num && (randint0(100) < 80))
1268         {
1269                 /* Choose annoyance spell */
1270                 return (annoy[randint0(annoy_num)]);
1271         }
1272
1273         /* Choose no spell */
1274         return (0);
1275 }
1276
1277
1278 /*!
1279  * @brief IDÃͤ¬ÈóËâ½ÑŪ¤ÊÆü쵻ǽ¤«¤É¤¦¤«¤òÊÖ¤¹ /
1280  * Return TRUE if a spell is inate spell.
1281  * @param spell È½ÄêÂоݤÎID
1282  * @return ÈóËâ½ÑŪ¤ÊÆü쵻ǽ¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
1283  */
1284 bool spell_is_inate(u16b spell)
1285 {
1286         if (spell < 32 * 4) /* Set RF4 */
1287         {
1288                 if ((1L << (spell - 32 * 3)) & RF4_NOMAGIC_MASK) return TRUE;
1289         }
1290         else if (spell < 32 * 5) /* Set RF5 */
1291         {
1292                 if ((1L << (spell - 32 * 4)) & RF5_NOMAGIC_MASK) return TRUE;
1293         }
1294         else if (spell < 32 * 6) /* Set RF6 */
1295         {
1296                 if ((1L << (spell - 32 * 5)) & RF6_NOMAGIC_MASK) return TRUE;
1297         }
1298
1299         /* This spell is not "inate" */
1300         return FALSE;
1301 }
1302
1303
1304 /*!
1305  * @brief ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤Ë¥À¥á¡¼¥¸¤òÍ¿¤¨¤ë¤¿¤á¤ÎºÇŬ¤ÊºÂɸ¤ò»»½Ð¤¹¤ë /
1306  * @param m_ptr µ»Ç½¤ò»ÈÍѤ¹¤ë¥â¥ó¥¹¥¿¡¼¹½Â¤ÂΤλ²¾È¥Ý¥¤¥ó¥¿
1307  * @param yp ºÇŬ¤ÊÌÜɸÃÏÅÀ¤ÎYºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
1308  * @param xp ºÇŬ¤ÊÌÜɸÃÏÅÀ¤ÎXºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
1309  * @param f_flag ¼ÍÀþ¤ËÆþ¤ì¤ë¤Î¤òÈò¤±¤ëÃÏ·Á¤Î½ê»ý¥Õ¥é¥°
1310  * @param path_check ¼ÍÀþ¤òȽÄꤹ¤ë¤¿¤á¤Î´Ø¿ô¥Ý¥¤¥ó¥¿
1311  * @return Í­¸ú¤ÊºÂɸ¤¬¤¢¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
1312  */
1313 static bool adjacent_grid_check(monster_type *m_ptr, int *yp, int *xp,
1314         int f_flag, bool (*path_check)(int, int, int, int))
1315 {
1316         int i;
1317         int tonari;
1318         static int tonari_y[4][8] = {{-1, -1, -1,  0,  0,  1,  1,  1},
1319                                              {-1, -1, -1,  0,  0,  1,  1,  1},
1320                                              { 1,  1,  1,  0,  0, -1, -1, -1},
1321                                              { 1,  1,  1,  0,  0, -1, -1, -1}};
1322         static int tonari_x[4][8] = {{-1,  0,  1, -1,  1, -1,  0,  1},
1323                                              { 1,  0, -1,  1, -1,  1,  0, -1},
1324                                              {-1,  0,  1, -1,  1, -1,  0,  1},
1325                                              { 1,  0, -1,  1, -1,  1,  0, -1}};
1326
1327         if (m_ptr->fy < py && m_ptr->fx < px) tonari = 0;
1328         else if (m_ptr->fy < py) tonari = 1;
1329         else if (m_ptr->fx < px) tonari = 2;
1330         else tonari = 3;
1331
1332         for (i = 0; i < 8; i++)
1333         {
1334                 int next_x = *xp + tonari_x[tonari][i];
1335                 int next_y = *yp + tonari_y[tonari][i];
1336                 cave_type *c_ptr;
1337
1338                 /* Access the next grid */
1339                 c_ptr = &cave[next_y][next_x];
1340
1341                 /* Skip this feature */
1342                 if (!cave_have_flag_grid(c_ptr, f_flag)) continue;
1343
1344                 if (path_check(m_ptr->fy, m_ptr->fx, next_y, next_x))
1345                 {
1346                         *yp = next_y;
1347                         *xp = next_x;
1348                         return TRUE;
1349                 }
1350         }
1351
1352         return FALSE;
1353 }
1354
1355 #define DO_SPELL_NONE    0
1356 #define DO_SPELL_BR_LITE 1
1357 #define DO_SPELL_BR_DISI 2
1358 #define DO_SPELL_BA_LITE 3
1359
1360 /*!
1361  * @brief ¥â¥ó¥¹¥¿¡¼¤ÎÆü쵻ǽ¥á¥¤¥ó¥ë¡¼¥Á¥ó /
1362  * Creatures can cast spells, shoot missiles, and breathe.
1363  * @param m_idx ¥â¥ó¥¹¥¿¡¼¹½Â¤ÂÎÇÛÎó¤ÎID
1364  * @return ¼ÂºÝ¤ËÆü쵻ǽ¤òÍøÍѤ·¤¿¤éTRUE¤òÊÖ¤¹
1365  * @details
1366  * Returns "TRUE" if a spell (or whatever) was (successfully) cast.\n
1367  *\n
1368  * XXX XXX XXX This function could use some work, but remember to\n
1369  * keep it as optimized as possible, while retaining generic code.\n
1370  *\n
1371  * Verify the various "blind-ness" checks in the code.\n
1372  *\n
1373  * XXX XXX XXX Note that several effects should really not be "seen"\n
1374  * if the player is blind.  See also "effects.c" for other "mistakes".\n
1375  *\n
1376  * Perhaps monsters should breathe at locations *near* the player,\n
1377  * since this would allow them to inflict "partial" damage.\n
1378  *\n
1379  * Perhaps smart monsters should decline to use "bolt" spells if\n
1380  * there is a monster in the way, unless they wish to kill it.\n
1381  *\n
1382  * Note that, to allow the use of the "track_target" option at some\n
1383  * later time, certain non-optimal things are done in the code below,\n
1384  * including explicit checks against the "direct" variable, which is\n
1385  * currently always true by the time it is checked, but which should\n
1386  * really be set according to an explicit "projectable()" test, and\n
1387  * the use of generic "x,y" locations instead of the player location,\n
1388  * with those values being initialized with the player location.\n
1389  *\n
1390  * It will not be possible to "correctly" handle the case in which a\n
1391  * monster attempts to attack a location which is thought to contain\n
1392  * the player, but which in fact is nowhere near the player, since this\n
1393  * might induce all sorts of messages about the attack itself, and about\n
1394  * the effects of the attack, which the player might or might not be in\n
1395  * a position to observe.  Thus, for simplicity, it is probably best to\n
1396  * only allow "faulty" attacks by a monster if one of the important grids\n
1397  * (probably the initial or final grid) is in fact in view of the player.\n
1398  * It may be necessary to actually prevent spell attacks except when the\n
1399  * monster actually has line of sight to the player.  Note that a monster\n
1400  * could be left in a bizarre situation after the player ducked behind a\n
1401  * pillar and then teleported away, for example.\n
1402  *\n
1403  * @note
1404  * that certain spell attacks do not use the "project()" function\n
1405  * but "simulate" it via the "direct" variable, which is always at least\n
1406  * as restrictive as the "project()" function.  This is necessary to\n
1407  * prevent "blindness" attacks and such from bending around walls, etc,\n
1408  * and to allow the use of the "track_target" option in the future.\n
1409  *\n
1410  * Note that this function attempts to optimize the use of spells for the\n
1411  * cases in which the monster has no spells, or has spells but cannot use\n
1412  * them, or has spells but they will have no "useful" effect.  Note that\n
1413  * this function has been an efficiency bottleneck in the past.\n
1414  *\n
1415  * Note the special "MFLAG_NICE" flag, which prevents a monster from using\n
1416  * any spell attacks until the player has had a single chance to move.\n
1417  */
1418 bool make_attack_spell(int m_idx)
1419 {
1420         int             k, thrown_spell = 0, rlev, failrate;
1421         byte            spell[96], num = 0;
1422         u32b            f4, f5, f6;
1423         monster_type    *m_ptr = &m_list[m_idx];
1424         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1425         char            m_name[80];
1426 #ifndef JP
1427         char            m_poss[80];
1428 #endif
1429         bool            no_inate = FALSE;
1430         bool            do_spell = DO_SPELL_NONE;
1431         int             dam = 0;
1432         u32b mode = 0L;
1433         int s_num_6 = (easy_band ? 2 : 6);
1434         int s_num_4 = (easy_band ? 1 : 4);
1435         int rad = 0; //For elemental spells
1436
1437         /* Target location */
1438         int x = px;
1439         int y = py;
1440
1441         /* Target location for lite breath */
1442         int x_br_lite = 0;
1443         int y_br_lite = 0;
1444
1445         /* Summon count */
1446         int count = 0;
1447
1448         /* Extract the blind-ness */
1449         bool blind = (p_ptr->blind ? TRUE : FALSE);
1450
1451         /* Extract the "see-able-ness" */
1452         bool seen = (!blind && m_ptr->ml);
1453         bool maneable = player_has_los_bold(m_ptr->fy, m_ptr->fx);
1454
1455         /* Check "projectable" */
1456         bool direct;
1457
1458         bool in_no_magic_dungeon = (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && dun_level
1459                 && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest));
1460
1461         bool can_use_lite_area = FALSE;
1462
1463         bool can_remember;
1464
1465         /* Cannot cast spells when confused */
1466         if (MON_CONFUSED(m_ptr))
1467         {
1468                 reset_target(m_ptr);
1469                 return (FALSE);
1470         }
1471
1472         /* Cannot cast spells when nice */
1473         if (m_ptr->mflag & MFLAG_NICE) return (FALSE);
1474         if (!is_hostile(m_ptr)) return (FALSE);
1475
1476
1477         /* Sometimes forbid inate attacks (breaths) */
1478         if (randint0(100) >= (r_ptr->freq_spell * 2)) no_inate = TRUE;
1479
1480         /* XXX XXX XXX Handle "track_target" option (?) */
1481
1482
1483         /* Extract the racial spell flags */
1484         f4 = r_ptr->flags4;
1485         f5 = r_ptr->flags5;
1486         f6 = r_ptr->flags6;
1487
1488         /*** require projectable player ***/
1489
1490         /* Check range */
1491         if ((m_ptr->cdis > MAX_RANGE) && !m_ptr->target_y) return (FALSE);
1492
1493         /* Check path for lite breath */
1494         if (f4 & RF4_BR_LITE)
1495         {
1496                 y_br_lite = y;
1497                 x_br_lite = x;
1498
1499                 if (los(m_ptr->fy, m_ptr->fx, y_br_lite, x_br_lite))
1500                 {
1501                         feature_type *f_ptr = &f_info[cave[y_br_lite][x_br_lite].feat];
1502
1503                         if (!have_flag(f_ptr->flags, FF_LOS))
1504                         {
1505                                 if (have_flag(f_ptr->flags, FF_PROJECT) && one_in_(2)) f4 &= ~(RF4_BR_LITE);
1506                         }
1507                 }
1508
1509                 /* Check path to next grid */
1510                 else if (!adjacent_grid_check(m_ptr, &y_br_lite, &x_br_lite, FF_LOS, los)) f4 &= ~(RF4_BR_LITE);
1511
1512                 /* Don't breath lite to the wall if impossible */
1513                 if (!(f4 & RF4_BR_LITE))
1514                 {
1515                         y_br_lite = 0;
1516                         x_br_lite = 0;
1517                 }
1518         }
1519
1520         /* Check path */
1521         if (projectable(m_ptr->fy, m_ptr->fx, y, x))
1522         {
1523                 feature_type *f_ptr = &f_info[cave[y][x].feat];
1524
1525                 if (!have_flag(f_ptr->flags, FF_PROJECT))
1526                 {
1527                         /* Breath disintegration to the wall if possible */
1528                         if ((f4 & RF4_BR_DISI) && have_flag(f_ptr->flags, FF_HURT_DISI) && one_in_(2)) do_spell = DO_SPELL_BR_DISI;
1529
1530                         /* Breath lite to the transparent wall if possible */
1531                         else if ((f4 & RF4_BR_LITE) && have_flag(f_ptr->flags, FF_LOS) && one_in_(2)) do_spell = DO_SPELL_BR_LITE;
1532                 }
1533         }
1534
1535         /* Check path to next grid */
1536         else
1537         {
1538                 bool success = FALSE;
1539
1540                 if ((f4 & RF4_BR_DISI) && (m_ptr->cdis < MAX_RANGE/2) &&
1541                     in_disintegration_range(m_ptr->fy, m_ptr->fx, y, x) &&
1542                     (one_in_(10) || (projectable(y, x, m_ptr->fy, m_ptr->fx) && one_in_(2))))
1543                 {
1544                         do_spell = DO_SPELL_BR_DISI;
1545                         success = TRUE;
1546                 }
1547                 else if ((f4 & RF4_BR_LITE) && (m_ptr->cdis < MAX_RANGE/2) &&
1548                     los(m_ptr->fy, m_ptr->fx, y, x) && one_in_(5))
1549                 {
1550                         do_spell = DO_SPELL_BR_LITE;
1551                         success = TRUE;
1552                 }
1553                 else if ((f5 & RF5_BA_LITE) && (m_ptr->cdis <= MAX_RANGE))
1554                 {
1555                         int by = y, bx = x;
1556                         get_project_point(m_ptr->fy, m_ptr->fx, &by, &bx, 0L);
1557                         if ((distance(by, bx, y, x) <= 3) && los(by, bx, y, x) && one_in_(5))
1558                         {
1559                                 do_spell = DO_SPELL_BA_LITE;
1560                                 success = TRUE;
1561                         }
1562                 }
1563
1564                 if (!success) success = adjacent_grid_check(m_ptr, &y, &x, FF_PROJECT, projectable);
1565
1566                 if (!success)
1567                 {
1568                         if (m_ptr->target_y && m_ptr->target_x)
1569                         {
1570                                 y = m_ptr->target_y;
1571                                 x = m_ptr->target_x;
1572                                 f4 &= (RF4_INDIRECT_MASK);
1573                                 f5 &= (RF5_INDIRECT_MASK);
1574                                 f6 &= (RF6_INDIRECT_MASK);
1575                                 success = TRUE;
1576                         }
1577
1578                         if (y_br_lite && x_br_lite && (m_ptr->cdis < MAX_RANGE/2) && one_in_(5))
1579                         {
1580                                 if (!success)
1581                                 {
1582                                         y = y_br_lite;
1583                                         x = x_br_lite;
1584                                         do_spell = DO_SPELL_BR_LITE;
1585                                         success = TRUE;
1586                                 }
1587                                 else f4 |= (RF4_BR_LITE);
1588                         }
1589                 }
1590
1591                 /* No spells */
1592                 if (!success) return FALSE;
1593         }
1594
1595         reset_target(m_ptr);
1596
1597         /* Extract the monster level */
1598         rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1599
1600         /* Forbid inate attacks sometimes */
1601         if (no_inate)
1602         {
1603                 f4 &= ~(RF4_NOMAGIC_MASK);
1604                 f5 &= ~(RF5_NOMAGIC_MASK);
1605                 f6 &= ~(RF6_NOMAGIC_MASK);
1606         }
1607
1608         if (f6 & RF6_DARKNESS)
1609         {
1610                 if ((p_ptr->pclass == CLASS_NINJA) &&
1611                     !(r_ptr->flags3 & (RF3_UNDEAD | RF3_HURT_LITE)) &&
1612                     !(r_ptr->flags7 & RF7_DARK_MASK))
1613                         can_use_lite_area = TRUE;
1614
1615                 if (!(r_ptr->flags2 & RF2_STUPID))
1616                 {
1617                         if (d_info[dungeon_type].flags1 & DF1_DARKNESS) f6 &= ~(RF6_DARKNESS);
1618                         else if ((p_ptr->pclass == CLASS_NINJA) && !can_use_lite_area) f6 &= ~(RF6_DARKNESS);
1619                 }
1620         }
1621
1622         if (in_no_magic_dungeon && !(r_ptr->flags2 & RF2_STUPID))
1623         {
1624                 f4 &= (RF4_NOMAGIC_MASK);
1625                 f5 &= (RF5_NOMAGIC_MASK);
1626                 f6 &= (RF6_NOMAGIC_MASK);
1627         }
1628
1629         if (r_ptr->flags2 & RF2_SMART)
1630         {
1631                 /* Hack -- allow "desperate" spells */
1632                 if ((m_ptr->hp < m_ptr->maxhp / 10) &&
1633                         (randint0(100) < 50))
1634                 {
1635                         /* Require intelligent spells */
1636                         f4 &= (RF4_INT_MASK);
1637                         f5 &= (RF5_INT_MASK);
1638                         f6 &= (RF6_INT_MASK);
1639                 }
1640
1641                 /* Hack -- decline "teleport level" in some case */
1642                 if ((f6 & RF6_TELE_LEVEL) && TELE_LEVEL_IS_INEFF(0))
1643                 {
1644                         f6 &= ~(RF6_TELE_LEVEL);
1645                 }
1646         }
1647
1648         /* No spells left */
1649         if (!f4 && !f5 && !f6) return (FALSE);
1650
1651         /* Remove the "ineffective" spells */
1652         remove_bad_spells(m_idx, &f4, &f5, &f6);
1653
1654         if (p_ptr->inside_arena || p_ptr->inside_battle)
1655         {
1656                 f4 &= ~(RF4_SUMMON_MASK);
1657                 f5 &= ~(RF5_SUMMON_MASK);
1658                 f6 &= ~(RF6_SUMMON_MASK | RF6_TELE_LEVEL);
1659
1660                 if (m_ptr->r_idx == MON_ROLENTO) f6 &= ~(RF6_SPECIAL);
1661         }
1662
1663         /* No spells left */
1664         if (!f4 && !f5 && !f6) return (FALSE);
1665
1666         if (!(r_ptr->flags2 & RF2_STUPID))
1667         {
1668                 if (!p_ptr->csp) f5 &= ~(RF5_DRAIN_MANA);
1669
1670                 /* Check for a clean bolt shot */
1671                 if (((f4 & RF4_BOLT_MASK) ||
1672                      (f5 & RF5_BOLT_MASK) ||
1673                      (f6 & RF6_BOLT_MASK)) &&
1674                     !clean_shot(m_ptr->fy, m_ptr->fx, py, px, FALSE))
1675                 {
1676                         /* Remove spells that will only hurt friends */
1677                         f4 &= ~(RF4_BOLT_MASK);
1678                         f5 &= ~(RF5_BOLT_MASK);
1679                         f6 &= ~(RF6_BOLT_MASK);
1680                 }
1681
1682                 /* Check for a possible summon */
1683                 if (((f4 & RF4_SUMMON_MASK) ||
1684                      (f5 & RF5_SUMMON_MASK) ||
1685                      (f6 & RF6_SUMMON_MASK)) &&
1686                     !(summon_possible(y, x)))
1687                 {
1688                         /* Remove summoning spells */
1689                         f4 &= ~(RF4_SUMMON_MASK);
1690                         f5 &= ~(RF5_SUMMON_MASK);
1691                         f6 &= ~(RF6_SUMMON_MASK);
1692                 }
1693
1694                 /* Check for a possible raise dead */
1695                 if ((f6 & RF6_RAISE_DEAD) && !raise_possible(m_ptr))
1696                 {
1697                         /* Remove raise dead spell */
1698                         f6 &= ~(RF6_RAISE_DEAD);
1699                 }
1700
1701                 /* Special moves restriction */
1702                 if (f6 & RF6_SPECIAL)
1703                 {
1704                         if ((m_ptr->r_idx == MON_ROLENTO) && !summon_possible(y, x))
1705                         {
1706                                 f6 &= ~(RF6_SPECIAL);
1707                         }
1708                 }
1709
1710                 /* No spells left */
1711                 if (!f4 && !f5 && !f6) return (FALSE);
1712         }
1713
1714         /* Extract the "inate" spells */
1715         for (k = 0; k < 32; k++)
1716         {
1717                 if (f4 & (1L << k)) spell[num++] = k + 32 * 3;
1718         }
1719
1720         /* Extract the "normal" spells */
1721         for (k = 0; k < 32; k++)
1722         {
1723                 if (f5 & (1L << k)) spell[num++] = k + 32 * 4;
1724         }
1725
1726         /* Extract the "bizarre" spells */
1727         for (k = 0; k < 32; k++)
1728         {
1729                 if (f6 & (1L << k)) spell[num++] = k + 32 * 5;
1730         }
1731
1732         /* No spells left */
1733         if (!num) return (FALSE);
1734
1735         /* Stop if player is dead or gone */
1736         if (!p_ptr->playing || p_ptr->is_dead) return (FALSE);
1737
1738         /* Stop if player is leaving */
1739         if (p_ptr->leaving) return (FALSE);
1740
1741         /* Get the monster name (or "it") */
1742         monster_desc(m_name, m_ptr, 0x00);
1743
1744 #ifndef JP
1745         /* Get the monster possessive ("his"/"her"/"its") */
1746         monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
1747 #endif
1748
1749         switch (do_spell)
1750         {
1751         case DO_SPELL_NONE:
1752                 {
1753                         int attempt = 10;
1754                         while (attempt--)
1755                         {
1756                                 thrown_spell = choose_attack_spell(m_idx, spell, num);
1757                                 if (thrown_spell) break;
1758                         }
1759                 }
1760                 break;
1761
1762         case DO_SPELL_BR_LITE:
1763                 thrown_spell = 96+14; /* RF4_BR_LITE */
1764                 break;
1765
1766         case DO_SPELL_BR_DISI:
1767                 thrown_spell = 96+31; /* RF4_BR_DISI */
1768                 break;
1769
1770         case DO_SPELL_BA_LITE:
1771                 thrown_spell = 128+20; /* RF5_BA_LITE */
1772                 break;
1773
1774         default:
1775                 return FALSE; /* Paranoia */
1776         }
1777
1778         /* Abort if no spell was chosen */
1779         if (!thrown_spell) return (FALSE);
1780
1781         /* Calculate spell failure rate */
1782         failrate = 25 - (rlev + 3) / 4;
1783
1784         /* Hack -- Stupid monsters will never fail (for jellies and such) */
1785         if (r_ptr->flags2 & RF2_STUPID) failrate = 0;
1786
1787         /* Check for spell failure (inate attacks never fail) */
1788         if (!spell_is_inate(thrown_spell)
1789             && (in_no_magic_dungeon || (MON_STUNNED(m_ptr) && one_in_(2)) || (randint0(100) < failrate)))
1790         {
1791                 disturb(1, 1);
1792                 /* Message */
1793                 msg_format(_("%^s¤Ï¼öʸ¤ò¾§¤¨¤è¤¦¤È¤·¤¿¤¬¼ºÇÔ¤·¤¿¡£", "%^s tries to cast a spell, but fails."), m_name);
1794
1795                 return (TRUE);
1796         }
1797
1798         /* Hex: Anti Magic Barrier */
1799         if (!spell_is_inate(thrown_spell) && magic_barrier(m_idx))
1800         {
1801                 msg_format(_("È¿ËâË¡¥Ð¥ê¥¢¤¬%^s¤Î¼öʸ¤ò¤«¤­¾Ã¤·¤¿¡£", "Anti magic barrier cancels the spell which %^s casts."), m_name);
1802                 return (TRUE);
1803         }
1804
1805         /* Projectable? */
1806         direct = player_bold(y, x);
1807
1808         can_remember = is_original_ap_and_seen(m_ptr);
1809
1810     if (!direct)
1811     {
1812         switch (thrown_spell)
1813         {
1814             case 96 + 2:    /* RF4_DISPEL */
1815             case 96 + 4:    /* RF4_SHOOT */
1816             case 128 + 9:   /* RF5_DRAIN_MANA */
1817             case 128 + 10:  /* RF5_MIND_BLAST */
1818             case 128 + 11:  /* RF5_BRAIN_SMASH */
1819             case 128 + 12:  /* RF5_CAUSE_1 */
1820             case 128 + 13:  /* RF5_CAUSE_2 */
1821             case 128 + 14:  /* RF5_CAUSE_3 */
1822             case 128 + 15:  /* RF5_CAUSE_4 */
1823             case 128 + 16:  /* RF5_BO_ACID */
1824             case 128 + 17:  /* RF5_BO_ELEC */
1825             case 128 + 18:  /* RF5_BO_FIRE */
1826             case 128 + 19:  /* RF5_BO_COLD */
1827             case 128 + 21:  /* RF5_BO_NETH */
1828             case 128 + 22:  /* RF5_BO_WATE */
1829             case 128 + 23:  /* RF5_BO_MANA */
1830             case 128 + 24:  /* RF5_BO_PLAS */
1831             case 128 + 25:  /* RF5_BO_ICEE */
1832             case 128 + 26:  /* RF5_MISSILE */
1833             case 128 + 27:  /* RF5_SCARE */
1834             case 128 + 28:  /* RF5_BLIND */
1835             case 128 + 29:  /* RF5_CONF */
1836             case 128 + 30:  /* RF5_SLOW */
1837             case 128 + 31:  /* RF5_HOLD */
1838             case 160 + 1:   /* RF6_HAND_DOOM */
1839             case 160 + 8:   /* RF6_TELE_TO */
1840             case 160 + 9:   /* RF6_TELE_AWAY */
1841             case 160 + 10:  /* RF6_TELE_LEVEL */
1842             case 160 + 11:  /* RF6_PSY_SPEAR */
1843             case 160 + 12:  /* RF6_DARKNESS */
1844             case 160 + 14:  /* RF6_FORGET */
1845                 return (FALSE);
1846         }
1847     }
1848
1849         /* Cast the spell. */
1850         switch (thrown_spell)
1851         {
1852         case 96 + 0:   MP_spell_RF4_SHRIEK(m_idx); break;  /* RF4_SHRIEK */
1853         case 96 + 1:   break;   /* RF4_XXX1 */
1854         case 96 + 2:   MP_spell_RF4_DISPEL(m_idx); break;  /* RF4_DISPEL */
1855         case 96 + 3:   dam = MP_spell_RF4_ROCKET(y, x, m_idx); break;   /* RF4_ROCKET */
1856         case 96 + 4:   dam = spell_RF4_SHOOT(m_idx); break;    /* RF4_SHOOT */
1857         case 96 + 5:   break;   /* RF4_XXX2 */
1858         case 96 + 6:   break;   /* RF4_XXX3 */
1859         case 96 + 7:   break;   /* RF4_XXX4 */
1860         case 96 + 8:   dam = spell_RF4_BREATH(GF_ACID, y, x, m_idx); break;    /* RF4_BR_ACID */
1861         case 96 + 9:   dam = spell_RF4_BREATH(GF_ELEC, y, x, m_idx); break;    /* RF4_BR_ELEC */
1862         case 96 + 10:  dam = spell_RF4_BREATH(GF_FIRE, y, x, m_idx); break;    /* RF4_BR_FIRE */
1863         case 96 + 11:  dam = spell_RF4_BREATH(GF_COLD, y, x, m_idx); break;    /* RF4_BR_COLD */
1864         case 96 + 12:  dam = spell_RF4_BREATH(GF_POIS, y, x, m_idx); break;    /* RF4_BR_POIS */
1865         case 96 + 13:  dam = spell_RF4_BREATH(GF_NETHER, y, x, m_idx); break;    /* RF4_BR_NETH */
1866         case 96 + 14:  dam = spell_RF4_BREATH(GF_LITE, y_br_lite, x_br_lite, m_idx); break;    /* RF4_BR_LITE */
1867         case 96 + 15:  dam = spell_RF4_BREATH(GF_DARK, y, x, m_idx); break;    /* RF4_BR_DARK */
1868         case 96 + 16:  dam = spell_RF4_BREATH(GF_CONFUSION, y, x, m_idx); break;    /* RF4_BR_CONF */
1869         case 96 + 17:  dam = spell_RF4_BREATH(GF_SOUND, y, x, m_idx); break;    /* RF4_BR_SOUN */
1870         case 96 + 18:  dam = spell_RF4_BREATH(GF_CHAOS, y, x, m_idx); break;    /* RF4_BR_CHAO */
1871         case 96 + 19:  dam = spell_RF4_BREATH(GF_DISENCHANT, y, x, m_idx); break;    /* RF4_BR_DISE */
1872         case 96 + 20:  dam = spell_RF4_BREATH(GF_NEXUS, y, x, m_idx); break;    /* RF4_BR_NEXU */
1873         case 96 + 21:  dam = spell_RF4_BREATH(GF_TIME, y, x, m_idx); break;    /* RF4_BR_TIME */
1874         case 96 + 22:  dam = spell_RF4_BREATH(GF_INERTIA, y, x, m_idx); break;    /* RF4_BR_INER */
1875         case 96 + 23:  dam = spell_RF4_BREATH(GF_GRAVITY, y, x, m_idx); break;    /* RF4_BR_GRAV */
1876         case 96 + 24:  dam = spell_RF4_BREATH(GF_SHARDS, y, x, m_idx); break;    /* RF4_BR_SHAR */
1877         case 96 + 25:  dam = spell_RF4_BREATH(GF_PLASMA, y, x, m_idx); break;    /* RF4_BR_PLAS */
1878         case 96 + 26:  dam = spell_RF4_BREATH(GF_FORCE, y, x, m_idx); break;    /* RF4_BR_WALL */
1879         case 96 + 27:  dam = spell_RF4_BREATH(GF_MANA, y, x, m_idx); break;    /* RF4_BR_MANA */
1880         case 96 + 28:  dam = spell_RF4_BA_NUKE(y, x, m_idx); break;   /* RF4_BA_NUKE */
1881         case 96 + 29:  dam = spell_RF4_BREATH(GF_NUKE, y, x, m_idx); break;    /* RF4_BR_NUKE */
1882         case 96 + 30:  dam = spell_RF4_BA_CHAO(y, x, m_idx); break;  /* RF4_BA_CHAO */
1883         case 96 + 31:  dam = spell_RF4_BREATH(GF_DISINTEGRATE, y, x, m_idx); break;    /* RF4_BR_DISI */
1884         case 128 + 0:  dam = spell_RF5_BA_ACID(y, x, m_idx); break;    /* RF5_BA_ACID */
1885         case 128 + 1:  dam = spell_RF5_BA_ELEC(y, x, m_idx); break;    /* RF5_BA_ELEC */
1886         case 128 + 2:  dam = spell_RF5_BA_FIRE(y, x, m_idx); break;    /* RF5_BA_FIRE */
1887         case 128 + 3:  dam = spell_RF5_BA_COLD(y, x, m_idx); break;    /* RF5_BA_COLD */
1888         case 128 + 4:  dam = spell_RF5_BA_POIS(y, x, m_idx); break;    /* RF5_BA_POIS */
1889         case 128 + 5:  dam = spell_RF5_BA_NETH(y, x, m_idx); break;    /* RF5_BA_NETH */
1890         case 128 + 6:  dam = spell_RF5_BA_WATE(y, x, m_idx); break;    /* RF5_BA_WATE */
1891         case 128 + 7:  dam = spell_RF5_BA_MANA(y, x, m_idx); break;    /* RF5_BA_MANA */
1892         case 128 + 8:  dam = spell_RF5_BA_DARK(y, x, m_idx); break;    /* RF5_BA_DARK */
1893         case 128 + 9:  dam = spell_RF5_DRAIN_MANA(y, x, m_idx); break;    /* RF5_DRAIN_MANA */
1894         case 128 + 10: dam = spell_RF5_MIND_BLAST(y, x, m_idx); break;    /* RF5_MIND_BLAST */
1895         case 128 + 11: dam = spell_RF5_BRAIN_SMASH(y, x, m_idx); break;    /* RF5_MIND_BLAST */
1896         case 128 + 12: dam = spell_RF5_CAUSE_1(y, x, m_idx); break;    /* RF5_CAUSE_1 */
1897         case 128 + 13: dam = spell_RF5_CAUSE_2(y, x, m_idx); break;    /* RF5_CAUSE_2 */
1898         case 128 + 14: dam = spell_RF5_CAUSE_3(y, x, m_idx); break;    /* RF5_CAUSE_3 */
1899         case 128 + 15: dam = spell_RF5_CAUSE_4(y, x, m_idx); break;    /* RF5_CAUSE_4 */
1900         case 128 + 16: dam = spell_RF5_BO_ACID(y, x, m_idx); break;    /* RF5_BO_ACID */
1901         case 128 + 17: dam = spell_RF5_BO_ELEC(y, x, m_idx); break;    /* RF5_BO_ELEC */
1902         case 128 + 18: dam = spell_RF5_BO_FIRE(y, x, m_idx); break;    /* RF5_BO_FIRE */
1903         case 128 + 19: dam = spell_RF5_BO_COLD(y, x, m_idx); break;    /* RF5_BO_COLD */
1904         case 128 + 20: dam = spell_RF5_BA_LITE(y, x, m_idx); break;    /* RF5_BA_LITE */
1905         case 128 + 21: dam = spell_RF5_BO_NETH(y, x, m_idx); break;    /* RF5_BO_NETH */
1906         case 128 + 22: dam = spell_RF5_BO_WATE(y, x, m_idx); break;    /* RF5_BO_WATE */
1907         case 128 + 23: dam = spell_RF5_BO_MANA(y, x, m_idx); break;    /* RF5_BO_MANA */
1908         case 128 + 24: dam = spell_RF5_BO_PLAS(y, x, m_idx); break;    /* RF5_BO_PLAS */
1909         case 128 + 25: dam = spell_RF5_BO_ICEE(y, x, m_idx); break;    /* RF5_BO_ICEE */
1910         case 128 + 26: dam = spell_RF5_MISSILE(y, x, m_idx); break;    /* RF5_MISSILE */
1911         case 128 + 27: spell_RF5_SCARE(y, x, m_idx); break;    /* RF5_SCARE */
1912         case 128 + 28: spell_RF5_BLIND(y, x, m_idx); break;    /* RF5_BLIND */
1913         case 128 + 29: spell_RF5_CONF(y, x, m_idx); break;    /* RF5_CONF */
1914         case 128 + 30: spell_RF5_SLOW(y, x, m_idx); break;    /* RF5_SLOW */
1915         case 128 + 31: spell_RF5_HOLD(y, x, m_idx); break;    /* RF5_HOLD */
1916         case 160 + 0:  spell_RF6_HASTE(m_idx); break;    /* RF6_HASTE */
1917         case 160 + 1:  dam = spell_RF6_HAND_DOOM(y, x, m_idx); break;    /* RF6_HAND_DOOM */
1918         case 160 + 2:  spell_RF6_HEAL(m_idx); break;     /* RF6_HEAL */
1919         case 160 + 3:  spell_RF6_INVULNER(m_idx); break;     /* RF6_INVULNER */
1920         case 160 + 4:  spell_RF6_BLINK(m_idx); break;     /* RF6_BLINK */
1921         case 160 + 5:  spell_RF6_TPORT(m_idx); break;     /* RF6_TPORT */
1922         case 160 + 6:  dam = spell_RF6_WORLD(m_idx); break;     /* RF6_WORLD */
1923             
1924         /* RF6_SPECIAL */
1925         case 160 + 7:  
1926             dam = spell_RF6_SPECIAL(y, x, m_idx);
1927             if (dam < 0) return FALSE; 
1928             break;
1929
1930         case 160 + 8:  spell_RF6_TELE_TO(m_idx); break;     /* RF6_TELE_TO */
1931         case 160 + 9:  spell_RF6_TELE_AWAY(m_idx); break;     /* RF6_TELE_AWAY */
1932         case 160 + 10: spell_RF6_TELE_LEVEL(m_idx); break;     /* RF6_TELE_LEVEL */
1933         case 160 + 11: spell_RF6_PSY_SPEAR(m_idx); break;    /* RF6_PSY_SPEAR */
1934         case 160 + 12: spell_RF6_DARKNESS(m_idx); break;     /* RF6_DARKNESS */
1935         case 160 + 13: spell_RF6_TRAPS(y, x, m_idx); break;     /* RF6_TRAPS */
1936         case 160 + 14: spell_RF6_FORGET(m_idx); break;     /* RF6_FORGET */
1937         case 160 + 15: spell_RF6_RAISE_DEAD(m_idx); break;    /* RF6_RAISE_DEAD */
1938         case 160 + 16: spell_RF6_S_KIN(y, x, m_idx); break;  /* RF6_S_KIN */
1939         case 160 + 17: spell_RF6_S_CYBER(y, x, m_idx); break;    /* RF6_S_CYBER */
1940         case 160 + 18: spell_RF6_S_MONSTER(y, x, m_idx); break;    /* RF6_S_MONSTER */
1941         case 160 + 19: spell_RF6_S_MONSTERS(y, x, m_idx); break;    /* RF6_S_MONSTER */
1942         case 160 + 20: spell_RF6_S_ANT(y, x, m_idx); break;    /* RF6_S_ANT */
1943         case 160 + 21: spell_RF6_S_SPIDER(y, x, m_idx); break;    /* RF6_S_SPIDER */
1944         case 160 + 22: spell_RF6_S_HOUND(y, x, m_idx); break;    /* RF6_S_HOUND */
1945         case 160 + 23: spell_RF6_S_HYDRA(y, x, m_idx); break;    /* RF6_S_HYDRA */
1946         case 160 + 24: spell_RF6_S_ANGEL(y, x, m_idx); break;   /* RF6_S_ANGEL */
1947         case 160 + 25: spell_RF6_S_DEMON(y, x, m_idx); break;   /* RF6_S_DEMON */
1948         case 160 + 26: spell_RF6_S_UNDEAD(y, x, m_idx); break;   /* RF6_S_UNDEAD */
1949         case 160 + 27: spell_RF6_S_DRAGON(y, x, m_idx); break;   /* RF6_S_DRAGON */
1950         case 160 + 28: spell_RF6_S_HI_UNDEAD(y, x, m_idx); break;  /* RF6_S_HI_UNDEAD */
1951         case 160 + 29: spell_RF6_S_HI_DRAGON(y, x, m_idx); break;  /* RF6_S_HI_DRAGON */
1952         case 160 + 30: spell_RF6_S_AMBERITES(y, x, m_idx); break;  /* RF6_S_AMBERITES */
1953         case 160 + 31: spell_RF6_S_UNIQUE(y, x, m_idx); break;     /* RF6_S_UNIQUE */
1954         }
1955
1956         if ((p_ptr->action == ACTION_LEARN) && thrown_spell > 175)
1957         {
1958                 learn_spell(thrown_spell - 96);
1959         }
1960
1961         if (seen && maneable && !world_monster && (p_ptr->pclass == CLASS_IMITATOR))
1962         {
1963                 if (thrown_spell != 167) /* Not RF6_SPECIAL */
1964                 {
1965                         if (p_ptr->mane_num == MAX_MANE)
1966                         {
1967                                 int i;
1968                                 p_ptr->mane_num--;
1969                                 for (i = 0;i < p_ptr->mane_num;i++)
1970                                 {
1971                                         p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
1972                                         p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
1973                                 }
1974                         }
1975                         p_ptr->mane_spell[p_ptr->mane_num] = thrown_spell - 96;
1976                         p_ptr->mane_dam[p_ptr->mane_num] = dam;
1977                         p_ptr->mane_num++;
1978                         new_mane = TRUE;
1979
1980                         p_ptr->redraw |= (PR_IMITATION);
1981                 }
1982         }
1983
1984         /* Remember what the monster did to us */
1985         if (can_remember)
1986         {
1987                 /* Inate spell */
1988                 if (thrown_spell < 32 * 4)
1989                 {
1990                         r_ptr->r_flags4 |= (1L << (thrown_spell - 32 * 3));
1991                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
1992                 }
1993
1994                 /* Bolt or Ball */
1995                 else if (thrown_spell < 32 * 5)
1996                 {
1997                         r_ptr->r_flags5 |= (1L << (thrown_spell - 32 * 4));
1998                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
1999                 }
2000
2001                 /* Special spell */
2002                 else if (thrown_spell < 32 * 6)
2003                 {
2004                         r_ptr->r_flags6 |= (1L << (thrown_spell - 32 * 5));
2005                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
2006                 }
2007         }
2008
2009
2010         /* Always take note of monsters that kill you */
2011         if (p_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !p_ptr->inside_arena)
2012         {
2013                 r_ptr->r_deaths++; /* Ignore appearance difference */
2014         }
2015
2016         /* A spell was cast */
2017         return (TRUE);
2018 }