Source:NetHack 3.6.2/src/priest.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to priest.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/priest.c#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. /* NetHack 3.6	priest.c	$NHDT-Date: 1545131519 2018/12/18 11:11:59 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.45 $ */
2. /* Copyright (c) Izchak Miller, Steve Linhart, 1989.              */
3. /* NetHack may be freely redistributed.  See license for details. */
4. 
5. #include "hack.h"
6. #include "mfndpos.h"
7. 
8. /* these match the categorizations shown by enlightenment */
9. #define ALGN_SINNED (-4) /* worse than strayed (-1..-3) */
10. #define ALGN_PIOUS 14    /* better than fervent (9..13) */
11. 
12. STATIC_DCL boolean FDECL(histemple_at, (struct monst *, XCHAR_P, XCHAR_P));
13. STATIC_DCL boolean FDECL(has_shrine, (struct monst *));
14. 
15. void
16. newepri(mtmp)
17. struct monst *mtmp;
18. {
19.     if (!mtmp->mextra)
20.         mtmp->mextra = newmextra();
21.     if (!EPRI(mtmp)) {
22.         EPRI(mtmp) = (struct epri *) alloc(sizeof(struct epri));
23.         (void) memset((genericptr_t) EPRI(mtmp), 0, sizeof(struct epri));
24.     }
25. }
26. 
27. void
28. free_epri(mtmp)
29. struct monst *mtmp;
30. {
31.     if (mtmp->mextra && EPRI(mtmp)) {
32.         free((genericptr_t) EPRI(mtmp));
33.         EPRI(mtmp) = (struct epri *) 0;
34.     }
35.     mtmp->ispriest = 0;
36. }
37. 
38. /*
39.  * Move for priests and shopkeepers.  Called from shk_move() and pri_move().
40.  * Valid returns are  1: moved  0: didn't  -1: let m_move do it  -2: died.
41.  */
42. int
43. move_special(mtmp, in_his_shop, appr, uondoor, avoid, omx, omy, gx, gy)
44. register struct monst *mtmp;
45. boolean in_his_shop;
46. schar appr;
47. boolean uondoor, avoid;
48. register xchar omx, omy, gx, gy;
49. {
50.     register xchar nx, ny, nix, niy;
51.     register schar i;
52.     schar chcnt, cnt;
53.     coord poss[9];
54.     long info[9];
55.     long allowflags;
56. #if 0 /* dead code; see below */
57.     struct obj *ib = (struct obj *) 0;
58. #endif
59. 
60.     if (omx == gx && omy == gy)
61.         return 0;
62.     if (mtmp->mconf) {
63.         avoid = FALSE;
64.         appr = 0;
65.     }
66. 
67.     nix = omx;
68.     niy = omy;
69.     if (mtmp->isshk)
70.         allowflags = ALLOW_SSM;
71.     else
72.         allowflags = ALLOW_SSM | ALLOW_SANCT;
73.     if (passes_walls(mtmp->data))
74.         allowflags |= (ALLOW_ROCK | ALLOW_WALL);
75.     if (throws_rocks(mtmp->data))
76.         allowflags |= ALLOW_ROCK;
77.     if (tunnels(mtmp->data))
78.         allowflags |= ALLOW_DIG;
79.     if (!nohands(mtmp->data) && !verysmall(mtmp->data)) {
80.         allowflags |= OPENDOOR;
81.         if (monhaskey(mtmp, TRUE))
82.             allowflags |= UNLOCKDOOR;
83.     }
84.     if (is_giant(mtmp->data))
85.         allowflags |= BUSTDOOR;
86.     cnt = mfndpos(mtmp, poss, info, allowflags);
87. 
88.     if (mtmp->isshk && avoid && uondoor) { /* perhaps we cannot avoid him */
89.         for (i = 0; i < cnt; i++)
90.             if (!(info[i] & NOTONL))
91.                 goto pick_move;
92.         avoid = FALSE;
93.     }
94. 
95. #define GDIST(x, y) (dist2(x, y, gx, gy))
96. pick_move:
97.     chcnt = 0;
98.     for (i = 0; i < cnt; i++) {
99.         nx = poss[i].x;
100.         ny = poss[i].y;
101.         if (IS_ROOM(levl[nx][ny].typ)
102.             || (mtmp->isshk && (!in_his_shop || ESHK(mtmp)->following))) {
103.             if (avoid && (info[i] & NOTONL))
104.                 continue;
105.             if ((!appr && !rn2(++chcnt))
106.                 || (appr && GDIST(nx, ny) < GDIST(nix, niy))) {
107.                 nix = nx;
108.                 niy = ny;
109.             }
110.         }
111.     }
112.     if (mtmp->ispriest && avoid && nix == omx && niy == omy
113.         && onlineu(omx, omy)) {
114.         /* might as well move closer as long it's going to stay
115.          * lined up */
116.         avoid = FALSE;
117.         goto pick_move;
118.     }
119. 
120.     if (nix != omx || niy != omy) {
121.         remove_monster(omx, omy);
122.         place_monster(mtmp, nix, niy);
123.         newsym(nix, niy);
124.         if (mtmp->isshk && !in_his_shop && inhishop(mtmp))
125.             check_special_room(FALSE);
126. #if 0 /* dead code; maybe someday someone will track down why... */
127.         if (ib) {
128.             if (cansee(mtmp->mx, mtmp->my))
129.                 pline("%s picks up %s.", Monnam(mtmp),
130.                       distant_name(ib, doname));
131.             obj_extract_self(ib);
132.             (void) mpickobj(mtmp, ib);
133.         }
134. #endif
135.         return 1;
136.     }
137.     return 0;
138. }
139. 
140. char
141. temple_occupied(array)
142. register char *array;
143. {
144.     register char *ptr;
145. 
146.     for (ptr = array; *ptr; ptr++)
147.         if (rooms[*ptr - ROOMOFFSET].rtype == TEMPLE)
148.             return *ptr;
149.     return '\0';
150. }
151. 
152. STATIC_OVL boolean
153. histemple_at(priest, x, y)
154. register struct monst *priest;
155. register xchar x, y;
156. {
157.     return (boolean) (priest && priest->ispriest
158.                       && (EPRI(priest)->shroom == *in_rooms(x, y, TEMPLE))
159.                       && on_level(&(EPRI(priest)->shrlevel), &u.uz));
160. }
161. 
162. boolean
163. inhistemple(priest)
164. struct monst *priest;
165. {
166.     /* make sure we have a priest */
167.     if (!priest || !priest->ispriest)
168.         return FALSE;
169.     /* priest must be on right level and in right room */
170.     if (!histemple_at(priest, priest->mx, priest->my))
171.         return FALSE;
172.     /* temple room must still contain properly aligned altar */
173.     return has_shrine(priest);
174. }
175. 
176. /*
177.  * pri_move: return 1: moved  0: didn't  -1: let m_move do it  -2: died
178.  */
179. int
180. pri_move(priest)
181. register struct monst *priest;
182. {
183.     register xchar gx, gy, omx, omy;
184.     schar temple;
185.     boolean avoid = TRUE;
186. 
187.     omx = priest->mx;
188.     omy = priest->my;
189. 
190.     if (!histemple_at(priest, omx, omy))
191.         return -1;
192. 
193.     temple = EPRI(priest)->shroom;
194. 
195.     gx = EPRI(priest)->shrpos.x;
196.     gy = EPRI(priest)->shrpos.y;
197. 
198.     gx += rn1(3, -1); /* mill around the altar */
199.     gy += rn1(3, -1);
200. 
201.     if (!priest->mpeaceful
202.         || (Conflict && !resist(priest, RING_CLASS, 0, 0))) {
203.         if (monnear(priest, u.ux, u.uy)) {
204.             if (Displaced)
205.                 Your("displaced image doesn't fool %s!", mon_nam(priest));
206.             (void) mattacku(priest);
207.             return 0;
208.         } else if (index(u.urooms, temple)) {
209.             /* chase player if inside temple & can see him */
210.             if (priest->mcansee && m_canseeu(priest)) {
211.                 gx = u.ux;
212.                 gy = u.uy;
213.             }
214.             avoid = FALSE;
215.         }
216.     } else if (Invis)
217.         avoid = FALSE;
218. 
219.     return move_special(priest, FALSE, TRUE, FALSE, avoid, omx, omy, gx, gy);
220. }
221. 
222. /* exclusively for mktemple() */
223. void
224. priestini(lvl, sroom, sx, sy, sanctum)
225. d_level *lvl;
226. struct mkroom *sroom;
227. int sx, sy;
228. boolean sanctum; /* is it the seat of the high priest? */
229. {
230.     struct monst *priest;
231.     struct obj *otmp;
232.     int cnt;
233. 
234.     if (MON_AT(sx + 1, sy))
235.         (void) rloc(m_at(sx + 1, sy), FALSE); /* insurance */
236. 
237.     priest = makemon(&mons[sanctum ? PM_HIGH_PRIEST : PM_ALIGNED_PRIEST],
238.                      sx + 1, sy, MM_EPRI);
239.     if (priest) {
240.         EPRI(priest)->shroom = (schar) ((sroom - rooms) + ROOMOFFSET);
241.         EPRI(priest)->shralign = Amask2align(levl[sx][sy].altarmask);
242.         EPRI(priest)->shrpos.x = sx;
243.         EPRI(priest)->shrpos.y = sy;
244.         assign_level(&(EPRI(priest)->shrlevel), lvl);
245.         priest->mtrapseen = ~0; /* traps are known */
246.         priest->mpeaceful = 1;
247.         priest->ispriest = 1;
248.         priest->isminion = 0;
249.         priest->msleeping = 0;
250.         set_malign(priest); /* mpeaceful may have changed */
251. 
252.         /* now his/her goodies... */
253.         if (sanctum && EPRI(priest)->shralign == A_NONE
254.             && on_level(&sanctum_level, &u.uz)) {
255.             (void) mongets(priest, AMULET_OF_YENDOR);
256.         }
257.         /* 2 to 4 spellbooks */
258.         for (cnt = rn1(3, 2); cnt > 0; --cnt) {
259.             (void) mpickobj(priest, mkobj(SPBOOK_CLASS, FALSE));
260.         }
261.         /* robe [via makemon()] */
262.         if (rn2(2) && (otmp = which_armor(priest, W_ARMC)) != 0) {
263.             if (p_coaligned(priest))
264.                 uncurse(otmp);
265.             else
266.                 curse(otmp);
267.         }
268.     }
269. }
270. 
271. /* get a monster's alignment type without caller needing EPRI & EMIN */
272. aligntyp
273. mon_aligntyp(mon)
274. struct monst *mon;
275. {
276.     aligntyp algn = mon->ispriest ? EPRI(mon)->shralign
277.                                   : mon->isminion ? EMIN(mon)->min_align
278.                                                   : mon->data->maligntyp;
279. 
280.     if (algn == A_NONE)
281.         return A_NONE; /* negative but differs from chaotic */
282.     return (algn > 0) ? A_LAWFUL : (algn < 0) ? A_CHAOTIC : A_NEUTRAL;
283. }
284. 
285. /*
286.  * Specially aligned monsters are named specially.
287.  *      - aligned priests with ispriest and high priests have shrines
288.  *              they retain ispriest and epri when polymorphed
289.  *      - aligned priests without ispriest are roamers
290.  *              they have isminion set and use emin rather than epri
291.  *      - minions do not have ispriest but have isminion and emin
292.  *      - caller needs to inhibit Hallucination if it wants to force
293.  *              the true name even when under that influence
294.  */
295. char *
296. priestname(mon, pname)
297. register struct monst *mon;
298. char *pname; /* caller-supplied output buffer */
299. {
300.     boolean do_hallu = Hallucination,
301.             aligned_priest = mon->data == &mons[PM_ALIGNED_PRIEST],
302.             high_priest = mon->data == &mons[PM_HIGH_PRIEST];
303.     char whatcode = '\0';
304.     const char *what = do_hallu ? rndmonnam(&whatcode) : mon->data->mname;
305. 
306.     if (!mon->ispriest && !mon->isminion) /* should never happen...  */
307.         return strcpy(pname, what);       /* caller must be confused */
308. 
309.     *pname = '\0';
310.     if (!do_hallu || !bogon_is_pname(whatcode))
311.         Strcat(pname, "the ");
312.     if (mon->minvis)
313.         Strcat(pname, "invisible ");
314.     if (mon->isminion && EMIN(mon)->renegade)
315.         Strcat(pname, "renegade ");
316. 
317.     if (mon->ispriest || aligned_priest) { /* high_priest implies ispriest */
318.         if (!aligned_priest && !high_priest) {
319.             ; /* polymorphed priest; use ``what as is */
320.         } else {
321.             if (high_priest)
322.                 Strcat(pname, "high ");
323.             if (Hallucination)
324.                 what = "poohbah";
325.             else if (mon->female)
326.                 what = "priestess";
327.             else
328.                 what = "priest";
329.         }
330.     } else {
331.         if (mon->mtame && !strcmpi(what, "Angel"))
332.             Strcat(pname, "guardian ");
333.     }
334. 
335.     Strcat(pname, what);
336.     /* same as distant_monnam(), more or less... */
337.     if (do_hallu || !high_priest || !Is_astralevel(&u.uz)
338.         || distu(mon->mx, mon->my) <= 2 || program_state.gameover) {
339.         Strcat(pname, " of ");
340.         Strcat(pname, halu_gname(mon_aligntyp(mon)));
341.     }
342.     return pname;
343. }
344. 
345. boolean
346. p_coaligned(priest)
347. struct monst *priest;
348. {
349.     return (boolean) (u.ualign.type == mon_aligntyp(priest));
350. }
351. 
352. STATIC_OVL boolean
353. has_shrine(pri)
354. struct monst *pri;
355. {
356.     struct rm *lev;
357.     struct epri *epri_p;
358. 
359.     if (!pri || !pri->ispriest)
360.         return FALSE;
361.     epri_p = EPRI(pri);
362.     lev = &levl[epri_p->shrpos.x][epri_p->shrpos.y];
363.     if (!IS_ALTAR(lev->typ) || !(lev->altarmask & AM_SHRINE))
364.         return FALSE;
365.     return (boolean) (epri_p->shralign
366.                       == (Amask2align(lev->altarmask & ~AM_SHRINE)));
367. }
368. 
369. struct monst *
370. findpriest(roomno)
371. char roomno;
372. {
373.     register struct monst *mtmp;
374. 
375.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
376.         if (DEADMONSTER(mtmp))
377.             continue;
378.         if (mtmp->ispriest && (EPRI(mtmp)->shroom == roomno)
379.             && histemple_at(mtmp, mtmp->mx, mtmp->my))
380.             return mtmp;
381.     }
382.     return (struct monst *) 0;
383. }
384. 
385. /* called from check_special_room() when the player enters the temple room */
386. void
387. intemple(roomno)
388. int roomno;
389. {
390.     struct monst *priest, *mtmp;
391.     struct epri *epri_p;
392.     boolean shrined, sanctum, can_speak;
393.     long *this_time, *other_time;
394.     const char *msg1, *msg2;
395.     char buf[BUFSZ];
396. 
397.     /* don't do anything if hero is already in the room */
398.     if (temple_occupied(u.urooms0))
399.         return;
400. 
401.     if ((priest = findpriest((char) roomno)) != 0) {
402.         /* tended */
403. 
404.         epri_p = EPRI(priest);
405.         shrined = has_shrine(priest);
406.         sanctum = (priest->data == &mons[PM_HIGH_PRIEST]
407.                    && (Is_sanctum(&u.uz) || In_endgame(&u.uz)));
408.         can_speak = (priest->mcanmove && !priest->msleeping);
409.         if (can_speak && !Deaf && moves >= epri_p->intone_time) {
410.             unsigned save_priest = priest->ispriest;
411. 
412.             /* don't reveal the altar's owner upon temple entry in
413.                the endgame; for the Sanctum, the next message names
414.                Moloch so suppress the "of Moloch" for him here too */
415.             if (sanctum && !Hallucination)
416.                 priest->ispriest = 0;
417.             pline("%s intones:",
418.                   canseemon(priest) ? Monnam(priest) : "A nearby voice");
419.             priest->ispriest = save_priest;
420.             epri_p->intone_time = moves + (long) d(10, 500); /* ~2505 */
421.             /* make sure that we don't suppress entry message when
422.                we've just given its "priest intones" introduction */
423.             epri_p->enter_time = 0L;
424.         }
425.         msg1 = msg2 = 0;
426.         if (sanctum && Is_sanctum(&u.uz)) {
427.             if (priest->mpeaceful) {
428.                 /* first time inside */
429.                 msg1 = "Infidel, you have entered Moloch's Sanctum!";
430.                 msg2 = "Be gone!";
431.                 priest->mpeaceful = 0;
432.                 /* became angry voluntarily; no penalty for attacking him */
433.                 set_malign(priest);
434.             } else {
435.                 /* repeat visit, or attacked priest before entering */
436.                 msg1 = "You desecrate this place by your presence!";
437.             }
438.         } else if (moves >= epri_p->enter_time) {
439.             Sprintf(buf, "Pilgrim, you enter a %s place!",
440.                     !shrined ? "desecrated" : "sacred");
441.             msg1 = buf;
442.         }
443.         if (msg1 && can_speak && !Deaf) {
444.             verbalize1(msg1);
445.             if (msg2)
446.                 verbalize1(msg2);
447.             epri_p->enter_time = moves + (long) d(10, 100); /* ~505 */
448.         }
449.         if (!sanctum) {
450.             if (!shrined || !p_coaligned(priest)
451.                 || u.ualign.record <= ALGN_SINNED) {
452.                 msg1 = "have a%s forbidding feeling...";
453.                 msg2 = (!shrined || !p_coaligned(priest)) ? "" : " strange";
454.                 this_time = &epri_p->hostile_time;
455.                 other_time = &epri_p->peaceful_time;
456.             } else {
457.                 msg1 = "experience %s sense of peace.";
458.                 msg2 = (u.ualign.record >= ALGN_PIOUS) ? "a" : "an unusual";
459.                 this_time = &epri_p->peaceful_time;
460.                 other_time = &epri_p->hostile_time;
461.             }
462.             /* give message if we haven't seen it recently or
463.                if alignment update has caused it to switch from
464.                forbidding to sense-of-peace or vice versa */
465.             if (moves >= *this_time || *other_time >= *this_time) {
466.                 You(msg1, msg2);
467.                 *this_time = moves + (long) d(10, 20); /* ~55 */
468.                 /* avoid being tricked by the RNG:  switch might have just
469.                    happened and previous random threshold could be larger */
470.                 if (*this_time <= *other_time)
471.                     *other_time = *this_time - 1L;
472.             }
473.         }
474.         /* recognize the Valley of the Dead and Moloch's Sanctum
475.            once hero has encountered the temple priest on those levels */
476.         mapseen_temple(priest);
477.     } else {
478.         /* untended */
479. 
480.         switch (rn2(4)) {
481.         case 0:
482.             You("have an eerie feeling...");
483.             break;
484.         case 1:
485.             You_feel("like you are being watched.");
486.             break;
487.         case 2:
488.             pline("A shiver runs down your %s.", body_part(SPINE));
489.             break;
490.         default:
491.             break; /* no message; unfortunately there's no
492.                       EPRI(priest)->eerie_time available to
493.                       make sure we give one the first time */
494.         }
495.         if (!rn2(5)
496.             && (mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS))
497.                    != 0) {
498.             int ngen = mvitals[PM_GHOST].born;
499.             if (canspotmon(mtmp))
500.                 pline("A%s ghost appears next to you%c",
501.                       ngen < 5 ? "n enormous" : "",
502.                       ngen < 10 ? '!' : '.');
503.             else
504.                 You("sense a presence close by!");
505.             mtmp->mpeaceful = 0;
506.             set_malign(mtmp);
507.             if (flags.verbose)
508.                 You("are frightened to death, and unable to move.");
509.             nomul(-3);
510.             multi_reason = "being terrified of a ghost";
511.             nomovemsg = "You regain your composure.";
512.         }
513.     }
514. }
515. 
516. /* reset the move counters used to limit temple entry feedback;
517.    leaving the level and then returning yields a fresh start */
518. void
519. forget_temple_entry(priest)
520. struct monst *priest;
521. {
522.     struct epri *epri_p = priest->ispriest ? EPRI(priest) : 0;
523. 
524.     if (!epri_p) {
525.         impossible("attempting to manipulate shrine data for non-priest?");
526.         return;
527.     }
528.     epri_p->intone_time = epri_p->enter_time = epri_p->peaceful_time =
529.         epri_p->hostile_time = 0L;
530. }
531. 
532. void
533. priest_talk(priest)
534. register struct monst *priest;
535. {
536.     boolean coaligned = p_coaligned(priest);
537.     boolean strayed = (u.ualign.record < 0);
538. 
539.     /* KMH, conduct */
540.     u.uconduct.gnostic++;
541. 
542.     if (priest->mflee || (!priest->ispriest && coaligned && strayed)) {
543.         pline("%s doesn't want anything to do with you!", Monnam(priest));
544.         priest->mpeaceful = 0;
545.         return;
546.     }
547. 
548.     /* priests don't chat unless peaceful and in their own temple */
549.     if (!inhistemple(priest) || !priest->mpeaceful
550.         || !priest->mcanmove || priest->msleeping) {
551.         static const char *cranky_msg[3] = {
552.             "Thou wouldst have words, eh?  I'll give thee a word or two!",
553.             "Talk?  Here is what I have to say!",
554.             "Pilgrim, I would speak no longer with thee."
555.         };
556. 
557.         if (!priest->mcanmove || priest->msleeping) {
558.             pline("%s breaks out of %s reverie!", Monnam(priest),
559.                   mhis(priest));
560.             priest->mfrozen = priest->msleeping = 0;
561.             priest->mcanmove = 1;
562.         }
563.         priest->mpeaceful = 0;
564.         verbalize1(cranky_msg[rn2(3)]);
565.         return;
566.     }
567. 
568.     /* you desecrated the temple and now you want to chat? */
569.     if (priest->mpeaceful && *in_rooms(priest->mx, priest->my, TEMPLE)
570.         && !has_shrine(priest)) {
571.         verbalize(
572.               "Begone!  Thou desecratest this holy place with thy presence.");
573.         priest->mpeaceful = 0;
574.         return;
575.     }
576.     if (!money_cnt(invent)) {
577.         if (coaligned && !strayed) {
578.             long pmoney = money_cnt(priest->minvent);
579.             if (pmoney > 0L) {
580.                 /* Note: two bits is actually 25 cents.  Hmm. */
581.                 pline("%s gives you %s for an ale.", Monnam(priest),
582.                       (pmoney == 1L) ? "one bit" : "two bits");
583.                 money2u(priest, pmoney > 1L ? 2 : 1);
584.             } else
585.                 pline("%s preaches the virtues of poverty.", Monnam(priest));
586.             exercise(A_WIS, TRUE);
587.         } else
588.             pline("%s is not interested.", Monnam(priest));
589.         return;
590.     } else {
591.         long offer;
592. 
593.         pline("%s asks you for a contribution for the temple.",
594.               Monnam(priest));
595.         if ((offer = bribe(priest)) == 0) {
596.             verbalize("Thou shalt regret thine action!");
597.             if (coaligned)
598.                 adjalign(-1);
599.         } else if (offer < (u.ulevel * 200)) {
600.             if (money_cnt(invent) > (offer * 2L)) {
601.                 verbalize("Cheapskate.");
602.             } else {
603.                 verbalize("I thank thee for thy contribution.");
604.                 /* give player some token */
605.                 exercise(A_WIS, TRUE);
606.             }
607.         } else if (offer < (u.ulevel * 400)) {
608.             verbalize("Thou art indeed a pious individual.");
609.             if (money_cnt(invent) < (offer * 2L)) {
610.                 if (coaligned && u.ualign.record <= ALGN_SINNED)
611.                     adjalign(1);
612.                 verbalize("I bestow upon thee a blessing.");
613.                 incr_itimeout(&HClairvoyant, rn1(500, 500));
614.             }
615.         } else if (offer < (u.ulevel * 600)
616.                    /* u.ublessed is only active when Protection is
617.                       enabled via something other than worn gear
618.                       (theft by gremlin clears the intrinsic but not
619.                       its former magnitude, making it recoverable) */
620.                    && (!(HProtection & INTRINSIC)
621.                        || (u.ublessed < 20
622.                            && (u.ublessed < 9 || !rn2(u.ublessed))))) {
623.             verbalize("Thy devotion has been rewarded.");
624.             if (!(HProtection & INTRINSIC)) {
625.                 HProtection |= FROMOUTSIDE;
626.                 if (!u.ublessed)
627.                     u.ublessed = rn1(3, 2);
628.             } else
629.                 u.ublessed++;
630.         } else {
631.             verbalize("Thy selfless generosity is deeply appreciated.");
632.             if (money_cnt(invent) < (offer * 2L) && coaligned) {
633.                 if (strayed && (moves - u.ucleansed) > 5000L) {
634.                     u.ualign.record = 0; /* cleanse thee */
635.                     u.ucleansed = moves;
636.                 } else {
637.                     adjalign(2);
638.                 }
639.             }
640.         }
641.     }
642. }
643. 
644. struct monst *
645. mk_roamer(ptr, alignment, x, y, peaceful)
646. register struct permonst *ptr;
647. aligntyp alignment;
648. xchar x, y;
649. boolean peaceful;
650. {
651.     register struct monst *roamer;
652.     register boolean coaligned = (u.ualign.type == alignment);
653. 
654. #if 0 /* this was due to permonst's pxlth field which is now gone */
655.     if (ptr != &mons[PM_ALIGNED_PRIEST] && ptr != &mons[PM_ANGEL])
656.         return (struct monst *) 0;
657. #endif
658. 
659.     if (MON_AT(x, y))
660.         (void) rloc(m_at(x, y), FALSE); /* insurance */
661. 
662.     if (!(roamer = makemon(ptr, x, y, MM_ADJACENTOK | MM_EMIN)))
663.         return (struct monst *) 0;
664. 
665.     EMIN(roamer)->min_align = alignment;
666.     EMIN(roamer)->renegade = (coaligned && !peaceful);
667.     roamer->ispriest = 0;
668.     roamer->isminion = 1;
669.     roamer->mtrapseen = ~0; /* traps are known */
670.     roamer->mpeaceful = peaceful;
671.     roamer->msleeping = 0;
672.     set_malign(roamer); /* peaceful may have changed */
673. 
674.     /* MORE TO COME */
675.     return roamer;
676. }
677. 
678. void
679. reset_hostility(roamer)
680. register struct monst *roamer;
681. {
682.     if (!roamer->isminion)
683.         return;
684.     if (roamer->data != &mons[PM_ALIGNED_PRIEST]
685.         && roamer->data != &mons[PM_ANGEL])
686.         return;
687. 
688.     if (EMIN(roamer)->min_align != u.ualign.type) {
689.         roamer->mpeaceful = roamer->mtame = 0;
690.         set_malign(roamer);
691.     }
692.     newsym(roamer->mx, roamer->my);
693. }
694. 
695. boolean
696. in_your_sanctuary(mon, x, y)
697. struct monst *mon; /* if non-null, <mx,my> overrides <x,y> */
698. xchar x, y;
699. {
700.     register char roomno;
701.     register struct monst *priest;
702. 
703.     if (mon) {
704.         if (is_minion(mon->data) || is_rider(mon->data))
705.             return FALSE;
706.         x = mon->mx, y = mon->my;
707.     }
708.     if (u.ualign.record <= ALGN_SINNED) /* sinned or worse */
709.         return FALSE;
710.     if ((roomno = temple_occupied(u.urooms)) == 0
711.         || roomno != *in_rooms(x, y, TEMPLE))
712.         return FALSE;
713.     if ((priest = findpriest(roomno)) == 0)
714.         return FALSE;
715.     return (boolean) (has_shrine(priest) && p_coaligned(priest)
716.                       && priest->mpeaceful);
717. }
718. 
719. /* when attacking "priest" in his temple */
720. void
721. ghod_hitsu(priest)
722. struct monst *priest;
723. {
724.     int x, y, ax, ay, roomno = (int) temple_occupied(u.urooms);
725.     struct mkroom *troom;
726. 
727.     if (!roomno || !has_shrine(priest))
728.         return;
729. 
730.     ax = x = EPRI(priest)->shrpos.x;
731.     ay = y = EPRI(priest)->shrpos.y;
732.     troom = &rooms[roomno - ROOMOFFSET];
733. 
734.     if ((u.ux == x && u.uy == y) || !linedup(u.ux, u.uy, x, y, 1)) {
735.         if (IS_DOOR(levl[u.ux][u.uy].typ)) {
736.             if (u.ux == troom->lx - 1) {
737.                 x = troom->hx;
738.                 y = u.uy;
739.             } else if (u.ux == troom->hx + 1) {
740.                 x = troom->lx;
741.                 y = u.uy;
742.             } else if (u.uy == troom->ly - 1) {
743.                 x = u.ux;
744.                 y = troom->hy;
745.             } else if (u.uy == troom->hy + 1) {
746.                 x = u.ux;
747.                 y = troom->ly;
748.             }
749.         } else {
750.             switch (rn2(4)) {
751.             case 0:
752.                 x = u.ux;
753.                 y = troom->ly;
754.                 break;
755.             case 1:
756.                 x = u.ux;
757.                 y = troom->hy;
758.                 break;
759.             case 2:
760.                 x = troom->lx;
761.                 y = u.uy;
762.                 break;
763.             default:
764.                 x = troom->hx;
765.                 y = u.uy;
766.                 break;
767.             }
768.         }
769.         if (!linedup(u.ux, u.uy, x, y, 1))
770.             return;
771.     }
772. 
773.     switch (rn2(3)) {
774.     case 0:
775.         pline("%s roars in anger:  \"Thou shalt suffer!\"",
776.               a_gname_at(ax, ay));
777.         break;
778.     case 1:
779.         pline("%s voice booms:  \"How darest thou harm my servant!\"",
780.               s_suffix(a_gname_at(ax, ay)));
781.         break;
782.     default:
783.         pline("%s roars:  \"Thou dost profane my shrine!\"",
784.               a_gname_at(ax, ay));
785.         break;
786.     }
787. 
788.     buzz(-10 - (AD_ELEC - 1), 6, x, y, sgn(tbx),
789.          sgn(tby)); /* bolt of lightning */
790.     exercise(A_WIS, FALSE);
791. }
792. 
793. void
794. angry_priest()
795. {
796.     register struct monst *priest;
797.     struct rm *lev;
798. 
799.     if ((priest = findpriest(temple_occupied(u.urooms))) != 0) {
800.         struct epri *eprip = EPRI(priest);
801. 
802.         wakeup(priest, FALSE);
803.         setmangry(priest, FALSE);
804.         /*
805.          * If the altar has been destroyed or converted, let the
806.          * priest run loose.
807.          * (When it's just a conversion and there happens to be
808.          * a fresh corpse nearby, the priest ought to have an
809.          * opportunity to try converting it back; maybe someday...)
810.          */
811.         lev = &levl[eprip->shrpos.x][eprip->shrpos.y];
812.         if (!IS_ALTAR(lev->typ)
813.             || ((aligntyp) Amask2align(lev->altarmask & AM_MASK)
814.                 != eprip->shralign)) {
815.             if (!EMIN(priest))
816.                 newemin(priest);
817.             priest->ispriest = 0; /* now a roaming minion */
818.             priest->isminion = 1;
819.             EMIN(priest)->min_align = eprip->shralign;
820.             EMIN(priest)->renegade = FALSE;
821.             /* discard priest's memory of his former shrine;
822.                if we ever implement the re-conversion mentioned
823.                above, this will need to be removed */
824.             free_epri(priest);
825.         }
826.     }
827. }
828. 
829. /*
830.  * When saving bones, find priests that aren't on their shrine level,
831.  * and remove them.  This avoids big problems when restoring bones.
832.  * [Perhaps we should convert them into roamers instead?]
833.  */
834. void
835. clearpriests()
836. {
837.     struct monst *mtmp;
838. 
839.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
840.         if (DEADMONSTER(mtmp))
841.             continue;
842.         if (mtmp->ispriest && !on_level(&(EPRI(mtmp)->shrlevel), &u.uz))
843.             mongone(mtmp);
844.     }
845. }
846. 
847. /* munge priest-specific structure when restoring -dlc */
848. void
849. restpriest(mtmp, ghostly)
850. register struct monst *mtmp;
851. boolean ghostly;
852. {
853.     if (u.uz.dlevel) {
854.         if (ghostly)
855.             assign_level(&(EPRI(mtmp)->shrlevel), &u.uz);
856.     }
857. }
858. 
859. /*
860.  * align_str(), piousness(), mstatusline() and ustatusline() used to be
861.  * in pline.c, presumeably because the latter two generate one line of
862.  * output.  The USE_OLDARGS config gets warnings from 2016ish-vintage
863.  * gcc (for -Wint-to-pointer-cast, activated by -Wall or -W) when they
864.  * follow pline() itself.  Fixing up the variadic calls like is done for
865.  * lev_comp would be needlessly messy there.
866.  *
867.  * They don't belong here.  If/when enlightenment ever gets split off
868.  * from cmd.c (which definitely doesn't belong there), they should go
869.  * with it.
870.  */
871. 
872. const char *
873. align_str(alignment)
874. aligntyp alignment;
875. {
876.     switch ((int) alignment) {
877.     case A_CHAOTIC:
878.         return "chaotic";
879.     case A_NEUTRAL:
880.         return "neutral";
881.     case A_LAWFUL:
882.         return "lawful";
883.     case A_NONE:
884.         return "unaligned";
885.     }
886.     return "unknown";
887. }
888. 
889. /* used for self-probing */
890. char *
891. piousness(showneg, suffix)
892. boolean showneg;
893. const char *suffix;
894. {
895.     static char buf[32]; /* bigger than "insufficiently neutral" */
896.     const char *pio;
897. 
898.     /* note: piousness 20 matches MIN_QUEST_ALIGN (quest.h) */
899.     if (u.ualign.record >= 20)
900.         pio = "piously";
901.     else if (u.ualign.record > 13)
902.         pio = "devoutly";
903.     else if (u.ualign.record > 8)
904.         pio = "fervently";
905.     else if (u.ualign.record > 3)
906.         pio = "stridently";
907.     else if (u.ualign.record == 3)
908.         pio = "";
909.     else if (u.ualign.record > 0)
910.         pio = "haltingly";
911.     else if (u.ualign.record == 0)
912.         pio = "nominally";
913.     else if (!showneg)
914.         pio = "insufficiently";
915.     else if (u.ualign.record >= -3)
916.         pio = "strayed";
917.     else if (u.ualign.record >= -8)
918.         pio = "sinned";
919.     else
920.         pio = "transgressed";
921. 
922.     Sprintf(buf, "%s", pio);
923.     if (suffix && (!showneg || u.ualign.record >= 0)) {
924.         if (u.ualign.record != 3)
925.             Strcat(buf, " ");
926.         Strcat(buf, suffix);
927.     }
928.     return buf;
929. }
930. 
931. /* stethoscope or probing applied to monster -- one-line feedback */
932. void
933. mstatusline(mtmp)
934. struct monst *mtmp;
935. {
936.     aligntyp alignment = mon_aligntyp(mtmp);
937.     char info[BUFSZ], monnambuf[BUFSZ];
938. 
939.     info[0] = 0;
940.     if (mtmp->mtame) {
941.         Strcat(info, ", tame");
942.         if (wizard) {
943.             Sprintf(eos(info), " (%d", mtmp->mtame);
944.             if (!mtmp->isminion)
945.                 Sprintf(eos(info), "; hungry %ld; apport %d",
946.                         EDOG(mtmp)->hungrytime, EDOG(mtmp)->apport);
947.             Strcat(info, ")");
948.         }
949.     } else if (mtmp->mpeaceful)
950.         Strcat(info, ", peaceful");
951. 
952.     if (mtmp->data == &mons[PM_LONG_WORM]) {
953.         int segndx, nsegs = count_wsegs(mtmp);
954. 
955.         /* the worm code internals don't consider the head of be one of
956.            the worm's segments, but we count it as such when presenting
957.            worm feedback to the player */
958.         if (!nsegs) {
959.             Strcat(info, ", single segment");
960.         } else {
961.             ++nsegs; /* include head in the segment count */
962.             segndx = wseg_at(mtmp, bhitpos.x, bhitpos.y);
963.             Sprintf(eos(info), ", %d%s of %d segments",
964.                     segndx, ordin(segndx), nsegs);
965.         }
966.     }
967.     if (mtmp->cham >= LOW_PM && mtmp->data != &mons[mtmp->cham])
968.         /* don't reveal the innate form (chameleon, vampire, &c),
969.            just expose the fact that this current form isn't it */
970.         Strcat(info, ", shapechanger");
971.     /* pets eating mimic corpses mimic while eating, so this comes first */
972.     if (mtmp->meating)
973.         Strcat(info, ", eating");
974.     /* a stethoscope exposes mimic before getting here so this
975.        won't be relevant for it, but wand of probing doesn't */
976.     if (mtmp->mundetected || mtmp->m_ap_type)
977.         mhidden_description(mtmp, TRUE, eos(info));
978.     if (mtmp->mcan)
979.         Strcat(info, ", cancelled");
980.     if (mtmp->mconf)
981.         Strcat(info, ", confused");
982.     if (mtmp->mblinded || !mtmp->mcansee)
983.         Strcat(info, ", blind");
984.     if (mtmp->mstun)
985.         Strcat(info, ", stunned");
986.     if (mtmp->msleeping)
987.         Strcat(info, ", asleep");
988. #if 0 /* unfortunately mfrozen covers temporary sleep and being busy \
989.          (donning armor, for instance) as well as paralysis */
990.     else if (mtmp->mfrozen)
991.         Strcat(info, ", paralyzed");
992. #else
993.     else if (mtmp->mfrozen || !mtmp->mcanmove)
994.         Strcat(info, ", can't move");
995. #endif
996.     /* [arbitrary reason why it isn't moving] */
997.     else if (mtmp->mstrategy & STRAT_WAITMASK)
998.         Strcat(info, ", meditating");
999.     if (mtmp->mflee)
1000.         Strcat(info, ", scared");
1001.     if (mtmp->mtrapped)
1002.         Strcat(info, ", trapped");
1003.     if (mtmp->mspeed)
1004.         Strcat(info, (mtmp->mspeed == MFAST) ? ", fast"
1005.                       : (mtmp->mspeed == MSLOW) ? ", slow"
1006.                          : ", [? speed]");
1007.     if (mtmp->minvis)
1008.         Strcat(info, ", invisible");
1009.     if (mtmp == u.ustuck)
1010.         Strcat(info, sticks(youmonst.data) ? ", held by you"
1011.                       : !u.uswallow ? ", holding you"
1012.                          : attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_DGST)
1013.                             ? ", digesting you"
1014.                             : is_animal(u.ustuck->data) ? ", swallowing you"
1015.                                : ", engulfing you");
1016.     if (mtmp == u.usteed)
1017.         Strcat(info, ", carrying you");
1018. 
1019.     /* avoid "Status of the invisible newt ..., invisible" */
1020.     /* and unlike a normal mon_nam, use "saddled" even if it has a name */
1021.     Strcpy(monnambuf, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
1022.                                (SUPPRESS_IT | SUPPRESS_INVISIBLE), FALSE));
1023. 
1024.     pline("Status of %s (%s):  Level %d  HP %d(%d)  AC %d%s.", monnambuf,
1025.           align_str(alignment), mtmp->m_lev, mtmp->mhp, mtmp->mhpmax,
1026.           find_mac(mtmp), info);
1027. }
1028. 
1029. /* stethoscope or probing applied to hero -- one-line feedback */
1030. void
1031. ustatusline()
1032. {
1033.     char info[BUFSZ];
1034. 
1035.     info[0] = '\0';
1036.     if (Sick) {
1037.         Strcat(info, ", dying from");
1038.         if (u.usick_type & SICK_VOMITABLE)
1039.             Strcat(info, " food poisoning");
1040.         if (u.usick_type & SICK_NONVOMITABLE) {
1041.             if (u.usick_type & SICK_VOMITABLE)
1042.                 Strcat(info, " and");
1043.             Strcat(info, " illness");
1044.         }
1045.     }
1046.     if (Stoned)
1047.         Strcat(info, ", solidifying");
1048.     if (Slimed)
1049.         Strcat(info, ", becoming slimy");
1050.     if (Strangled)
1051.         Strcat(info, ", being strangled");
1052.     if (Vomiting)
1053.         Strcat(info, ", nauseated"); /* !"nauseous" */
1054.     if (Confusion)
1055.         Strcat(info, ", confused");
1056.     if (Blind) {
1057.         Strcat(info, ", blind");
1058.         if (u.ucreamed) {
1059.             if ((long) u.ucreamed < Blinded || Blindfolded
1060.                 || !haseyes(youmonst.data))
1061.                 Strcat(info, ", cover");
1062.             Strcat(info, "ed by sticky goop");
1063.         } /* note: "goop" == "glop"; variation is intentional */
1064.     }
1065.     if (Stunned)
1066.         Strcat(info, ", stunned");
1067.     if (!u.usteed && Wounded_legs) {
1068.         const char *what = body_part(LEG);
1069.         if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
1070.             what = makeplural(what);
1071.         Sprintf(eos(info), ", injured %s", what);
1072.     }
1073.     if (Glib)
1074.         Sprintf(eos(info), ", slippery %s", makeplural(body_part(HAND)));
1075.     if (u.utrap)
1076.         Strcat(info, ", trapped");
1077.     if (Fast)
1078.         Strcat(info, Very_fast ? ", very fast" : ", fast");
1079.     if (u.uundetected)
1080.         Strcat(info, ", concealed");
1081.     if (Invis)
1082.         Strcat(info, ", invisible");
1083.     if (u.ustuck) {
1084.         if (sticks(youmonst.data))
1085.             Strcat(info, ", holding ");
1086.         else
1087.             Strcat(info, ", held by ");
1088.         Strcat(info, mon_nam(u.ustuck));
1089.     }
1090. 
1091.     pline("Status of %s (%s):  Level %d  HP %d(%d)  AC %d%s.", plname,
1092.           piousness(FALSE, align_str(u.ualign.type)),
1093.           Upolyd ? mons[u.umonnum].mlevel : u.ulevel, Upolyd ? u.mh : u.uhp,
1094.           Upolyd ? u.mhmax : u.uhpmax, u.uac, info);
1095. }
1096. 
1097. /*priest.c*/