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