OSDN Git Service

refactor: extract monst_spell_monst
[hengbandforosx/hengbandosx.git] / src / mspells2.c
1 /*!
2  * @file mspells2.c
3  * @brief ¥â¥ó¥¹¥¿¡¼ËâË¡¤Î¼ÂÁõ(ÂÐ¥â¥ó¥¹¥¿¡¼½èÍý) / Monster spells (attack monster)
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  */
13
14 #include "angband.h"
15
16 /*!
17  * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨ÂÐ¥â¥ó¥¹¥¿¡¼¤Ë¥Ó¡¼¥à¤òÅö¤Æ¤ë¤³¤È²Äǽ¤«¤òȽÄꤹ¤ë /
18  * Determine if a beam spell will hit the target.
19  * @param y1 »ÏÅÀ¤ÎYºÂɸ
20  * @param x1 »ÏÅÀ¤ÎXºÂɸ
21  * @param y2 ÌÜɸ¤ÎYºÂɸ
22  * @param x2 ÌÜɸ¤ÎXºÂɸ
23  * @param m_ptr »ÈÍѤ¹¤ë¥â¥ó¥¹¥¿¡¼¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
24  * @return ¥Ó¡¼¥à¤¬Åþã²Äǽ¤Ê¤é¤ÐTRUE¤òÊÖ¤¹
25  */
26 static bool direct_beam(int y1, int x1, int y2, int x2, monster_type *m_ptr)
27 {
28         bool hit2 = FALSE;
29         int i, y, x;
30
31         int grid_n = 0;
32         u16b grid_g[512];
33
34         bool is_friend = is_pet(m_ptr);
35
36         /* Check the projection path */
37         grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, PROJECT_THRU);
38
39         /* No grid is ever projectable from itself */
40         if (!grid_n) return (FALSE);
41
42         for (i = 0; i < grid_n; i++)
43         {
44                 y = GRID_Y(grid_g[i]);
45                 x = GRID_X(grid_g[i]);
46
47                 if (y == y2 && x == x2)
48                         hit2 = TRUE;
49                 else if (is_friend && cave[y][x].m_idx > 0 &&
50                          !are_enemies(m_ptr, &m_list[cave[y][x].m_idx]))
51                 {
52                         /* Friends don't shoot friends */
53                         return FALSE;
54                 }
55
56                 if (is_friend && player_bold(y, x))
57                         return FALSE;
58         }
59         if (!hit2)
60                 return FALSE;
61         return TRUE;
62 }
63
64 /*!
65  * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨ÂÐ¥â¥ó¥¹¥¿¡¼¤ËľÀܥ֥쥹¤òÅö¤Æ¤ë¤³¤È¤¬²Äǽ¤«¤òȽÄꤹ¤ë /
66  * Determine if a breath will hit the target.
67  * @param y1 »ÏÅÀ¤ÎYºÂɸ
68  * @param x1 »ÏÅÀ¤ÎXºÂɸ
69  * @param y2 ÌÜɸ¤ÎYºÂɸ
70  * @param x2 ÌÜɸ¤ÎXºÂɸ
71  * @param rad È¾·Â
72  * @param typ ¸ú²Ì°À­ID
73  * @param is_friend TRUE¤Ê¤é¤Ð¡¢¥×¥ì¥¤¥ä¡¼¤ò´¬¤­¹þ¤à»þ¤Ë¥Ö¥ì¥¹¤ÎȽÄê¤òFALSE¤Ë¤¹¤ë¡£
74  * @return ¥Ö¥ì¥¹¤òľÀÜÅö¤Æ¤é¤ì¤ë¤Ê¤é¤ÐTRUE¤òÊÖ¤¹
75  */
76 static bool breath_direct(int y1, int x1, int y2, int x2, int rad, int typ, bool is_friend)
77 {
78         /* Must be the same as projectable() */
79
80         int i;
81
82         /* Initial grid */
83         int y = y1;
84         int x = x1;
85
86         int grid_n = 0;
87         u16b grid_g[512];
88
89         int grids = 0;
90         byte gx[1024], gy[1024];
91         byte gm[32];
92         int gm_rad = rad;
93
94         bool hit2 = FALSE;
95         bool hityou = FALSE;
96
97         int flg;
98
99         switch (typ)
100         {
101         case GF_LITE:
102         case GF_LITE_WEAK:
103                 flg = PROJECT_LOS;
104                 break;
105         case GF_DISINTEGRATE:
106                 flg = PROJECT_DISI;
107                 break;
108         default:
109                 flg = 0;
110                 break;
111         }
112
113         /* Check the projection path */
114         grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, flg);
115
116         /* Project along the path */
117         for (i = 0; i < grid_n; ++i)
118         {
119                 int ny = GRID_Y(grid_g[i]);
120                 int nx = GRID_X(grid_g[i]);
121
122                 if (flg & PROJECT_DISI)
123                 {
124                         /* Hack -- Balls explode before reaching walls */
125                         if (cave_stop_disintegration(ny, nx)) break;
126                 }
127                 else if (flg & PROJECT_LOS)
128                 {
129                         /* Hack -- Balls explode before reaching walls */
130                         if (!cave_los_bold(ny, nx)) break;
131                 }
132                 else
133                 {
134                         /* Hack -- Balls explode before reaching walls */
135                         if (!cave_have_flag_bold(ny, nx, FF_PROJECT)) break;
136                 }
137
138                 /* Save the "blast epicenter" */
139                 y = ny;
140                 x = nx;
141         }
142
143         grid_n = i;
144
145         if (!grid_n)
146         {
147                 if (flg & PROJECT_DISI)
148                 {
149                         if (in_disintegration_range(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
150                         if (in_disintegration_range(y1, x1, py, px) && (distance(y1, x1, py, px) <= rad)) hityou = TRUE;
151                 }
152                 else if (flg & PROJECT_LOS)
153                 {
154                         if (los(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
155                         if (los(y1, x1, py, px) && (distance(y1, x1, py, px) <= rad)) hityou = TRUE;
156                 }
157                 else
158                 {
159                         if (projectable(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
160                         if (projectable(y1, x1, py, px) && (distance(y1, x1, py, px) <= rad)) hityou = TRUE;
161                 }
162         }
163         else
164         {
165                 breath_shape(grid_g, grid_n, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, y, x, typ);
166
167                 for (i = 0; i < grids; i++)
168                 {
169                         /* Extract the location */
170                         y = gy[i];
171                         x = gx[i];
172
173                         if ((y == y2) && (x == x2)) hit2 = TRUE;
174                         if (player_bold(y, x)) hityou = TRUE;
175                 }
176         }
177
178         if (!hit2) return FALSE;
179         if (is_friend && hityou) return FALSE;
180
181         return TRUE;
182 }
183
184 /*!
185  * @brief ¥â¥ó¥¹¥¿¡¼¤¬ÆüìǽÎϤÎÌÜɸÃÏÅÀ¤ò·è¤á¤ë½èÍý /
186  * Get the actual center point of ball spells (rad > 1) (originally from TOband)
187  * @param sy »ÏÅÀ¤ÎYºÂɸ
188  * @param sx »ÏÅÀ¤ÎXºÂɸ
189  * @param ty ÌÜɸYºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
190  * @param tx ÌÜɸXºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
191  * @param flg È½Äê¤Î¥Õ¥é¥°ÇÛÎó
192  * @return ¤Ê¤·
193  */
194 void get_project_point(int sy, int sx, int *ty, int *tx, int flg)
195 {
196         u16b path_g[128];
197         int  path_n, i;
198
199         path_n = project_path(path_g, MAX_RANGE, sy, sx, *ty, *tx, flg);
200
201         *ty = sy;
202         *tx = sx;
203
204         /* Project along the path */
205         for (i = 0; i < path_n; i++)
206         {
207                 sy = GRID_Y(path_g[i]);
208                 sx = GRID_X(path_g[i]);
209
210                 /* Hack -- Balls explode before reaching walls */
211                 if (!cave_have_flag_bold(sy, sx, FF_PROJECT)) break;
212
213                 *ty = sy;
214                 *tx = sx;
215         }
216 }
217
218 /*!
219  * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨¥â¥ó¥¹¥¿¡¼¤ËËâÎϾõî¤ò»È¤¦¤«¤É¤¦¤«¤òÊÖ¤¹ /
220  * Check should monster cast dispel spell at other monster.
221  * @param m_idx ½Ñ¼Ô¤Î¥â¥ó¥¹¥¿¡¼ID
222  * @param t_idx ÌÜɸ¤Î¥â¥ó¥¹¥¿¡¼ID
223  * @return ËâÎϾõî¤ò»È¤¦¤Ù¤­¤Ê¤é¤ÐTRUE¤òÊѤ¨¤¹¡£
224  */
225 static bool dispel_check_monster(int m_idx, int t_idx)
226 {
227         monster_type *t_ptr = &m_list[t_idx];
228
229         /* Invulnabilty */
230         if (MON_INVULNER(t_ptr)) return TRUE;
231
232         /* Speed */
233         if (t_ptr->mspeed < 135)
234         {
235                 if (MON_FAST(t_ptr)) return TRUE;
236         }
237
238         /* Riding monster */
239         if (t_idx == p_ptr->riding)
240         {
241                 if (dispel_check(m_idx)) return TRUE;
242         }
243
244         /* No need to cast dispel spell */
245         return FALSE;
246 }
247
248 /*!
249  * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨¥â¥ó¥¹¥¿¡¼¤ËÆüìǽÎϤò»È¤¦½èÍý¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
250  * Monster tries to 'cast a spell' (or breath, etc) at another monster.
251  * @param m_idx ½Ñ¼Ô¤Î¥â¥ó¥¹¥¿¡¼ID
252  * @return ¼ÂºÝ¤ËÆüìǽÎϤò»È¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
253  * @details
254  * The player is only disturbed if able to be affected by the spell.
255  */
256 bool monst_spell_monst(int m_idx)
257 {
258         int y = 0, x = 0;
259         int i, k, t_idx = 0;
260         int thrown_spell, count = 0;
261         int rlev;
262         int dam = 0;
263         int start;
264         int plus = 1;
265         u32b u_mode = 0L;
266         int s_num_6 = (easy_band ? 2 : 6);
267         int s_num_4 = (easy_band ? 1 : 4);
268         int rad = 0; //For elemental balls
269
270         byte spell[96], num = 0;
271
272         char m_name[160];
273         char t_name[160];
274
275 #ifndef JP
276         char m_poss[160];
277 #endif
278
279         monster_type *m_ptr = &m_list[m_idx];
280         monster_type *t_ptr = NULL;
281
282         monster_race *r_ptr = &r_info[m_ptr->r_idx];
283         monster_race *tr_ptr = NULL;
284
285         u32b f4, f5, f6;
286
287         bool wake_up = FALSE;
288         bool fear = FALSE;
289
290         bool blind = (p_ptr->blind ? TRUE : FALSE);
291
292         bool see_m = is_seen(m_ptr);
293         bool maneable = player_has_los_bold(m_ptr->fy, m_ptr->fx);
294         bool see_t;
295         bool see_either;
296         bool known;
297
298         bool pet = is_pet(m_ptr);
299
300         bool in_no_magic_dungeon = (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && dun_level
301                 && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest));
302
303         bool can_use_lite_area = FALSE;
304
305         bool can_remember;
306
307         bool resists_tele = FALSE;
308
309         /* Prepare flags for summoning */
310         if (!pet) u_mode |= PM_ALLOW_UNIQUE;
311
312         /* Cannot cast spells when confused */
313         if (MON_CONFUSED(m_ptr)) return (FALSE);
314
315         /* Extract the racial spell flags */
316         f4 = r_ptr->flags4;
317         f5 = r_ptr->flags5;
318         f6 = r_ptr->flags6;
319
320         /* Target is given for pet? */
321         if (pet_t_m_idx && pet)
322         {
323                 t_idx = pet_t_m_idx;
324                 t_ptr = &m_list[t_idx];
325
326                 /* Cancel if not projectable (for now) */
327                 if ((m_idx == t_idx) || !projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
328                 {
329                         t_idx = 0;
330                 }
331         }
332
333         /* Is there counter attack target? */
334         if (!t_idx && m_ptr->target_y)
335         {
336                 t_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
337
338                 if (t_idx)
339                 {
340                         t_ptr = &m_list[t_idx];
341
342                         /* Cancel if neither enemy nor a given target */
343                         if ((m_idx == t_idx) ||
344                             ((t_idx != pet_t_m_idx) && !are_enemies(m_ptr, t_ptr)))
345                         {
346                                 t_idx = 0;
347                         }
348
349                         /* Allow only summoning etc.. if not projectable */
350                         else if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
351                         {
352                                 f4 &= (RF4_INDIRECT_MASK);
353                                 f5 &= (RF5_INDIRECT_MASK);
354                                 f6 &= (RF6_INDIRECT_MASK);
355                         }
356                 }
357         }
358
359         /* Look for enemies normally */
360         if (!t_idx)
361         {
362                 bool success = FALSE;
363
364                 if (p_ptr->inside_battle)
365                 {
366                         start = randint1(m_max-1) + m_max;
367                         if (randint0(2)) plus = -1;
368                 }
369                 else start = m_max + 1;
370
371                 /* Scan thru all monsters */
372                 for (i = start; ((i < start + m_max) && (i > start - m_max)); i += plus)
373                 {
374                         int dummy = (i % m_max);
375                         if (!dummy) continue;
376
377                         t_idx = dummy;
378                         t_ptr = &m_list[t_idx];
379
380                         /* Skip dead monsters */
381                         if (!t_ptr->r_idx) continue;
382
383                         /* Monster must be 'an enemy' */
384                         if ((m_idx == t_idx) || !are_enemies(m_ptr, t_ptr)) continue;
385
386                         /* Monster must be projectable */
387                         if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
388
389                         /* Get it */
390                         success = TRUE;
391                         break;
392                 }
393
394                 /* No enemy found */
395                 if (!success) return FALSE;
396         }
397
398
399         /* OK -- we've got a target */
400         y = t_ptr->fy;
401         x = t_ptr->fx;
402         tr_ptr = &r_info[t_ptr->r_idx];
403
404         /* Forget old counter attack target */
405         reset_target(m_ptr);
406
407         /* Extract the monster level */
408         rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
409
410         /* Remove unimplemented spells */
411         f6 &= ~(RF6_WORLD | RF6_TRAPS | RF6_FORGET);
412
413         if (f4 & RF4_BR_LITE)
414         {
415                 if (!los(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
416                         f4 &= ~(RF4_BR_LITE);
417         }
418
419         /* Remove unimplemented special moves */
420         if (f6 & RF6_SPECIAL)
421         {
422                 if ((m_ptr->r_idx != MON_ROLENTO) && (r_ptr->d_char != 'B'))
423                         f6 &= ~(RF6_SPECIAL);
424         }
425
426         if (f6 & RF6_DARKNESS)
427         {
428                 bool vs_ninja = (p_ptr->pclass == CLASS_NINJA) && !is_hostile(t_ptr);
429
430                 if (vs_ninja &&
431                     !(r_ptr->flags3 & (RF3_UNDEAD | RF3_HURT_LITE)) &&
432                     !(r_ptr->flags7 & RF7_DARK_MASK))
433                         can_use_lite_area = TRUE;
434
435                 if (!(r_ptr->flags2 & RF2_STUPID))
436                 {
437                         if (d_info[dungeon_type].flags1 & DF1_DARKNESS) f6 &= ~(RF6_DARKNESS);
438                         else if (vs_ninja && !can_use_lite_area) f6 &= ~(RF6_DARKNESS);
439                 }
440         }
441
442         if (in_no_magic_dungeon && !(r_ptr->flags2 & RF2_STUPID))
443         {
444                 f4 &= (RF4_NOMAGIC_MASK);
445                 f5 &= (RF5_NOMAGIC_MASK);
446                 f6 &= (RF6_NOMAGIC_MASK);
447         }
448
449         if (p_ptr->inside_arena || p_ptr->inside_battle)
450         {
451                 f4 &= ~(RF4_SUMMON_MASK);
452                 f5 &= ~(RF5_SUMMON_MASK);
453                 f6 &= ~(RF6_SUMMON_MASK | RF6_TELE_LEVEL);
454
455                 if (m_ptr->r_idx == MON_ROLENTO) f6 &= ~(RF6_SPECIAL);
456         }
457
458         if (p_ptr->inside_battle && !one_in_(3))
459         {
460                 f6 &= ~(RF6_HEAL);
461         }
462
463         if (m_idx == p_ptr->riding)
464         {
465                 f4 &= ~(RF4_RIDING_MASK);
466                 f5 &= ~(RF5_RIDING_MASK);
467                 f6 &= ~(RF6_RIDING_MASK);
468         }
469
470         if (pet)
471         {
472                 f4 &= ~(RF4_SHRIEK);
473                 f6 &= ~(RF6_DARKNESS | RF6_TRAPS);
474
475                 if (!(p_ptr->pet_extra_flags & PF_TELEPORT))
476                 {
477                         f6 &= ~(RF6_BLINK | RF6_TPORT | RF6_TELE_TO | RF6_TELE_AWAY | RF6_TELE_LEVEL);
478                 }
479
480                 if (!(p_ptr->pet_extra_flags & PF_ATTACK_SPELL))
481                 {
482                         f4 &= ~(RF4_ATTACK_MASK);
483                         f5 &= ~(RF5_ATTACK_MASK);
484                         f6 &= ~(RF6_ATTACK_MASK);
485                 }
486
487                 if (!(p_ptr->pet_extra_flags & PF_SUMMON_SPELL))
488                 {
489                         f4 &= ~(RF4_SUMMON_MASK);
490                         f5 &= ~(RF5_SUMMON_MASK);
491                         f6 &= ~(RF6_SUMMON_MASK);
492                 }
493
494                 /* Prevent collateral damage */
495                 if (!(p_ptr->pet_extra_flags & PF_BALL_SPELL) && (m_idx != p_ptr->riding))
496                 {
497                         if ((f4 & (RF4_BALL_MASK & ~(RF4_ROCKET))) ||
498                             (f5 & RF5_BALL_MASK) ||
499                             (f6 & RF6_BALL_MASK))
500                         {
501                                 int real_y = y;
502                                 int real_x = x;
503
504                                 get_project_point(m_ptr->fy, m_ptr->fx, &real_y, &real_x, 0L);
505
506                                 if (projectable(real_y, real_x, py, px))
507                                 {
508                                         int dist = distance(real_y, real_x, py, px);
509
510                                         if (dist <= 2)
511                                         {
512                                                 f4 &= ~(RF4_BALL_MASK & ~(RF4_ROCKET));
513                                                 f5 &= ~(RF5_BALL_MASK);
514                                                 f6 &= ~(RF6_BALL_MASK);
515                                         }
516                                         else if (dist <= 4)
517                                         {
518                                                 f4 &= ~(RF4_BIG_BALL_MASK);
519                                                 f5 &= ~(RF5_BIG_BALL_MASK);
520                                                 f6 &= ~(RF6_BIG_BALL_MASK);
521                                         }
522                                 }
523                                 else if (f5 & RF5_BA_LITE)
524                                 {
525                                         if ((distance(real_y, real_x, py, px) <= 4) && los(real_y, real_x, py, px))
526                                                 f5 &= ~(RF5_BA_LITE);
527                                 }
528                         }
529
530                         if (f4 & RF4_ROCKET)
531                         {
532                                 int real_y = y;
533                                 int real_x = x;
534
535                                 get_project_point(m_ptr->fy, m_ptr->fx, &real_y, &real_x, PROJECT_STOP);
536                                 if (projectable(real_y, real_x, py, px) && (distance(real_y, real_x, py, px) <= 2))
537                                         f4 &= ~(RF4_ROCKET);
538                         }
539
540                         if (((f4 & RF4_BEAM_MASK) ||
541                              (f5 & RF5_BEAM_MASK) ||
542                              (f6 & RF6_BEAM_MASK)) &&
543                             !direct_beam(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, m_ptr))
544                         {
545                                 f4 &= ~(RF4_BEAM_MASK);
546                                 f5 &= ~(RF5_BEAM_MASK);
547                                 f6 &= ~(RF6_BEAM_MASK);
548                         }
549
550                         if ((f4 & RF4_BREATH_MASK) ||
551                             (f5 & RF5_BREATH_MASK) ||
552                             (f6 & RF6_BREATH_MASK))
553                         {
554                                 /* Expected breath radius */
555                                 int rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2;
556
557                                 if (!breath_direct(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, 0, TRUE))
558                                 {
559                                         f4 &= ~(RF4_BREATH_MASK);
560                                         f5 &= ~(RF5_BREATH_MASK);
561                                         f6 &= ~(RF6_BREATH_MASK);
562                                 }
563                                 else if ((f4 & RF4_BR_LITE) &&
564                                          !breath_direct(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_LITE, TRUE))
565                                 {
566                                         f4 &= ~(RF4_BR_LITE);
567                                 }
568                                 else if ((f4 & RF4_BR_DISI) &&
569                                          !breath_direct(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_DISINTEGRATE, TRUE))
570                                 {
571                                         f4 &= ~(RF4_BR_DISI);
572                                 }
573                         }
574                 }
575
576                 /* Special moves restriction */
577                 if (f6 & RF6_SPECIAL)
578                 {
579                         if (m_ptr->r_idx == MON_ROLENTO)
580                         {
581                                 if ((p_ptr->pet_extra_flags & (PF_ATTACK_SPELL | PF_SUMMON_SPELL)) != (PF_ATTACK_SPELL | PF_SUMMON_SPELL))
582                                         f6 &= ~(RF6_SPECIAL);
583                         }
584                         else if (r_ptr->d_char == 'B')
585                         {
586                                 if ((p_ptr->pet_extra_flags & (PF_ATTACK_SPELL | PF_TELEPORT)) != (PF_ATTACK_SPELL | PF_TELEPORT))
587                                         f6 &= ~(RF6_SPECIAL);
588                         }
589                         else f6 &= ~(RF6_SPECIAL);
590                 }
591         }
592
593         /* Remove some spells if necessary */
594
595         if (!(r_ptr->flags2 & RF2_STUPID))
596         {
597                 /* Check for a clean bolt shot */
598                 if (((f4 & RF4_BOLT_MASK) ||
599                      (f5 & RF5_BOLT_MASK) ||
600                      (f6 & RF6_BOLT_MASK)) &&
601                     !clean_shot(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, pet))
602                 {
603                         f4 &= ~(RF4_BOLT_MASK);
604                         f5 &= ~(RF5_BOLT_MASK);
605                         f6 &= ~(RF6_BOLT_MASK);
606                 }
607
608                 /* Check for a possible summon */
609                 if (((f4 & RF4_SUMMON_MASK) ||
610                      (f5 & RF5_SUMMON_MASK) ||
611                      (f6 & RF6_SUMMON_MASK)) &&
612                     !(summon_possible(t_ptr->fy, t_ptr->fx)))
613                 {
614                         /* Remove summoning spells */
615                         f4 &= ~(RF4_SUMMON_MASK);
616                         f5 &= ~(RF5_SUMMON_MASK);
617                         f6 &= ~(RF6_SUMMON_MASK);
618                 }
619
620                 /* Dispel magic */
621                 if ((f4 & RF4_DISPEL) && !dispel_check_monster(m_idx, t_idx))
622                 {
623                         /* Remove dispel spell */
624                         f4 &= ~(RF4_DISPEL);
625                 }
626
627                 /* Check for a possible raise dead */
628                 if ((f6 & RF6_RAISE_DEAD) && !raise_possible(m_ptr))
629                 {
630                         /* Remove raise dead spell */
631                         f6 &= ~(RF6_RAISE_DEAD);
632                 }
633
634                 /* Special moves restriction */
635                 if (f6 & RF6_SPECIAL)
636                 {
637                         if ((m_ptr->r_idx == MON_ROLENTO) && !summon_possible(t_ptr->fy, t_ptr->fx))
638                         {
639                                 f6 &= ~(RF6_SPECIAL);
640                         }
641                 }
642         }
643
644         if (r_ptr->flags2 & RF2_SMART)
645         {
646                 /* Hack -- allow "desperate" spells */
647                 if ((m_ptr->hp < m_ptr->maxhp / 10) &&
648                     (randint0(100) < 50))
649                 {
650                         /* Require intelligent spells */
651                         f4 &= (RF4_INT_MASK);
652                         f5 &= (RF5_INT_MASK);
653                         f6 &= (RF6_INT_MASK);
654                 }
655
656                 /* Hack -- decline "teleport level" in some case */
657                 if ((f6 & RF6_TELE_LEVEL) && TELE_LEVEL_IS_INEFF((t_idx == p_ptr->riding) ? 0 : t_idx))
658                 {
659                         f6 &= ~(RF6_TELE_LEVEL);
660                 }
661         }
662
663         /* No spells left */
664         if (!f4 && !f5 && !f6) return FALSE;
665
666         /* Extract the "inate" spells */
667         for (k = 0; k < 32; k++)
668         {
669                 if (f4 & (1L << k)) spell[num++] = k + 32 * 3;
670         }
671
672         /* Extract the "normal" spells */
673         for (k = 0; k < 32; k++)
674         {
675                 if (f5 & (1L << k)) spell[num++] = k + 32 * 4;
676         }
677
678         /* Extract the "bizarre" spells */
679         for (k = 0; k < 32; k++)
680         {
681                 if (f6 & (1L << k)) spell[num++] = k + 32 * 5;
682         }
683
684         /* No spells left */
685         if (!num) return (FALSE);
686
687         /* Stop if player is dead or gone */
688         if (!p_ptr->playing || p_ptr->is_dead) return (FALSE);
689
690         /* Handle "leaving" */
691         if (p_ptr->leaving) return (FALSE);
692
693         /* Get the monster name (or "it") */
694         monster_desc(m_name, m_ptr, 0x00);
695
696 #ifndef JP
697         /* Get the monster possessive ("his"/"her"/"its") */
698         monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
699 #endif
700
701         /* Get the target's name (or "it") */
702         monster_desc(t_name, t_ptr, 0x00);
703
704         /* Choose a spell to cast */
705         thrown_spell = spell[randint0(num)];
706
707         see_t = is_seen(t_ptr);
708         see_either = (see_m || see_t);
709
710         /* Can the player be aware of this attack? */
711         known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
712
713         if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 1);
714
715         /* Check for spell failure (inate attacks never fail) */
716         if (!spell_is_inate(thrown_spell) && (in_no_magic_dungeon || (MON_STUNNED(m_ptr) && one_in_(2))))
717         {
718                 disturb(1, 1);
719                 /* Message */
720                 if (see_m) msg_format(_("%^s¤Ï¼öʸ¤ò¾§¤¨¤è¤¦¤È¤·¤¿¤¬¼ºÇÔ¤·¤¿¡£", 
721                                             "%^s tries to cast a spell, but fails."), m_name);
722
723                 return (TRUE);
724         }
725
726         /* Hex: Anti Magic Barrier */
727         if (!spell_is_inate(thrown_spell) && magic_barrier(m_idx))
728         {
729                 if (see_m) msg_format(_("È¿ËâË¡¥Ð¥ê¥¢¤¬%^s¤Î¼öʸ¤ò¤«¤­¾Ã¤·¤¿¡£", 
730                                             "Anti magic barrier cancels the spell which %^s casts."), m_name);
731                 return (TRUE);
732         }
733
734         can_remember = is_original_ap_and_seen(m_ptr);
735
736     dam = monspell_to_monster(thrown_spell, y, x, m_idx, t_idx);
737     if (dam < 0)return FALSE;
738
739         switch (thrown_spell)
740     {
741
742         /* RF6_SPECIAL */
743         case 160+7:
744                 switch (m_ptr->r_idx)
745                 {
746                 case MON_OHMU:
747                         /* Moved to process_monster(), like multiplication */
748                         return FALSE;
749
750                 case MON_ROLENTO:
751                         if (known)
752                         {
753                                 if (see_either)
754                                 {
755                                         disturb(1, 1);
756
757                                         msg_format(_("%^s¤Ï¼êÜØÃƤò¤Ð¤é¤Þ¤¤¤¿¡£", "%^s throws some hand grenades."), m_name);
758                                 }
759                                 else
760                                 {
761                                         mon_fight = TRUE;
762                                 }
763                         }
764
765                         {
766                                 int num = 1 + randint1(3);
767                                 for (k = 0; k < num; k++)
768                                 {
769                                         count += summon_named_creature(m_idx, y, x, MON_SHURYUUDAN, 0);
770                                 }
771                         }
772
773                         if (known && !see_t && count)
774                         {
775                                 mon_fight = TRUE;
776                         }
777                         break;
778
779                 default:
780                         if (r_ptr->d_char == 'B')
781                         {
782                                 if (one_in_(3))
783                                 {
784                                         if (see_m)
785                                         {
786                                                 msg_format(_("%^s¤ÏÆÍÁ³µÞ¾å¾º¤·¤Æ»ë³¦¤«¤é¾Ã¤¨¤¿!", "%^s suddenly go out of your sight!"), m_name);
787                                         }
788                                         teleport_away(m_idx, 10, TELEPORT_NONMAGICAL);
789                                         p_ptr->update |= (PU_MONSTERS);
790                                 }
791                                 else
792                                 {
793                                         if (known)
794                                         {
795                                                 if (see_either)
796                                                 {
797                                                         msg_format(_("%^s¤¬%s¤òÄϤó¤Ç¶õÃ椫¤éÅꤲÍî¤È¤·¤¿¡£", "%^s holds %s, and drops from the sky."), m_name, t_name);
798                                                 }
799                                                 else
800                                                 {
801                                                         mon_fight = TRUE;
802                                                 }
803                                         }
804
805                                         dam = damroll(4, 8);
806
807                                         if (t_idx == p_ptr->riding) teleport_player_to(m_ptr->fy, m_ptr->fx, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
808                                         else teleport_monster_to(t_idx, m_ptr->fy, m_ptr->fx, 100, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
809
810                                         sound(SOUND_FALL);
811
812                                         if (tr_ptr->flags7 & RF7_CAN_FLY)
813                                         {
814                                                 if (see_t) msg_format(_("%^s¤ÏÀŤ«¤ËÃåÃϤ·¤¿¡£", "%^s floats gently down to the ground."), t_name);
815                                         }
816                                         else
817                                         {
818                                                 if (see_t) msg_format(_("%^s¤ÏÃÏÌ̤Ë᤭¤Ä¤±¤é¤ì¤¿¡£", "%^s crashed into the ground."), t_name);
819
820                                                 dam += damroll(6, 8);
821                                         }
822
823                                         if (p_ptr->riding == t_idx)
824                                         {
825                                                 int get_damage = 0;
826
827                                                 /* Mega hack -- this special action deals damage to the player. Therefore the code of "eyeeye" is necessary.
828                                                    -- henkma
829                                                  */
830                                                 get_damage = take_hit(DAMAGE_NOESCAPE, dam, m_name, -1);
831                                                 if (p_ptr->tim_eyeeye && get_damage > 0 && !p_ptr->is_dead)
832                                                 {
833                                                         char m_name_self[80];
834
835                                                         /* hisself */
836                                                         monster_desc(m_name_self, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE);
837
838                                                         _(msg_format("¹¶·â¤¬%s¼«¿È¤ò½ý¤Ä¤±¤¿¡ª", m_name),
839                                                           msg_format("The attack of %s has wounded %s!", m_name, m_name_self));
840
841                                                         project(0, 0, m_ptr->fy, m_ptr->fx, get_damage, GF_MISSILE, PROJECT_KILL, -1);
842                                                         set_tim_eyeeye(p_ptr->tim_eyeeye-5, TRUE);
843                                                 }
844                                         }
845
846                                         mon_take_hit_mon(t_idx, dam, &fear, extract_note_dies(real_r_ptr(t_ptr)), m_idx);
847                                 }
848                                 break;
849                         }
850
851                         /* Something is wrong */
852                         else return FALSE;
853                 }
854
855                 /* done */
856                 break;
857
858         /* RF6_TELE_TO */
859         case 160+8:
860                 if (known)
861                 {
862                         if (see_either)
863                         {
864                                 msg_format(_("%^s¤¬%s¤ò°ú¤­Ìᤷ¤¿¡£", "%^s commands %s to return."), m_name, t_name);
865                         }
866                         else
867                         {
868                                 mon_fight = TRUE;
869                         }
870                 }
871
872                 if (tr_ptr->flagsr & RFR_RES_TELE)
873                 {
874                         if ((tr_ptr->flags1 & RF1_UNIQUE) || (tr_ptr->flagsr & RFR_RES_ALL))
875                         {
876                                 if (is_original_ap_and_seen(t_ptr)) tr_ptr->r_flagsr |= RFR_RES_TELE;
877                                 if (see_t)
878                                 {
879                                         msg_format(_("%^s¤Ë¤Ï¸ú²Ì¤¬¤Ê¤«¤Ã¤¿¡£", "%^s is unaffected!"), t_name);
880                                 }
881
882                                 resists_tele = TRUE;
883                         }
884                         else if (tr_ptr->level > randint1(100))
885                         {
886                                 if (is_original_ap_and_seen(t_ptr)) tr_ptr->r_flagsr |= RFR_RES_TELE;
887                                 if (see_t)
888                                 {
889                                         msg_format(_("%^s¤ÏÂÑÀ­¤ò»ý¤Ã¤Æ¤¤¤ë¡ª", "%^s resists!"), t_name);
890                                 }
891
892                                 resists_tele = TRUE;
893                         }
894                 }
895
896                 if (!resists_tele)
897                 {
898                         if (t_idx == p_ptr->riding) teleport_player_to(m_ptr->fy, m_ptr->fx, TELEPORT_PASSIVE);
899                         else teleport_monster_to(t_idx, m_ptr->fy, m_ptr->fx, 100, TELEPORT_PASSIVE);
900                 }
901
902                 wake_up = TRUE;
903                 break;
904
905         /* RF6_TELE_AWAY */
906         case 160+9:
907                 if (known)
908                 {
909                         if (see_either)
910                         {
911                                 msg_format(_("%^s¤Ï%s¤ò¥Æ¥ì¥Ý¡¼¥È¤µ¤»¤¿¡£", "%^s teleports %s away."), m_name, t_name);
912                         }
913                         else
914                         {
915                                 mon_fight = TRUE;
916                         }
917                 }
918
919                 if (tr_ptr->flagsr & RFR_RES_TELE)
920                 {
921                         if ((tr_ptr->flags1 & RF1_UNIQUE) || (tr_ptr->flagsr & RFR_RES_ALL))
922                         {
923                                 if (is_original_ap_and_seen(t_ptr)) tr_ptr->r_flagsr |= RFR_RES_TELE;
924                                 if (see_t)
925                                 {
926                                         msg_format(_("%^s¤Ë¤Ï¸ú²Ì¤¬¤Ê¤«¤Ã¤¿¡£", "%^s is unaffected!"), t_name);
927                                 }
928
929                                 resists_tele = TRUE;
930                         }
931                         else if (tr_ptr->level > randint1(100))
932                         {
933                                 if (is_original_ap_and_seen(t_ptr)) tr_ptr->r_flagsr |= RFR_RES_TELE;
934                                 if (see_t)
935                                 {
936                                         msg_format(_("%^s¤ÏÂÑÀ­¤ò»ý¤Ã¤Æ¤¤¤ë¡ª", "%^s resists!"), t_name);
937                                 }
938
939                                 resists_tele = TRUE;
940                         }
941                 }
942
943                 if (!resists_tele)
944                 {
945                         if (t_idx == p_ptr->riding) teleport_player_away(m_idx, MAX_SIGHT * 2 + 5);
946                         else teleport_away(t_idx, MAX_SIGHT * 2 + 5, TELEPORT_PASSIVE);
947                 }
948
949                 wake_up = TRUE;
950                 break;
951
952         /* RF6_TELE_LEVEL */
953         case 160+10:
954                 if (known)
955                 {
956                         if (see_either)
957                         {
958                                 msg_format(_("%^s¤¬%s¤Î­¤ò»Ø¤µ¤·¤¿¡£", "%^s gestures at %s's feet."), m_name, t_name);
959                         }
960                         else
961                         {
962                                 mon_fight = TRUE;
963                         }
964                 }
965
966                 if (tr_ptr->flagsr & (RFR_EFF_RES_NEXU_MASK | RFR_RES_TELE))
967                 {
968                         if (see_t) msg_format(_("%^s¤Ë¤Ï¸ú²Ì¤¬¤Ê¤«¤Ã¤¿¡£", "%^s is unaffected!"), t_name);
969                 }
970                 else if ((tr_ptr->flags1 & RF1_QUESTOR) ||
971                             (tr_ptr->level > randint1((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10))
972                 {
973                         if (see_t) msg_format(_("%^s¤Ï¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª", "%^s resist the effects!"), t_name);
974                 }
975                 else teleport_level((t_idx == p_ptr->riding) ? 0 : t_idx);
976
977                 wake_up = TRUE;
978                 break;
979
980         /* RF6_PSY_SPEAR */
981         case 160+11:
982                 if (known)
983                 {
984                         if (see_either)
985                         {
986                                 msg_format(_("%^s¤¬%s¤Ë¸þ¤«¤Ã¤Æ¸÷¤Î·õ¤òÊü¤Ã¤¿¡£", "%^s throw a Psycho-spear at %s."), m_name, t_name);
987                         }
988                         else
989                         {
990                                 mon_fight = TRUE;
991                         }
992                 }
993
994                 dam = (r_ptr->flags2 & RF2_POWERFUL) ? (randint1(rlev * 2) + 180) : (randint1(rlev * 3 / 2) + 120);
995                 beam(m_idx, y, x, GF_PSY_SPEAR, dam, MS_PSY_SPEAR, MONSTER_TO_MONSTER);
996                 break;
997
998         /* RF6_DARKNESS */
999         case 160+12:
1000                 if (known)
1001                 {
1002                         if (see_m)
1003                         {
1004                                 if (can_use_lite_area)
1005                                 {
1006                                         msg_format(_("%^s¤¬ÊÕ¤ê¤òÌÀ¤ë¤¯¾È¤é¤·¤¿¡£", "%^s cast a spell to light up."), m_name);
1007                                 }
1008                                 else
1009                                 {
1010                                         msg_format(_("%^s¤¬°Å°Ç¤ÎÃæ¤Ç¼ê¤ò¿¶¤Ã¤¿¡£", "%^s gestures in shadow."), m_name);
1011                                 }
1012
1013                                 if (see_t)
1014                                 {
1015                                         if (can_use_lite_area)
1016                                         {
1017                                                 msg_format(_("%^s¤ÏÇò¤¤¸÷¤ËÊñ¤Þ¤ì¤¿¡£", "%^s is surrounded by a white light."), t_name);
1018                                         }
1019                                         else
1020                                         {
1021                                                 msg_format(_("%^s¤Ï°Å°Ç¤ËÊñ¤Þ¤ì¤¿¡£", "%^s is surrounded by darkness."), t_name);
1022                                         }
1023                                 }
1024                         }
1025                         else
1026                         {
1027                                 mon_fight = TRUE;
1028                         }
1029                 }
1030
1031                 if (can_use_lite_area)
1032                 {
1033                         (void)project(m_idx, 3, y, x, 0, GF_LITE_WEAK, PROJECT_GRID | PROJECT_KILL, -1);
1034                         lite_room(y, x);
1035                 }
1036                 else
1037                 {
1038                         (void)project(m_idx, 3, y, x, 0, GF_DARK_WEAK, PROJECT_GRID | PROJECT_KILL, MS_DARKNESS);
1039                         unlite_room(y, x);
1040                 }
1041
1042                 break;
1043
1044         /* RF6_TRAPS */
1045         case 160+13:
1046 #if 0
1047                 if (known)
1048                 {
1049                         if (see_m)
1050                         {
1051                                 msg_format(_("%^s¤¬¼öʸ¤ò¾§¤¨¤Æ¼Ù°­¤ËÈù¾Ð¤ó¤À¡£", "%^s casts a spell and cackles evilly."), m_name);
1052                         }
1053                         else
1054                         {
1055                                 msg_format(_("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", "%^s mumbles."), m_name);
1056                         }
1057                 }
1058
1059                 trap_creation(y, x);
1060
1061                 break;
1062 #else
1063                 /* Not implemented */
1064                 return FALSE;
1065 #endif
1066
1067         /* RF6_FORGET */
1068         case 160+14:
1069                 /* Not implemented */
1070                 return FALSE;
1071
1072         /* RF6_RAISE_DEAD */
1073         case 160+15:
1074                 if (known)
1075                 {
1076                         if (see_either)
1077                         {
1078                                 disturb(1, 1);
1079                                 if (blind)
1080                                 {
1081                                         msg_format(_("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", "%^s mumbles."), m_name);
1082                                 }
1083                                 else
1084                                 {
1085                                         msg_format(_("%^s¤¬»à¼ÔÉü³è¤Î¼öʸ¤ò¾§¤¨¤¿¡£", "%^s casts a spell to revive corpses."), m_name);
1086                                 }
1087                         }
1088                         else
1089                         {
1090                                 mon_fight = TRUE;
1091                         }
1092                 }
1093                 animate_dead(m_idx, m_ptr->fy, m_ptr->fx);
1094                 break;
1095
1096         /* RF6_S_KIN */
1097         case 160+16:
1098                 if (known)
1099                 {
1100                         if (see_either)
1101                         {
1102                                 disturb(1, 1);
1103
1104                                 if (m_ptr->r_idx == MON_SERPENT || m_ptr->r_idx == MON_ZOMBI_SERPENT)
1105                                 {
1106                                         msg_format(_("%^s¤¬¥À¥ó¥¸¥ç¥ó¤Î¼ç¤ò¾¤´­¤·¤¿¡£", "%^s magically summons guardians of dungeons."), m_name);
1107                                 }
1108                                 else
1109                                 {
1110                                         _(msg_format("%s¤¬ËâË¡¤Ç%s¤ò¾¤´­¤·¤¿¡£", m_name, ((r_ptr->flags1 & RF1_UNIQUE) ? "¼ê²¼" : "Ãç´Ö")),   
1111                                           msg_format("%^s magically summons %s %s.", m_name, m_poss, ((r_ptr->flags1 & RF1_UNIQUE) ? "minions" : "kin")));
1112                                 }
1113
1114                         }
1115                         else
1116                         {
1117                                 mon_fight = TRUE;
1118                         }
1119                 }
1120
1121                 switch (m_ptr->r_idx)
1122                 {
1123                 case MON_MENELDOR:
1124                 case MON_GWAIHIR:
1125                 case MON_THORONDOR:
1126                         {
1127                                 int num = 4 + randint1(3);
1128                                 for (k = 0; k < num; k++)
1129                                 {
1130                                         count += summon_specific(m_idx, y, x, rlev, SUMMON_EAGLES, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1131                                 }
1132                         }
1133                         break;
1134
1135                 case MON_BULLGATES:
1136                         {
1137                                 int num = 2 + randint1(3);
1138                                 for (k = 0; k < num; k++)
1139                                 {
1140                                         count += summon_named_creature(m_idx, y, x, MON_IE, 0);
1141                                 }
1142                         }
1143                         break;
1144
1145                 case MON_SERPENT:
1146                 case MON_ZOMBI_SERPENT:
1147                         if (r_info[MON_JORMUNGAND].cur_num < r_info[MON_JORMUNGAND].max_num && one_in_(6))
1148                         {
1149                                 if (known && see_t)
1150                                 {
1151                                         msg_print(_("ÃÏÌ̤«¤é¿å¤¬¿á¤­½Ð¤·¤¿¡ª", "Water blew off from the ground!"));
1152                                 }
1153                                 project(t_idx, 8, y, x, 3, GF_WATER_FLOW, PROJECT_GRID | PROJECT_HIDE, -1);
1154                         }
1155
1156                         {
1157                                 int num = 2 + randint1(3);
1158                                 for (k = 0; k < num; k++)
1159                                 {
1160                                         count += summon_specific(m_idx, y, x, rlev, SUMMON_GUARDIANS, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1161                                 }
1162                         }
1163                         break;
1164
1165                 case MON_CALDARM:
1166                         {
1167                                 int num = randint1(3);
1168                                 for (k = 0; k < num; k++)
1169                                 {
1170                                         count += summon_named_creature(m_idx, y, x, MON_LOCKE_CLONE, 0);
1171                                 }
1172                         }
1173                         break;
1174
1175                 case MON_LOUSY:
1176                         {
1177                                 int num = 2 + randint1(3);
1178                                 for (k = 0; k < num; k++)
1179                                 {
1180                                         count += summon_specific(m_idx, y, x, rlev, SUMMON_LOUSE, (PM_ALLOW_GROUP));
1181                                 }
1182                         }
1183                         break;
1184
1185                 default:
1186                         summon_kin_type = r_ptr->d_char;
1187
1188                         for (k = 0; k < 4; k++)
1189                         {
1190                                 count += summon_specific(m_idx, y, x, rlev, SUMMON_KIN, (PM_ALLOW_GROUP));
1191                         }
1192                         break;
1193                 }
1194
1195                 if (known && !see_t && count)
1196                 {
1197                         mon_fight = TRUE;
1198                 }
1199
1200                 break;
1201
1202         /* RF6_S_CYBER */
1203         case 160+17:
1204                 if (known)
1205                 {
1206                         if (see_either)
1207                         {
1208                                 disturb(1, 1);
1209
1210                                 msg_format(_("%^s¤¬¥µ¥¤¥Ð¡¼¥Ç¡¼¥â¥ó¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons Cyberdemons!"), m_name);
1211                         }
1212                         else
1213                         {
1214                                 mon_fight = TRUE;
1215                         }
1216                 }
1217
1218                 if (is_friendly(m_ptr))
1219                 {
1220                         count += summon_specific(m_idx, y, x, rlev, SUMMON_CYBER, (PM_ALLOW_GROUP));
1221                 }
1222                 else
1223                 {
1224                         count += summon_cyber(m_idx, y, x);
1225                 }
1226
1227                 if (known && !see_t && count)
1228                 {
1229                         mon_fight = TRUE;
1230                 }
1231
1232                 break;
1233
1234         /* RF6_S_MONSTER */
1235         case 160+18:
1236                 if (known)
1237                 {
1238                         if (see_either)
1239                         {
1240                                 disturb(1, 1);
1241
1242                                 msg_format(_("%^s¤¬ËâË¡¤ÇÃç´Ö¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons help!"), m_name);
1243                         }
1244                         else
1245                         {
1246                                 mon_fight = TRUE;
1247                         }
1248                 }
1249
1250                 count += summon_specific(m_idx, y, x, rlev, 0, (u_mode));
1251
1252                 if (known && !see_t && count)
1253                 {
1254                         mon_fight = TRUE;
1255                 }
1256
1257                 break;
1258
1259         /* RF6_S_MONSTERS */
1260         case 160+19:
1261                 if (known)
1262                 {
1263                         if (see_either)
1264                         {
1265                                 disturb(1, 1);
1266
1267                                 msg_format(_("%^s¤¬ËâË¡¤Ç¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons monsters!"), m_name);
1268                         }
1269                         else
1270                         {
1271                                 mon_fight = TRUE;
1272                         }
1273                 }
1274
1275                 for (k = 0; k < s_num_6; k++)
1276                 {
1277                         count += summon_specific(m_idx, y, x, rlev, 0, (PM_ALLOW_GROUP | u_mode));
1278                 }
1279
1280                 if (known && !see_t && count)
1281                 {
1282                         mon_fight = TRUE;
1283                 }
1284
1285                 break;
1286
1287         /* RF6_S_ANT */
1288         case 160+20:
1289                 if (known)
1290                 {
1291                         if (see_either)
1292                         {
1293                                 disturb(1, 1);
1294
1295                                 msg_format(_("%^s¤¬ËâË¡¤Ç¥¢¥ê¤ò¾¤´­¤·¤¿¡£", "%^s magically summons ants."), m_name);
1296                         }
1297                         else
1298                         {
1299                                 mon_fight = TRUE;
1300                         }
1301                 }
1302
1303                 for (k = 0; k < s_num_6; k++)
1304                 {
1305                         count += summon_specific(m_idx, y, x, rlev, SUMMON_ANT, (PM_ALLOW_GROUP));
1306                 }
1307
1308                 if (known && !see_t && count)
1309                 {
1310                         mon_fight = TRUE;
1311                 }
1312
1313                 break;
1314
1315         /* RF6_S_SPIDER */
1316         case 160+21:
1317                 if (known)
1318                 {
1319                         if (see_either)
1320                         {
1321                                 disturb(1, 1);
1322
1323                                 msg_format(_("%^s¤¬ËâË¡¤Ç¥¯¥â¤ò¾¤´­¤·¤¿¡£", "%^s magically summons spiders."), m_name);
1324                         }
1325                         else
1326                         {
1327                                 mon_fight = TRUE;
1328                         }
1329                 }
1330
1331                 for (k = 0; k < s_num_6; k++)
1332                 {
1333                         count += summon_specific(m_idx, y, x, rlev, SUMMON_SPIDER, (PM_ALLOW_GROUP));
1334                 }
1335
1336                 if (known && !see_t && count)
1337                 {
1338                         mon_fight = TRUE;
1339                 }
1340
1341                 break;
1342
1343         /* RF6_S_HOUND */
1344         case 160+22:
1345                 if (known)
1346                 {
1347                         if (see_either)
1348                         {
1349                                 disturb(1, 1);
1350
1351                                 msg_format(_("%^s¤¬ËâË¡¤Ç¥Ï¥¦¥ó¥É¤ò¾¤´­¤·¤¿¡£", "%^s magically summons hounds."), m_name);
1352                         }
1353                         else
1354                         {
1355                                 mon_fight = TRUE;
1356                         }
1357                 }
1358
1359                 for (k = 0; k < s_num_4; k++)
1360                 {
1361                         count += summon_specific(m_idx, y, x, rlev, SUMMON_HOUND, (PM_ALLOW_GROUP));
1362                 }
1363
1364                 if (known && !see_t && count)
1365                 {
1366                         mon_fight = TRUE;
1367                 }
1368
1369                 break;
1370
1371         /* RF6_S_HYDRA */
1372         case 160+23:
1373                 if (known)
1374                 {
1375                         if (see_either)
1376                         {
1377                                 disturb(1, 1);
1378
1379                                 msg_format(_("%^s¤¬ËâË¡¤Ç¥Ò¥É¥é¤ò¾¤´­¤·¤¿¡£", "%^s magically summons hydras."), m_name);
1380                         }
1381                         else
1382                         {
1383                                 mon_fight = TRUE;
1384                         }
1385                 }
1386
1387                 for (k = 0; k < s_num_4; k++)
1388                 {
1389                         count += summon_specific(m_idx, y, x, rlev, SUMMON_HYDRA, (PM_ALLOW_GROUP));
1390                 }
1391
1392                 if (known && !see_t && count)
1393                 {
1394                         mon_fight = TRUE;
1395                 }
1396
1397                 break;
1398
1399         /* RF6_S_ANGEL */
1400         case 160+24:
1401                 if (known)
1402                 {
1403                         if (see_either)
1404                         {
1405                                 disturb(1, 1);
1406
1407                                 msg_format(_("%^s¤¬ËâË¡¤ÇÅ·»È¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons an angel!"), m_name);
1408                         }
1409                         else
1410                         {
1411                                 mon_fight = TRUE;
1412                         }
1413                 }
1414
1415                 {
1416                         int num = 1;
1417
1418                         if ((r_ptr->flags1 & RF1_UNIQUE) && !easy_band)
1419                         {
1420                                 num += r_ptr->level/40;
1421                         }
1422
1423                         for (k = 0; k < num; k++)
1424                         {
1425                                 count += summon_specific(m_idx, y, x, rlev, SUMMON_ANGEL, (PM_ALLOW_GROUP));
1426                         }
1427                 }
1428
1429                 if (known && !see_t && count)
1430                 {
1431                         mon_fight = TRUE;
1432                 }
1433
1434                 break;
1435
1436         /* RF6_S_DEMON */
1437         case 160+25:
1438                 if (known)
1439                 {
1440                         if (see_either)
1441                         {
1442                                 disturb(1, 1);
1443
1444                                 msg_format(_("%^s¤¬ËâË¡¤Çº®Æ٤εÜÄ¤é¥Ç¡¼¥â¥ó¤ò¾¤´­¤·¤¿¡ª", 
1445                                                  "%^s magically summons a demon from the Courts of Chaos!"), m_name);
1446                         }
1447                         else
1448                         {
1449                                 mon_fight = TRUE;
1450                         }
1451                 }
1452
1453                 for (k = 0; k < 1; k++)
1454                 {
1455                         count += summon_specific(m_idx, y, x, rlev, SUMMON_DEMON, (PM_ALLOW_GROUP));
1456                 }
1457
1458                 if (known && !see_t && count)
1459                 {
1460                         mon_fight = TRUE;
1461                 }
1462
1463                 break;
1464
1465         /* RF6_S_UNDEAD */
1466         case 160+26:
1467                 if (known)
1468                 {
1469                         if (see_either)
1470                         {
1471                                 disturb(1, 1);
1472
1473                                 msg_format(_("%s¤¬ËâË¡¤Ç¥¢¥ó¥Ç¥Ã¥É¤ò¾¤´­¤·¤¿¡£", "%^s magically summons undead."), m_name);
1474                         }
1475                         else
1476                         {
1477                                 mon_fight = TRUE;
1478                         }
1479                 }
1480
1481                 for (k = 0; k < 1; k++)
1482                 {
1483                         count += summon_specific(m_idx, y, x, rlev, SUMMON_UNDEAD, (PM_ALLOW_GROUP));
1484                 }
1485
1486                 if (known && !see_t && count)
1487                 {
1488                         mon_fight = TRUE;
1489                 }
1490
1491                 break;
1492
1493         /* RF6_S_DRAGON */
1494         case 160+27:
1495                 if (known)
1496                 {
1497                         if (see_either)
1498                         {
1499                                 disturb(1, 1);
1500
1501                                 msg_format(_("%^s¤¬ËâË¡¤Ç¥É¥é¥´¥ó¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons a dragon!"), m_name);
1502                         }
1503                         else
1504                         {
1505                                 mon_fight = TRUE;
1506                         }
1507                 }
1508
1509                 for (k = 0; k < 1; k++)
1510                 {
1511                         count += summon_specific(m_idx, y, x, rlev, SUMMON_DRAGON, (PM_ALLOW_GROUP));
1512                 }
1513
1514                 if (known && !see_t && count)
1515                 {
1516                         mon_fight = TRUE;
1517                 }
1518
1519                 break;
1520
1521         /* RF6_S_HI_UNDEAD */
1522         case 160+28:
1523                 if (known)
1524                 {
1525                         if (see_either)
1526                         {
1527                                 disturb(1, 1);
1528
1529                                 msg_format(_("%s¤¬ËâË¡¤Ç¥¢¥ó¥Ç¥Ã¥É¤ò¾¤´­¤·¤¿¡£", "%^s magically summons undead."), m_name);
1530                         }
1531                         else
1532                         {
1533                                 mon_fight = TRUE;
1534                         }
1535                 }
1536
1537                 for (k = 0; k < s_num_6; k++)
1538                 {
1539                         count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_UNDEAD, (PM_ALLOW_GROUP | u_mode));
1540                 }
1541
1542                 if (known && !see_t && count)
1543                 {
1544                         mon_fight = TRUE;
1545                 }
1546
1547                 break;
1548
1549         /* RF6_S_HI_DRAGON */
1550         case 160+29:
1551                 if (known)
1552                 {
1553                         if (see_either)
1554                         {
1555                                 disturb(1, 1);
1556
1557                                 msg_format(_("%^s¤¬ËâË¡¤Ç¸ÅÂå¥É¥é¥´¥ó¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons ancient dragons!"), m_name);
1558                         }
1559                         else
1560                         {
1561                                 mon_fight = TRUE;
1562                         }
1563                 }
1564
1565                 for (k = 0; k < s_num_4; k++)
1566                 {
1567                         count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_DRAGON, (PM_ALLOW_GROUP | u_mode));
1568                 }
1569
1570                 if (known && !see_t && count)
1571                 {
1572                         mon_fight = TRUE;
1573                 }
1574
1575                 break;
1576
1577         /* RF6_S_AMBERITES */
1578         case 160+30:
1579                 if (known)
1580                 {
1581                         if (see_either)
1582                         {
1583                                 disturb(1, 1);
1584
1585                                 msg_format(_("%^s¤¬¥¢¥ó¥Ð¡¼¤Î²¦Â²¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons Lords of Amber!"), m_name);
1586                         }
1587                         else
1588                         {
1589                                 mon_fight = TRUE;
1590                         }
1591                 }
1592
1593                 for (k = 0; k < s_num_4; k++)
1594                 {
1595                         count += summon_specific(m_idx, y, x, rlev, SUMMON_AMBERITES, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1596                 }
1597
1598                 if (known && !see_t && count)
1599                 {
1600                         mon_fight = TRUE;
1601                 }
1602
1603                 break;
1604
1605         /* RF6_S_UNIQUE */
1606         case 160+31:
1607                 if (known)
1608                 {
1609                         if (see_either)
1610                         {
1611                                 disturb(1, 1);
1612
1613                                 msg_format(_("%^s¤¬ËâË¡¤ÇÆÃÊ̤ʶ¯Å¨¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons special opponents!"), m_name);
1614                         }
1615                         else
1616                         {
1617                                 mon_fight = TRUE;
1618                         }
1619                 }
1620
1621                 for (k = 0; k < s_num_4; k++)
1622                 {
1623                         count += summon_specific(m_idx, y, x, rlev, SUMMON_UNIQUE, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1624                 }
1625
1626                 {
1627                         int non_unique_type = SUMMON_HI_UNDEAD;
1628
1629                         if ((m_ptr->sub_align & (SUB_ALIGN_GOOD | SUB_ALIGN_EVIL)) == (SUB_ALIGN_GOOD | SUB_ALIGN_EVIL))
1630                                 non_unique_type = 0;
1631                         else if (m_ptr->sub_align & SUB_ALIGN_GOOD)
1632                                 non_unique_type = SUMMON_ANGEL;
1633
1634                         for (k = count; k < s_num_4; k++)
1635                         {
1636                                 count += summon_specific(m_idx, y, x, rlev, non_unique_type, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1637                         }
1638                 }
1639
1640                 if (known && !see_t && count)
1641                 {
1642                         mon_fight = TRUE;
1643                 }
1644
1645                 break;
1646         }
1647
1648         if (wake_up) (void)set_monster_csleep(t_idx, 0);
1649
1650         if (fear && see_t)
1651         {
1652                 msg_format(_("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", "%^s flees in terror!"), t_name);
1653         }
1654
1655         if (m_ptr->ml && maneable && !world_monster && !p_ptr->blind && (p_ptr->pclass == CLASS_IMITATOR))
1656         {
1657                 if (thrown_spell != 167) /* Not RF6_SPECIAL */
1658                 {
1659                         if (p_ptr->mane_num == MAX_MANE)
1660                         {
1661                                 p_ptr->mane_num--;
1662                                 for (i = 0; i < p_ptr->mane_num - 1; i++)
1663                                 {
1664                                         p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
1665                                         p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
1666                                 }
1667                         }
1668                         p_ptr->mane_spell[p_ptr->mane_num] = thrown_spell - 96;
1669                         p_ptr->mane_dam[p_ptr->mane_num] = dam;
1670                         p_ptr->mane_num++;
1671                         new_mane = TRUE;
1672
1673                         p_ptr->redraw |= (PR_IMITATION);
1674                 }
1675         }
1676
1677         /* Remember what the monster did, if we saw it */
1678         if (can_remember)
1679         {
1680                 /* Inate spell */
1681                 if (thrown_spell < 32*4)
1682                 {
1683                         r_ptr->r_flags4 |= (1L << (thrown_spell - 32*3));
1684                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
1685                 }
1686
1687                 /* Bolt or Ball */
1688                 else if (thrown_spell < 32*5)
1689                 {
1690                         r_ptr->r_flags5 |= (1L << (thrown_spell - 32*4));
1691                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
1692                 }
1693
1694                 /* Special spell */
1695                 else if (thrown_spell < 32*6)
1696                 {
1697                         r_ptr->r_flags6 |= (1L << (thrown_spell - 32*5));
1698                         if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
1699                 }
1700         }
1701
1702         /* Always take note of monsters that kill you */
1703         if (p_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !p_ptr->inside_arena)
1704         {
1705                 r_ptr->r_deaths++; /* Ignore appearance difference */
1706         }
1707
1708         /* A spell was cast */
1709         return TRUE;
1710 }