OSDN Git Service

fix #36370
[jnethack/source.git] / src / priest.c
1 /* NetHack 3.6  priest.c        $NHDT-Date: 1446892452 2015/11/07 10:34:12 $  $NHDT-Branch: master $:$NHDT-Revision: 1.41 $ */
2 /* Copyright (c) Izchak Miller, Steve Linhart, 1989.              */
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 #include "mfndpos.h"
12
13 /* these match the categorizations shown by enlightenment */
14 #define ALGN_SINNED (-4) /* worse than strayed (-1..-3) */
15 #define ALGN_PIOUS 14    /* better than fervent (9..13) */
16
17 STATIC_DCL boolean FDECL(histemple_at, (struct monst *, XCHAR_P, XCHAR_P));
18 STATIC_DCL boolean FDECL(has_shrine, (struct monst *));
19
20 void
21 newepri(mtmp)
22 struct monst *mtmp;
23 {
24     if (!mtmp->mextra)
25         mtmp->mextra = newmextra();
26     if (!EPRI(mtmp)) {
27         EPRI(mtmp) = (struct epri *) alloc(sizeof(struct epri));
28         (void) memset((genericptr_t) EPRI(mtmp), 0, sizeof(struct epri));
29     }
30 }
31
32 void
33 free_epri(mtmp)
34 struct monst *mtmp;
35 {
36     if (mtmp->mextra && EPRI(mtmp)) {
37         free((genericptr_t) EPRI(mtmp));
38         EPRI(mtmp) = (struct epri *) 0;
39     }
40     mtmp->ispriest = 0;
41 }
42
43 /*
44  * Move for priests and shopkeepers.  Called from shk_move() and pri_move().
45  * Valid returns are  1: moved  0: didn't  -1: let m_move do it  -2: died.
46  */
47 int
48 move_special(mtmp, in_his_shop, appr, uondoor, avoid, omx, omy, gx, gy)
49 register struct monst *mtmp;
50 boolean in_his_shop;
51 schar appr;
52 boolean uondoor, avoid;
53 register xchar omx, omy, gx, gy;
54 {
55     register xchar nx, ny, nix, niy;
56     register schar i;
57     schar chcnt, cnt;
58     coord poss[9];
59     long info[9];
60     long allowflags;
61     struct obj *ib = (struct obj *) 0;
62
63     if (omx == gx && omy == gy)
64         return 0;
65     if (mtmp->mconf) {
66         avoid = FALSE;
67         appr = 0;
68     }
69
70     nix = omx;
71     niy = omy;
72     if (mtmp->isshk)
73         allowflags = ALLOW_SSM;
74     else
75         allowflags = ALLOW_SSM | ALLOW_SANCT;
76     if (passes_walls(mtmp->data))
77         allowflags |= (ALLOW_ROCK | ALLOW_WALL);
78     if (throws_rocks(mtmp->data))
79         allowflags |= ALLOW_ROCK;
80     if (tunnels(mtmp->data))
81         allowflags |= ALLOW_DIG;
82     if (!nohands(mtmp->data) && !verysmall(mtmp->data)) {
83         allowflags |= OPENDOOR;
84         if (monhaskey(mtmp, TRUE))
85             allowflags |= UNLOCKDOOR;
86     }
87     if (is_giant(mtmp->data))
88         allowflags |= BUSTDOOR;
89     cnt = mfndpos(mtmp, poss, info, allowflags);
90
91     if (mtmp->isshk && avoid && uondoor) { /* perhaps we cannot avoid him */
92         for (i = 0; i < cnt; i++)
93             if (!(info[i] & NOTONL))
94                 goto pick_move;
95         avoid = FALSE;
96     }
97
98 #define GDIST(x, y) (dist2(x, y, gx, gy))
99 pick_move:
100     chcnt = 0;
101     for (i = 0; i < cnt; i++) {
102         nx = poss[i].x;
103         ny = poss[i].y;
104         if (IS_ROOM(levl[nx][ny].typ)
105             || (mtmp->isshk && (!in_his_shop || ESHK(mtmp)->following))) {
106             if (avoid && (info[i] & NOTONL))
107                 continue;
108             if ((!appr && !rn2(++chcnt))
109                 || (appr && GDIST(nx, ny) < GDIST(nix, niy))) {
110                 nix = nx;
111                 niy = ny;
112             }
113         }
114     }
115     if (mtmp->ispriest && avoid && nix == omx && niy == omy
116         && onlineu(omx, omy)) {
117         /* might as well move closer as long it's going to stay
118          * lined up */
119         avoid = FALSE;
120         goto pick_move;
121     }
122
123     if (nix != omx || niy != omy) {
124         remove_monster(omx, omy);
125         place_monster(mtmp, nix, niy);
126         newsym(nix, niy);
127         if (mtmp->isshk && !in_his_shop && inhishop(mtmp))
128             check_special_room(FALSE);
129         if (ib) {
130             if (cansee(mtmp->mx, mtmp->my))
131 #if 0 /*JP*/
132                 pline("%s picks up %s.", Monnam(mtmp),
133                       distant_name(ib, doname));
134 #else
135                 pline("%s\82Í%s\82ð\8fE\82Á\82½\81D", Monnam(mtmp),
136                       distant_name(ib, doname));
137 #endif
138             obj_extract_self(ib);
139             (void) mpickobj(mtmp, ib);
140         }
141         return 1;
142     }
143     return 0;
144 }
145
146 char
147 temple_occupied(array)
148 register char *array;
149 {
150     register char *ptr;
151
152     for (ptr = array; *ptr; ptr++)
153         if (rooms[*ptr - ROOMOFFSET].rtype == TEMPLE)
154             return *ptr;
155     return '\0';
156 }
157
158 STATIC_OVL boolean
159 histemple_at(priest, x, y)
160 register struct monst *priest;
161 register xchar x, y;
162 {
163     return (boolean) (priest && priest->ispriest
164                       && (EPRI(priest)->shroom == *in_rooms(x, y, TEMPLE))
165                       && on_level(&(EPRI(priest)->shrlevel), &u.uz));
166 }
167
168 boolean
169 inhistemple(priest)
170 struct monst *priest;
171 {
172     /* make sure we have a priest */
173     if (!priest || !priest->ispriest)
174         return FALSE;
175     /* priest must be on right level and in right room */
176     if (!histemple_at(priest, priest->mx, priest->my))
177         return FALSE;
178     /* temple room must still contain properly aligned altar */
179     return has_shrine(priest);
180 }
181
182 /*
183  * pri_move: return 1: moved  0: didn't  -1: let m_move do it  -2: died
184  */
185 int
186 pri_move(priest)
187 register struct monst *priest;
188 {
189     register xchar gx, gy, omx, omy;
190     schar temple;
191     boolean avoid = TRUE;
192
193     omx = priest->mx;
194     omy = priest->my;
195
196     if (!histemple_at(priest, omx, omy))
197         return -1;
198
199     temple = EPRI(priest)->shroom;
200
201     gx = EPRI(priest)->shrpos.x;
202     gy = EPRI(priest)->shrpos.y;
203
204     gx += rn1(3, -1); /* mill around the altar */
205     gy += rn1(3, -1);
206
207     if (!priest->mpeaceful
208         || (Conflict && !resist(priest, RING_CLASS, 0, 0))) {
209         if (monnear(priest, u.ux, u.uy)) {
210             if (Displaced)
211 /*JP
212                 Your("displaced image doesn't fool %s!", mon_nam(priest));
213 */
214                 Your("\8c\89e\82Í%s\82ð\82¾\82Ü\82¹\82È\82©\82Á\82½\81I", mon_nam(priest));
215             (void) mattacku(priest);
216             return 0;
217         } else if (index(u.urooms, temple)) {
218             /* chase player if inside temple & can see him */
219             if (priest->mcansee && m_canseeu(priest)) {
220                 gx = u.ux;
221                 gy = u.uy;
222             }
223             avoid = FALSE;
224         }
225     } else if (Invis)
226         avoid = FALSE;
227
228     return move_special(priest, FALSE, TRUE, FALSE, avoid, omx, omy, gx, gy);
229 }
230
231 /* exclusively for mktemple() */
232 void
233 priestini(lvl, sroom, sx, sy, sanctum)
234 d_level *lvl;
235 struct mkroom *sroom;
236 int sx, sy;
237 boolean sanctum; /* is it the seat of the high priest? */
238 {
239     struct monst *priest;
240     struct obj *otmp;
241     int cnt;
242
243     if (MON_AT(sx + 1, sy))
244         (void) rloc(m_at(sx + 1, sy), FALSE); /* insurance */
245
246     priest = makemon(&mons[sanctum ? PM_HIGH_PRIEST : PM_ALIGNED_PRIEST],
247                      sx + 1, sy, MM_EPRI);
248     if (priest) {
249         EPRI(priest)->shroom = (schar) ((sroom - rooms) + ROOMOFFSET);
250         EPRI(priest)->shralign = Amask2align(levl[sx][sy].altarmask);
251         EPRI(priest)->shrpos.x = sx;
252         EPRI(priest)->shrpos.y = sy;
253         assign_level(&(EPRI(priest)->shrlevel), lvl);
254         priest->mtrapseen = ~0; /* traps are known */
255         priest->mpeaceful = 1;
256         priest->ispriest = 1;
257         priest->isminion = 0;
258         priest->msleeping = 0;
259         set_malign(priest); /* mpeaceful may have changed */
260
261         /* now his/her goodies... */
262         if (sanctum && EPRI(priest)->shralign == A_NONE
263             && on_level(&sanctum_level, &u.uz)) {
264             (void) mongets(priest, AMULET_OF_YENDOR);
265         }
266         /* 2 to 4 spellbooks */
267         for (cnt = rn1(3, 2); cnt > 0; --cnt) {
268             (void) mpickobj(priest, mkobj(SPBOOK_CLASS, FALSE));
269         }
270         /* robe [via makemon()] */
271         if (rn2(2) && (otmp = which_armor(priest, W_ARMC)) != 0) {
272             if (p_coaligned(priest))
273                 uncurse(otmp);
274             else
275                 curse(otmp);
276         }
277     }
278 }
279
280 /* get a monster's alignment type without caller needing EPRI & EMIN */
281 aligntyp
282 mon_aligntyp(mon)
283 struct monst *mon;
284 {
285     aligntyp algn = mon->ispriest ? EPRI(mon)->shralign
286                                   : mon->isminion ? EMIN(mon)->min_align
287                                                   : mon->data->maligntyp;
288
289     if (algn == A_NONE)
290         return A_NONE; /* negative but differs from chaotic */
291     return (algn > 0) ? A_LAWFUL : (algn < 0) ? A_CHAOTIC : A_NEUTRAL;
292 }
293
294 /*
295  * Specially aligned monsters are named specially.
296  *      - aligned priests with ispriest and high priests have shrines
297  *              they retain ispriest and epri when polymorphed
298  *      - aligned priests without ispriest are roamers
299  *              they have isminion set and use emin rather than epri
300  *      - minions do not have ispriest but have isminion and emin
301  *      - caller needs to inhibit Hallucination if it wants to force
302  *              the true name even when under that influence
303  */
304 char *
305 priestname(mon, pname)
306 register struct monst *mon;
307 char *pname; /* caller-supplied output buffer */
308 {
309     boolean do_hallu = Hallucination,
310             aligned_priest = mon->data == &mons[PM_ALIGNED_PRIEST],
311             high_priest = mon->data == &mons[PM_HIGH_PRIEST];
312     char whatcode = '\0';
313     const char *what = do_hallu ? rndmonnam(&whatcode) : mon->data->mname;
314
315     if (!mon->ispriest && !mon->isminion) /* should never happen...  */
316         return strcpy(pname, what);       /* caller must be confused */
317
318     *pname = '\0';
319 #if 0 /*JP*//*\93ú\96{\8cê\82Å\82Í\95s\97v*/
320     if (!do_hallu || !bogon_is_pname(whatcode))
321         Strcat(pname, "the ");
322 #endif
323     if (mon->minvis)
324 /*JP
325         Strcat(pname, "invisible ");
326 */
327         Strcat(pname, "\93§\96¾\82È");
328     if (mon->isminion && EMIN(mon)->renegade)
329 /*JP
330         Strcat(pname, "renegade ");
331 */
332         Strcat(pname, "\97 \90Ø\82è\8eÒ\82Ì");
333
334     if (mon->ispriest || aligned_priest) { /* high_priest implies ispriest */
335         if (!aligned_priest && !high_priest) {
336             ; /* polymorphed priest; use ``what'' as is */
337         } else {
338             if (high_priest)
339 #if 0 /*JP*/
340                 Strcat(pname, "high ");
341 #else
342                 {
343                     if (Hallucination)
344                         what = "\96³\94\\8d\82\8b\89\8a¯\97»";
345                     else
346                         what = "\96@\89¤";
347                 }
348             else /* \8fã\8bL\82Å\8a®\90¬\82³\82¹\82Ä\81A\88È\89º\82Ì\83R\81[\83h\82Í\92Ê\82ç\82È\82­\82·\82é */
349 #endif
350             if (Hallucination)
351 /*JP
352                 what = "poohbah";
353 */
354                 what = "\96³\94\\8a¯\97»";
355             else if (mon->female)
356 /*JP
357                 what = "priestess";
358 */
359                 what = "\93ò\91m";
360             else
361 /*JP
362                 what = "priest";
363 */
364                 what = "\91m\97µ";
365         }
366     } else {
367 /*JP
368         if (mon->mtame && !strcmpi(what, "Angel"))
369 */
370         if (mon->mtame && !strcmpi(what, "\93V\8eg"))
371 /*JP
372             Strcat(pname, "guardian ");
373 */
374             Strcat(pname, "\8cx\8cì");
375     }
376
377     Strcat(pname, what);
378     /* same as distant_monnam(), more or less... */
379     if (do_hallu || !high_priest || !Is_astralevel(&u.uz)
380         || distu(mon->mx, mon->my) <= 2 || program_state.gameover) {
381 #if 0 /*JP*/
382         Strcat(pname, " of ");
383         Strcat(pname, halu_gname(mon_aligntyp(mon)));
384 #endif
385     }
386     return pname;
387 }
388
389 boolean
390 p_coaligned(priest)
391 struct monst *priest;
392 {
393     return (boolean) (u.ualign.type == mon_aligntyp(priest));
394 }
395
396 STATIC_OVL boolean
397 has_shrine(pri)
398 struct monst *pri;
399 {
400     struct rm *lev;
401     struct epri *epri_p;
402
403     if (!pri || !pri->ispriest)
404         return FALSE;
405     epri_p = EPRI(pri);
406     lev = &levl[epri_p->shrpos.x][epri_p->shrpos.y];
407     if (!IS_ALTAR(lev->typ) || !(lev->altarmask & AM_SHRINE))
408         return FALSE;
409     return (boolean) (epri_p->shralign
410                       == (Amask2align(lev->altarmask & ~AM_SHRINE)));
411 }
412
413 struct monst *
414 findpriest(roomno)
415 char roomno;
416 {
417     register struct monst *mtmp;
418
419     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
420         if (DEADMONSTER(mtmp))
421             continue;
422         if (mtmp->ispriest && (EPRI(mtmp)->shroom == roomno)
423             && histemple_at(mtmp, mtmp->mx, mtmp->my))
424             return mtmp;
425     }
426     return (struct monst *) 0;
427 }
428
429 /* called from check_special_room() when the player enters the temple room */
430 void
431 intemple(roomno)
432 int roomno;
433 {
434     struct monst *priest, *mtmp;
435     struct epri *epri_p;
436     boolean shrined, sanctum, can_speak;
437     long *this_time, *other_time;
438     const char *msg1, *msg2;
439     char buf[BUFSZ];
440
441     /* don't do anything if hero is already in the room */
442     if (temple_occupied(u.urooms0))
443         return;
444
445     if ((priest = findpriest((char) roomno)) != 0) {
446         /* tended */
447
448         epri_p = EPRI(priest);
449         shrined = has_shrine(priest);
450         sanctum = (priest->data == &mons[PM_HIGH_PRIEST]
451                    && (Is_sanctum(&u.uz) || In_endgame(&u.uz)));
452         can_speak = (priest->mcanmove && !priest->msleeping);
453         if (can_speak && !Deaf && moves >= epri_p->intone_time) {
454             unsigned save_priest = priest->ispriest;
455
456             /* don't reveal the altar's owner upon temple entry in
457                the endgame; for the Sanctum, the next message names
458                Moloch so suppress the "of Moloch" for him here too */
459             if (sanctum && !Hallucination)
460                 priest->ispriest = 0;
461 #if 0 /*JP*/
462             pline("%s intones:",
463                   canseemon(priest) ? Monnam(priest) : "A nearby voice");
464 #else
465             pline("%s\82ª\89r\8f¥\82µ\82½\81F",
466                   canseemon(priest) ? Monnam(priest) : "\8bß\82­\82Å\92N\82©");
467 #endif
468             priest->ispriest = save_priest;
469             epri_p->intone_time = moves + (long) d(10, 500); /* ~2505 */
470             /* make sure that we don't suppress entry message when
471                we've just given its "priest intones" introduction */
472             epri_p->enter_time = 0L;
473         }
474         msg1 = msg2 = 0;
475         if (sanctum && Is_sanctum(&u.uz)) {
476             if (priest->mpeaceful) {
477                 /* first time inside */
478 /*JP
479                 msg1 = "Infidel, you have entered Moloch's Sanctum!";
480 */
481                 msg1 = "\88Ù\92[\8eÒ\82æ\81I\82±\82±\82Í\81C\83\82\81[\83\8d\83b\83N\82Ì\90¹\88æ\82¾\81I";
482 /*JP
483                 msg2 = "Be gone!";
484 */
485                 msg2 = "\97§\82¿\82³\82ê\81I";
486                 priest->mpeaceful = 0;
487                 /* became angry voluntarily; no penalty for attacking him */
488                 set_malign(priest);
489             } else {
490                 /* repeat visit, or attacked priest before entering */
491 /*JP
492                 msg1 = "You desecrate this place by your presence!";
493 */
494                 msg1 = "\82¨\82Ü\82¦\82Í\82±\82Ì\90_\90¹\82È\8fê\8f\8a\82ð\89\98\82µ\82Ä\82¢\82é\81I";
495             }
496         } else if (moves >= epri_p->enter_time) {
497 #if 0 /*JP*/
498             Sprintf(buf, "Pilgrim, you enter a %s place!",
499                     !shrined ? "desecrated" : "sacred");
500 #else
501             Sprintf(buf, "\8f\84\97ç\8eÒ\82æ\81C\82¨\82Ü\82¦\82Í%s\92n\82É\82¢\82é\81I",
502                     !shrined ? "\95s\8fò\82Ì" : "\90_\90¹\82È\82é");
503 #endif
504             msg1 = buf;
505         }
506         if (msg1 && can_speak && !Deaf) {
507             verbalize1(msg1);
508             if (msg2)
509                 verbalize1(msg2);
510             epri_p->enter_time = moves + (long) d(10, 100); /* ~505 */
511         }
512         if (!sanctum) {
513             if (!shrined || !p_coaligned(priest)
514                 || u.ualign.record <= ALGN_SINNED) {
515 /*JP
516                 msg1 = "have a%s forbidding feeling...";
517 */
518                 msg1 = "%s\8bß\82Ã\82«\82ª\82½\82¢\8bC\8e\9d\82ª\82µ\82½\81D\81D\81D";
519 /*JP
520                 msg2 = (!shrined || !p_coaligned(priest)) ? "" : " strange";
521 */
522                 msg2 = (!shrined || !p_coaligned(priest)) ? "" : "\8aï\96­\82È";
523                 this_time = &epri_p->hostile_time;
524                 other_time = &epri_p->peaceful_time;
525             } else {
526 /*JP
527                 msg1 = "experience %s sense of peace.";
528 */
529                 msg1 = "%s\96\9e\82¿\91«\82è\82½\8bC\8e\9d\82¿\82É\82È\82Á\82½\81D";
530 /*JP
531                 msg2 = (u.ualign.record >= ALGN_PIOUS) ? "a" : "an unusual";
532 */
533                 msg2 = (u.ualign.record >= ALGN_PIOUS) ? "a" : "\82¢\82Â\82É\82È\82­";
534                 this_time = &epri_p->peaceful_time;
535                 other_time = &epri_p->hostile_time;
536             }
537             /* give message if we haven't seen it recently or
538                if alignment update has caused it to switch from
539                forbidding to sense-of-peace or vice versa */
540             if (moves >= *this_time || *other_time >= *this_time) {
541                 You(msg1, msg2);
542                 *this_time = moves + (long) d(10, 20); /* ~55 */
543                 /* avoid being tricked by the RNG:  switch might have just
544                    happened and previous random threshold could be larger */
545                 if (*this_time <= *other_time)
546                     *other_time = *this_time - 1L;
547             }
548         }
549         /* recognize the Valley of the Dead and Moloch's Sanctum
550            once hero has encountered the temple priest on those levels */
551         mapseen_temple(priest);
552     } else {
553         /* untended */
554
555         switch (rn2(4)) {
556         case 0:
557 /*JP
558             You("have an eerie feeling...");
559 */
560             You("\82¼\82Á\82Æ\82µ\82½\81D\81D\81D");
561             break;
562         case 1:
563 /*JP
564             You_feel("like you are being watched.");
565 */
566             You("\8c©\82Â\82ß\82ç\82ê\82Ä\82¢\82é\82æ\82¤\82È\8bC\82ª\82µ\82½\81D");
567             break;
568         case 2:
569 /*JP
570             pline("A shiver runs down your %s.", body_part(SPINE));
571 */
572             pline("\82 \82È\82½\82Ì%s\82ð\90k\82¦\82ª\91\96\82Á\82½\81D", body_part(SPINE));
573             break;
574         default:
575             break; /* no message; unfortunately there's no
576                       EPRI(priest)->eerie_time available to
577                       make sure we give one the first time */
578         }
579         if (!rn2(5)
580             && (mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS))
581                    != 0) {
582             /* [TODO: alter this (at a minimum, by switching from
583                an exclamation to a simple declaration) if hero has
584                already killed enough ghosts.] */
585             if (canspotmon(mtmp))
586 /*JP
587                 pline("An enormous ghost appears next to you!");
588 */
589                 pline("\8b\90\91å\82È\97H\97ì\82ª\82 \82È\82½\82Ì\82·\82®\82»\82Î\82É\8c»\82í\82ê\82½\81I");
590             else
591 /*JP
592                 You("sense a presence close by!");
593 */
594                 You("\82·\82®\82»\82Î\82É\89½\82©\82ª\82¢\82é\82Ì\82ð\8a´\82\82½\81I");
595             mtmp->mpeaceful = 0;
596             set_malign(mtmp);
597             if (flags.verbose)
598 /*JP
599                 You("are frightened to death, and unable to move.");
600 */
601                 You("\82Ü\82Á\82³\82¨\82É\82È\82Á\82Ä\8bÁ\82«\81C\93®\82¯\82È\82­\82È\82Á\82½\81D");
602             nomul(-3);
603 /*JP
604             multi_reason = "being terrified of a demon";
605 */
606             multi_reason = "\88«\97ì\82É\8b°\95|\82µ\82Ä\82¢\82é\8e\9e\82É";
607 /*JP
608             nomovemsg = "You regain your composure.";
609 */
610             nomovemsg = "\82 \82È\82½\82Í\95½\90Ã\82ð\8eæ\82è\96ß\82µ\82½\81D";
611         }
612     }
613 }
614
615 /* reset the move counters used to limit temple entry feedback;
616    leaving the level and then returning yields a fresh start */
617 void
618 forget_temple_entry(priest)
619 struct monst *priest;
620 {
621     struct epri *epri_p = priest->ispriest ? EPRI(priest) : 0;
622
623     if (!epri_p) {
624         impossible("attempting to manipulate shrine data for non-priest?");
625         return;
626     }
627     epri_p->intone_time = epri_p->enter_time = epri_p->peaceful_time =
628         epri_p->hostile_time = 0L;
629 }
630
631 void
632 priest_talk(priest)
633 register struct monst *priest;
634 {
635     boolean coaligned = p_coaligned(priest);
636     boolean strayed = (u.ualign.record < 0);
637
638     /* KMH, conduct */
639     u.uconduct.gnostic++;
640
641     if (priest->mflee || (!priest->ispriest && coaligned && strayed)) {
642 /*JP
643         pline("%s doesn't want anything to do with you!", Monnam(priest));
644 */
645         pline("%s\82Í\82 \82È\82½\82É\8d\\82¢\82½\82­\82È\82¢\82æ\82¤\82¾\81I", Monnam(priest));
646         priest->mpeaceful = 0;
647         return;
648     }
649
650     /* priests don't chat unless peaceful and in their own temple */
651     if (!inhistemple(priest) || !priest->mpeaceful
652         || !priest->mcanmove || priest->msleeping) {
653         static const char *cranky_msg[3] = {
654 /*JP
655             "Thou wouldst have words, eh?  I'll give thee a word or two!",
656 */
657             "\93ð\8c¾\97t\82ð\96]\82Þ\82Ì\82©\81H",
658 /*JP
659             "Talk?  Here is what I have to say!",
660 */
661             "\98b\82·\81H\89½\82ð\8c¾\82¦\82Î\82æ\82¢\82Ì\82¾\81I",
662 /*JP
663             "Pilgrim, I would speak no longer with thee."
664 */
665             "\8f\84\97ç\8eÒ\82æ\81C\93ð\82É\8cê\82é\82±\82Æ\82È\82Ç\82È\82¢\81D"
666         };
667
668         if (!priest->mcanmove || priest->msleeping) {
669 #if 0 /*JP*/
670             pline("%s breaks out of %s reverie!", Monnam(priest),
671                   mhis(priest));
672 #else
673             pline("%s\82ÍáÒ\91z\82ð\92\86\92f\82µ\82½\81I", Monnam(priest));
674 #endif
675             priest->mfrozen = priest->msleeping = 0;
676             priest->mcanmove = 1;
677         }
678         priest->mpeaceful = 0;
679         verbalize1(cranky_msg[rn2(3)]);
680         return;
681     }
682
683     /* you desecrated the temple and now you want to chat? */
684     if (priest->mpeaceful && *in_rooms(priest->mx, priest->my, TEMPLE)
685         && !has_shrine(priest)) {
686         verbalize(
687 /*JP
688               "Begone!  Thou desecratest this holy place with thy presence.");
689 */
690               "\97§\82¿\8b\8e\82ê\81I\93ð\82Í\82±\82Ì\90_\90¹\82È\82é\8fê\8f\8a\82ð\89\98\82µ\82Ä\82¢\82é\81D");
691         priest->mpeaceful = 0;
692         return;
693     }
694     if (!money_cnt(invent)) {
695         if (coaligned && !strayed) {
696             long pmoney = money_cnt(priest->minvent);
697             if (pmoney > 0L) {
698                 /* Note: two bits is actually 25 cents.  Hmm. */
699 #if 0 /*JP*/
700                 pline("%s gives you %s for an ale.", Monnam(priest),
701                       (pmoney == 1L) ? "one bit" : "two bits");
702 #else
703                 pline("%s\82Í\82 \82È\82½\82ª\83G\81[\83\8b\8eð\82ð\88ù\82ß\82é\82æ\82¤\82É\81C%s\82ð\97^\82¦\82½\81D", Monnam(priest),
704                       (pmoney == 1L) ? "\8bà\89Ý1\96\87" : "\8bà\89Ý2\96\87");
705 #endif
706                 money2u(priest, pmoney > 1L ? 2 : 1);
707             } else
708 /*JP
709                 pline("%s preaches the virtues of poverty.", Monnam(priest));
710 */
711                 pline("%s\82Í\90´\95n\82Ì\94ü\93¿\82É\82Â\82¢\82Ä\90à\8b³\82µ\82½\81D", Monnam(priest));
712             exercise(A_WIS, TRUE);
713         } else
714 /*JP
715             pline("%s is not interested.", Monnam(priest));
716 */
717             pline("%s\82Í\8b»\96¡\82ð\8e¦\82³\82È\82¢\81D", Monnam(priest));
718         return;
719     } else {
720         long offer;
721
722 /*JP
723         pline("%s asks you for a contribution for the temple.",
724 */
725         pline("%s\82Í\82 \82È\82½\82É\8e\9b\89@\82Ö\82Ì\8añ\91¡\82ð\8b\81\82ß\82½\81D",
726               Monnam(priest));
727         if ((offer = bribe(priest)) == 0) {
728 /*JP
729             verbalize("Thou shalt regret thine action!");
730 */
731             verbalize("\93ð\82Ì\8ds\88×\82Í\90_\82ð\96`\93À\82·\82é\82à\82Ì\82È\82è\81I");
732             if (coaligned)
733                 adjalign(-1);
734         } else if (offer < (u.ulevel * 200)) {
735             if (money_cnt(invent) > (offer * 2L)) {
736 /*JP
737                 verbalize("Cheapskate.");
738 */
739                 verbalize("\83P\83`\82ß\81D");
740             } else {
741 /*JP
742                 verbalize("I thank thee for thy contribution.");
743 */
744                 verbalize("\93ð\82Ì\8añ\91¡\82É\95ñ\82¢\82æ\82¤\82¼\81D");
745                 /* give player some token */
746                 exercise(A_WIS, TRUE);
747             }
748         } else if (offer < (u.ulevel * 400)) {
749 /*JP
750             verbalize("Thou art indeed a pious individual.");
751 */
752             verbalize("\93ð\81C\82Ü\82³\82É\8chåi\82È\82è\81D");
753             if (money_cnt(invent) < (offer * 2L)) {
754                 if (coaligned && u.ualign.record <= ALGN_SINNED)
755                     adjalign(1);
756 /*JP
757                 verbalize("I bestow upon thee a blessing.");
758 */
759                 verbalize("\93ð\82É\8fj\95\9f\82ð\81D");
760                 incr_itimeout(&HClairvoyant, rn1(500, 500));
761             }
762         } else if (offer < (u.ulevel * 600)
763                    /* u.ublessed is only active when Protection is
764                       enabled via something other than worn gear
765                       (theft by gremlin clears the intrinsic but not
766                       its former magnitude, making it recoverable) */
767                    && (!(HProtection & INTRINSIC)
768                        || (u.ublessed < 20
769                            && (u.ublessed < 9 || !rn2(u.ublessed))))) {
770 /*JP
771             verbalize("Thy devotion has been rewarded.");
772 */
773             verbalize("\93ð\82ª\8c£\90g\82É\95ñ\82í\82ñ\81D");
774             if (!(HProtection & INTRINSIC)) {
775                 HProtection |= FROMOUTSIDE;
776                 if (!u.ublessed)
777                     u.ublessed = rn1(3, 2);
778             } else
779                 u.ublessed++;
780         } else {
781 /*JP
782             verbalize("Thy selfless generosity is deeply appreciated.");
783 */
784             verbalize("\93ð\8e©\90g\82Ì\90^\89¿\82Í\91å\82¢\82É\94F\82ß\82ç\82ê\82½\81D");
785             if (money_cnt(invent) < (offer * 2L) && coaligned) {
786                 if (strayed && (moves - u.ucleansed) > 5000L) {
787                     u.ualign.record = 0; /* cleanse thee */
788                     u.ucleansed = moves;
789                 } else {
790                     adjalign(2);
791                 }
792             }
793         }
794     }
795 }
796
797 struct monst *
798 mk_roamer(ptr, alignment, x, y, peaceful)
799 register struct permonst *ptr;
800 aligntyp alignment;
801 xchar x, y;
802 boolean peaceful;
803 {
804     register struct monst *roamer;
805     register boolean coaligned = (u.ualign.type == alignment);
806
807 #if 0 /* this was due to permonst's pxlth field which is now gone */
808     if (ptr != &mons[PM_ALIGNED_PRIEST] && ptr != &mons[PM_ANGEL])
809         return (struct monst *) 0;
810 #endif
811
812     if (MON_AT(x, y))
813         (void) rloc(m_at(x, y), FALSE); /* insurance */
814
815     if (!(roamer = makemon(ptr, x, y, MM_ADJACENTOK | MM_EMIN)))
816         return (struct monst *) 0;
817
818     EMIN(roamer)->min_align = alignment;
819     EMIN(roamer)->renegade = (coaligned && !peaceful);
820     roamer->ispriest = 0;
821     roamer->isminion = 1;
822     roamer->mtrapseen = ~0; /* traps are known */
823     roamer->mpeaceful = peaceful;
824     roamer->msleeping = 0;
825     set_malign(roamer); /* peaceful may have changed */
826
827     /* MORE TO COME */
828     return roamer;
829 }
830
831 void
832 reset_hostility(roamer)
833 register struct monst *roamer;
834 {
835     if (!roamer->isminion)
836         return;
837     if (roamer->data != &mons[PM_ALIGNED_PRIEST]
838         && roamer->data != &mons[PM_ANGEL])
839         return;
840
841     if (EMIN(roamer)->min_align != u.ualign.type) {
842         roamer->mpeaceful = roamer->mtame = 0;
843         set_malign(roamer);
844     }
845     newsym(roamer->mx, roamer->my);
846 }
847
848 boolean
849 in_your_sanctuary(mon, x, y)
850 struct monst *mon; /* if non-null, <mx,my> overrides <x,y> */
851 xchar x, y;
852 {
853     register char roomno;
854     register struct monst *priest;
855
856     if (mon) {
857         if (is_minion(mon->data) || is_rider(mon->data))
858             return FALSE;
859         x = mon->mx, y = mon->my;
860     }
861     if (u.ualign.record <= ALGN_SINNED) /* sinned or worse */
862         return FALSE;
863     if ((roomno = temple_occupied(u.urooms)) == 0
864         || roomno != *in_rooms(x, y, TEMPLE))
865         return FALSE;
866     if ((priest = findpriest(roomno)) == 0)
867         return FALSE;
868     return (boolean) (has_shrine(priest) && p_coaligned(priest)
869                       && priest->mpeaceful);
870 }
871
872 /* when attacking "priest" in his temple */
873 void
874 ghod_hitsu(priest)
875 struct monst *priest;
876 {
877     int x, y, ax, ay, roomno = (int) temple_occupied(u.urooms);
878     struct mkroom *troom;
879
880     if (!roomno || !has_shrine(priest))
881         return;
882
883     ax = x = EPRI(priest)->shrpos.x;
884     ay = y = EPRI(priest)->shrpos.y;
885     troom = &rooms[roomno - ROOMOFFSET];
886
887     if ((u.ux == x && u.uy == y) || !linedup(u.ux, u.uy, x, y, 1)) {
888         if (IS_DOOR(levl[u.ux][u.uy].typ)) {
889             if (u.ux == troom->lx - 1) {
890                 x = troom->hx;
891                 y = u.uy;
892             } else if (u.ux == troom->hx + 1) {
893                 x = troom->lx;
894                 y = u.uy;
895             } else if (u.uy == troom->ly - 1) {
896                 x = u.ux;
897                 y = troom->hy;
898             } else if (u.uy == troom->hy + 1) {
899                 x = u.ux;
900                 y = troom->ly;
901             }
902         } else {
903             switch (rn2(4)) {
904             case 0:
905                 x = u.ux;
906                 y = troom->ly;
907                 break;
908             case 1:
909                 x = u.ux;
910                 y = troom->hy;
911                 break;
912             case 2:
913                 x = troom->lx;
914                 y = u.uy;
915                 break;
916             default:
917                 x = troom->hx;
918                 y = u.uy;
919                 break;
920             }
921         }
922         if (!linedup(u.ux, u.uy, x, y, 1))
923             return;
924     }
925
926     switch (rn2(3)) {
927     case 0:
928 /*JP
929         pline("%s roars in anger:  \"Thou shalt suffer!\"",
930 */
931         pline("%s\82Í\93{\82è\82Ì\90º\82ð\82 \82°\82½\81F\81u\93ð\81C\8bê\82µ\82Þ\82ª\82æ\82¢\81I\81v",
932               a_gname_at(ax, ay));
933         break;
934     case 1:
935 /*JP
936         pline("%s voice booms:  \"How darest thou harm my servant!\"",
937 */
938         pline("%s\82Ì\90º\82ª\8b¿\82¢\82½\81F\81u\82í\82ª\89º\96l\82É\8bê\82µ\82Þ\82ª\82æ\82¢\81I\81v",
939               s_suffix(a_gname_at(ax, ay)));
940         break;
941     default:
942 /*JP
943         pline("%s roars:  \"Thou dost profane my shrine!\"",
944 */
945         pline("%s\82Ì\90º\82ª\95·\82±\82¦\82é\81F\81u\93ð\81C\89ä\82ª\90¹\93°\82ð\89\98\82µ\82½\82è\81I\81v",
946               a_gname_at(ax, ay));
947         break;
948     }
949
950     buzz(-10 - (AD_ELEC - 1), 6, x, y, sgn(tbx),
951          sgn(tby)); /* bolt of lightning */
952     exercise(A_WIS, FALSE);
953 }
954
955 void
956 angry_priest()
957 {
958     register struct monst *priest;
959     struct rm *lev;
960
961     if ((priest = findpriest(temple_occupied(u.urooms))) != 0) {
962         struct epri *eprip = EPRI(priest);
963
964         wakeup(priest);
965         /*
966          * If the altar has been destroyed or converted, let the
967          * priest run loose.
968          * (When it's just a conversion and there happens to be
969          * a fresh corpse nearby, the priest ought to have an
970          * opportunity to try converting it back; maybe someday...)
971          */
972         lev = &levl[eprip->shrpos.x][eprip->shrpos.y];
973         if (!IS_ALTAR(lev->typ)
974             || ((aligntyp) Amask2align(lev->altarmask & AM_MASK)
975                 != eprip->shralign)) {
976             if (!EMIN(priest))
977                 newemin(priest);
978             priest->ispriest = 0; /* now a roaming minion */
979             priest->isminion = 1;
980             EMIN(priest)->min_align = eprip->shralign;
981             EMIN(priest)->renegade = FALSE;
982             /* discard priest's memory of his former shrine;
983                if we ever implement the re-conversion mentioned
984                above, this will need to be removed */
985             free_epri(priest);
986         }
987     }
988 }
989
990 /*
991  * When saving bones, find priests that aren't on their shrine level,
992  * and remove them.  This avoids big problems when restoring bones.
993  * [Perhaps we should convert them into roamers instead?]
994  */
995 void
996 clearpriests()
997 {
998     struct monst *mtmp;
999
1000     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
1001         if (DEADMONSTER(mtmp))
1002             continue;
1003         if (mtmp->ispriest && !on_level(&(EPRI(mtmp)->shrlevel), &u.uz))
1004             mongone(mtmp);
1005     }
1006 }
1007
1008 /* munge priest-specific structure when restoring -dlc */
1009 void
1010 restpriest(mtmp, ghostly)
1011 register struct monst *mtmp;
1012 boolean ghostly;
1013 {
1014     if (u.uz.dlevel) {
1015         if (ghostly)
1016             assign_level(&(EPRI(mtmp)->shrlevel), &u.uz);
1017     }
1018 }
1019
1020 /*priest.c*/