OSDN Git Service

update year to 2020
[jnethack/source.git] / src / wizard.c
1 /* NetHack 3.6  wizard.c        $NHDT-Date: 1561336025 2019/06/24 00:27:05 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.56 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Robert Patrick Rankin, 2016. */
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-2020            */
9 /* JNetHack may be freely redistributed.  See license for details. */
10
11 /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
12 /*             - heavily modified to give the wiz balls.  (genat!mike)   */
13 /*             - dewimped and given some maledictions. -3. */
14 /*             - generalized for 3.1 (mike@bullns.on01.bull.ca) */
15
16 #include "hack.h"
17 #include "qtext.h"
18
19 STATIC_DCL short FDECL(which_arti, (int));
20 STATIC_DCL boolean FDECL(mon_has_arti, (struct monst *, SHORT_P));
21 STATIC_DCL struct monst *FDECL(other_mon_has_arti, (struct monst *, SHORT_P));
22 STATIC_DCL struct obj *FDECL(on_ground, (SHORT_P));
23 STATIC_DCL boolean FDECL(you_have, (int));
24 STATIC_DCL unsigned long FDECL(target_on, (int, struct monst *));
25 STATIC_DCL unsigned long FDECL(strategy, (struct monst *));
26
27 /* adding more neutral creatures will tend to reduce the number of monsters
28    summoned by nasty(); adding more lawful creatures will reduce the number
29    of monsters summoned by lawfuls; adding more chaotic creatures will reduce
30    the number of monsters summoned by chaotics; prior to 3.6.1, there were
31    only four lawful candidates, so lawful summoners tended to summon more
32    (trying to get lawful or neutral but obtaining chaotic instead) than
33    their chaotic counterparts */
34 static NEARDATA const int nasties[] = {
35     /* neutral */
36     PM_COCKATRICE, PM_ETTIN, PM_STALKER, PM_MINOTAUR,
37     PM_OWLBEAR, PM_PURPLE_WORM, PM_XAN, PM_UMBER_HULK,
38     PM_XORN, PM_ZRUTY, PM_LEOCROTTA, PM_BALUCHITHERIUM,
39     PM_CARNIVOROUS_APE, PM_FIRE_ELEMENTAL, PM_JABBERWOCK,
40     PM_IRON_GOLEM, PM_OCHRE_JELLY, PM_GREEN_SLIME,
41     /* chaotic */
42     PM_BLACK_DRAGON, PM_RED_DRAGON, PM_ARCH_LICH, PM_VAMPIRE_LORD,
43     PM_MASTER_MIND_FLAYER, PM_DISENCHANTER, PM_WINGED_GARGOYLE,
44     PM_STORM_GIANT, PM_OLOG_HAI, PM_ELF_LORD, PM_ELVENKING,
45     PM_OGRE_KING, PM_CAPTAIN, PM_GREMLIN,
46     /* lawful */
47     PM_SILVER_DRAGON, PM_ORANGE_DRAGON, PM_GREEN_DRAGON,
48     PM_YELLOW_DRAGON, PM_GUARDIAN_NAGA, PM_FIRE_GIANT,
49     PM_ALEAX, PM_COUATL, PM_HORNED_DEVIL, PM_BARBED_DEVIL,
50     /* (titans, ki-rin, and golden nagas are suitably nasty, but
51        they're summoners so would aggravate excessive summoning) */
52 };
53
54 static NEARDATA const unsigned wizapp[] = {
55     PM_HUMAN,      PM_WATER_DEMON,  PM_VAMPIRE,       PM_RED_DRAGON,
56     PM_TROLL,      PM_UMBER_HULK,   PM_XORN,          PM_XAN,
57     PM_COCKATRICE, PM_FLOATING_EYE, PM_GUARDIAN_NAGA, PM_TRAPPER,
58 };
59
60 /* If you've found the Amulet, make the Wizard appear after some time */
61 /* Also, give hints about portal locations, if amulet is worn/wielded -dlc */
62 void
63 amulet()
64 {
65     struct monst *mtmp;
66     struct trap *ttmp;
67     struct obj *amu;
68
69 #if 0 /* caller takes care of this check */
70     if (!u.uhave.amulet)
71         return;
72 #endif
73     if ((((amu = uamul) != 0 && amu->otyp == AMULET_OF_YENDOR)
74          || ((amu = uwep) != 0 && amu->otyp == AMULET_OF_YENDOR))
75         && !rn2(15)) {
76         for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) {
77             if (ttmp->ttyp == MAGIC_PORTAL) {
78                 int du = distu(ttmp->tx, ttmp->ty);
79                 if (du <= 9)
80 /*JP
81                     pline("%s hot!", Tobjnam(amu, "feel"));
82 */
83                     pline("%s\82Í\94M\82­\8a´\82\82½\81I", xname(amu));
84                 else if (du <= 64)
85 /*JP
86                     pline("%s very warm.", Tobjnam(amu, "feel"));
87 */
88                     pline("%s\82Í\82Æ\82Ä\82à\92g\82©\82­\8a´\82\82½\81D", xname(amu));
89                 else if (du <= 144)
90 /*JP
91                     pline("%s warm.", Tobjnam(amu, "feel"));
92 */
93                     pline("%s\82Í\92g\82©\82­\8a´\82\82½\81D", xname(amu));
94                 /* else, the amulet feels normal */
95                 break;
96             }
97         }
98     }
99
100     if (!context.no_of_wizards)
101         return;
102     /* find Wizard, and wake him if necessary */
103     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
104         if (DEADMONSTER(mtmp))
105             continue;
106         if (mtmp->iswiz && mtmp->msleeping && !rn2(40)) {
107             mtmp->msleeping = 0;
108             if (distu(mtmp->mx, mtmp->my) > 2)
109                 You(
110 /*JP
111       "get the creepy feeling that somebody noticed your taking the Amulet.");
112 */
113       "\82 \82È\82½\82ª\96\82\8f\9c\82¯\82ð\8e\9d\82Á\82Ä\82¢\82é\82±\82Æ\82ª\92N\82©\82É\92m\82ç\82ê\82½\82Æ\8a´\82\82Ä\82¼\82Á\82Æ\82µ\82½\81D");
114             return;
115         }
116     }
117 }
118
119 int
120 mon_has_amulet(mtmp)
121 register struct monst *mtmp;
122 {
123     register struct obj *otmp;
124
125     for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
126         if (otmp->otyp == AMULET_OF_YENDOR)
127             return 1;
128     return 0;
129 }
130
131 int
132 mon_has_special(mtmp)
133 register struct monst *mtmp;
134 {
135     register struct obj *otmp;
136
137     for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
138         if (otmp->otyp == AMULET_OF_YENDOR
139             || any_quest_artifact(otmp)
140             || otmp->otyp == BELL_OF_OPENING
141             || otmp->otyp == CANDELABRUM_OF_INVOCATION
142             || otmp->otyp == SPE_BOOK_OF_THE_DEAD)
143             return 1;
144     return 0;
145 }
146
147 /*
148  *      New for 3.1  Strategy / Tactics for the wiz, as well as other
149  *      monsters that are "after" something (defined via mflag3).
150  *
151  *      The strategy section decides *what* the monster is going
152  *      to attempt, the tactics section implements the decision.
153  */
154 #define STRAT(w, x, y, typ)                            \
155     ((unsigned long) (w) | ((unsigned long) (x) << 16) \
156      | ((unsigned long) (y) << 8) | (unsigned long) (typ))
157
158 #define M_Wants(mask) (mtmp->data->mflags3 & (mask))
159
160 STATIC_OVL short
161 which_arti(mask)
162 register int mask;
163 {
164     switch (mask) {
165     case M3_WANTSAMUL:
166         return AMULET_OF_YENDOR;
167     case M3_WANTSBELL:
168         return BELL_OF_OPENING;
169     case M3_WANTSCAND:
170         return CANDELABRUM_OF_INVOCATION;
171     case M3_WANTSBOOK:
172         return SPE_BOOK_OF_THE_DEAD;
173     default:
174         break; /* 0 signifies quest artifact */
175     }
176     return 0;
177 }
178
179 /*
180  *      If "otyp" is zero, it triggers a check for the quest_artifact,
181  *      since bell, book, candle, and amulet are all objects, not really
182  *      artifacts right now.  [MRS]
183  */
184 STATIC_OVL boolean
185 mon_has_arti(mtmp, otyp)
186 register struct monst *mtmp;
187 register short otyp;
188 {
189     register struct obj *otmp;
190
191     for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) {
192         if (otyp) {
193             if (otmp->otyp == otyp)
194                 return 1;
195         } else if (any_quest_artifact(otmp))
196             return 1;
197     }
198     return 0;
199 }
200
201 STATIC_OVL struct monst *
202 other_mon_has_arti(mtmp, otyp)
203 register struct monst *mtmp;
204 register short otyp;
205 {
206     register struct monst *mtmp2;
207
208     for (mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon)
209         /* no need for !DEADMONSTER check here since they have no inventory */
210         if (mtmp2 != mtmp)
211             if (mon_has_arti(mtmp2, otyp))
212                 return mtmp2;
213
214     return (struct monst *) 0;
215 }
216
217 STATIC_OVL struct obj *
218 on_ground(otyp)
219 register short otyp;
220 {
221     register struct obj *otmp;
222
223     for (otmp = fobj; otmp; otmp = otmp->nobj)
224         if (otyp) {
225             if (otmp->otyp == otyp)
226                 return otmp;
227         } else if (any_quest_artifact(otmp))
228             return otmp;
229     return (struct obj *) 0;
230 }
231
232 STATIC_OVL boolean
233 you_have(mask)
234 register int mask;
235 {
236     switch (mask) {
237     case M3_WANTSAMUL:
238         return (boolean) u.uhave.amulet;
239     case M3_WANTSBELL:
240         return (boolean) u.uhave.bell;
241     case M3_WANTSCAND:
242         return (boolean) u.uhave.menorah;
243     case M3_WANTSBOOK:
244         return (boolean) u.uhave.book;
245     case M3_WANTSARTI:
246         return (boolean) u.uhave.questart;
247     default:
248         break;
249     }
250     return 0;
251 }
252
253 STATIC_OVL unsigned long
254 target_on(mask, mtmp)
255 register int mask;
256 register struct monst *mtmp;
257 {
258     register short otyp;
259     register struct obj *otmp;
260     register struct monst *mtmp2;
261
262     if (!M_Wants(mask))
263         return (unsigned long) STRAT_NONE;
264
265     otyp = which_arti(mask);
266     if (!mon_has_arti(mtmp, otyp)) {
267         if (you_have(mask))
268             return STRAT(STRAT_PLAYER, u.ux, u.uy, mask);
269         else if ((otmp = on_ground(otyp)))
270             return STRAT(STRAT_GROUND, otmp->ox, otmp->oy, mask);
271         else if ((mtmp2 = other_mon_has_arti(mtmp, otyp)) != 0
272                  /* when seeking the Amulet, avoid targetting the Wizard
273                     or temple priests (to protect Moloch's high priest) */
274                  && (otyp != AMULET_OF_YENDOR
275                      || (!mtmp2->iswiz && !inhistemple(mtmp2))))
276             return STRAT(STRAT_MONSTR, mtmp2->mx, mtmp2->my, mask);
277     }
278     return (unsigned long) STRAT_NONE;
279 }
280
281 STATIC_OVL unsigned long
282 strategy(mtmp)
283 register struct monst *mtmp;
284 {
285     unsigned long strat, dstrat;
286
287     if (!is_covetous(mtmp->data)
288         /* perhaps a shopkeeper has been polymorphed into a master
289            lich; we don't want it teleporting to the stairs to heal
290            because that will leave its shop untended */
291         || (mtmp->isshk && inhishop(mtmp))
292         /* likewise for temple priests */
293         || (mtmp->ispriest && inhistemple(mtmp)))
294         return (unsigned long) STRAT_NONE;
295
296     switch ((mtmp->mhp * 3) / mtmp->mhpmax) { /* 0-3 */
297
298     default:
299     case 0: /* panic time - mtmp is almost snuffed */
300         return (unsigned long) STRAT_HEAL;
301
302     case 1: /* the wiz is less cautious */
303         if (mtmp->data != &mons[PM_WIZARD_OF_YENDOR])
304             return (unsigned long) STRAT_HEAL;
305     /* else fall through */
306
307     case 2:
308         dstrat = STRAT_HEAL;
309         break;
310
311     case 3:
312         dstrat = STRAT_NONE;
313         break;
314     }
315
316     if (context.made_amulet)
317         if ((strat = target_on(M3_WANTSAMUL, mtmp)) != STRAT_NONE)
318             return strat;
319
320     if (u.uevent.invoked) { /* priorities change once gate opened */
321         if ((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE)
322             return strat;
323         if ((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE)
324             return strat;
325         if ((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE)
326             return strat;
327         if ((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE)
328             return strat;
329     } else {
330         if ((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE)
331             return strat;
332         if ((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE)
333             return strat;
334         if ((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE)
335             return strat;
336         if ((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE)
337             return strat;
338     }
339     return dstrat;
340 }
341
342 void
343 choose_stairs(sx, sy)
344 xchar *sx;
345 xchar *sy;
346 {
347     xchar x = 0, y = 0;
348
349     if (builds_up(&u.uz)) {
350         if (xdnstair) {
351             x = xdnstair;
352             y = ydnstair;
353         } else if (xdnladder) {
354             x = xdnladder;
355             y = ydnladder;
356         }
357     } else {
358         if (xupstair) {
359             x = xupstair;
360             y = yupstair;
361         } else if (xupladder) {
362             x = xupladder;
363             y = yupladder;
364         }
365     }
366
367     if (!x && sstairs.sx) {
368         x = sstairs.sx;
369         y = sstairs.sy;
370     }
371
372     if (x && y) {
373         *sx = x;
374         *sy = y;
375     }
376 }
377
378 int
379 tactics(mtmp)
380 register struct monst *mtmp;
381 {
382     unsigned long strat = strategy(mtmp);
383     xchar sx = 0, sy = 0, mx, my;
384
385     mtmp->mstrategy =
386         (mtmp->mstrategy & (STRAT_WAITMASK | STRAT_APPEARMSG)) | strat;
387
388     switch (strat) {
389     case STRAT_HEAL: /* hide and recover */
390         mx = mtmp->mx, my = mtmp->my;
391         /* if wounded, hole up on or near the stairs (to block them) */
392         choose_stairs(&sx, &sy);
393         mtmp->mavenge = 1; /* covetous monsters attack while fleeing */
394         if (In_W_tower(mx, my, &u.uz)
395             || (mtmp->iswiz && !sx && !mon_has_amulet(mtmp))) {
396             if (!rn2(3 + mtmp->mhp / 10))
397                 (void) rloc(mtmp, TRUE);
398         } else if (sx && (mx != sx || my != sy)) {
399             if (!mnearto(mtmp, sx, sy, TRUE)) {
400                 /* couldn't move to the target spot for some reason,
401                    so stay where we are (don't actually need rloc_to()
402                    because mtmp is still on the map at <mx,my>... */
403                 rloc_to(mtmp, mx, my);
404                 return 0;
405             }
406             mx = mtmp->mx, my = mtmp->my; /* update cached location */
407         }
408         /* if you're not around, cast healing spells */
409         if (distu(mx, my) > (BOLT_LIM * BOLT_LIM))
410             if (mtmp->mhp <= mtmp->mhpmax - 8) {
411                 mtmp->mhp += rnd(8);
412                 return 1;
413             }
414         /*FALLTHRU*/
415
416     case STRAT_NONE: /* harass */
417         if (!rn2(!mtmp->mflee ? 5 : 33))
418             mnexto(mtmp);
419         return 0;
420
421     default: /* kill, maim, pillage! */
422     {
423         long where = (strat & STRAT_STRATMASK);
424         xchar tx = STRAT_GOALX(strat), ty = STRAT_GOALY(strat);
425         int targ = (int) (strat & STRAT_GOAL);
426         struct obj *otmp;
427
428         if (!targ) { /* simply wants you to close */
429             return 0;
430         }
431         if ((u.ux == tx && u.uy == ty) || where == STRAT_PLAYER) {
432             /* player is standing on it (or has it) */
433             mnexto(mtmp);
434             return 0;
435         }
436         if (where == STRAT_GROUND) {
437             if (!MON_AT(tx, ty) || (mtmp->mx == tx && mtmp->my == ty)) {
438                 /* teleport to it and pick it up */
439                 rloc_to(mtmp, tx, ty); /* clean old pos */
440
441                 if ((otmp = on_ground(which_arti(targ))) != 0) {
442                     if (cansee(mtmp->mx, mtmp->my))
443 #if 0 /*JP:T*/
444                         pline("%s picks up %s.", Monnam(mtmp),
445                               (distu(mtmp->mx, mtmp->my) <= 5)
446                                   ? doname(otmp)
447                                   : distant_name(otmp, doname));
448 #else
449                         pline("%s\82Í%s\82ð\8fE\82Á\82½\81D", Monnam(mtmp),
450                               (distu(mtmp->mx, mtmp->my) <= 5)
451                                   ? doname(otmp)
452                                   : distant_name(otmp, doname));
453 #endif
454                     obj_extract_self(otmp);
455                     (void) mpickobj(mtmp, otmp);
456                     return 1;
457                 } else
458                     return 0;
459             } else {
460                 /* a monster is standing on it - cause some trouble */
461                 if (!rn2(5))
462                     mnexto(mtmp);
463                 return 0;
464             }
465         } else { /* a monster has it - 'port beside it. */
466             mx = mtmp->mx, my = mtmp->my;
467             if (!mnearto(mtmp, tx, ty, FALSE))
468                 rloc_to(mtmp, mx, my); /* no room? stay put */
469             return 0;
470         }
471     } /* default case */
472     } /* switch */
473     /*NOTREACHED*/
474     return 0;
475 }
476
477 /* are there any monsters mon could aggravate? */
478 boolean
479 has_aggravatables(mon)
480 struct monst *mon;
481 {
482     struct monst *mtmp;
483     boolean in_w_tower = In_W_tower(mon->mx, mon->my, &u.uz);
484
485     if (in_w_tower != In_W_tower(u.ux, u.uy, &u.uz))
486         return FALSE;
487
488     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
489         if (DEADMONSTER(mtmp))
490             continue;
491         if (in_w_tower != In_W_tower(mtmp->mx, mtmp->my, &u.uz))
492             continue;
493         if ((mtmp->mstrategy & STRAT_WAITFORU) != 0
494             || mtmp->msleeping || !mtmp->mcanmove)
495             return TRUE;
496     }
497     return FALSE;
498 }
499
500 void
501 aggravate()
502 {
503     register struct monst *mtmp;
504     boolean in_w_tower = In_W_tower(u.ux, u.uy, &u.uz);
505
506     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
507         if (DEADMONSTER(mtmp))
508             continue;
509         if (in_w_tower != In_W_tower(mtmp->mx, mtmp->my, &u.uz))
510             continue;
511         mtmp->mstrategy &= ~(STRAT_WAITFORU | STRAT_APPEARMSG);
512         mtmp->msleeping = 0;
513         if (!mtmp->mcanmove && !rn2(5)) {
514             mtmp->mfrozen = 0;
515             mtmp->mcanmove = 1;
516         }
517     }
518 }
519
520 void
521 clonewiz()
522 {
523     register struct monst *mtmp2;
524
525     if ((mtmp2 = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy, NO_MM_FLAGS))
526         != 0) {
527         mtmp2->msleeping = mtmp2->mtame = mtmp2->mpeaceful = 0;
528         if (!u.uhave.amulet && rn2(2)) { /* give clone a fake */
529             (void) add_to_minv(mtmp2,
530                                mksobj(FAKE_AMULET_OF_YENDOR, TRUE, FALSE));
531         }
532         mtmp2->m_ap_type = M_AP_MONSTER;
533         mtmp2->mappearance = wizapp[rn2(SIZE(wizapp))];
534         newsym(mtmp2->mx, mtmp2->my);
535     }
536 }
537
538 /* also used by newcham() */
539 int
540 pick_nasty()
541 {
542     int res = nasties[rn2(SIZE(nasties))];
543
544     /* To do?  Possibly should filter for appropriate forms when
545      * in the elemental planes or surrounded by water or lava.
546      *
547      * We want monsters represented by uppercase on rogue level,
548      * but we don't try very hard.
549      */
550     if (Is_rogue_level(&u.uz)
551         && !('A' <= mons[res].mlet && mons[res].mlet <= 'Z'))
552         res = nasties[rn2(SIZE(nasties))];
553
554     return res;
555 }
556
557 /* create some nasty monsters, aligned with the caster or neutral; chaotic
558    and unaligned are treated as equivalent; if summoner is Null, this is
559    for late-game harassment (after the Wizard has been killed at least once
560    or the invocation ritual has been performed), in which case we treat
561    'summoner' as neutral, since that will produce the greatest number of
562    creatures on average (in 3.6.0 and earlier, Null was treated as chaotic);
563    returns the number of monsters created */
564 int
565 nasty(summoner)
566 struct monst *summoner;
567 {
568     register struct monst *mtmp;
569     register int i, j;
570     int castalign = (summoner ? sgn(summoner->data->maligntyp) : 0);
571     coord bypos;
572     int count, census, tmp, makeindex, s_cls, m_cls;
573
574 #define MAXNASTIES 10 /* more than this can be created */
575
576     /* some candidates may be created in groups, so simple count
577        of non-null makemon() return is inadequate */
578     census = monster_census(FALSE);
579
580     if (!rn2(10) && Inhell) {
581         /* this might summon a demon prince or lord */
582         count = msummon((struct monst *) 0); /* summons like WoY */
583     } else {
584         count = 0;
585         s_cls = summoner ? summoner->data->mlet : 0;
586         tmp = (u.ulevel > 3) ? u.ulevel / 3 : 1;
587         /* if we don't have a casting monster, nasties appear around hero,
588            otherwise they'll appear around spot summoner thinks she's at */
589         bypos.x = u.ux;
590         bypos.y = u.uy;
591         for (i = rnd(tmp); i > 0 && count < MAXNASTIES; --i)
592             /* Of the 42 nasties[], 10 are lawful, 14 are chaotic,
593              * and 18 are neutral.
594              *
595              * Neutral caster, used for late-game harrassment,
596              * has 18/42 chance to stop the inner loop on each
597              * critter, 24/42 chance for another iteration.
598              * Lawful caster has 28/42 chance to stop unless the
599              * summoner is an angel or demon, in which case the
600              * chance is 26/42.
601              * Chaotic or unaligned caster has 32/42 chance to
602              * stop, so will summon fewer creatures on average.
603              *
604              * The outer loop potentially gives chaotic/unaligned
605              * a chance to even things up since others will hit
606              * MAXNASTIES sooner, but its number of iterations is
607              * randomized so it won't always do so.
608              */
609             for (j = 0; j < 20; j++) {
610                 /* Don't create more spellcasters of the monsters' level or
611                  * higher--avoids chain summoners filling up the level.
612                  */
613                 do {
614                     makeindex = pick_nasty();
615                     m_cls = mons[makeindex].mlet;
616                 } while (summoner
617                          && ((attacktype(&mons[makeindex], AT_MAGC)
618                               && mons[makeindex].difficulty
619                                  >= mons[summoner->mnum].difficulty)
620                              || (s_cls == S_DEMON && m_cls == S_ANGEL)
621                              || (s_cls == S_ANGEL && m_cls == S_DEMON)));
622                 /* do this after picking the monster to place */
623                 if (summoner && !enexto(&bypos, summoner->mux, summoner->muy,
624                                         &mons[makeindex]))
625                     continue;
626                 /* this honors genocide but overrides extinction; it ignores
627                    inside-hell-only (G_HELL) & outside-hell-only (G_NOHELL) */
628                 if ((mtmp = makemon(&mons[makeindex], bypos.x, bypos.y,
629                                     NO_MM_FLAGS)) != 0) {
630                     mtmp->msleeping = mtmp->mpeaceful = mtmp->mtame = 0;
631                     set_malign(mtmp);
632                 } else /* random monster to substitute for geno'd selection */
633                     mtmp = makemon((struct permonst *) 0, bypos.x, bypos.y,
634                                    NO_MM_FLAGS);
635                 if (mtmp) {
636                     /* delay first use of spell or breath attack */
637                     mtmp->mspec_used = rnd(4);
638                     if (++count >= MAXNASTIES
639                         || mtmp->data->maligntyp == 0
640                         || sgn(mtmp->data->maligntyp) == castalign)
641                         break;
642                 }
643             }
644     }
645
646     if (count)
647         count = monster_census(FALSE) - census;
648     return count;
649 }
650
651 /* Let's resurrect the wizard, for some unexpected fun. */
652 void
653 resurrect()
654 {
655     struct monst *mtmp, **mmtmp;
656     long elapsed;
657     const char *verb;
658
659     if (!context.no_of_wizards) {
660         /* make a new Wizard */
661 /*JP
662         verb = "kill";
663 */
664         verb = "\82ð\93¢\82Ä\82µ";
665         mtmp = makemon(&mons[PM_WIZARD_OF_YENDOR], u.ux, u.uy, MM_NOWAIT);
666         /* affects experience; he's not coming back from a corpse
667            but is subject to repeated killing like a revived corpse */
668         if (mtmp) mtmp->mrevived = 1;
669     } else {
670         /* look for a migrating Wizard */
671 /*JP
672         verb = "elude";
673 */
674         verb = "\82æ\82è\93¦\82ê\82ñ";
675         mmtmp = &migrating_mons;
676         while ((mtmp = *mmtmp) != 0) {
677             if (mtmp->iswiz
678                 /* if he has the Amulet, he won't bring it to you */
679                 && !mon_has_amulet(mtmp)
680                 && (elapsed = monstermoves - mtmp->mlstmv) > 0L) {
681                 mon_catchup_elapsed_time(mtmp, elapsed);
682                 if (elapsed >= LARGEST_INT)
683                     elapsed = LARGEST_INT - 1;
684                 elapsed /= 50L;
685                 if (mtmp->msleeping && rn2((int) elapsed + 1))
686                     mtmp->msleeping = 0;
687                 if (mtmp->mfrozen == 1) /* would unfreeze on next move */
688                     mtmp->mfrozen = 0, mtmp->mcanmove = 1;
689                 if (mtmp->mcanmove && !mtmp->msleeping) {
690                     *mmtmp = mtmp->nmon;
691                     mon_arrive(mtmp, TRUE);
692                     /* note: there might be a second Wizard; if so,
693                        he'll have to wait til the next resurrection */
694                     break;
695                 }
696             }
697             mmtmp = &mtmp->nmon;
698         }
699     }
700
701     if (mtmp) {
702         mtmp->mtame = mtmp->mpeaceful = 0; /* paranoia */
703         set_malign(mtmp);
704         if (!Deaf) {
705 /*JP
706             pline("A voice booms out...");
707 */
708             pline("\90º\82ª\8d\82\82­\96Â\82è\8b¿\82¢\82½\81D\81D\81D");
709 /*JP
710             verbalize("So thou thought thou couldst %s me, fool.", verb);
711 */
712             verbalize("\97]%s\82Æ\8ev\82¢\82µ\82©\81C\92s\82ê\8eÒ\82ª\81D", verb);
713         }
714     }
715 }
716
717 /* Here, we make trouble for the poor shmuck who actually
718    managed to do in the Wizard. */
719 void
720 intervene()
721 {
722     int which = Is_astralevel(&u.uz) ? rnd(4) : rn2(6);
723     /* cases 0 and 5 don't apply on the Astral level */
724     switch (which) {
725     case 0:
726     case 1:
727 /*JP
728         You_feel("vaguely nervous.");
729 */
730         You("\89½\82Æ\82È\82­\95s\88À\82É\82È\82Á\82½\81D");
731         break;
732     case 2:
733         if (!Blind)
734 /*JP
735             You("notice a %s glow surrounding you.", hcolor(NH_BLACK));
736 */
737             pline("%s\8cõ\82ª\82 \82È\82½\82ð\82Æ\82è\82Ü\82¢\82Ä\82¢\82é\82Ì\82É\8bC\82ª\82Â\82¢\82½\81D", hcolor(NH_BLACK));
738         rndcurse();
739         break;
740     case 3:
741         aggravate();
742         break;
743     case 4:
744         (void) nasty((struct monst *) 0);
745         break;
746     case 5:
747         resurrect();
748         break;
749     }
750 }
751
752 void
753 wizdead()
754 {
755     context.no_of_wizards--;
756     if (!u.uevent.udemigod) {
757         u.uevent.udemigod = TRUE;
758         u.udg_cnt = rn1(250, 50);
759     }
760 }
761
762 const char *const random_insult[] = {
763 #if 0 /*JP:T*/
764     "antic",      "blackguard",   "caitiff",    "chucklehead",
765     "coistrel",   "craven",       "cretin",     "cur",
766     "dastard",    "demon fodder", "dimwit",     "dolt",
767     "fool",       "footpad",      "imbecile",   "knave",
768     "maledict",   "miscreant",    "niddering",  "poltroon",
769     "rattlepate", "reprobate",    "scapegrace", "varlet",
770     "villein", /* (sic.) */
771     "wittol",     "worm",         "wretch",
772 #else
773     "\82Ó\82´\82¯\82½\96ì\98Y", "\88«\93}",       "\82­\82»\82Á\82½\82ê", "\82Ì\82ë\82Ü",
774     "\82 \82ñ\82Û\82ñ\82½\82ñ", "\89°\95a\8eÒ",     "\94\92\92s",       "\82ë\82­\82Å\82È\82µ",
775     "\82¤\82Â\82¯",       "\88«\96\82\82Ì\89a\90H", "\82¤\82·\82Ì\82ë",   "\82Ü\82Ê\82¯",
776     "\94n\8e­",         "\82¨\82¢\82Í\82¬",   "\8bð\82©\8eÒ",     "\82È\82ç\82¸\8eÒ",
777     "\88«\90l",         "\8bÉ\88«\90l",     "\94n\8e­\82½\82ê",   "\94Ú\8b¯\8eÒ",
778     "\95\97\91D\93ª",       "\93¹\8ay\8eÒ",     "\96ï\89î\8eÒ",     "\89º\98Y",
779     "\93z\97ê", /* (sic.) */
780     "\82Ó\82È\82Þ\82µ",     "åv\92\8e",       "\90l\82Å\82È\82µ",
781 #endif
782 };
783
784 const char *const random_malediction[] = {
785 #if 0 /*JP:T*/
786     "Hell shall soon claim thy remains,", "I chortle at thee, thou pathetic",
787     "Prepare to die, thou", "Resistance is useless,",
788     "Surrender or die, thou", "There shall be no mercy, thou",
789     "Thou shalt repent of thy cunning,", "Thou art as a flea to me,",
790     "Thou art doomed,", "Thy fate is sealed,",
791     "Verily, thou shalt be one dead"
792 #else
793     "\92n\8d\96\82Í\82¢\82Ã\82ê\81C\93ð\82Ì\96S\8a[\82ð\97v\8b\81\82·\82é\82Å\82 \82ë\82¤\81C",
794     "\88£\82ê\82È\82â\82Â\82æ\82Ì\82¤\81D\97]\82Í\96\9e\91«\82\82á",
795     "\93ð\81C\8e\80\82É\94õ\82¦\82æ",
796     "\92ï\8dR\82µ\82Ä\82à\96³\91Ê\82\82á\81C",
797     "\8d~\8eQ\82¹\82æ\81D\82³\82à\82È\82­\82Î\8e\80\82\82á\81D",
798     "\8e\9c\94ß\82Í\96³\82©\82ç\82ñ",
799     "\93ð\81C\82¸\82é\82ð\8cã\89÷\82·\82×\82µ\81C",
800     "\93ð\82Í\97]\82É\82Æ\82Á\82Ä\83m\83~\82Ì\82æ\82¤\82È\82à\82Ì\82\82á\81C",
801     "\93ð\82Í\8eô\82í\82ê\82Ä\82¨\82é\81C",
802     "\93ð\82Ì\89^\96½\82Í\95\95\88ó\82³\82ê\82Ä\82¨\82é\81C",
803     "\82Ü\82±\82Æ\82É\93ð\82Í\8e\80\82É\82½\82é\8eÒ\82È\82è"
804 #endif
805 };
806
807 /* Insult or intimidate the player */
808 void
809 cuss(mtmp)
810 register struct monst *mtmp;
811 {
812     if (Deaf)
813         return;
814     if (mtmp->iswiz) {
815         if (!rn2(5)) /* typical bad guy action */
816 /*JP
817             pline("%s laughs fiendishly.", Monnam(mtmp));
818 */
819             pline("%s\82Í\88«\96\82\82Ì\82æ\82¤\82É\8fÎ\82Á\82½\81D", Monnam(mtmp));
820         else if (u.uhave.amulet && !rn2(SIZE(random_insult)))
821 /*JP
822             verbalize("Relinquish the amulet, %s!",
823 */
824             verbalize("\96\82\82æ\82¯\82ð\8eè\95ú\82¹\81C%s\81I",
825                       random_insult[rn2(SIZE(random_insult))]);
826         else if (u.uhp < 5 && !rn2(2)) /* Panic */
827 #if 0 /*JP:T*/
828             verbalize(rn2(2) ? "Even now thy life force ebbs, %s!"
829                              : "Savor thy breath, %s, it be thy last!",
830                       random_insult[rn2(SIZE(random_insult))]);
831 #else
832             verbalize(rn2(2) ? "\8d¡\82Æ\82È\82Á\82Ä\82à\82È\82¨\93ð\82Ì\96½\82Í\82 \82¦\82Ä\90\8a\82¦\82é\82Ì\82¾\81C%s\81I"
833                              : "\96³\91Ê\82È\82±\82Æ\82ð\82·\82é\82È\81C%s\81C\93ð\82Ì\8dÅ\8aú\82Ì\8e\9e\82¾\81I",
834                       random_insult[rn2(SIZE(random_insult))]);
835 #endif
836         else if (mtmp->mhp < 5 && !rn2(2)) /* Parthian shot */
837 /*JP
838             verbalize(rn2(2) ? "I shall return." : "I'll be back.");
839 */
840             verbalize(rn2(2) ? "\97]\82Í\95K\82¸\8bA\82Á\82Ä\82­\82é\81D" : "\97]\82Í\96ß\82Á\82Ä\82­\82é\81D");
841         else
842 #if 0 /*JP:T*/
843             verbalize("%s %s!",
844                       random_malediction[rn2(SIZE(random_malediction))],
845                       random_insult[rn2(SIZE(random_insult))]);
846 #else
847             verbalize("%s\81C%s\81I",
848                       random_malediction[rn2(SIZE(random_malediction))],
849                       random_insult[rn2(SIZE(random_insult))]);
850 #endif
851     } else if (is_lminion(mtmp)
852                && !(mtmp->isminion && EMIN(mtmp)->renegade)) {
853         com_pager(rn2(QTN_ANGELIC - 1 + (Hallucination ? 1 : 0))
854                   + QT_ANGELIC);
855     } else {
856         if (!rn2(is_minion(mtmp->data) ? 100 : 5))
857 /*JP
858             pline("%s casts aspersions on your ancestry.", Monnam(mtmp));
859 */
860             pline("%s\82Í\82 \82È\82½\82Ì\89Æ\95¿\82ð\92\86\8f\9d\82µ\82½\81D", Monnam(mtmp));
861         else
862             com_pager(rn2(QTN_DEMONIC) + QT_DEMONIC);
863     }
864 }
865
866 /*wizard.c*/