OSDN Git Service

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