Source:NetHack 3.4.0/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.4.0. To link to a particular line, write [[NetHack 3.4.0/priest.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

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.    /*	SCCS Id: @(#)priest.c	3.4	2001/11/07	*/
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.    #include "eshk.h"
8.    #include "epri.h"
9.    #include "emin.h"
10.   
11.   /* this matches the categorizations shown by enlightenment */
12.   #define ALGN_SINNED	(-4)	/* worse than strayed */
13.   
14.   #ifdef OVLB
15.   
16.   STATIC_DCL boolean FDECL(histemple_at,(struct monst *,XCHAR_P,XCHAR_P));
17.   STATIC_DCL boolean FDECL(has_shrine,(struct monst *));
18.   
19.   /*
20.    * Move for priests and shopkeepers.  Called from shk_move() and pri_move().
21.    * Valid returns are  1: moved  0: didn't  -1: let m_move do it  -2: died.
22.    */
23.   int
24.   move_special(mtmp,in_his_shop,appr,uondoor,avoid,omx,omy,gx,gy)
25.   register struct monst *mtmp;
26.   boolean in_his_shop;
27.   schar appr;
28.   boolean uondoor,avoid;
29.   register xchar omx,omy,gx,gy;
30.   {
31.   	register xchar nx,ny,nix,niy;
32.   	register schar i;
33.   	schar chcnt,cnt;
34.   	coord poss[9];
35.   	long info[9];
36.   	long allowflags;
37.   	struct obj *ib = (struct obj *)0;
38.   
39.   	if(omx == gx && omy == gy)
40.   		return(0);
41.   	if(mtmp->mconf) {
42.   		avoid = FALSE;
43.   		appr = 0;
44.   	}
45.   
46.   	nix = omx;
47.   	niy = omy;
48.   	if (mtmp->isshk) allowflags = ALLOW_SSM;
49.   	else allowflags = ALLOW_SSM | ALLOW_SANCT;
50.   	if (passes_walls(mtmp->data)) allowflags |= (ALLOW_ROCK|ALLOW_WALL);
51.   	if (throws_rocks(mtmp->data)) allowflags |= ALLOW_ROCK;
52.   	if (tunnels(mtmp->data) &&
53.   		    (!needspick(mtmp->data) || m_carrying(mtmp, PICK_AXE) ||
54.   		     m_carrying(mtmp, DWARVISH_MATTOCK)))
55.   		allowflags |= ALLOW_DIG;
56.   	if (!nohands(mtmp->data) && !verysmall(mtmp->data)) {
57.   		allowflags |= OPENDOOR;
58.   		if (m_carrying(mtmp, SKELETON_KEY)) allowflags |= BUSTDOOR;
59.   	}
60.   	if (is_giant(mtmp->data)) allowflags |= BUSTDOOR;
61.   	cnt = mfndpos(mtmp, poss, info, allowflags);
62.   
63.   	if(mtmp->isshk && avoid && uondoor) { /* perhaps we cannot avoid him */
64.   		for(i=0; i<cnt; i++)
65.   		    if(!(info[i] & NOTONL)) goto pick_move;
66.   		avoid = FALSE;
67.   	}
68.   
69.   #define GDIST(x,y)	(dist2(x,y,gx,gy))
70.   pick_move:
71.   	chcnt = 0;
72.   	for(i=0; i<cnt; i++) {
73.   		nx = poss[i].x;
74.   		ny = poss[i].y;
75.   		if(levl[nx][ny].typ == ROOM ||
76.   			(mtmp->ispriest &&
77.   			    levl[nx][ny].typ == ALTAR) ||
78.   			(mtmp->isshk &&
79.   			    (!in_his_shop || ESHK(mtmp)->following))) {
80.   		    if(avoid && (info[i] & NOTONL))
81.   			continue;
82.   		    if((!appr && !rn2(++chcnt)) ||
83.   			(appr && GDIST(nx,ny) < GDIST(nix,niy))) {
84.   			    nix = nx;
85.   			    niy = ny;
86.   		    }
87.   		}
88.   	}
89.   	if(mtmp->ispriest && avoid &&
90.   			nix == omx && niy == omy && onlineu(omx,omy)) {
91.   		/* might as well move closer as long it's going to stay
92.   		 * lined up */
93.   		avoid = FALSE;
94.   		goto pick_move;
95.   	}
96.   
97.   	if(nix != omx || niy != omy) {
98.   		remove_monster(omx, omy);
99.   		place_monster(mtmp, nix, niy);
100.  		newsym(nix,niy);
101.  		if (mtmp->isshk && !in_his_shop && inhishop(mtmp))
102.  		    check_special_room(FALSE);
103.  		if(ib) {
104.  			if (cansee(mtmp->mx,mtmp->my))
105.  			    pline("%s picks up %s.", Monnam(mtmp),
106.  				distant_name(ib,doname));
107.  			obj_extract_self(ib);
108.  			(void) mpickobj(mtmp, ib);
109.  		}
110.  		return(1);
111.  	}
112.  	return(0);
113.  }
114.  
115.  #endif /* OVLB */
116.  
117.  #ifdef OVL0
118.  
119.  char
120.  temple_occupied(array)
121.  register char *array;
122.  {
123.  	register char *ptr;
124.  
125.  	for (ptr = array; *ptr; ptr++)
126.  		if (rooms[*ptr - ROOMOFFSET].rtype == TEMPLE)
127.  			return(*ptr);
128.  	return('\0');
129.  }
130.  
131.  #endif /* OVL0 */
132.  #ifdef OVLB
133.  
134.  STATIC_OVL boolean
135.  histemple_at(priest, x, y)
136.  register struct monst *priest;
137.  register xchar x, y;
138.  {
139.  	return((boolean)((EPRI(priest)->shroom == *in_rooms(x, y, TEMPLE)) &&
140.  	       on_level(&(EPRI(priest)->shrlevel), &u.uz)));
141.  }
142.  
143.  /*
144.   * pri_move: return 1: moved  0: didn't  -1: let m_move do it  -2: died
145.   */
146.  int
147.  pri_move(priest)
148.  register struct monst *priest;
149.  {
150.  	register xchar gx,gy,omx,omy;
151.  	schar temple;
152.  	boolean avoid = TRUE;
153.  
154.  	omx = priest->mx;
155.  	omy = priest->my;
156.  
157.  	if(!histemple_at(priest, omx, omy)) return(-1);
158.  
159.  	temple = EPRI(priest)->shroom;
160.  
161.  	gx = EPRI(priest)->shrpos.x;
162.  	gy = EPRI(priest)->shrpos.y;
163.  
164.  	gx += rn1(3,-1);	/* mill around the altar */
165.  	gy += rn1(3,-1);
166.  
167.  	if(!priest->mpeaceful ||
168.  	   (Conflict && !resist(priest, RING_CLASS, 0, 0))) {
169.  		if(monnear(priest, u.ux, u.uy)) {
170.  			if(Displaced)
171.  				Your("displaced image doesn't fool %s!",
172.  					mon_nam(priest));
173.  			(void) mattacku(priest);
174.  			return(0);
175.  		} else if(index(u.urooms, temple)) {
176.  			/* chase player if inside temple & can see him */
177.  			if(priest->mcansee && m_canseeu(priest)) {
178.  				gx = u.ux;
179.  				gy = u.uy;
180.  			}
181.  			avoid = FALSE;
182.  		}
183.  	} else if(Invis) avoid = FALSE;
184.  
185.  	return(move_special(priest,FALSE,TRUE,FALSE,avoid,omx,omy,gx,gy));
186.  }
187.  
188.  /* exclusively for mktemple() */
189.  void
190.  priestini(lvl, sroom, sx, sy, sanctum)
191.  d_level	*lvl;
192.  struct mkroom *sroom;
193.  int sx, sy;
194.  boolean sanctum;   /* is it the seat of the high priest? */
195.  {
196.  	struct monst *priest;
197.  	struct obj *otmp;
198.  	int cnt;
199.  
200.  	if(MON_AT(sx+1, sy))
201.  		rloc(m_at(sx+1, sy)); /* insurance */
202.  
203.  	priest = makemon(&mons[sanctum ? PM_HIGH_PRIEST : PM_ALIGNED_PRIEST],
204.  			 sx + 1, sy, NO_MM_FLAGS);
205.  	if (priest) {
206.  		EPRI(priest)->shroom = (sroom - rooms) + ROOMOFFSET;
207.  		EPRI(priest)->shralign = Amask2align(levl[sx][sy].altarmask);
208.  		EPRI(priest)->shrpos.x = sx;
209.  		EPRI(priest)->shrpos.y = sy;
210.  		assign_level(&(EPRI(priest)->shrlevel), lvl);
211.  		priest->mtrapseen = ~0;	/* traps are known */
212.  		priest->mpeaceful = 1;
213.  		priest->ispriest = 1;
214.  		priest->msleeping = 0;
215.  		set_malign(priest); /* mpeaceful may have changed */
216.  
217.  		/* now his/her goodies... */
218.  		if(sanctum && EPRI(priest)->shralign == A_NONE &&
219.  		     on_level(&sanctum_level, &u.uz)) {
220.  			(void) mongets(priest, AMULET_OF_YENDOR);
221.  		}
222.  		/* 2 to 4 spellbooks */
223.  		for (cnt = rn1(3,2); cnt > 0; --cnt) {
224.  		    (void) mpickobj(priest, mkobj(SPBOOK_CLASS, FALSE));
225.  		}
226.  		/* robe [via makemon()] */
227.  		if (rn2(2) && (otmp = which_armor(priest, W_ARMC)) != 0) {
228.  		    if (p_coaligned(priest))
229.  			uncurse(otmp);
230.  		    else
231.  			curse(otmp);
232.  		}
233.  	}
234.  }
235.  
236.  /*
237.   * Specially aligned monsters are named specially.
238.   *	- aligned priests with ispriest and high priests have shrines
239.   *		they retain ispriest and epri when polymorphed
240.   *	- aligned priests without ispriest and Angels are roamers
241.   *		they retain isminion and access epri as emin when polymorphed
242.   *		(coaligned Angels are also created as minions, but they
243.   *		use the same naming convention)
244.   *	- minions do not have ispriest but have isminion and emin
245.   *	- caller needs to inhibit Hallucination if it wants to force
246.   *		the true name even when under that influence
247.   */
248.  char *
249.  priestname(mon, pname)
250.  register struct monst *mon;
251.  char *pname;		/* caller-supplied output buffer */
252.  {
253.  	const char *what = Hallucination ? rndmonnam() : mon->data->mname;
254.  
255.  	Strcpy(pname, "the ");
256.  	if (mon->minvis) Strcat(pname, "invisible ");
257.  	if (mon->ispriest || mon->data == &mons[PM_ALIGNED_PRIEST] ||
258.  					mon->data == &mons[PM_ANGEL]) {
259.  		/* use epri */
260.  		if (mon->mtame && mon->data == &mons[PM_ANGEL])
261.  			Strcat(pname, "guardian ");
262.  		if (mon->data != &mons[PM_ALIGNED_PRIEST] &&
263.  				mon->data != &mons[PM_HIGH_PRIEST]) {
264.  			Strcat(pname, what);
265.  			Strcat(pname, " ");
266.  		}
267.  		if (mon->data != &mons[PM_ANGEL]) {
268.  			if (!mon->ispriest && EPRI(mon)->renegade)
269.  				Strcat(pname, "renegade ");
270.  			if (mon->data == &mons[PM_HIGH_PRIEST])
271.  				Strcat(pname, "high ");
272.  			if (Hallucination)
273.  				Strcat(pname, "poohbah ");
274.  			else if (mon->female)
275.  				Strcat(pname, "priestess ");
276.  			else
277.  				Strcat(pname, "priest ");
278.  		}
279.  		Strcat(pname, "of ");
280.  		Strcat(pname, halu_gname((int)EPRI(mon)->shralign));
281.  		return(pname);
282.  	}
283.  	/* use emin instead of epri */
284.  	Strcat(pname, what);
285.  	Strcat(pname, " of ");
286.  	Strcat(pname, halu_gname(EMIN(mon)->min_align));
287.  	return(pname);
288.  }
289.  
290.  boolean
291.  p_coaligned(priest)
292.  struct monst *priest;
293.  {
294.  	return((boolean)(u.ualign.type == ((int)EPRI(priest)->shralign)));
295.  }
296.  
297.  STATIC_OVL boolean
298.  has_shrine(pri)
299.  struct monst *pri;
300.  {
301.  	struct rm *lev;
302.  
303.  	if(!pri)
304.  		return(FALSE);
305.  	lev = &levl[EPRI(pri)->shrpos.x][EPRI(pri)->shrpos.y];
306.  	if (!IS_ALTAR(lev->typ) || !(lev->altarmask & AM_SHRINE))
307.  		return(FALSE);
308.  	return((boolean)(EPRI(pri)->shralign == Amask2align(lev->altarmask & ~AM_SHRINE)));
309.  }
310.  
311.  struct monst *
312.  findpriest(roomno)
313.  char roomno;
314.  {
315.  	register struct monst *mtmp;
316.  
317.  	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
318.  	    if (DEADMONSTER(mtmp)) continue;
319.  	    if(mtmp->ispriest && (EPRI(mtmp)->shroom == roomno) &&
320.  	       histemple_at(mtmp,mtmp->mx,mtmp->my))
321.  		return(mtmp);
322.  	}
323.  	return (struct monst *)0;
324.  }
325.  
326.  /* called from check_special_room() when the player enters the temple room */
327.  void
328.  intemple(roomno)
329.  register int roomno;
330.  {
331.  	register struct monst *priest = findpriest((char)roomno);
332.  	boolean tended = (priest != (struct monst *)0);
333.  	boolean shrined, sanctum, can_speak;
334.  	const char *msg1, *msg2;
335.  	char buf[BUFSZ];
336.  
337.  	if(!temple_occupied(u.urooms0)) {
338.  	    if(tended) {
339.  		shrined = has_shrine(priest);
340.  		sanctum = (priest->data == &mons[PM_HIGH_PRIEST] &&
341.  			   (Is_sanctum(&u.uz) || In_endgame(&u.uz)));
342.  		can_speak = (priest->mcanmove && !priest->msleeping);
343.  		if (can_speak)
344.  		    pline("%s intones:",
345.  			  (!Blind ? Monnam(priest) : "A nearby voice"));
346.  		msg2 = 0;
347.  		if(sanctum && Is_sanctum(&u.uz)) {
348.  		    if(priest->mpeaceful) {
349.  			msg1 = "Infidel, you entered Moloch's Sanctum!";
350.  			msg2 = "Be gone!";
351.  			priest->mpeaceful = 0;
352.  			set_malign(priest);
353.  		    } else
354.  			msg1 = "You desecrate this place by your presence!";
355.  		} else {
356.  		    Sprintf(buf, "Pilgrim, you enter a %s place!",
357.  			    !shrined ? "desecrated" : "sacred");
358.  		    msg1 = buf;
359.  		}
360.  		if (can_speak) {
361.  		    verbalize(msg1);
362.  		    if (msg2) verbalize(msg2);
363.  		}
364.  		if(!sanctum) {
365.  		    /* !tended -> !shrined */
366.  		    if (!shrined || !p_coaligned(priest) ||
367.  			    u.ualign.record <= ALGN_SINNED)
368.  			You("have a%s forbidding feeling...",
369.  				(!shrined) ? "" : " strange");
370.  		    else You("experience a strange sense of peace.");
371.  		}
372.  	    } else {
373.  		switch(rn2(3)) {
374.  		  case 0: You("have an eerie feeling..."); break;
375.  		  case 1: You_feel("like you are being watched."); break;
376.  		  default: pline("A shiver runs down your %s.",
377.  			body_part(SPINE)); break;
378.  		}
379.  		if(!rn2(5)) {
380.  		    struct monst *mtmp;
381.  
382.  		    if(!(mtmp = makemon(&mons[PM_GHOST],u.ux,u.uy,NO_MM_FLAGS)))
383.  			return;
384.  		    pline("An enormous ghost appears next to you!");
385.  		    mtmp->mpeaceful = 0;
386.  		    set_malign(mtmp);
387.  		    if(flags.verbose)
388.  			You("are frightened to death, and unable to move.");
389.  		    nomul(-3);
390.  		    nomovemsg = "You regain your composure.";
391.  	       }
392.  	   }
393.         }
394.  }
395.  
396.  void
397.  priest_talk(priest)
398.  register struct monst *priest;
399.  {
400.  	boolean coaligned = p_coaligned(priest);
401.  	boolean strayed = (u.ualign.record < 0);
402.  
403.  	/* KMH, conduct */
404.  	u.uconduct.gnostic++;
405.  
406.  	if(priest->mflee || (!priest->ispriest && coaligned && strayed)) {
407.  	    pline("%s doesn't want anything to do with you!",
408.  				Monnam(priest));
409.  	    priest->mpeaceful = 0;
410.  	    return;
411.  	}
412.  
413.  	/* priests don't chat unless peaceful and in their own temple */
414.  	if(!histemple_at(priest,priest->mx,priest->my) ||
415.  		 !priest->mpeaceful || !priest->mcanmove || priest->msleeping) {
416.  	    static const char *cranky_msg[3] = {
417.  		"Thou wouldst have words, eh?  I'll give thee a word or two!",
418.  		"Talk?  Here is what I have to say!",
419.  		"Pilgrim, I would speak no longer with thee."
420.  	    };
421.  
422.  	    if(!priest->mcanmove || priest->msleeping) {
423.  		pline("%s breaks out of %s reverie!",
424.  		      Monnam(priest), mhis(priest));
425.  		priest->mfrozen = priest->msleeping = 0;
426.  		priest->mcanmove = 1;
427.  	    }
428.  	    priest->mpeaceful = 0;
429.  	    verbalize(cranky_msg[rn2(3)]);
430.  	    return;
431.  	}
432.  
433.  	/* you desecrated the temple and now you want to chat? */
434.  	if(priest->mpeaceful && *in_rooms(priest->mx, priest->my, TEMPLE) &&
435.  		  !has_shrine(priest)) {
436.  	    verbalize("Begone!  Thou desecratest this holy place with thy presence.");
437.  	    priest->mpeaceful = 0;
438.  	    return;
439.  	}
440.  #ifndef GOLDOBJ
441.  	if(!u.ugold) {
442.  	    if(coaligned && !strayed) {
443.  		if (priest->mgold > 0L) {
444.  		    /* Note: two bits is actually 25 cents.  Hmm. */
445.  		    pline("%s gives you %s for an ale.", Monnam(priest),
446.  			(priest->mgold == 1L) ? "one bit" : "two bits");
447.  		    if (priest->mgold > 1L)
448.  			u.ugold = 2L;
449.  		    else
450.  			u.ugold = 1L;
451.  		    priest->mgold -= u.ugold;
452.  		    flags.botl = 1;
453.  #else
454.  	if(!money_cnt(invent)) {
455.  	    if(coaligned && !strayed) {
456.                  long pmoney = money_cnt(priest->minvent);
457.  		if (pmoney > 0L) {
458.  		    /* Note: two bits is actually 25 cents.  Hmm. */
459.  		    pline("%s gives you %s for an ale.", Monnam(priest),
460.  			(pmoney == 1L) ? "one bit" : "two bits");
461.  		     money2u(priest, pmoney > 1L ? 2 : 1);
462.  #endif
463.  		} else
464.  		    pline("%s preaches the virtues of poverty.", Monnam(priest));
465.  		exercise(A_WIS, TRUE);
466.  	    } else
467.  		pline("%s is not interested.", Monnam(priest));
468.  	    return;
469.  	} else {
470.  	    long offer;
471.  
472.  	    pline("%s asks you for a contribution for the temple.",
473.  			Monnam(priest));
474.  	    if((offer = bribe(priest)) == 0) {
475.  		verbalize("Thou shalt regret thine action!");
476.  		if(coaligned) adjalign(-1);
477.  	    } else if(offer < (u.ulevel * 200)) {
478.  #ifndef GOLDOBJ
479.  		if(u.ugold > (offer * 2L)) verbalize("Cheapskate.");
480.  #else
481.  		if(money_cnt(invent) > (offer * 2L)) verbalize("Cheapskate.");
482.  #endif
483.  		else {
484.  		    verbalize("I thank thee for thy contribution.");
485.  		    /*  give player some token  */
486.  		    exercise(A_WIS, TRUE);
487.  		}
488.  	    } else if(offer < (u.ulevel * 400)) {
489.  		verbalize("Thou art indeed a pious individual.");
490.  #ifndef GOLDOBJ
491.  		if(u.ugold < (offer * 2L)) {
492.  #else
493.  		if(money_cnt(invent) < (offer * 2L)) {
494.  #endif
495.  		    if (coaligned && u.ualign.record <= ALGN_SINNED)
496.  			adjalign(1);
497.  		    verbalize("I bestow upon thee a blessing.");
498.  		    incr_itimeout(&HClairvoyant, rn1(500,500));
499.  		}
500.  	    } else if(offer < (u.ulevel * 600) &&
501.  		      u.ublessed < 20 &&
502.  		      (u.ublessed < 9 || !rn2(u.ublessed))) {
503.  		verbalize("Thy devotion has been rewarded.");
504.  		if (!(HProtection & INTRINSIC))  {
505.  			HProtection |= FROMOUTSIDE;
506.  			if (!u.ublessed)  u.ublessed = rn1(3, 2);
507.  		} else u.ublessed++;
508.  	    } else {
509.  		verbalize("Thy selfless generosity is deeply appreciated.");
510.  #ifndef GOLDOBJ
511.  		if(u.ugold < (offer * 2L) && coaligned) {
512.  #else
513.  		if(money_cnt(invent) < (offer * 2L) && coaligned) {
514.  #endif
515.  		    if(strayed && (moves - u.ucleansed) > 5000L) {
516.  			u.ualign.record = 0; /* cleanse thee */
517.  			u.ucleansed = moves;
518.  		    } else {
519.  			adjalign(2);
520.  		    }
521.  		}
522.  	    }
523.  	}
524.  }
525.  
526.  struct monst *
527.  mk_roamer(ptr, alignment, x, y, peaceful)
528.  register struct permonst *ptr;
529.  aligntyp alignment;
530.  xchar x, y;
531.  boolean peaceful;
532.  {
533.  	register struct monst *roamer;
534.  	register boolean coaligned = (u.ualign.type == alignment);
535.  
536.  	if (ptr != &mons[PM_ALIGNED_PRIEST] && ptr != &mons[PM_ANGEL])
537.  		return((struct monst *)0);
538.  	
539.  	if (MON_AT(x, y)) rloc(m_at(x, y));	/* insurance */
540.  
541.  	if (!(roamer = makemon(ptr, x, y, NO_MM_FLAGS)))
542.  		return((struct monst *)0);
543.  
544.  	EPRI(roamer)->shralign = alignment;
545.  	if (coaligned && !peaceful)
546.  		EPRI(roamer)->renegade = TRUE;
547.  	/* roamer->ispriest == FALSE naturally */
548.  	roamer->isminion = TRUE;	/* borrowing this bit */
549.  	roamer->mtrapseen = ~0;		/* traps are known */
550.  	roamer->mpeaceful = peaceful;
551.  	roamer->msleeping = 0;
552.  	set_malign(roamer); /* peaceful may have changed */
553.  
554.  	/* MORE TO COME */
555.  	return(roamer);
556.  }
557.  
558.  void
559.  reset_hostility(roamer)
560.  register struct monst *roamer;
561.  {
562.  	if(!(roamer->isminion && (roamer->data == &mons[PM_ALIGNED_PRIEST] ||
563.  				  roamer->data == &mons[PM_ANGEL])))
564.  	        return;
565.  
566.  	if(EPRI(roamer)->shralign != u.ualign.type) {
567.  	    roamer->mpeaceful = roamer->mtame = 0;
568.  	    set_malign(roamer);
569.  	}
570.  	newsym(roamer->mx, roamer->my);
571.  }
572.  
573.  boolean
574.  in_your_sanctuary(mon, x, y)
575.  struct monst *mon;	/* if non-null, <mx,my> overrides <x,y> */
576.  xchar x, y;
577.  {
578.  	register char roomno;
579.  	register struct monst *priest;
580.  
581.  	if (mon) {
582.  	    if (is_minion(mon->data) || is_rider(mon->data)) return FALSE;
583.  	    x = mon->mx, y = mon->my;
584.  	}
585.  	if (u.ualign.record <= ALGN_SINNED)	/* sinned or worse */
586.  	    return FALSE;
587.  	if ((roomno = temple_occupied(u.urooms)) == 0 ||
588.  		roomno != *in_rooms(x, y, TEMPLE))
589.  	    return FALSE;
590.  	if ((priest = findpriest(roomno)) == 0)
591.  	    return FALSE;
592.  	return (boolean)(has_shrine(priest) &&
593.  			 p_coaligned(priest) &&
594.  			 priest->mpeaceful);
595.  }
596.  
597.  void
598.  ghod_hitsu(priest)	/* when attacking "priest" in his temple */
599.  struct monst *priest;
600.  {
601.  	int x, y, ax, ay, roomno = (int)temple_occupied(u.urooms);
602.  	struct mkroom *troom;
603.  
604.  	if (!roomno || !has_shrine(priest))
605.  		return;
606.  
607.  	ax = x = EPRI(priest)->shrpos.x;
608.  	ay = y = EPRI(priest)->shrpos.y;
609.  	troom = &rooms[roomno - ROOMOFFSET];
610.  
611.  	if((u.ux == x && u.uy == y) || !linedup(u.ux, u.uy, x, y)) {
612.  	    if(IS_DOOR(levl[u.ux][u.uy].typ)) {
613.  
614.  		if(u.ux == troom->lx - 1) {
615.  		    x = troom->hx;
616.  		    y = u.uy;
617.  		} else if(u.ux == troom->hx + 1) {
618.  		    x = troom->lx;
619.  		    y = u.uy;
620.  		} else if(u.uy == troom->ly - 1) {
621.  		    x = u.ux;
622.  		    y = troom->hy;
623.  		} else if(u.uy == troom->hy + 1) {
624.  		    x = u.ux;
625.  		    y = troom->ly;
626.  		}
627.  	    } else {
628.  		switch(rn2(4)) {
629.  		case 0:  x = u.ux; y = troom->ly; break;
630.  		case 1:  x = u.ux; y = troom->hy; break;
631.  		case 2:  x = troom->lx; y = u.uy; break;
632.  		default: x = troom->hx; y = u.uy; break;
633.  		}
634.  	    }
635.  	    if(!linedup(u.ux, u.uy, x, y)) return;
636.  	}
637.  
638.  	switch(rn2(3)) {
639.  	case 0:
640.  	    pline("%s roars in anger:  \"Thou shalt suffer!\"",
641.  			a_gname_at(ax, ay));
642.  	    break;
643.  	case 1:
644.  	    pline("%s voice booms:  \"How darest thou harm my servant!\"",
645.  			s_suffix(a_gname_at(ax, ay)));
646.  	    break;
647.  	default:
648.  	    pline("%s roars:  \"Thou dost profane my shrine!\"",
649.  			a_gname_at(ax, ay));
650.  	    break;
651.  	}
652.  
653.  	buzz(-10-(AD_ELEC-1), 6, x, y, sgn(tbx), sgn(tby)); /* bolt of lightning */
654.  	exercise(A_WIS, FALSE);
655.  }
656.  
657.  void
658.  angry_priest()
659.  {
660.  	register struct monst *priest;
661.  	struct rm *lev;
662.  
663.  	if ((priest = findpriest(temple_occupied(u.urooms))) != 0) {
664.  	    wakeup(priest);
665.  	    /*
666.  	     * If the altar has been destroyed or converted, let the
667.  	     * priest run loose.
668.  	     * (When it's just a conversion and there happens to be
669.  	     *	a fresh corpse nearby, the priest ought to have an
670.  	     *	opportunity to try converting it back; maybe someday...)
671.  	     */
672.  	    lev = &levl[EPRI(priest)->shrpos.x][EPRI(priest)->shrpos.y];
673.  	    if (!IS_ALTAR(lev->typ) ||
674.  		((aligntyp)Amask2align(lev->altarmask & AM_MASK) !=
675.  			EPRI(priest)->shralign)) {
676.  		priest->ispriest = 0;		/* now a roamer */
677.  		priest->isminion = 1;		/* but still aligned */
678.  		/* this overloads the `shroom' field, which is now clobbered */
679.  		EPRI(priest)->renegade = 0;
680.  	    }
681.  	}
682.  }
683.  
684.  /*
685.   * When saving bones, find priests that aren't on their shrine level,
686.   * and remove them.   This avoids big problems when restoring bones.
687.   */
688.  void
689.  clearpriests()
690.  {
691.      register struct monst *mtmp, *mtmp2;
692.  
693.      for(mtmp = fmon; mtmp; mtmp = mtmp2) {
694.  	mtmp2 = mtmp->nmon;
695.  	if (!DEADMONSTER(mtmp) && mtmp->ispriest && !on_level(&(EPRI(mtmp)->shrlevel), &u.uz))
696.  	    mongone(mtmp);
697.      }
698.  }
699.  
700.  /* munge priest-specific structure when restoring -dlc */
701.  void
702.  restpriest(mtmp, ghostly)
703.  register struct monst *mtmp;
704.  boolean ghostly;
705.  {
706.      if(u.uz.dlevel) {
707.  	if (ghostly)
708.  	    assign_level(&(EPRI(mtmp)->shrlevel), &u.uz);
709.      }
710.  }
711.  
712.  #endif /* OVLB */
713.  
714.  /*priest.c*/