OSDN Git Service

fix indent
[jnethack/source.git] / src / mcastu.c
1 /* NetHack 3.6  mcastu.c        $NHDT-Date: 1436753517 2015/07/13 02:11:57 $  $NHDT-Branch: master $:$NHDT-Revision: 1.44 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Robert Patrick Rankin, 2011. */
4 /* NetHack may be freely redistributed.  See license for details. */
5
6 /* JNetHack Copyright */
7 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
8 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2019            */
9 /* JNetHack may be freely redistributed.  See license for details. */
10
11 #include "hack.h"
12
13 /* monster mage spells */
14 enum mcast_mage_spells {
15     MGC_PSI_BOLT = 0,
16     MGC_CURE_SELF,
17     MGC_HASTE_SELF,
18     MGC_STUN_YOU,
19     MGC_DISAPPEAR,
20     MGC_WEAKEN_YOU,
21     MGC_DESTRY_ARMR,
22     MGC_CURSE_ITEMS,
23     MGC_AGGRAVATION,
24     MGC_SUMMON_MONS,
25     MGC_CLONE_WIZ,
26     MGC_DEATH_TOUCH
27 };
28
29 /* monster cleric spells */
30 enum mcast_cleric_spells {
31     CLC_OPEN_WOUNDS = 0,
32     CLC_CURE_SELF,
33     CLC_CONFUSE_YOU,
34     CLC_PARALYZE,
35     CLC_BLIND_YOU,
36     CLC_INSECTS,
37     CLC_CURSE_ITEMS,
38     CLC_LIGHTNING,
39     CLC_FIRE_PILLAR,
40     CLC_GEYSER
41 };
42
43 STATIC_DCL void FDECL(cursetxt, (struct monst *, BOOLEAN_P));
44 STATIC_DCL int FDECL(choose_magic_spell, (int));
45 STATIC_DCL int FDECL(choose_clerical_spell, (int));
46 STATIC_DCL int FDECL(m_cure_self, (struct monst *, int));
47 STATIC_DCL void FDECL(cast_wizard_spell, (struct monst *, int, int));
48 STATIC_DCL void FDECL(cast_cleric_spell, (struct monst *, int, int));
49 STATIC_DCL boolean FDECL(is_undirected_spell, (unsigned int, int));
50 STATIC_DCL boolean
51 FDECL(spell_would_be_useless, (struct monst *, unsigned int, int));
52
53 extern const char *const flash_types[]; /* from zap.c */
54
55 /* feedback when frustrated monster couldn't cast a spell */
56 STATIC_OVL
57 void
58 cursetxt(mtmp, undirected)
59 struct monst *mtmp;
60 boolean undirected;
61 {
62     if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) {
63         const char *point_msg; /* spellcasting monsters are impolite */
64
65         if (undirected)
66 /*JP
67             point_msg = "all around, then curses";
68 */
69             point_msg = "\82 \82½\82è\88ê\96Ê\82ð";
70         else if ((Invis && !perceives(mtmp->data)
71                   && (mtmp->mux != u.ux || mtmp->muy != u.uy))
72                  || is_obj_mappear(&youmonst, STRANGE_OBJECT)
73                  || u.uundetected)
74 /*JP
75             point_msg = "and curses in your general direction";
76 */
77             point_msg = "\82 \82È\82½\82Ì\82¢\82é\82 \82½\82è\82ð";
78         else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
79 /*JP
80             point_msg = "and curses at your displaced image";
81 */
82             point_msg = "\82 \82È\82½\82Ì\8c\89e\82ð";
83         else
84 /*JP
85             point_msg = "at you, then curses";
86 */
87             point_msg = "\82 \82È\82½\82ð";
88
89 /*JP
90         pline("%s points %s.", Monnam(mtmp), point_msg);
91 */
92         pline("%s\82Í%s\8ew\8d·\82µ\81C\8eô\82¢\82ð\82©\82¯\82½\81D", Monnam(mtmp), point_msg);
93     } else if ((!(moves % 4) || !rn2(4))) {
94         if (!Deaf)
95 /*JP
96             Norep("You hear a mumbled curse.");
97 */
98             Norep("\8eô\82¢\82Ì\8c¾\97t\82ð\82Â\82Ô\82â\82­\90º\82ð\95·\82¢\82½\81D");
99     }
100 }
101
102 /* convert a level based random selection into a specific mage spell;
103    inappropriate choices will be screened out by spell_would_be_useless() */
104 STATIC_OVL int
105 choose_magic_spell(spellval)
106 int spellval;
107 {
108     /* for 3.4.3 and earlier, val greater than 22 selected the default spell
109      */
110     while (spellval > 24 && rn2(25))
111         spellval = rn2(spellval);
112
113     switch (spellval) {
114     case 24:
115     case 23:
116         if (Antimagic || Hallucination)
117             return MGC_PSI_BOLT;
118         /*FALLTHRU*/
119     case 22:
120     case 21:
121     case 20:
122         return MGC_DEATH_TOUCH;
123     case 19:
124     case 18:
125         return MGC_CLONE_WIZ;
126     case 17:
127     case 16:
128     case 15:
129         return MGC_SUMMON_MONS;
130     case 14:
131     case 13:
132         return MGC_AGGRAVATION;
133     case 12:
134     case 11:
135     case 10:
136         return MGC_CURSE_ITEMS;
137     case 9:
138     case 8:
139         return MGC_DESTRY_ARMR;
140     case 7:
141     case 6:
142         return MGC_WEAKEN_YOU;
143     case 5:
144     case 4:
145         return MGC_DISAPPEAR;
146     case 3:
147         return MGC_STUN_YOU;
148     case 2:
149         return MGC_HASTE_SELF;
150     case 1:
151         return MGC_CURE_SELF;
152     case 0:
153     default:
154         return MGC_PSI_BOLT;
155     }
156 }
157
158 /* convert a level based random selection into a specific cleric spell */
159 STATIC_OVL int
160 choose_clerical_spell(spellnum)
161 int spellnum;
162 {
163     /* for 3.4.3 and earlier, num greater than 13 selected the default spell
164      */
165     while (spellnum > 15 && rn2(16))
166         spellnum = rn2(spellnum);
167
168     switch (spellnum) {
169     case 15:
170     case 14:
171         if (rn2(3))
172             return CLC_OPEN_WOUNDS;
173         /*FALLTHRU*/
174     case 13:
175         return CLC_GEYSER;
176     case 12:
177         return CLC_FIRE_PILLAR;
178     case 11:
179         return CLC_LIGHTNING;
180     case 10:
181     case 9:
182         return CLC_CURSE_ITEMS;
183     case 8:
184         return CLC_INSECTS;
185     case 7:
186     case 6:
187         return CLC_BLIND_YOU;
188     case 5:
189     case 4:
190         return CLC_PARALYZE;
191     case 3:
192     case 2:
193         return CLC_CONFUSE_YOU;
194     case 1:
195         return CLC_CURE_SELF;
196     case 0:
197     default:
198         return CLC_OPEN_WOUNDS;
199     }
200 }
201
202 /* return values:
203  * 1: successful spell
204  * 0: unsuccessful spell
205  */
206 int
207 castmu(mtmp, mattk, thinks_it_foundyou, foundyou)
208 register struct monst *mtmp;
209 register struct attack *mattk;
210 boolean thinks_it_foundyou;
211 boolean foundyou;
212 {
213     int dmg, ml = mtmp->m_lev;
214     int ret;
215     int spellnum = 0;
216
217     /* Three cases:
218      * -- monster is attacking you.  Search for a useful spell.
219      * -- monster thinks it's attacking you.  Search for a useful spell,
220      *    without checking for undirected.  If the spell found is directed,
221      *    it fails with cursetxt() and loss of mspec_used.
222      * -- monster isn't trying to attack.  Select a spell once.  Don't keep
223      *    searching; if that spell is not useful (or if it's directed),
224      *    return and do something else.
225      * Since most spells are directed, this means that a monster that isn't
226      * attacking casts spells only a small portion of the time that an
227      * attacking monster does.
228      */
229     if ((mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) && ml) {
230         int cnt = 40;
231
232         do {
233             spellnum = rn2(ml);
234             if (mattk->adtyp == AD_SPEL)
235                 spellnum = choose_magic_spell(spellnum);
236             else
237                 spellnum = choose_clerical_spell(spellnum);
238             /* not trying to attack?  don't allow directed spells */
239             if (!thinks_it_foundyou) {
240                 if (!is_undirected_spell(mattk->adtyp, spellnum)
241                     || spell_would_be_useless(mtmp, mattk->adtyp, spellnum)) {
242                     if (foundyou)
243                         impossible(
244                        "spellcasting monster found you and doesn't know it?");
245                     return 0;
246                 }
247                 break;
248             }
249         } while (--cnt > 0
250                  && spell_would_be_useless(mtmp, mattk->adtyp, spellnum));
251         if (cnt == 0)
252             return 0;
253     }
254
255     /* monster unable to cast spells? */
256     if (mtmp->mcan || mtmp->mspec_used || !ml) {
257         cursetxt(mtmp, is_undirected_spell(mattk->adtyp, spellnum));
258         return (0);
259     }
260
261     if (mattk->adtyp == AD_SPEL || mattk->adtyp == AD_CLRC) {
262         mtmp->mspec_used = 10 - mtmp->m_lev;
263         if (mtmp->mspec_used < 2)
264             mtmp->mspec_used = 2;
265     }
266
267     /* monster can cast spells, but is casting a directed spell at the
268        wrong place?  If so, give a message, and return.  Do this *after*
269        penalizing mspec_used. */
270     if (!foundyou && thinks_it_foundyou
271         && !is_undirected_spell(mattk->adtyp, spellnum)) {
272 #if 0 /*JP*/
273         pline("%s casts a spell at %s!",
274               canseemon(mtmp) ? Monnam(mtmp) : "Something",
275               levl[mtmp->mux][mtmp->muy].typ == WATER ? "empty water"
276                                                       : "thin air");
277 #else
278         pline("%s\82Í\89½\82à\82È\82¢%s\82É\96\82\96@\82ð\82©\82¯\82½\81I",
279               canseemon(mtmp) ? Monnam(mtmp) : "\89½\8eÒ\82©",
280               levl[mtmp->mux][mtmp->muy].typ == WATER ? "\90\85\92\86"
281                                                       : "\8bó\8aÔ");
282 #endif
283         return (0);
284     }
285
286     nomul(0);
287     if (rn2(ml * 10) < (mtmp->mconf ? 100 : 20)) { /* fumbled attack */
288         if (canseemon(mtmp) && !Deaf)
289 /*JP
290             pline_The("air crackles around %s.", mon_nam(mtmp));
291 */
292             pline("%s\82Ì\89ñ\82è\82Ì\8bó\8bC\82ª\83p\83`\83p\83`\89¹\82ð\82½\82Ä\82Ä\82¢\82é\81D", mon_nam(mtmp));
293         return (0);
294     }
295     if (canspotmon(mtmp) || !is_undirected_spell(mattk->adtyp, spellnum)) {
296 #if 0 /*JP*/
297         pline("%s casts a spell%s!",
298               canspotmon(mtmp) ? Monnam(mtmp) : "Something",
299               is_undirected_spell(mattk->adtyp, spellnum)
300                   ? ""
301                   : (Invisible && !perceives(mtmp->data)
302                      && (mtmp->mux != u.ux || mtmp->muy != u.uy))
303                         ? " at a spot near you"
304                         : (Displaced
305                            && (mtmp->mux != u.ux || mtmp->muy != u.uy))
306                               ? " at your displaced image"
307                               : " at you");
308 #else
309         const char *who = (canspotmon(mtmp) ? Monnam(mtmp) : "\89½\8eÒ\82©");
310         if(is_undirected_spell(mattk->adtyp, spellnum)){
311             pline("%s\82Í\8eô\95\82ð\8f¥\82¦\82½\81I", who);
312         } else {
313             pline("%s\82Í\82 \82È\82½%s\82É\96\82\96@\82ð\82©\82¯\82½\81I",
314                   who,
315                   (Invisible && !perceives(mtmp->data) && 
316                    (mtmp->mux != u.ux || mtmp->muy != u.uy)) ?
317                   "\82Ì\82·\82®\82»\82Î" :
318                   (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy)) ?
319                   "\82Ì\8c\89e" :
320                   "");
321         }
322 #endif
323     }
324
325     /*
326      * As these are spells, the damage is related to the level
327      * of the monster casting the spell.
328      */
329     if (!foundyou) {
330         dmg = 0;
331         if (mattk->adtyp != AD_SPEL && mattk->adtyp != AD_CLRC) {
332             impossible(
333               "%s casting non-hand-to-hand version of hand-to-hand spell %d?",
334                        Monnam(mtmp), mattk->adtyp);
335             return (0);
336         }
337     } else if (mattk->damd)
338         dmg = d((int) ((ml / 2) + mattk->damn), (int) mattk->damd);
339     else
340         dmg = d((int) ((ml / 2) + 1), 6);
341     if (Half_spell_damage)
342         dmg = (dmg + 1) / 2;
343
344     ret = 1;
345
346     switch (mattk->adtyp) {
347     case AD_FIRE:
348 /*JP
349         pline("You're enveloped in flames.");
350 */
351         You("\89\8a\82É\82Â\82Â\82Ü\82ê\82½\81D");
352         if (Fire_resistance) {
353             shieldeff(u.ux, u.uy);
354 /*JP
355             pline("But you resist the effects.");
356 */
357             pline("\82µ\82©\82µ\81C\82 \82È\82½\82Í\89e\8b¿\82ð\8eó\82¯\82È\82¢\81D");
358             dmg = 0;
359         }
360         burn_away_slime();
361         break;
362     case AD_COLD:
363 /*JP
364         pline("You're covered in frost.");
365 */
366         You("\95X\82É\95¢\82í\82ê\82½\81D");
367         if (Cold_resistance) {
368             shieldeff(u.ux, u.uy);
369 /*JP
370             pline("But you resist the effects.");
371 */
372             pline("\82µ\82©\82µ\81C\82 \82È\82½\82Í\89e\8b¿\82ð\8eó\82¯\82È\82¢\81D");
373             dmg = 0;
374         }
375         break;
376     case AD_MAGM:
377 /*JP
378         You("are hit by a shower of missiles!");
379 */
380         You("\96\82\96@\82Ì\96î\82ð\82­\82ç\82Á\82½\81I");
381         if (Antimagic) {
382             shieldeff(u.ux, u.uy);
383 /*JP
384             pline_The("missiles bounce off!");
385 */
386             pline("\96\82\96@\82Ì\96î\82Í\94½\8eË\82µ\82½\81I");
387             dmg = 0;
388         } else
389             dmg = d((int) mtmp->m_lev / 2 + 1, 6);
390         break;
391     case AD_SPEL: /* wizard spell */
392     case AD_CLRC: /* clerical spell */
393     {
394         if (mattk->adtyp == AD_SPEL)
395             cast_wizard_spell(mtmp, dmg, spellnum);
396         else
397             cast_cleric_spell(mtmp, dmg, spellnum);
398         dmg = 0; /* done by the spell casting functions */
399         break;
400     }
401     }
402     if (dmg)
403         mdamageu(mtmp, dmg);
404     return (ret);
405 }
406
407 STATIC_OVL int
408 m_cure_self(mtmp, dmg)
409 struct monst *mtmp;
410 int dmg;
411 {
412     if (mtmp->mhp < mtmp->mhpmax) {
413         if (canseemon(mtmp))
414 /*JP
415             pline("%s looks better.", Monnam(mtmp));
416 */
417             pline("%s\82Í\8bC\95ª\82ª\82æ\82­\82È\82Á\82½\82æ\82¤\82¾\81D", Monnam(mtmp));
418         /* note: player healing does 6d4; this used to do 1d8 */
419         if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax)
420             mtmp->mhp = mtmp->mhpmax;
421         dmg = 0;
422     }
423     return dmg;
424 }
425
426 /* monster wizard and cleric spellcasting functions */
427 /*
428    If dmg is zero, then the monster is not casting at you.
429    If the monster is intentionally not casting at you, we have previously
430    called spell_would_be_useless() and spellnum should always be a valid
431    undirected spell.
432    If you modify either of these, be sure to change is_undirected_spell()
433    and spell_would_be_useless().
434  */
435 STATIC_OVL
436 void
437 cast_wizard_spell(mtmp, dmg, spellnum)
438 struct monst *mtmp;
439 int dmg;
440 int spellnum;
441 {
442     if (dmg == 0 && !is_undirected_spell(AD_SPEL, spellnum)) {
443         impossible("cast directed wizard spell (%d) with dmg=0?", spellnum);
444         return;
445     }
446
447     switch (spellnum) {
448     case MGC_DEATH_TOUCH:
449 /*JP
450         pline("Oh no, %s's using the touch of death!", mhe(mtmp));
451 */
452         pline("\82È\82ñ\82Ä\82±\82Á\82½\82¢\81C%s\82Í\8e\80\82Ì\90é\8d\90\82ð\8eg\82Á\82Ä\82¢\82é\81I", mhe(mtmp));
453         if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
454 /*JP
455             You("seem no deader than before.");
456 */
457             You("\82±\82ê\88È\8fã\8e\80\82Ë\82È\82¢\82æ\82¤\82¾\81D");
458         } else if (!Antimagic && rn2(mtmp->m_lev) > 12) {
459             if (Hallucination) {
460 /*JP
461                 You("have an out of body experience.");
462 */
463                 You("\97H\91Ì\97£\92E\82ð\91Ì\8c±\82µ\82½\81D");
464             } else {
465                 killer.format = KILLED_BY_AN;
466 /*JP
467                 Strcpy(killer.name, "touch of death");
468 */
469                 Strcpy(killer.name, "\8e\80\82Ì\90é\8d\90\82Å");
470                 done(DIED);
471             }
472         } else {
473             if (Antimagic)
474                 shieldeff(u.ux, u.uy);
475 /*JP
476             pline("Lucky for you, it didn't work!");
477 */
478             pline("\89^\82Ì\82æ\82¢\82±\82Æ\82É\82È\82ñ\82Æ\82à\82È\82©\82Á\82½\81I");
479         }
480         dmg = 0;
481         break;
482     case MGC_CLONE_WIZ:
483         if (mtmp->iswiz && context.no_of_wizards == 1) {
484 /*JP
485             pline("Double Trouble...");
486 */
487             pline("\93ñ\8fd\8bê\82¾\81D\81D\81D");
488             clonewiz();
489             dmg = 0;
490         } else
491             impossible("bad wizard cloning?");
492         break;
493     case MGC_SUMMON_MONS: {
494 #if 0 /*JP*/
495         int count;
496
497         count = nasty(mtmp); /* summon something nasty */
498 #endif
499         if (mtmp->iswiz)
500 /*JP
501             verbalize("Destroy the thief, my pet%s!", plur(count));
502 */
503             verbalize("\93\90\91¯\82ð\8eE\82¹\81I\89ä\82ª\89º\96l\82æ\81I");
504         else {
505 #if 0 /*JP*/
506             const char *mappear =
507                 (count == 1) ? "A monster appears" : "Monsters appear";
508 #endif
509
510             /* messages not quite right if plural monsters created but
511                only a single monster is seen */
512             if (Invisible && !perceives(mtmp->data)
513                 && (mtmp->mux != u.ux || mtmp->muy != u.uy))
514 #if 0 /*JP*/
515                 pline("%s around a spot near you!", mappear);
516 #else
517                 pline("\89ö\95¨\82ª\82 \82È\82½\82Ì\82·\82®\82»\82Î\82É\8c»\82ê\82½\81I");
518 #endif
519             else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
520 #if 0 /*JP*/
521                 pline("%s around your displaced image!", mappear);
522 #else
523                 pline("\89ö\95¨\82ª\82 \82È\82½\82Ì\8c\89e\82Ì\82·\82®\82»\82Î\82É\8c»\82ê\82½\81I");
524 #endif
525             else
526 #if 0 /*JP*/
527                 pline("%s from nowhere!", mappear);
528 #else
529                 pline("\89ö\95¨\82ª\82Ç\82±\82©\82ç\82Æ\82à\82È\82­\8c»\82ê\82½\81I");
530 #endif
531         }
532         dmg = 0;
533         break;
534     }
535     case MGC_AGGRAVATION:
536 /*JP
537         You_feel("that monsters are aware of your presence.");
538 */
539         You_feel("\89ö\95¨\82½\82¿\82ª\82 \82È\82½\82Ì\91\8dÝ\82É\8bC\95t\82¢\82½\82æ\82¤\82È\8bC\82ª\82µ\82½\81D");
540         aggravate();
541         dmg = 0;
542         break;
543     case MGC_CURSE_ITEMS:
544 /*JP
545         You_feel("as if you need some help.");
546 */
547         You_feel("\8f\95\82¯\82ª\95K\97v\82È\8bC\82ª\82µ\82½\81D");
548         rndcurse();
549         dmg = 0;
550         break;
551     case MGC_DESTRY_ARMR:
552         if (Antimagic) {
553             shieldeff(u.ux, u.uy);
554 /*JP
555             pline("A field of force surrounds you!");
556 */
557             pline("\95s\8ev\8bc\82È\97Í\82ª\82 \82È\82½\82ð\82Æ\82è\82Ü\82¢\82½\81I");
558         } else if (!destroy_arm(some_armor(&youmonst))) {
559 /*JP
560             Your("skin itches.");
561 */
562             You("\83\80\83Y\83\80\83Y\82µ\82½\81D");
563         }
564         dmg = 0;
565         break;
566     case MGC_WEAKEN_YOU: /* drain strength */
567         if (Antimagic) {
568             shieldeff(u.ux, u.uy);
569 /*JP
570             You_feel("momentarily weakened.");
571 */
572             You_feel("\88ê\8fu\8eã\82­\82È\82Á\82½\82æ\82¤\82È\8bC\82ª\82µ\82½\81D");
573         } else {
574 /*JP
575             You("suddenly feel weaker!");
576 */
577             You("\93Ë\91R\8eã\82­\82È\82Á\82½\82æ\82¤\82È\8bC\82ª\82µ\82½\81D");
578             dmg = mtmp->m_lev - 6;
579             if (Half_spell_damage)
580                 dmg = (dmg + 1) / 2;
581             losestr(rnd(dmg));
582             if (u.uhp < 1)
583                 done_in_by(mtmp, DIED);
584         }
585         dmg = 0;
586         break;
587     case MGC_DISAPPEAR: /* makes self invisible */
588         if (!mtmp->minvis && !mtmp->invis_blkd) {
589             if (canseemon(mtmp))
590 #if 0 /*JP*/
591                 pline("%s suddenly %s!", Monnam(mtmp),
592                       !See_invisible ? "disappears" : "becomes transparent");
593 #else
594                 pline("%s\82Í\93Ë\91R%s\81I", Monnam(mtmp),
595                       !See_invisible ? "\8fÁ\82¦\82½" : "\93§\96¾\82É\82È\82Á\82½");
596 #endif
597             mon_set_minvis(mtmp);
598             if (cansee(mtmp->mx, mtmp->my) && !canspotmon(mtmp))
599                 map_invisible(mtmp->mx, mtmp->my);
600             dmg = 0;
601         } else
602             impossible("no reason for monster to cast disappear spell?");
603         break;
604     case MGC_STUN_YOU:
605         if (Antimagic || Free_action) {
606             shieldeff(u.ux, u.uy);
607             if (!Stunned)
608 /*JP
609                 You_feel("momentarily disoriented.");
610 */
611                 You("\88ê\8fu\95û\8cü\8a´\8ao\82ð\8e¸\82Á\82½\81D");
612             make_stunned(1L, FALSE);
613         } else {
614 /*JP
615             You(Stunned ? "struggle to keep your balance." : "reel...");
616 */
617             You(Stunned ? "\83o\83\89\83\93\83X\82ð\8eæ\82ë\82¤\82Æ\82à\82ª\82¢\82½\81D" : "\82æ\82ë\82ß\82¢\82½\81D\81D\81D");
618             dmg = d(ACURR(A_DEX) < 12 ? 6 : 4, 4);
619             if (Half_spell_damage)
620                 dmg = (dmg + 1) / 2;
621             make_stunned((HStun & TIMEOUT) + (long) dmg, FALSE);
622         }
623         dmg = 0;
624         break;
625     case MGC_HASTE_SELF:
626         mon_adjust_speed(mtmp, 1, (struct obj *) 0);
627         dmg = 0;
628         break;
629     case MGC_CURE_SELF:
630         dmg = m_cure_self(mtmp, dmg);
631         break;
632     case MGC_PSI_BOLT:
633         /* prior to 3.4.0 Antimagic was setting the damage to 1--this
634            made the spell virtually harmless to players with magic res. */
635         if (Antimagic) {
636             shieldeff(u.ux, u.uy);
637             dmg = (dmg + 1) / 2;
638         }
639         if (dmg <= 5)
640 /*JP
641             You("get a slight %sache.", body_part(HEAD));
642 */
643             You("\82¿\82å\82Á\82Æ%s\92É\82ª\82µ\82½\81D",body_part(HEAD));
644         else if (dmg <= 10)
645 /*JP
646             Your("brain is on fire!");
647 */
648             You("\93{\82è\82É\82Â\82Â\82Ü\82ê\82½\81I");
649         else if (dmg <= 20)
650 /*JP
651             Your("%s suddenly aches painfully!", body_part(HEAD));
652 */
653             You("\93Ë\91R%s\92É\82É\82¨\82»\82í\82ê\82½\81I", body_part(HEAD));
654         else
655 /*JP
656             Your("%s suddenly aches very painfully!", body_part(HEAD));
657 */
658             You("\93Ë\91R\8c\83\82µ\82¢%s\92É\82É\82¨\82»\82í\82ê\82½\81I", body_part(HEAD));
659         break;
660     default:
661         impossible("mcastu: invalid magic spell (%d)", spellnum);
662         dmg = 0;
663         break;
664     }
665
666     if (dmg)
667         mdamageu(mtmp, dmg);
668 }
669
670 STATIC_OVL
671 void
672 cast_cleric_spell(mtmp, dmg, spellnum)
673 struct monst *mtmp;
674 int dmg;
675 int spellnum;
676 {
677     if (dmg == 0 && !is_undirected_spell(AD_CLRC, spellnum)) {
678         impossible("cast directed cleric spell (%d) with dmg=0?", spellnum);
679         return;
680     }
681
682     switch (spellnum) {
683     case CLC_GEYSER:
684         /* this is physical damage (force not heat),
685          * not magical damage or fire damage
686          */
687 /*JP
688         pline("A sudden geyser slams into you from nowhere!");
689 */
690         pline("\91÷\97¬\82ª\82Ç\82±\82©\82ç\82Æ\82à\82È\82­\8c»\82ê\82Ä\82 \82È\82½\82ð\91Å\82¿\82Â\82¯\82½\81I");
691         dmg = d(8, 6);
692         if (Half_physical_damage)
693             dmg = (dmg + 1) / 2;
694         break;
695     case CLC_FIRE_PILLAR:
696 /*JP
697         pline("A pillar of fire strikes all around you!");
698 */
699         pline("\82 \82È\82½\82Ì\8eü\82è\82É\89Î\92\8c\82ª\97§\82Á\82½\81I");
700         if (Fire_resistance) {
701             shieldeff(u.ux, u.uy);
702             dmg = 0;
703         } else
704             dmg = d(8, 6);
705         if (Half_spell_damage)
706             dmg = (dmg + 1) / 2;
707         burn_away_slime();
708         (void) burnarmor(&youmonst);
709         destroy_item(SCROLL_CLASS, AD_FIRE);
710         destroy_item(POTION_CLASS, AD_FIRE);
711         destroy_item(SPBOOK_CLASS, AD_FIRE);
712         (void) burn_floor_objects(u.ux, u.uy, TRUE, FALSE);
713         break;
714     case CLC_LIGHTNING: {
715         boolean reflects;
716
717 /*JP
718         pline("A bolt of lightning strikes down at you from above!");
719 */
720         pline("\82 \82È\82½\82Ì\90^\8fã\82©\82ç\88î\8dÈ\82ª\8d~\82è\92\8d\82¢\82¾\81I");
721 /*JP
722         reflects = ureflects("It bounces off your %s%s.", "");
723 */
724         reflects = ureflects("\82»\82ê\82Í\82 \82È\82½\82Ì%s%s\82Å\92µ\82Ë\95Ô\82Á\82½\81D", "");
725         if (reflects || Shock_resistance) {
726             shieldeff(u.ux, u.uy);
727             dmg = 0;
728             if (reflects)
729                 break;
730         } else
731             dmg = d(8, 6);
732         if (Half_spell_damage)
733             dmg = (dmg + 1) / 2;
734         destroy_item(WAND_CLASS, AD_ELEC);
735         destroy_item(RING_CLASS, AD_ELEC);
736         (void) flashburn((long) rnd(100));
737         break;
738     }
739     case CLC_CURSE_ITEMS:
740 /*JP
741         You_feel("as if you need some help.");
742 */
743         You_feel("\8f\95\82¯\82ª\95K\97v\82È\8bC\82ª\82µ\82½\81D");
744         rndcurse();
745         dmg = 0;
746         break;
747     case CLC_INSECTS: {
748         /* Try for insects, and if there are none
749            left, go for (sticks to) snakes.  -3. */
750         struct permonst *pm = mkclass(S_ANT, 0);
751         struct monst *mtmp2 = (struct monst *) 0;
752         char let = (pm ? S_ANT : S_SNAKE);
753         boolean success = FALSE, seecaster;
754         int i, quan, oldseen, newseen;
755         coord bypos;
756         const char *fmt;
757
758         oldseen = monster_census(TRUE);
759         quan = (mtmp->m_lev < 2) ? 1 : rnd((int) mtmp->m_lev / 2);
760         if (quan < 3)
761             quan = 3;
762         for (i = 0; i <= quan; i++) {
763             if (!enexto(&bypos, mtmp->mux, mtmp->muy, mtmp->data))
764                 break;
765             if ((pm = mkclass(let, 0)) != 0
766                 && (mtmp2 = makemon(pm, bypos.x, bypos.y, MM_ANGRY)) != 0) {
767                 success = TRUE;
768                 mtmp2->msleeping = mtmp2->mpeaceful = mtmp2->mtame = 0;
769                 set_malign(mtmp2);
770             }
771         }
772         newseen = monster_census(TRUE);
773
774         /* not canspotmon(), which includes unseen things sensed via warning
775          */
776         seecaster = canseemon(mtmp) || tp_sensemon(mtmp) || Detect_monsters;
777
778         fmt = 0;
779         if (!seecaster) {
780             char *arg; /* [not const: upstart(N==1 ? an() : makeplural())] */
781 /*JP
782             const char *what = (let == S_SNAKE) ? "snake" : "insect";
783 */
784             const char *what = (let == S_SNAKE) ? "\83w\83r" : "\92\8e";
785
786             if (newseen <= oldseen || Unaware) {
787                 /* unseen caster fails or summons unseen critters,
788                    or unconscious hero ("You dream that you hear...") */
789 /*JP
790                 You_hear("someone summoning %s.", makeplural(what));
791 */
792                 You_hear("\92N\82©\82ª%s\82ð\8f¢\8a«\82µ\82Ä\82¢\82é\82Ì\82ð\95·\82¢\82½\81D", what);
793             } else {
794                 /* unseen caster summoned seen critter(s) */
795                 arg = (newseen == oldseen + 1) ? an(what) : makeplural(what);
796                 if (!Deaf)
797 #if 0 /*JP*/
798                     You_hear("someone summoning something, and %s %s.", arg,
799                              vtense(arg, "appear"));
800 #else
801                     You_hear("\92N\82©\82ª\89½\82©\82ð\8f¢\8a«\82·\82é\82Ì\82ð\95·\82¢\82½\81C\82»\82µ\82Ä%s\82ª\8c»\82ê\82½\81D",
802                              arg);
803 #endif
804                 else
805 /*JP
806                     pline("%s %s.", upstart(arg), vtense(arg, "appear"));
807 */
808                     pline("%s\82ª\8c»\82ê\82½\81D", arg);
809             }
810
811             /* seen caster, possibly producing unseen--or just one--critters;
812                hero is told what the caster is doing and doesn't necessarily
813                observe complete accuracy of that caster's results (in other
814                words, no need to fuss with visibility or singularization;
815                player is told what's happening even if hero is unconscious) */
816         } else if (!success)
817 /*JP
818             fmt = "%s casts at a clump of sticks, but nothing happens.";
819 */
820             fmt = "%s\82Í\96_\90Ø\82ê\82É\96\82\96@\82ð\82©\82¯\82½\82ª\81C\82È\82É\82à\82¨\82±\82ç\82È\82©\82Á\82½\81D";
821         else if (let == S_SNAKE)
822 /*JP
823             fmt = "%s transforms a clump of sticks into snakes!";
824 */
825             fmt = "%s\82Í\96_\90Ø\82ê\82ð\83w\83r\82É\95Ï\82¦\82½\81I";
826         else if (Invisible && !perceives(mtmp->data)
827                  && (mtmp->mux != u.ux || mtmp->muy != u.uy))
828 /*JP
829             fmt = "%s summons insects around a spot near you!";
830 */
831             fmt = "%s\82Í\92\8e\82ð\82 \82È\82½\82Ì\82·\82®\82»\82Î\82É\8f¢\8a«\82µ\82½\81I";
832         else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
833 /*JP
834             fmt = "%s summons insects around your displaced image!";
835 */
836             fmt = "%s\82Í\92\8e\82ð\82 \82È\82½\82Ì\8c\89e\82Ì\8eü\82è\82É\8f¢\8a«\82µ\82½\81I";
837         else
838 /*JP
839             fmt = "%s summons insects!";
840 */
841             fmt = "%s\82Í\92\8e\82ð\8f¢\8a«\82µ\82½\81I";
842         if (fmt)
843             pline(fmt, Monnam(mtmp));
844
845         dmg = 0;
846         break;
847     }
848     case CLC_BLIND_YOU:
849         /* note: resists_blnd() doesn't apply here */
850         if (!Blinded) {
851 #if 0 /*JP*/
852             int num_eyes = eyecount(youmonst.data);
853             pline("Scales cover your %s!", (num_eyes == 1)
854                                                ? body_part(EYE)
855                                                : makeplural(body_part(EYE)));
856 #else
857             pline("\97Ø\82ª\82 \82È\82½\82Ì%s\82ð\95¢\82Á\82½\81I", body_part(EYE));
858 #endif
859             make_blinded(Half_spell_damage ? 100L : 200L, FALSE);
860             if (!Blind)
861                 Your1(vision_clears);
862             dmg = 0;
863         } else
864             impossible("no reason for monster to cast blindness spell?");
865         break;
866     case CLC_PARALYZE:
867         if (Antimagic || Free_action) {
868             shieldeff(u.ux, u.uy);
869             if (multi >= 0)
870 /*JP
871                 You("stiffen briefly.");
872 */
873                 You("\88ê\8fu\8dd\92¼\82µ\82½\81D");
874             nomul(-1);
875 /*JP
876             multi_reason = "paralyzed by a monster";
877 */
878             multi_reason = "\89ö\95¨\82É\96\83á\83\82³\82¹\82ç\82ê\82½\8c\84\82É";
879         } else {
880             if (multi >= 0)
881 /*JP
882                 You("are frozen in place!");
883 */
884                 You("\82»\82Ì\8fê\82Å\93®\82¯\82È\82­\82È\82Á\82½\81I");
885             dmg = 4 + (int) mtmp->m_lev;
886             if (Half_spell_damage)
887                 dmg = (dmg + 1) / 2;
888             nomul(-dmg);
889 /*JP
890             multi_reason = "paralyzed by a monster";
891 */
892             multi_reason = "\89ö\95¨\82É\96\83á\83\82³\82¹\82ç\82ê\82½\8c\84\82É";
893         }
894         nomovemsg = 0;
895         dmg = 0;
896         break;
897     case CLC_CONFUSE_YOU:
898         if (Antimagic) {
899             shieldeff(u.ux, u.uy);
900 /*JP
901             You_feel("momentarily dizzy.");
902 */
903             You("\88ê\8fu\82ß\82Ü\82¢\82ª\82µ\82½\81D");
904         } else {
905             boolean oldprop = !!Confusion;
906
907             dmg = (int) mtmp->m_lev;
908             if (Half_spell_damage)
909                 dmg = (dmg + 1) / 2;
910             make_confused(HConfusion + dmg, TRUE);
911             if (Hallucination)
912 /*JP
913                 You_feel("%s!", oldprop ? "trippier" : "trippy");
914 */
915                 You("%s\82Ö\82ë\82Ö\82ë\82É\82È\82Á\82½\81I", oldprop ? "\82à\82Á\82Æ" : "");
916             else
917 /*JP
918                 You_feel("%sconfused!", oldprop ? "more " : "");
919 */
920                 You("%s\8d¬\97\90\82µ\82½\81I", oldprop ? "\82à\82Á\82Æ" : "");
921         }
922         dmg = 0;
923         break;
924     case CLC_CURE_SELF:
925         dmg = m_cure_self(mtmp, dmg);
926         break;
927     case CLC_OPEN_WOUNDS:
928         if (Antimagic) {
929             shieldeff(u.ux, u.uy);
930             dmg = (dmg + 1) / 2;
931         }
932         if (dmg <= 5)
933 /*JP
934             Your("skin itches badly for a moment.");
935 */
936             Your("\94ç\95\86\82Í\88ê\8fu\81C\83\80\83Y\83\80\83Y\82Á\82Æ\82µ\82½\81D");
937         else if (dmg <= 10)
938 /*JP
939             pline("Wounds appear on your body!");
940 */
941             pline("\8f\9d\82ª\82 \82È\82½\82Ì\91Ì\82É\8fo\97\88\82½\81I");
942         else if (dmg <= 20)
943 /*JP
944             pline("Severe wounds appear on your body!");
945 */
946             pline("\82Ð\82Ç\82¢\8f\9d\82ª\82 \82È\82½\82Ì\91Ì\82É\8fo\97\88\82½\81I");
947         else
948 /*JP
949             Your("body is covered with painful wounds!");
950 */
951             pline("\91Ì\82ª\8f\9d\82¾\82ç\82¯\82É\82È\82Á\82½\81I");
952         break;
953     default:
954         impossible("mcastu: invalid clerical spell (%d)", spellnum);
955         dmg = 0;
956         break;
957     }
958
959     if (dmg)
960         mdamageu(mtmp, dmg);
961 }
962
963 STATIC_DCL
964 boolean
965 is_undirected_spell(adtyp, spellnum)
966 unsigned int adtyp;
967 int spellnum;
968 {
969     if (adtyp == AD_SPEL) {
970         switch (spellnum) {
971         case MGC_CLONE_WIZ:
972         case MGC_SUMMON_MONS:
973         case MGC_AGGRAVATION:
974         case MGC_DISAPPEAR:
975         case MGC_HASTE_SELF:
976         case MGC_CURE_SELF:
977             return TRUE;
978         default:
979             break;
980         }
981     } else if (adtyp == AD_CLRC) {
982         switch (spellnum) {
983         case CLC_INSECTS:
984         case CLC_CURE_SELF:
985             return TRUE;
986         default:
987             break;
988         }
989     }
990     return FALSE;
991 }
992
993 /* Some spells are useless under some circumstances. */
994 STATIC_DCL
995 boolean
996 spell_would_be_useless(mtmp, adtyp, spellnum)
997 struct monst *mtmp;
998 unsigned int adtyp;
999 int spellnum;
1000 {
1001     /* Some spells don't require the player to really be there and can be cast
1002      * by the monster when you're invisible, yet still shouldn't be cast when
1003      * the monster doesn't even think you're there.
1004      * This check isn't quite right because it always uses your real position.
1005      * We really want something like "if the monster could see mux, muy".
1006      */
1007     boolean mcouldseeu = couldsee(mtmp->mx, mtmp->my);
1008
1009     if (adtyp == AD_SPEL) {
1010         /* aggravate monsters, etc. won't be cast by peaceful monsters */
1011         if (mtmp->mpeaceful
1012             && (spellnum == MGC_AGGRAVATION || spellnum == MGC_SUMMON_MONS
1013                 || spellnum == MGC_CLONE_WIZ))
1014             return TRUE;
1015         /* haste self when already fast */
1016         if (mtmp->permspeed == MFAST && spellnum == MGC_HASTE_SELF)
1017             return TRUE;
1018         /* invisibility when already invisible */
1019         if ((mtmp->minvis || mtmp->invis_blkd) && spellnum == MGC_DISAPPEAR)
1020             return TRUE;
1021         /* peaceful monster won't cast invisibility if you can't see
1022            invisible,
1023            same as when monsters drink potions of invisibility.  This doesn't
1024            really make a lot of sense, but lets the player avoid hitting
1025            peaceful monsters by mistake */
1026         if (mtmp->mpeaceful && !See_invisible && spellnum == MGC_DISAPPEAR)
1027             return TRUE;
1028         /* healing when already healed */
1029         if (mtmp->mhp == mtmp->mhpmax && spellnum == MGC_CURE_SELF)
1030             return TRUE;
1031         /* don't summon monsters if it doesn't think you're around */
1032         if (!mcouldseeu && (spellnum == MGC_SUMMON_MONS
1033                             || (!mtmp->iswiz && spellnum == MGC_CLONE_WIZ)))
1034             return TRUE;
1035         if ((!mtmp->iswiz || context.no_of_wizards > 1)
1036             && spellnum == MGC_CLONE_WIZ)
1037             return TRUE;
1038         /* aggravation (global wakeup) when everyone is already active */
1039         if (spellnum == MGC_AGGRAVATION) {
1040             /* if nothing needs to be awakened then this spell is useless
1041                but caster might not realize that [chance to pick it then
1042                must be very small otherwise caller's many retry attempts
1043                will eventually end up picking it too often] */
1044             if (!has_aggravatables(mtmp))
1045                 return rn2(100) ? TRUE : FALSE;
1046         }
1047     } else if (adtyp == AD_CLRC) {
1048         /* summon insects/sticks to snakes won't be cast by peaceful monsters
1049          */
1050         if (mtmp->mpeaceful && spellnum == CLC_INSECTS)
1051             return TRUE;
1052         /* healing when already healed */
1053         if (mtmp->mhp == mtmp->mhpmax && spellnum == CLC_CURE_SELF)
1054             return TRUE;
1055         /* don't summon insects if it doesn't think you're around */
1056         if (!mcouldseeu && spellnum == CLC_INSECTS)
1057             return TRUE;
1058         /* blindness spell on blinded player */
1059         if (Blinded && spellnum == CLC_BLIND_YOU)
1060             return TRUE;
1061     }
1062     return FALSE;
1063 }
1064
1065 /* convert 1..10 to 0..9; add 10 for second group (spell casting) */
1066 #define ad_to_typ(k) (10 + (int) k - 1)
1067
1068 /* monster uses spell (ranged) */
1069 int
1070 buzzmu(mtmp, mattk)
1071 register struct monst *mtmp;
1072 register struct attack *mattk;
1073 {
1074     /* don't print constant stream of curse messages for 'normal'
1075        spellcasting monsters at range */
1076     if (mattk->adtyp > AD_SPC2)
1077         return (0);
1078
1079     if (mtmp->mcan) {
1080         cursetxt(mtmp, FALSE);
1081         return (0);
1082     }
1083     if (lined_up(mtmp) && rn2(3)) {
1084         nomul(0);
1085         if (mattk->adtyp && (mattk->adtyp < 11)) { /* no cf unsigned >0 */
1086             if (canseemon(mtmp))
1087 #if 0 /*JP*/
1088                 pline("%s zaps you with a %s!", Monnam(mtmp),
1089                       flash_types[ad_to_typ(mattk->adtyp)]);
1090 #else
1091                 pline("%s\82Í%s\82ð\82 \82È\82½\82É\8cü\82¯\82Ä\95ú\82Á\82½\81D", Monnam(mtmp),
1092                       flash_types[ad_to_typ(mattk->adtyp)]);
1093 #endif
1094             buzz(-ad_to_typ(mattk->adtyp), (int) mattk->damn, mtmp->mx,
1095                  mtmp->my, sgn(tbx), sgn(tby));
1096         } else
1097             impossible("Monster spell %d cast", mattk->adtyp - 1);
1098     }
1099     return (1);
1100 }
1101
1102 /*mcastu.c*/