Source:NetHack 2.3e/pray.c

From NetHackWiki
Revision as of 03:47, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 2.3e/pray.c moved to Source:NetHack 2.3e/pray.c: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to pray.c from the source code of NetHack 2.3e. To link to a particular line, write [[NetHack 2.3e/pray.c#line123]], for example.

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

Screenshots and source code from Hack are used under the CWI license.

1.    /*	SCCS Id: @(#)pray.c	2.3	87/12/12
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    
4.    #include "hack.h"
5.    
6.    extern char *nomovemsg;
7.    extern struct monst *mkmon_at();
8.    extern struct obj *mkobj_at();
9.    
10.   #ifdef PRAYERS
11.   #ifdef THEOLOGY
12.   
13.   #define TROUBLE_STONED 1
14.   #define TROUBLE_STARVING 2
15.   #define TROUBLE_SICK 3
16.   #define TROUBLE_HIT 4
17.   
18.   #define TROUBLE_PUNISHED (-1)
19.   #define TROUBLE_CURSED_ITEMS (-2)
20.   #define TROUBLE_HUNGRY (-3)
21.   #define TROUBLE_HALLUCINATION (-4)
22.   #define TROUBLE_BLIND (-5)
23.   #define TROUBLE_POISONED (-6)
24.   #define TROUBLE_WOUNDED_LEGS (-7)
25.   #define TROUBLE_CONFUSED (-8)
26.   
27.   /* We could force rehumanize of polyselfed people, but we can't tell
28.      unintentional shape changes from the other kind. Oh well. */
29.   
30.   /* Return 0 if nothing particular seems wrong, positive numbers for
31.      serious trouble, and negative numbers for comparative annoyances. This
32.      returns the worst problem. There may be others, and the gods may fix 
33.      more than one.
34.   
35.   This could get as bizarre as noting surrounding opponents, (or hostile dogs),
36.   but that's really hard.
37.    */
38.   
39.   
40.   in_trouble () {
41.   
42.   /* Borrowed from eat.c */
43.   
44.   #define	SATIATED	0
45.   #define NOT_HUNGRY	1
46.   #define	HUNGRY		2
47.   #define	WEAK		3
48.   #define	FAINTING	4
49.   #define FAINTED		5
50.   #define STARVED		6
51.   
52.     if (Stoned) return (TROUBLE_STONED);
53.     if (u.uhs >= WEAK) return (TROUBLE_STARVING);
54.     if (Sick) return (TROUBLE_SICK);
55.     if (u.uhp < 5) return (TROUBLE_HIT);
56.     if (Punished) return (TROUBLE_PUNISHED);
57.     if (
58.         (uarmh && uarmh->cursed)	/* helmet */
59.         ||
60.         (uarms && uarms->cursed)	/* shield */
61.         ||
62.         (uarmg && uarmg->cursed)	/* gloves */
63.         ||
64.         (uarm && uarm->cursed)	/* armor */
65.         ||
66.         (uarm2 && uarm2->cursed)	/* cloak */
67.         ||
68.         (uwep && (uwep->olet == WEAPON_SYM) && (uwep->cursed))
69.         ||
70.         (uleft && uleft->cursed)
71.         ||
72.         (uright && uright->cursed))
73.       return (TROUBLE_CURSED_ITEMS);
74.     
75.     if (u.uhs >= HUNGRY) return (TROUBLE_HUNGRY);
76.     if (Hallucination) return (TROUBLE_HALLUCINATION);
77.     if (Blinded > 1) return (TROUBLE_BLIND); /* don't loop when fixing sets to 1 */
78.     if (u.ustr < u.ustrmax) return (TROUBLE_POISONED);
79.     if (Wounded_legs) return (TROUBLE_WOUNDED_LEGS);
80.     if (Confusion) return (TROUBLE_CONFUSED);
81.     return (0);
82.   }
83.   
84.   fix_worst_trouble ()
85.   {
86.     char *tmp, *hcolor();
87.   
88.     switch (in_trouble ()) {
89.     case TROUBLE_STONED: pline ("You feel more limber."); Stoned = 0; break;
90.     case TROUBLE_HUNGRY:
91.     case TROUBLE_STARVING: pline ("Your stomach feels content."); init_uhunger (); break;
92.     case TROUBLE_SICK: pline ("You feel better."); Sick = 0; break;
93.     case TROUBLE_HIT: 
94.       pline("A %s glow surrounds you",
95.   	  Hallucination ? hcolor () : "golden");
96.       u.uhp = u.uhpmax += 5;
97.       break;
98.   
99.    case TROUBLE_PUNISHED:
100.     Punished = 0;
101.     freeobj(uchain);
102.     unpobj(uchain);
103.     free((char *) uchain);
104.     uball->spe = 0;
105.     uball->owornmask &= ~W_BALL;
106.     uchain = uball = (struct obj *) 0;
107.     break;
108.  
109.   case TROUBLE_CURSED_ITEMS:
110.      { struct obj *otmp;
111.        char * what;
112.        otmp = (struct obj *) 0;
113.        what = (char *) 0;
114.        if (uarmh && uarmh->cursed) 	/* helmet */
115.  	otmp = uarmh;
116.        else if (uarms && uarms->cursed) /* shield */
117.  	otmp = uarms;
118.        else if (uarmg && uarmg->cursed) /* gloves */
119.  	otmp = uarmg;
120.        else if (uarm && uarm->cursed) /* armor */
121.  	otmp = uarm;
122.        else if (uarm2 && uarm2->cursed) /* cloak, probably */
123.  	otmp = uarm2;
124.        else if (uleft && uleft->cursed) {
125.  	otmp = uleft;
126.  	what = "left hand";
127.        }
128.        else if (uright && uright->cursed) {
129.  	otmp = uright;
130.  	what = "right hand";
131.        }
132.        else if(uwep && (uwep->olet == WEAPON_SYM) && (uwep->cursed))
133.  	otmp = uwep;
134.        
135.        otmp->cursed = 0;
136.        pline ("Your %s %s.", what ? what : aobjnam (otmp, "softly glow"),
137.  	     Hallucination ? hcolor() : "amber");
138.        break;
139.      }
140.  
141.   case TROUBLE_HALLUCINATION:
142.     pline ("Looks like you are back in kansas."); Hallucination = 0; break;
143.   case TROUBLE_BLIND:
144.      pline ("Your eyes feel better."); Blinded = 1; break;
145.   case TROUBLE_POISONED:
146.     pline("There's a tiger in your tank.");
147.     if(u.ustr < u.ustrmax) {
148.       u.ustr = u.ustrmax;
149.       flags.botl = 1;
150.     }
151.     break;
152.   case TROUBLE_WOUNDED_LEGS:
153.     heal_legs ();
154.     break;
155.   case TROUBLE_CONFUSED:
156.     HConfusion = 0;
157.     break;
158.   }
159.  }
160.  
161.  #define CORPSE_I_TO_C(otyp)	(char) ((otyp >= DEAD_ACID_BLOB)\
162.  					?  'a' + (otyp - DEAD_ACID_BLOB)\
163.  					:	'@' + (otyp - DEAD_HUMAN))
164.  
165.  extern char POISONOUS[];
166.  
167.  dosacrifice () {
168.    register struct obj *otmp;
169.    register struct objclass *ftmp;
170.    int value;
171.    char let;
172.    char *hcolor ();
173.  
174.    otmp = getobj("%", "sacrifice");
175.    if(!otmp) return(0);
176.  
177.    ftmp = &objects[otmp->otyp];
178.  #ifdef KAA
179.    if(otmp->otyp == DEAD_DEMON) let='&';
180.    else if (otmp->otyp == DEAD_GIANT) let='9';
181.    else let = CORPSE_I_TO_C(otmp->otyp);
182.  #else
183.    let = CORPSE_I_TO_C(otmp->otyp);
184.  #endif
185.  
186.    /* judge the food value by the nutrition, as well as some aging behavior */
187.  
188.    value = ftmp->nutrition;
189.  
190.    if (otmp->otyp >= CORPSE)
191.      {
192.        if (let != 'a' && (moves > otmp->age + 50))
193.  	value = 0;		/* old stuff */
194.      }
195.    else if(index(POISONOUS, let)) {
196.      value = -10;		/* gods get annoyed */
197.    }
198.  
199.  
200.    if (value == 0)
201.      {
202.        pline ("Nothing happens.");
203.        return (1);
204.      }
205.    if (value < 0) /* Gods don't like poision as an offering. */
206.      {
207.  #ifdef HARD
208.        u.ugangr++;
209.        angrygods();
210.  #else
211.        if (u.ugangr++)	angrygods();
212.        else {			/* exactly one warning */
213.  	pline("A voice booms out: You have angered us,");
214.  	pline("Disturb us again at your own risk!");
215.        }
216.  #endif
217.      }
218.    if (value > 0)
219.      {
220.        int saved_anger = u.ugangr;
221.        int saved_cnt = u.ublesscnt;
222.        int saved_luck = u.uluck;
223.        /* OK, you get brownie points. */
224.        if (Hallucination)
225.  	pline("Your sacrifice sprouts wings and a propeller and roars away!");
226.        else pline("Your sacrifice is consumed in a burst of flame!");
227.        if(u.ugangr)
228.  	{
229.  	  u.ugangr -= ((value / 800) * 4);
230.  	  if(u.ugangr < 0) u.ugangr = 0;
231.  	  if(u.ugangr != saved_anger)
232.  	    if (u.ugangr)
233.  	      {
234.  		if (Hallucination) pline ("The gods seem %s.", hcolor ());
235.  		else pline("The gods seem slightly molified.");	  
236.  	      }
237.  	    else {
238.  	      if (Hallucination) pline ("The gods seem cosmic (not a new fact).");
239.  	      else pline ("The gods seem mollified.");
240.  	    }
241.  	  if ((int)u.uluck < 0) u.uluck = 0;
242.  	}
243.        else if (u.ublesscnt > 0)
244.  	{
245.  	  u.ublesscnt -= ((value / 800 /* a food ration */) * 300);
246.  	  if(u.ublesscnt < 0) u.ublesscnt = 0;
247.  	  if(u.ublesscnt != saved_cnt)
248.  	    {
249.  	      if ((int)u.uluck < 0) u.uluck = 0;
250.  	      if (u.ublesscnt) {
251.  		if (Hallucination) pline ("You realize that the gods are not like you and I.");
252.  		else pline ("You have a hopeful feeling.");
253.  	      }
254.  	      else {
255.  		if (Hallucination) pline ("Overall, there is a smell of fried onions.");
256.  		else pline ("You have a feeling of reconciliation.");
257.  	      }
258.  	    }
259.  	}
260.        else /* you were already in pretty good standing */
261.  	{
262.  	  change_luck((value / 800) * LUCKMAX);
263.  	  if (u.uluck != saved_luck)
264.  	    {
265.  	      if (Hallucination) pline ("You see crabgrass at your feet. A funny thing in a dungeon.");
266.  	      else pline ("You see a four-leaf clover at your feet.");
267.  	    }
268.  	}
269.      }
270.    useup(otmp);
271.    return(1);
272.  }
273.  #endif 
274.  #endif
275.  
276.  dopray() {		/* M. Stephenson (1.0.3b) */
277.  #ifdef PRAYERS
278.  #ifdef THEOLOGY
279.    int trouble = in_trouble ();
280.    if ((!trouble && (u.ublesscnt > 0)) ||
281.        ((trouble < 0) && (u.ublesscnt > 100)) /* minor difficulties */ ||
282.        ((trouble > 0) && (u.ublesscnt > 200)) /* big trouble */
283.        ) {
284.  #else      
285.      if (u.ublesscnt > 0)  {		/* disturbing the gods too much */
286.  #endif
287.  		u.ublesscnt += rnz(250);
288.  		change_luck(-3);
289.  #ifdef HARD
290.  		u.ugangr++;
291.  		angrygods();
292.  #else
293.  		if (u.ugangr++)	angrygods();
294.  		else {			/* exactly one warning */
295.  			pline("A voice booms out: You have angered us,");
296.  			pline("Disturb us again at your own risk!");
297.  		}
298.  #endif
299.  	} else  if ((int)u.uluck < 0) angrygods();	/* a bad player */
300.  	else	pleased();		    		/* or a good player */
301.  #endif
302.  	nomovemsg = "You finished your prayer.";
303.  	nomul(-3);
304.  	return(1);
305.  }
306.  
307.  #ifdef PRAYERS
308.  angrygods() {
309.  	register int	tmp;
310.  
311.  	pline ("You get the feeling the gods are angry...");
312.  	/* changed from tmp = u.ugangr + abs (u.uluck) -- rph */
313.  	tmp =  3*u.ugangr + (u.uluck > 0 ? -u.uluck/3 : -u.uluck);
314.  	tmp =  (tmp > 15 ? 15 : tmp);  /* lets be a little reasonable */
315.  	switch (tmp ? rn2(tmp): 0) {
316.  
317.  	    case 0:
318.  	    case 1:	pline("but nothing appears to happen.");
319.  			break;
320.  	    case 2:
321.  	    case 3:	pline("A voice booms out: You are arrogant, mortal.");
322.  			pline("You must relearn your lessons!");
323.  			if (u.ulevel > 1)	losexp();
324.  			else  {
325.  			    u.uexp = 0;
326.  			    flags.botl = 1;
327.  			}
328.  			break;
329.  	    case 4:
330.  	    case 5:
331.  	    case 6:	pline("A black glow surrounds you.");
332.  			rndcurse();
333.  			break;
334.  	    case 7:
335.  	    case 8:	pline("A voice booms out: You dare to call upon us?");
336.  			pline("Then, die mortal!");
337.  			mkmon_at('&', u.ux, u.uy);
338.  			break;
339.  				
340.  	    default:	pline("Suddenly, a bolt of lightning strikes you!");
341.  			pline("You are fried to a crisp.");
342.  			killer = "pissed off deity";
343.  			done("died");
344.  			break;
345.  	}
346.  	u.ublesscnt = rnz(300);
347.  	return(0);
348.  }
349.  
350.  
351.  
352.  pleased() {
353.  
354.  	char	*tmp, *hcolor();
355.  #ifdef THEOLOGY	
356.  	int trouble = in_trouble ();		/* what's your worst difficulty? */
357.  	int pat_on_head = 0;
358.  #endif
359.  	u.ugangr--;
360.  	if (u.ugangr < 0) u.ugangr = 0;
361.  	pline("You feel the gods are pleased.");
362.  
363.  #ifdef THEOLOGY
364.  	/* depending on your luck, the gods will :
365.  	   - fix your worst problem if its major.
366.  	   - fix all your major problems.
367.  	   - fix your worst problem if its minor.
368.  	   - fix all of your problems.
369.  	   - do you a gratuitous favor.
370.  
371.  	   if you make it to the the last category, you roll randomly again
372.  	   to see what they do for you. 
373.  
374.  	   If your luck is at least 0, then you are guaranteed rescued
375.  	   from your worst major problem. */
376.  
377.  	if (!trouble) pat_on_head = 1;
378.  	else 
379.  	  { int action = rn1(5,u.uluck+1);
380.  	    if (action>=5) pat_on_head = 1;
381.  	    if (action>=4) while (in_trouble ()) fix_worst_trouble ();
382.  	    if (action<4 && action>=3) fix_worst_trouble ();
383.  	    if (action<4 && action>=2) while (in_trouble () > 0) fix_worst_trouble ();
384.  	    if (action==1 && trouble > 0) fix_worst_trouble ();
385.  	    if (action==0) pline("but nothing seems to happen.");
386.  	  };
387.  	if (pat_on_head)pline("The gods seem especially pleased ...");
388.  
389.       if (pat_on_head)
390.  #endif
391.  	switch(rn2((u.uluck + 6)/2))  {
392.  
393.  	    case 0:	pline("but nothing seems to happen.");
394.  			break;
395.  	    case 1:
396.  			if(!uwep) {
397.  			    if(uleft && uleft->cursed) {
398.  				pline("your left hand glows amber.");
399.  				uleft->cursed = 0;
400.  			    } else if(uright && uright->cursed) {
401.  				pline("your right hand glows amber.");
402.  				uright->cursed = 0;
403.  			    } else    pline("but nothing seems to happen.");
404.  			    break;
405.  			}
406.  #ifdef KAA
407.  			if(uwep && (uwep->olet == WEAPON_SYM)) {
408.  			    if (uwep->cursed) {
409.  				uwep->cursed=0;
410.  				pline("Your %s %s.", aobjnam(uwep,"softly glow"), 
411.  				Hallucination ? hcolor() : "amber");
412.  			    } else if(uwep->otyp >= ARROW && uwep->otyp <= SPEAR) {
413.  				uwep->dknown=1;
414.  				tmp = Hallucination ? hcolor() : "light blue";
415.  				pline("Your %s with a%s %s aura.", aobjnam(uwep,"softly glow"),
416.  				index("aeiou",*tmp) ? "n" : "", tmp);
417.  			    }
418.  			} else
419.  #endif
420.  				pline("but nothing seems to happen.");
421.  			break;
422.  	    case 2:
423.  	    case 3:
424.  			pline("A %s glow surrounds you",
425.  			      Hallucination ? hcolor() : "golden");
426.  			u.uhp = u.uhpmax += 5;
427.  			u.ustr = u.ustrmax;
428.  			if (u.uhunger < 900)	init_uhunger();
429.  			if (u.uluck < 0)	u.uluck = 0;
430.  			if (Blinded)		Blinded = 1;
431.  			flags.botl = 1;
432.  			break;
433.  	    case 4:
434.  	    case 5:	pline("A voice booms out: We are pleased with your progress,");
435.  			pline("and grant you the gift of");
436.  			if (!(HTelepat & INTRINSIC))  {
437.  				HTelepat |= INTRINSIC;
438.  				pline ("Telepathy,");
439.  			} else if (!(Fast & INTRINSIC))  {
440.  				Fast |= INTRINSIC;
441.  				pline ("Speed,");
442.  			} else if (!(Stealth & INTRINSIC))  {
443.  				Stealth |= INTRINSIC;
444.  				pline ("Stealth,");
445.  			} else {
446.  			    if (!(Protection & INTRINSIC))  {
447.  				Protection |= INTRINSIC;
448.  				if (!u.ublessed)  u.ublessed = rnd(3) + 1;
449.  			    } else u.ublessed++;
450.  			    pline ("our protection,");
451.  			}
452.  			pline ("Use it wisely in our names!");
453.  			break;
454.  
455.  	    case 6:	pline ("An object appears at your feet!");
456.  #ifdef SPELLS
457.  			mkobj_at('+', u.ux, u.uy);
458.  #else
459.  			mkobj_at('?', u.ux, u.uy);
460.  #endif
461.  			break;
462.  
463.  	    case 7:	pline("A voice booms out:  We crown thee...");
464.  			pline("The Hand of Elbereth!");
465.  			HInvis |= INTRINSIC;
466.  			HSee_invisible |= INTRINSIC;
467.  			HFire_resistance |= INTRINSIC;
468.  			HCold_resistance |= INTRINSIC;
469.  			HPoison_resistance |= INTRINSIC;
470.  #ifdef RPH
471.  			if(uwep && (uwep->otyp == LONG_SWORD))
472.  				oname(uwep, "Excalibur");
473.  #endif
474.  			break;
475.  
476.  	    default:	impossible("Confused deity!");
477.  			break;
478.  	}
479.  	u.ublesscnt = rnz(350);
480.  #ifdef HARD
481.  	u.ublesscnt += (u.udemigod * rnz(1000));
482.  #endif
483.  	return(0);
484.  }
485.  #endif /* PRAYERS /**/
486.  #ifdef NEWCLASS
487.  doturn() {	/* Knights & Priest(esse)s only please */
488.  
489.  	register struct monst *mtmp;
490.  	register int	xlev = 6;
491.  	extern char	pl_character[];
492.  
493.  	if((pl_character[0] != 'P') &&
494.  	   (pl_character[0] != 'K')) {
495.  
496.  		pline("You don't know how to turn undead!");
497.  		return(0);
498.  	}
499.  	if (Inhell) {
500.  
501.  		pline("Being in hell, your gods won't help you.");
502.  		aggravate();
503.  		return(0);
504.  	}
505.  	pline("Calling upon your gods, you chant an arcane formula.");
506.  	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
507.  	    if(cansee(mtmp->mx,mtmp->my)) {
508.  		if(index(UNDEAD,mtmp->data->mlet) ||
509.  		   ((mtmp->data->mlet == '&') && (u.ulevel > 10))) {
510.  
511.  		    if(Confusion) {
512.  			pline("Unfortunately, your voice falters.");
513.  			mtmp->mflee = mtmp->mfroz = mtmp->msleep = 0;
514.  		    } else if (! resist(mtmp, '+', 0, TELL))
515.  			switch (mtmp->data->mlet) {
516.  			    case 'V':   xlev += 2;
517.  			    case 'W':   xlev += 4;
518.  			    case 'Z':   if(u.ulevel >= xlev)  {
519.  					    if(!resist(mtmp, '+', 0, NOTELL)) {
520.  						pline("You destroy the %s", monnam(mtmp));
521.  						mondied(mtmp);
522.  					    } else	mtmp->mflee = 1;
523.  					} else	mtmp->mflee = 1;
524.  					break;
525.  			    default:    mtmp->mflee = 1;
526.  					break;
527.  			}
528.  		   }
529.  	    }
530.  	    nomul(-5);
531.  	    return(1);
532.  }
533.  #endif /* NEWCLASS /**/