Source:NetHack 3.1.0/exper.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to exper.c from the source code of NetHack 3.1.0.

Warning! This is the source code from an old release. For newer releases, 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: @(#)exper.c	3.1	90/22/02
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include "hack.h"
6.    
7.    #ifdef LINT
8.    #define	NEW_SCORING
9.    #endif
10.   long
11.   newuexp(lev)
12.   register unsigned lev;
13.   {
14.   #ifdef LINT	/* long conversion */
15.   	return(0L * lev);
16.   #else
17.   	if(lev < 10) return (10L*(1L << lev));
18.   	if(lev < 20) return (10000L*(1L << (lev-10)));
19.   	return (10000000L*(lev-19));
20.   #endif
21.   }
22.   
23.   int
24.   experience(mtmp, nk)	/* return # of exp points for mtmp after nk killed */
25.   	register struct	monst *mtmp;
26.   	register int	nk;
27.   {
28.   	register struct permonst *ptr = mtmp->data;
29.   	int	i, tmp, tmp2;
30.   
31.   	tmp = 1 + mtmp->m_lev * mtmp->m_lev;
32.   
33.   /*	For higher ac values, give extra experience */
34.   	if((i = find_mac(mtmp)) < 3) tmp += (7 - i) * (i < 0) ? 2 : 1;
35.   
36.   /*	For very fast monsters, give extra experience */
37.   	if(ptr->mmove >= 12) tmp += (ptr->mmove >= 18) ? 5 : 3;
38.   
39.   /*	For each "special" attack type give extra experience */
40.   	for(i = 0; i < NATTK; i++) {
41.   
42.   	    tmp2 = ptr->mattk[i].aatyp;
43.   	    if(tmp2 > AT_BUTT) {
44.   
45.   		if(tmp2 == AT_WEAP) tmp += 5;
46.   		else if(tmp2 == AT_MAGC) tmp += 10;
47.   		else tmp += 3;
48.   	    }
49.   	}
50.   
51.   /*	For each "special" damage type give extra experience */
52.   	for(i = 0; i < NATTK; i++) {
53.   
54.   	    tmp2 = ptr->mattk[i].adtyp;
55.   	    if(tmp2 > AD_PHYS && tmp2 < AD_BLND) tmp += 2*mtmp->m_lev;
56.   	    else if((tmp2 == AD_DRLI) || (tmp2 == AD_STON)) tmp += 50;
57.   	    else if(tmp != AD_PHYS) tmp += mtmp->m_lev;
58.   		/* extra heavy damage bonus */
59.   	    if((int)(ptr->mattk[i].damd * ptr->mattk[i].damn) > 23)
60.   		tmp += mtmp->m_lev;
61.   	}
62.   
63.   /*	For certain "extra nasty" monsters, give even more */
64.   	if(extra_nasty(ptr)) tmp += (7*mtmp->m_lev);
65.   	if(ptr->mlet == S_EEL) tmp += 1000;
66.   
67.   /*	For higher level monsters, an additional bonus is given */
68.   	if(mtmp->m_lev > 8) tmp += 50;
69.   
70.   #ifdef NEW_SCORING
71.   	/* ------- recent addition: make nr of points decrease
72.   		   when this is not the first of this kind */
73.   	{ unsigned ul = u.ulevel;
74.   	  int ml = mtmp->m_lev;
75.   	/* points are given based on present and future level */
76.   	  if(ul < MAXULEV)
77.   	    for(tmp2 = 0; !tmp2 || ul + tmp2 <= ml; tmp2++)
78.   		if(u.uexp + 1 + (tmp + ((tmp2 <= 0) ? 0 : 4<<(tmp2-1)))/nk
79.   		    >= newuexp(ul) )
80.   			if(++ul == MAXULEV) break;
81.   
82.   	  tmp2 = ml - ul -1;
83.   	  tmp = (tmp + ((tmp2 < 0) ? 0 : 4<<tmp2))/nk;
84.   	  if(tmp <= 0) tmp = 1;
85.   	}
86.   	/* note: ul is not necessarily the future value of u.ulevel */
87.   	/* ------- end of recent valuation change ------- */
88.   #endif /* NEW_SCORING /**/
89.   
90.   #ifdef MAIL
91.   	/* Mail daemons put up no fight. */
92.   	if(mtmp->data == &mons[PM_MAIL_DAEMON]) tmp = 1;
93.   #endif
94.   
95.   	return(tmp);
96.   }
97.   
98.   void
99.   more_experienced(exp, rexp)
100.  	register int exp, rexp;
101.  {
102.  	u.uexp += exp;
103.  	u.urexp += 4*exp + rexp;
104.  	if(exp
105.  #ifdef SCORE_ON_BOTL
106.  	   || flags.showscore
107.  #endif
108.  	   ) flags.botl = 1;
109.  	if(u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000))
110.  		flags.beginner = 0;
111.  }
112.  
113.  void
114.  losexp() {	/* hit by drain life attack */
115.  
116.  	register int num;
117.  
118.  #ifdef POLYSELF
119.  	if(resists_drli(uasmon)) return;
120.  #endif
121.  
122.  	if(u.ulevel > 1) {
123.  		pline("Goodbye level %u.", u.ulevel--);
124.  		/* remove intrinsic abilities */
125.  		adjabil((int)u.ulevel+1, (int)u.ulevel);
126.  	} else
127.  		u.uhp = -1;
128.  	num = newhp();
129.  	u.uhp -= num;
130.  	u.uhpmax -= num;
131.  	num = rn1((int)u.ulevel/2+1, 2);		/* M. Stephenson */
132.  	u.uen -= num;
133.  	if (u.uen < 0)		u.uen = 0;
134.  	u.uenmax -= num;
135.  	if (u.uenmax < 0)	u.uenmax = 0;
136.  	u.uexp = newuexp(u.ulevel) - 1;
137.  	flags.botl = 1;
138.  }
139.  
140.  /*
141.   * Make experience gaining similar to AD&D(tm), whereby you can at most go
142.   * up by one level at a time, extra expr possibly helping you along.
143.   * After all, how much real experience does one get shooting a wand of death
144.   * at a dragon created with a wand of polymorph??
145.   */
146.  void
147.  newexplevel() {
148.  
149.  	register int tmp;
150.  
151.  	if(u.ulevel < MAXULEV && u.uexp >= newuexp(u.ulevel)) {
152.  
153.  		u.ulevel++;
154.  		if (u.uexp >= newuexp(u.ulevel)) u.uexp = newuexp(u.ulevel) - 1;
155.  		pline("Welcome to experience level %u.", u.ulevel);
156.  		set_uasmon();	/* set up for the new level. */
157.  		/* give new intrinsics */
158.  		adjabil((int)u.ulevel-1, (int)u.ulevel);
159.  		tmp = newhp();
160.  		u.uhpmax += tmp;
161.  		u.uhp += tmp;
162.  		tmp = rn1((int)ACURR(A_WIS)/2+1, 2); /* M. Stephenson */
163.  		u.uenmax += tmp;
164.  		u.uen += tmp;
165.  		flags.botl = 1;
166.  	}
167.  }
168.  
169.  void
170.  pluslvl() {
171.  	register int num;
172.  
173.  	You("feel more experienced.");
174.  	num = newhp();
175.  	u.uhpmax += num;
176.  	u.uhp += num;
177.  	num = rn1((int)ACURR(A_WIS)/2+1, 2);	/* M. Stephenson */
178.  	u.uenmax += num;
179.  	u.uen += num;
180.  	if(u.ulevel < MAXULEV) {
181.  		u.uexp = newuexp(u.ulevel);
182.  		pline("Welcome to experience level %u.", ++u.ulevel);
183.  		adjabil((int)u.ulevel-1, (int)u.ulevel);
184.  	}
185.  	flags.botl = 1;
186.  }
187.  
188.  long
189.  rndexp()
190.  {
191.  	register long minexp,maxexp;
192.  
193.  	if(u.ulevel == 1)
194.  		return rn2((int)newuexp(1));
195.  	else {
196.  		minexp = newuexp(u.ulevel - 1);
197.  		maxexp = newuexp(u.ulevel);
198.  		return(minexp + rn2((int)(maxexp - minexp)));
199.  	}
200.  }
201.  
202.  /*exper.c*/