Fandom

Wikihack

Source:NetHack 3.0.0/priest.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Below is the full text to priest.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.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.
1.    /*	SCCS Id: @(#)priest.c	3.0	89/06/26
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* Copyright (c) Izchak Miller, Steve Linhart, 1989. */
4.    /* NetHack may be freely redistributed.  See license for details. */
5.    
6.    /* block some unused #defines to avoid overloading some cpp's */
7.    #define MONATTK_H
8.    #include "hack.h"
9.    #include "mfndpos.h"
10.   #include "eshk.h"
11.   #include "epri.h"
12.   
13.   /* used for the insides of shk_move and pri_move */
14.   int
15.   move_special(mtmp,monroom,appr,uondoor,avoid,omx,omy,gx,gy)
16.   register struct monst *mtmp;
17.   schar monroom,appr;
18.   boolean uondoor,avoid;
19.   register xchar omx,omy,gx,gy;
20.   {
21.   	register xchar nx,ny,nix,niy;
22.   	register schar i;
23.   	schar chcnt,cnt;
24.   	coord poss[9];
25.   	long info[9];
26.   	long allowflags;
27.   	struct obj *ib = 0;
28.   
29.   	if(omx == gx && omy == gy)
30.   		return(0);
31.   	if(mtmp->mconf) {
32.   		avoid = FALSE;
33.   		appr = 0;
34.   	}
35.   
36.   	nix = omx;
37.   	niy = omy;
38.   	if (mtmp->isshk) allowflags = ALLOW_SSM;
39.   	else allowflags = ALLOW_SSM | ALLOW_SANCT;
40.   	if (passes_walls(mtmp->data)) allowflags |= (ALLOW_ROCK|ALLOW_WALL);
41.   	if (throws_rocks(mtmp->data)) allowflags |= ALLOW_ROCK;
42.   	if (tunnels(mtmp->data) &&
43.   		    (!needspick(mtmp->data) || m_carrying(mtmp, PICK_AXE)))
44.   		allowflags |= ALLOW_DIG;
45.   	cnt = mfndpos(mtmp, poss, info, allowflags);
46.   	if (allowflags & ALLOW_DIG) if(!mdig_tunnel(mtmp)) return(-2);
47.   
48.   	if(mtmp->isshk && avoid && uondoor) { /* perhaps we cannot avoid him */
49.   		for(i=0; i<cnt; i++)
50.   		    if(!(info[i] & NOTONL)) goto pick_move;
51.   		avoid = FALSE;
52.   	}
53.   
54.   #define	GDIST(x,y)	(dist2(x,y,gx,gy))
55.   pick_move:
56.   	chcnt = 0;
57.   	for(i=0; i<cnt; i++) {
58.   		nx = poss[i].x;
59.   		ny = poss[i].y;
60.   		if(levl[nx][ny].typ == ROOM ||
61.   #if defined(ALTARS) && defined(THEOLOGY)
62.   			(mtmp->ispriest &&
63.   			    levl[nx][ny].typ == ALTAR) ||
64.   #endif
65.   			(mtmp->isshk &&
66.   			    (monroom != ESHK(mtmp)->shoproom
67.   			    || ESHK(mtmp)->following))) {
68.   		    if(avoid && (info[i] & NOTONL))
69.   			continue;
70.   		    if((!appr && !rn2(++chcnt)) ||
71.   			(appr && GDIST(nx,ny) < GDIST(nix,niy))) {
72.   			    nix = nx;
73.   			    niy = ny;
74.   		    }
75.   		}
76.   	}
77.   #if defined(ALTARS) && defined(THEOLOGY)
78.   	if(mtmp->ispriest && avoid &&
79.   			nix == omx && niy == omy && online(omx,omy)) {
80.   		/* might as well move closer as long it's going to stay
81.   		 * lined up */
82.   		avoid = FALSE;
83.   		goto pick_move;
84.   	}
85.   #endif
86.   
87.   	if(nix != omx || niy != omy) {
88.   		levl[omx][omy].mmask = 0;
89.   		levl[nix][niy].mmask = 1;
90.   		mtmp->mx = nix;
91.   		mtmp->my = niy;
92.   		pmon(mtmp);
93.   		if(ib) {
94.   			if (cansee(mtmp->mx,mtmp->my))
95.   			    pline("%s picks up %s.", Monnam(mtmp),
96.   				distant_name(ib,doname));
97.   			freeobj(ib);
98.   			mpickobj(mtmp, ib);
99.   		}
100.  		return(1);
101.  	}
102.  	return(0);
103.  }
104.  
105.  #if defined(ALTARS) && defined(THEOLOGY)
106.  
107.  struct mkroom *
108.  in_temple(x, y)
109.  register int x, y;
110.  {
111.  	register int roomno = inroom(x, y);
112.  
113.  	if (roomno < 0 || rooms[roomno].rtype != TEMPLE) return(FALSE);
114.  	return(&rooms[roomno]);
115.  }
116.  
117.  static boolean
118.  histemple_at(priest, x, y)
119.  register struct monst *priest;
120.  register int x, y;
121.  {
122.  	return(EPRI(priest)->shroom == inroom(x, y) && 
123.  	       EPRI(priest)->shrlevel == dlevel);
124.  }
125.  
126.  /*
127.   * pri_move: return 1: he moved  0: he didn't  -1: let m_move do it  -2: died
128.   */
129.  int
130.  pri_move(priest)
131.  register struct monst *priest;
132.  {
133.  	register xchar gx,gy,omx,omy;
134.  	schar temple;
135.  	boolean avoid = TRUE;
136.  
137.  	omx = priest->mx;
138.  	omy = priest->my;
139.  
140.  	if(!histemple_at(priest, omx, omy)) return(-1);
141.  
142.  	temple = EPRI(priest)->shroom;
143.  	
144.  	gx = EPRI(priest)->shrpos.x;
145.  	gy = EPRI(priest)->shrpos.y;
146.  
147.  	gx += rn1(3,-1);	/* mill around the altar */
148.  	gy += rn1(3,-1);
149.  
150.  	if(!priest->mpeaceful) {
151.  		if(dist(omx,omy) < 3) {
152.  			if(Displaced)
153.  				Your("displaced image doesn't fool %s!",
154.  					mon_nam(priest));
155.  			(void) mattacku(priest);
156.  			return(0);
157.  		} else if(temple == inroom(u.ux,u.uy)) {
158.  			/* don't chase player outside temple */
159.  			long saveBlind = Blinded;
160.  			struct obj *saveUblindf = ublindf;
161.  			Blinded = 0;
162.  			ublindf = (struct obj *)0;
163.  			if(priest->mcansee && !Invis && cansee(omx,omy)) {
164.  				gx = u.ux;
165.  				gy = u.uy;
166.  			}
167.  			Blinded = saveBlind;
168.  			ublindf = saveUblindf;
169.  			avoid = FALSE;
170.  		}
171.  	} else if(Invis) avoid = FALSE;
172.  	
173.  	return(move_special(priest,temple,TRUE,FALSE,avoid,omx,omy,gx,gy));
174.  }
175.  
176.  /* exclusevely for mktemple() */
177.  void
178.  priestini(lvl, sx, sy, align)
179.  register int lvl, sx, sy, align;
180.  {
181.  	register struct monst *priest;
182.  	register struct obj *otmp = (struct obj *)0;
183.  #ifdef SPELLS
184.  	register int cnt;
185.  #endif
186.  
187.  	if (priest = makemon(&mons[!rn2(2) ? PM_TEMPLE_PRIEST : 
188.  			PM_TEMPLE_PRIESTESS], sx+1, sy)) {
189.  		EPRI(priest)->shroom = inroom(sx, sy);
190.  		EPRI(priest)->shralign = align;
191.  		EPRI(priest)->shrpos.x = sx;
192.  		EPRI(priest)->shrpos.y = sy;
193.  		EPRI(priest)->shrlevel = lvl;
194.  		EPRI(priest)->ismale = 
195.  				(priest->data == &mons[PM_TEMPLE_PRIEST]);
196.  		Strcpy(EPRI(priest)->deitynam, a_gname_at(sx, sy));
197.  		priest->mtrapseen = ~0;	/* traps are known */
198.  		priest->mpeaceful = 1;
199.  		priest->ispriest = 1;
200.  		priest->msleep = 0;
201.  
202.  		/* now his/her goodies... */
203.  		(void) mongets(priest, CHAIN_MAIL);
204.  		(void) mongets(priest, SMALL_SHIELD);
205.  
206.  		/* Do NOT put the rest in m_initinv.    */
207.  		/* Priests created elsewhere than in a  */
208.  		/* temple should not carry these items, */
209.  		/* except for the mace.			*/
210.  #ifdef SPELLS
211.  		cnt = rn1(2,3);
212.  		while(cnt) {
213.  		    otmp = mkobj(SPBOOK_SYM, FALSE);
214.  		    if(otmp) mpickobj(priest, otmp);
215.  		    cnt--;
216.  		}
217.  #endif
218.  		if(p_coaligned(priest)) {
219.  		    (void) mongets(priest, rn2(2) ? CLOAK_OF_PROTECTION
220.  						  : CLOAK_OF_MAGIC_RESISTANCE);
221.  #ifdef NAMED_ITEMS
222.  		    otmp = mk_aligned_artifact(EPRI(priest)->shralign);
223.  		    if(otmp) {
224.  			otmp->spe = rnd(4);
225.  			mpickobj(priest, otmp);
226.  		    }
227.  #endif
228.  		} else {
229.  		    if(!rn2(5)) 
230.  			otmp = mksobj(CLOAK_OF_MAGIC_RESISTANCE, FALSE); 
231.  		    else otmp = mksobj(CLOAK_OF_PROTECTION, FALSE); 
232.  		    if(otmp) {
233.  			if(!rn2(2)) curse(otmp);
234.  			mpickobj(priest, otmp);
235.  		    }
236.  		    otmp = mksobj(MACE, FALSE);
237.  		    if(otmp) {
238.  			otmp->spe = rnd(3);
239.  			if(!rn2(2)) curse(otmp);
240.  			mpickobj(priest, otmp);
241.  		    }
242.  		}
243.  	}
244.  }
245.  
246.  char *
247.  priestname(priest)
248.  register struct monst *priest;
249.  {
250.  	static char pname[PL_NSIZ];
251.  
252.  	Strcpy(pname, "the ");
253.  	if(priest->minvis) Strcat(pname, "invisible ");
254.  	if(priest->data != &mons[PM_TEMPLE_PRIEST] &&
255.  			priest->data != &mons[PM_TEMPLE_PRIESTESS]) {
256.  		Strcat(pname, priest->data->mname);
257.  		Strcat(pname, " ");
258.  	}
259.  	if(EPRI(priest)->ismale)
260.  		Strcat(pname, "priest of ");
261.  	else 	Strcat(pname, "priestess of ");
262.  	Strcat(pname, EPRI(priest)->deitynam);
263.  	return(pname);
264.  }
265.  
266.  boolean
267.  p_coaligned(priest)
268.  struct monst *priest;
269.  {
270.  	return(!strcmp(u_gname(), EPRI(priest)->deitynam));
271.  }
272.  
273.  static int
274.  t_alignment(troom)
275.  struct mkroom *troom;
276.  {
277.  	int x, y;
278.  
279.  	shrine_pos(&x,&y,troom);
280.  
281.  	if(IS_ALTAR(levl[x][y].typ) && (levl[x][y].altarmask & A_SHRINE) != 0)
282.  		return(levl[x][y].altarmask & ~A_SHRINE); 
283.  	return(-2); /* arbitrary non-alignment type value */
284.  }
285.  
286.  static boolean
287.  is_shrined(troom)
288.  struct mkroom *troom;
289.  {
290.  	int x, y;
291.  
292.  	shrine_pos(&x,&y,troom);
293.  
294.  	if(IS_ALTAR(levl[x][y].typ) && (levl[x][y].altarmask & A_SHRINE) != 0)
295.  		return(TRUE);
296.  	return(FALSE);
297.  }
298.  
299.  static boolean
300.  t_coaligned(troom)
301.  struct mkroom *troom;
302.  {
303.  	return(t_alignment(troom) == u.ualigntyp + 1);
304.  }
305.  
306.  struct monst *
307.  findpriest(troom)
308.  struct mkroom *troom;
309.  {
310.  	register struct monst *mtmp;
311.  
312.  	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
313.  	    if(mtmp->ispriest && histemple_at(mtmp,mtmp->mx,mtmp->my)
314.  			&& &rooms[EPRI(mtmp)->shroom] == troom)
315.  		return(mtmp);
316.  	return (struct monst *)0;
317.  }
318.  
319.  static boolean
320.  p_inhistemple(troom)
321.  struct mkroom *troom;
322.  {
323.  	register struct monst *priest;
324.  
325.  	priest = findpriest(troom);
326.  	if(priest) return(TRUE);
327.  	return(FALSE);
328.  }
329.  
330.  void
331.  intemple() {
332.  	register struct mkroom *troom;
333.  
334.  	if(troom = in_temple(u.ux, u.uy)) {
335.  	    boolean shrined = is_shrined(troom);
336.  	    boolean tended = p_inhistemple(troom);
337.  
338.  	    if(!in_temple(u.ux0, u.uy0)) {
339.  		pline("Pilgrim, you enter a%s place!",
340.  			(!(shrined || tended) ? " desecrated and deserted" :
341.  			 !shrined ? " desecrated" :
342.  			 !tended ? "n untended sacred" :
343.  			  " sacred"));
344.  		if(!t_coaligned(troom) || u.ualign < -5 || !shrined || !tended)
345.  		    You("have a%s forbidding feeling...",
346.  				(!shrined || !tended) ? "" :
347.  				 " strange");
348.  		else You("experience a strange sense of peace.");
349.  	    } else if(!(shrined || tended) && !rn2(5)) {
350.  		switch(rn2(3)) {
351.  		    case 0: You("have an eerie feeling..."); break;
352.  		    case 1: You("feel like you are being watched."); break;
353.  		    default: pline("A shiver runs down your spine."); break;
354.  		}
355.  		if(!rn2(5)) {
356.  		    struct monst *mtmp;
357.  
358.  		    if(!(mtmp = makemon(&mons[PM_GHOST],u.ux,u.uy))) return;
359.  		    pline("An enormous ghost appears next to you!");
360.  		    mnexto(mtmp);
361.  		    mtmp->mpeaceful = 0;
362.  		    if(flags.verbose)
363.  		        You("are frightened to death, and unable to move.");
364.  		    nomul(-3);
365.  		    nomovemsg = "You regain your composure.";
366.  		}
367.  	    }
368.  	}
369.  }
370.  
371.  void
372.  priest_talk(priest)
373.  register struct monst *priest;
374.  {
375.  	boolean coaligned = p_coaligned(priest);
376.  	boolean strayed = (u.ualign < 0);
377.   
378.  	if(priest->mflee) {
379.  	    kludge("%s doesn't want anything to do with you!", 
380.  				Monnam(priest));
381.  	    priest->mtame = priest->mpeaceful = 0;
382.  	    return;
383.  	}
384.  
385.  	/* priests don't chat unless peaceful and in their own temple */
386.  	if(!histemple_at(priest,priest->mx,priest->my) || priest->mtame ||
387.  		 !priest->mpeaceful || priest->mfroz || priest->msleep) {
388.              if(priest->mfroz || priest->msleep) {
389.  	        kludge("%s breaks out of his reverie!", Monnam(priest));
390.                  priest->mfroz = priest->msleep = 0;
391.  	    }
392.  	    /* The following is now impossible according to monst.c, */
393.  	    /* but it should stay just in case we change the latter. */
394.  	    if(priest->mtame)
395.  		kludge("%s breaks out of your taming spell!", Monnam(priest));
396.  	    priest->mtame = priest->mpeaceful = 0;
397.  	    switch(rn2(3)) {
398.  	        case 0: 
399.  		   verbalize("Thou wouldst have words, eh?  I'll give thee a word or two!"); 
400.  		   break;
401.  	        case 1: 
402.  		   verbalize("Talk?  Here is what I have to say!"); 
403.  		   break;
404.  	        default: 
405.  		   verbalize("Pilgrim, I have lost mine desire to talk.");
406.  		   break;
407.  	    }
408.  	    return;
409.  	}
410.  
411.  	/* he desecrated the temple and now he wants to chat? */
412.  	if(!is_shrined(&rooms[inroom(priest->mx, priest->my)])
413.  		&& priest->mpeaceful) {
414.  	    verbalize("Begone!  Thou desecratest this holy place with thy presence.");
415.  	    priest->mpeaceful = 0;
416.  	    return;
417.  	} 
418.  
419.  	if(!u.ugold) {
420.  	    if(coaligned && !strayed) {
421.  	        kludge("%s gives you two bits for an ale.", Monnam(priest));
422.  	        u.ugold = 2L;
423.  		if (priest->mgold) priest->mgold -= 2L;
424.  	    } else
425.  		kludge("%s is not interested.", Monnam(priest));
426.  	    return;
427.  	} else {
428.  	    long offer;
429.  
430.  	    kludge("%s asks you for a contribution for the temple.",
431.  			Monnam(priest));
432.  	    if((offer = bribe(priest)) == 0) {
433.  		verbalize("Thou shalt regret thine action!");
434.  		if(coaligned) u.ualign--;
435.  	    } else if(offer < (u.ulevel * 200)) {
436.  		if(u.ugold > (offer * 2L)) verbalize("Cheapskate.");
437.  		else {
438.  		    verbalize("I thank thee for thy contribution.");
439.  		    /*  give player some token  */
440.  		}
441.  	    } else if(offer < (u.ulevel * 400)) {
442.  		verbalize("Thou art indeed a pious individual.");
443.  		if(u.ugold < (offer * 2L)) { 
444.  		    if(coaligned && u.ualign < -5) u.ualign++;
445.  		    verbalize("I bestow upon thee a blessing.");
446.  		    Clairvoyant += rn1(500,500);
447.  		}
448.  	    } else if(offer < (u.ulevel * 600)) {
449.  		verbalize("Thy devotion has been rewarded.");
450.  		if (!(Protection & INTRINSIC))  {
451.  			Protection |= INTRINSIC;
452.  			if (!u.ublessed)  u.ublessed = rnd(3) + 1;
453.  		} else u.ublessed++;
454.  	    } else {
455.  		verbalize("Thy selfless generosity is deeply appreciated.");
456.  		if(u.ugold < (offer * 2L) && coaligned) {
457.  		    if(strayed && (moves - u.ucleansed) > 5000L) { 
458.  			u.ualign = 0; /* cleanse him */
459.  			u.ucleansed = moves;
460.  		    } else { 
461.  		        u.ualign += 2;
462.  		    }
463.  		}
464.  	    }
465.  	}
466.  }
467.  
468.  boolean
469.  u_in_sanctuary(troom) 
470.  register struct mkroom *troom;
471.  {
472.  	register struct mkroom *troom2;
473.  
474.  	troom2 = in_temple(u.ux, u.uy);
475.  
476.  	return(troom && troom2 && troom == troom2 && is_shrined(troom2) && 
477.  			t_coaligned(troom2) && u.ualign > -5);
478.  }
479.  
480.  void
481.  ghod_hitsu() 	/* when attacking a priest in his temple */
482.  {
483.  	int x, y, ax, ay;
484.  	struct monst *priest;
485.  	struct mkroom *troom = in_temple(u.ux, u.uy);
486.  
487.  	if(!troom || !is_shrined(troom)) return;
488.  
489.  	/* shrine converted by human sacrifice */
490.  	if((priest = findpriest(troom)) && 
491.  	    strcmp(EPRI(priest)->deitynam,
492.  		a_gname_at(EPRI(priest)->shrpos.x, EPRI(priest)->shrpos.y))) 
493.  		    return;
494.  
495.  	shrine_pos(&x,&y,troom);
496.  	ax = x;
497.  	ay = y;
498.  
499.  	if((u.ux == x && u.uy == y) || !linedup(u.ux, u.uy, x, y)) {
500.  	    if(IS_DOOR(levl[u.ux][u.uy].typ)) {
501.  		if(u.ux == troom->lx - 1) {
502.  		    x = troom->hx;
503.  		    y = u.uy;
504.  		} else if(u.ux == troom->hx + 1) {
505.  		    x = troom->lx;
506.  		    y = u.uy;
507.  		} else if(u.uy == troom->ly - 1) {
508.  		    x = u.ux;
509.  		    y = troom->hy;
510.  		} else if(u.uy == troom->hy + 1) {
511.  		    x = u.ux;
512.  		    y = troom->ly;
513.  		}
514.  	    } else {
515.  		switch(rn2(4)) {
516.  		case 0:  x = u.ux; y = troom->ly; break;
517.  		case 1:  x = u.ux; y = troom->hy; break;
518.  		case 2:  x = troom->lx; y = u.uy; break;
519.  		default: x = troom->hx; y = u.uy; break;
520.  		}
521.  	    }
522.  	    if(!linedup(u.ux, u.uy, x, y)) return;
523.  	}
524.  
525.  	switch(rn2(3)) {
526.  	case 0: 
527.  	    pline("%s roars in anger:  \"Thou shalt suffer!\"", 
528.  			a_gname_at(ax, ay));
529.  	    break;
530.  	case 1: 
531.  	    pline("%s's voice booms:  \"How darest thou harm my servant!\"",
532.  			a_gname_at(ax, ay));
533.  	    break;
534.  	default: 
535.  	    pline("%s roars:  \"Thou dost profane my shrine!\"",
536.  			a_gname_at(ax, ay));
537.  	    break;
538.  	}
539.  
540.  	buzz(-15, 6, x, y, sgn(tbx), sgn(tby)); /* -15: bolt of lightning */
541.  }
542.  
543.  void
544.  angry_priest()
545.  {
546.  	register struct monst *priest;
547.  
548.  	if(!(priest = findpriest(in_temple(u.ux, u.uy)))) return;
549.  	wakeup(priest);
550.  }
551.  #endif /* ALTARS && THEOLOGY */

Also on Fandom

Random Wiki