Source:NetHack 3.2.0/exper.c

From NetHackWiki
Revision as of 08:34, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 3.2.0/exper.c moved to Source:NetHack 3.2.0/exper.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 exper.c from the source code of NetHack 3.2.0. To link to a particular line, write [[NetHack 3.2.0/exper.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: @(#)exper.c	3.2	96/01/21	*/
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.    static long FDECL(newuexp, (int));
8.    static int FDECL(enermod, (int));
9.    
10.   static long
11.   newuexp(lev)
12.   int lev;
13.   {
14.   	if (lev < 10) return (10L * (1L << lev));
15.   	if (lev < 20) return (10000L * (1L << (lev - 10)));
16.   	return (10000000L * ((long)(lev - 19)));
17.   }
18.   
19.   static int
20.   enermod(en)
21.   int en;
22.   {
23.   	if(Role_is('W') || Role_is('P')) return(2 * en);
24.   	else if(Role_is('H') || Role_is('K')) return((3 * en) / 2);
25.   	else if(Role_is('B') || Role_is('V')) return((3 * en) / 4);
26.   	else return(en);
27.   }
28.   
29.   int
30.   experience(mtmp, nk)	/* return # of exp points for mtmp after nk killed */
31.   	register struct	monst *mtmp;
32.   	register int	nk;
33.   #if defined(applec)
34.   # pragma unused(nk)
35.   #endif
36.   {
37.   	register struct permonst *ptr = mtmp->data;
38.   	int	i, tmp, tmp2;
39.   
40.   	tmp = 1 + mtmp->m_lev * mtmp->m_lev;
41.   
42.   /*	For higher ac values, give extra experience */
43.   	if((i = find_mac(mtmp)) < 3) tmp += (7 - i) * (i < 0) ? 2 : 1;
44.   
45.   /*	For very fast monsters, give extra experience */
46.   	if(ptr->mmove >= 12) tmp += (ptr->mmove >= 18) ? 5 : 3;
47.   
48.   /*	For each "special" attack type give extra experience */
49.   	for(i = 0; i < NATTK; i++) {
50.   
51.   	    tmp2 = ptr->mattk[i].aatyp;
52.   	    if(tmp2 > AT_BUTT) {
53.   
54.   		if(tmp2 == AT_WEAP) tmp += 5;
55.   		else if(tmp2 == AT_MAGC) tmp += 10;
56.   		else tmp += 3;
57.   	    }
58.   	}
59.   
60.   /*	For each "special" damage type give extra experience */
61.   	for(i = 0; i < NATTK; i++) {
62.   
63.   	    tmp2 = ptr->mattk[i].adtyp;
64.   	    if(tmp2 > AD_PHYS && tmp2 < AD_BLND) tmp += 2*mtmp->m_lev;
65.   	    else if((tmp2 == AD_DRLI) || (tmp2 == AD_STON)) tmp += 50;
66.   	    else if(tmp != AD_PHYS) tmp += mtmp->m_lev;
67.   		/* extra heavy damage bonus */
68.   	    if((int)(ptr->mattk[i].damd * ptr->mattk[i].damn) > 23)
69.   		tmp += mtmp->m_lev;
70.   	}
71.   
72.   /*	For certain "extra nasty" monsters, give even more */
73.   	if (extra_nasty(ptr)) tmp += (7 * mtmp->m_lev);
74.   	if (ptr->mlet == S_EEL && !Amphibious) tmp += 1000;
75.   
76.   /*	For higher level monsters, an additional bonus is given */
77.   	if(mtmp->m_lev > 8) tmp += 50;
78.   
79.   #ifdef MAIL
80.   	/* Mail daemons put up no fight. */
81.   	if(mtmp->data == &mons[PM_MAIL_DAEMON]) tmp = 1;
82.   #endif
83.   
84.   	return(tmp);
85.   }
86.   
87.   void
88.   more_experienced(exp, rexp)
89.   	register int exp, rexp;
90.   {
91.   	u.uexp += exp;
92.   	u.urexp += 4*exp + rexp;
93.   	if(exp
94.   #ifdef SCORE_ON_BOTL
95.   	   || flags.showscore
96.   #endif
97.   	   ) flags.botl = 1;
98.   	if (u.urexp >= (Role_is('W') ? 1000 : 2000))
99.   		flags.beginner = 0;
100.  }
101.  
102.  void
103.  losexp()		/* hit by drain life attack */
104.  {
105.  	register int num;
106.  
107.  	if (resists_drli(&youmonst)) return;
108.  
109.  	if(u.ulevel > 1) {
110.  		pline("Goodbye level %d.", u.ulevel--);
111.  		/* remove intrinsic abilities */
112.  		adjabil(u.ulevel + 1, u.ulevel);
113.  		reset_rndmonst(NON_PM);	/* new monster selection */
114.  #ifdef WEAPON_SKILLS
115.  		lose_weapon_skill();
116.  #endif /* WEAPON_SKILLS */
117.  	} else
118.  		u.uhp = -1;
119.  	num = newhp();
120.  	u.uhp -= num;
121.  	u.uhpmax -= num;
122.  	num = enermod(rn1(u.ulevel/2 + 1, 2));		/* M. Stephenson */
123.  	u.uen -= num;
124.  	if (u.uen < 0)		u.uen = 0;
125.  	u.uenmax -= num;
126.  	if (u.uenmax < 0)	u.uenmax = 0;
127.  	u.uexp = newuexp(u.ulevel) - 1;
128.  	flags.botl = 1;
129.  }
130.  
131.  /*
132.   * Make experience gaining similar to AD&D(tm), whereby you can at most go
133.   * up by one level at a time, extra expr possibly helping you along.
134.   * After all, how much real experience does one get shooting a wand of death
135.   * at a dragon created with a wand of polymorph??
136.   */
137.  void
138.  newexplevel()
139.  {
140.  	register int tmp;
141.  
142.  	if(u.ulevel < MAXULEV && u.uexp >= newuexp(u.ulevel)) {
143.  
144.  		u.ulevel++;
145.  		if (u.uexp >= newuexp(u.ulevel)) u.uexp = newuexp(u.ulevel) - 1;
146.  		pline("Welcome to experience level %d.", u.ulevel);
147.  		/* give new intrinsics */
148.  		adjabil(u.ulevel - 1, u.ulevel);
149.  		reset_rndmonst(NON_PM);	/* new monster selection */
150.  		tmp = newhp();
151.  		u.uhpmax += tmp;
152.  		u.uhp += tmp;
153.  		tmp = enermod(rn1((int)ACURR(A_WIS)/2+1, 2)); /* M. Stephenson */
154.  		u.uenmax += tmp;
155.  		u.uen += tmp;
156.  #ifdef WEAPON_SKILLS
157.  		add_weapon_skill();
158.  #endif /* WEAPON_SKILLS */
159.  		flags.botl = 1;
160.  	}
161.  }
162.  
163.  void
164.  pluslvl()
165.  {
166.  	register int num;
167.  
168.  	You_feel("more experienced.");
169.  	num = newhp();
170.  	u.uhpmax += num;
171.  	u.uhp += num;
172.  	num = enermod(rn1((int)ACURR(A_WIS)/2+1, 2));	/* M. Stephenson */
173.  	u.uenmax += num;
174.  	u.uen += num;
175.  	if(u.ulevel < MAXULEV) {
176.  		u.uexp = newuexp(u.ulevel);
177.  		pline("Welcome to experience level %d.", ++u.ulevel);
178.  		adjabil(u.ulevel - 1, u.ulevel);
179.  		reset_rndmonst(NON_PM);	/* new monster selection */
180.  	}
181.  #ifdef WEAPON_SKILLS
182.  	add_weapon_skill();
183.  #endif /* WEAPON_SKILLS */
184.  	flags.botl = 1;
185.  }
186.  
187.  long
188.  rndexp()
189.  {
190.  	register long minexp,maxexp;
191.  
192.  	if(u.ulevel == 1)
193.  		return rn2((int)newuexp(1));
194.  	else {
195.  		minexp = newuexp(u.ulevel - 1);
196.  		maxexp = newuexp(u.ulevel);
197.  		return(minexp + rn2((int)(maxexp - minexp)));
198.  	}
199.  }
200.  
201.  /*exper.c*/