Source:NetHack 3.4.0/botl.c

From NetHackWiki
Revision as of 12:29, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 3.4.0/botl.c moved to Source:NetHack 3.4.0/botl.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 botl.c from the source code of NetHack 3.4.0. To link to a particular line, write [[NetHack 3.4.0/botl.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: @(#)botl.c	3.4	1996/07/15	*/
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 OVL0
8.    extern const char *hu_stat[];	/* defined in eat.c */
9.    
10.   const char *enc_stat[] = {
11.   	"",
12.   	"Burdened",
13.   	"Stressed",
14.   	"Strained",
15.   	"Overtaxed",
16.   	"Overloaded"
17.   };
18.   
19.   STATIC_DCL void NDECL(bot1);
20.   STATIC_DCL void NDECL(bot2);
21.   #endif /* OVL0 */
22.   
23.   /* MAXCO must hold longest uncompressed status line, and must be larger
24.    * than COLNO
25.    *
26.    * longest practical second status line at the moment is
27.    *	Astral Plane $:12345 HP:700(700) Pw:111(111) AC:-127 Xp:30/123456789
28.    *	T:123456 Satiated Conf FoodPois Ill Blind Stun Hallu Overloaded
29.    * -- or somewhat over 130 characters
30.    */
31.   #if COLNO <= 140
32.   #define MAXCO 160
33.   #else
34.   #define MAXCO (COLNO+20)
35.   #endif
36.   
37.   #ifndef OVLB
38.   STATIC_DCL int mrank_sz;
39.   #else /* OVLB */
40.   STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */
41.   #endif /* OVLB */
42.   
43.   STATIC_DCL const char *NDECL(rank);
44.   
45.   #ifdef OVL1
46.   
47.   /* convert experience level (1..30) to rank index (0..8) */
48.   int xlev_to_rank(xlev)
49.   int xlev;
50.   {
51.   	return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8;
52.   }
53.   
54.   #if 0	/* not currently needed */
55.   /* convert rank index (0..8) to experience level (1..30) */
56.   int rank_to_xlev(rank)
57.   int rank;
58.   {
59.   	return (rank <= 0) ? 1 : (rank <= 8) ? ((rank * 4) - 2) : 30;
60.   }
61.   #endif
62.   
63.   const char *
64.   rank_of(lev, monnum, female)
65.   	int lev;
66.   	short monnum;
67.   	boolean female;
68.   {
69.   	register struct Role *role;
70.   	register int i;
71.   
72.   
73.   	/* Find the role */
74.   	for (role = (struct Role *) roles; role->name.m; role++)
75.   	    if (monnum == role->malenum || monnum == role->femalenum)
76.   	    	break;
77.   	if (!role->name.m)
78.   	    role = &urole;
79.   
80.   	/* Find the rank */
81.   	for (i = xlev_to_rank((int)lev); i >= 0; i--) {
82.   	    if (female && role->rank[i].f) return (role->rank[i].f);
83.   	    if (role->rank[i].m) return (role->rank[i].m);
84.   	}
85.   
86.   	/* Try the role name, instead */
87.   	if (female && role->name.f) return (role->name.f);
88.   	else if (role->name.m) return (role->name.m);
89.   	return ("Player");
90.   }
91.   
92.   
93.   STATIC_OVL const char *
94.   rank()
95.   {
96.   	return(rank_of(u.ulevel, Role_switch, flags.female));
97.   }
98.   
99.   int
100.  title_to_mon(str, rank_indx, title_length)
101.  const char *str;
102.  int *rank_indx, *title_length;
103.  {
104.  	register int i, j;
105.  
106.  
107.  	/* Loop through each of the roles */
108.  	for (i = 0; roles[i].name.m; i++)
109.  	    for (j = 0; j < 9; j++) {
110.  	    	if (roles[i].rank[j].m && !strncmpi(str,
111.  	    			roles[i].rank[j].m, strlen(roles[i].rank[j].m))) {
112.  	    	    if (rank_indx) *rank_indx = j;
113.  	    	    if (title_length) *title_length = strlen(roles[i].rank[j].m);
114.  	    	    return roles[i].malenum;
115.  	    	}
116.  	    	if (roles[i].rank[j].f && !strncmpi(str,
117.  	    			roles[i].rank[j].f, strlen(roles[i].rank[j].f))) {
118.  	    	    if (rank_indx) *rank_indx = j;
119.  	    	    if (title_length) *title_length = strlen(roles[i].rank[j].f);
120.  	    	    return ((roles[i].femalenum != NON_PM) ?
121.  	    	    		roles[i].femalenum : roles[i].malenum);
122.  	    	}
123.  	    }
124.  	return NON_PM;
125.  }
126.  
127.  #endif /* OVL1 */
128.  #ifdef OVLB
129.  
130.  void
131.  max_rank_sz()
132.  {
133.  	register int i, r, maxr = 0;
134.  	for (i = 0; i < 9; i++) {
135.  	    if (urole.rank[i].m && (r = strlen(urole.rank[i].m)) > maxr) maxr = r;
136.  	    if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr) maxr = r;
137.  	}
138.  	mrank_sz = maxr;
139.  	return;
140.  }
141.  
142.  #endif /* OVLB */
143.  #ifdef OVL0
144.  
145.  #ifdef SCORE_ON_BOTL
146.  long
147.  botl_score()
148.  {
149.      int deepest = deepest_lev_reached(FALSE);
150.  #ifndef GOLDOBJ
151.      long ugold = u.ugold + hidden_gold();
152.  
153.      if ((ugold -= u.ugold0) < 0L) ugold = 0L;
154.      return ugold + u.urexp + (long)(50 * (deepest - 1))
155.  #else
156.      long umoney = money_cnt(invent) + hidden_gold();
157.  
158.      if ((umoney -= u.umoney0) < 0L) umoney = 0L;
159.      return umoney + u.urexp + (long)(50 * (deepest - 1))
160.  #endif
161.  			  + (long)(deepest > 30 ? 10000 :
162.  				   deepest > 20 ? 1000*(deepest - 20) : 0);
163.  }
164.  #endif
165.  
166.  STATIC_OVL void
167.  bot1()
168.  {
169.  	char newbot1[MAXCO];
170.  	register char *nb;
171.  	register int i,j;
172.  
173.  	Strcpy(newbot1, plname);
174.  	if('a' <= newbot1[0] && newbot1[0] <= 'z') newbot1[0] += 'A'-'a';
175.  	newbot1[10] = 0;
176.  	Sprintf(nb = eos(newbot1)," the ");
177.  
178.  	if (Upolyd) {
179.  		char mbot[BUFSZ];
180.  		int k = 0;
181.  
182.  		Strcpy(mbot, mons[u.umonnum].mname);
183.  		while(mbot[k] != 0) {
184.  		    if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) &&
185.  					'a' <= mbot[k] && mbot[k] <= 'z')
186.  			mbot[k] += 'A' - 'a';
187.  		    k++;
188.  		}
189.  		Sprintf(nb = eos(nb), mbot);
190.  	} else
191.  		Sprintf(nb = eos(nb), rank());
192.  
193.  	Sprintf(nb = eos(nb),"  ");
194.  	i = mrank_sz + 15;
195.  	j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */
196.  	if((i - j) > 0)
197.  		Sprintf(nb = eos(nb),"%*s", i-j, " ");	/* pad with spaces */
198.  	if (ACURR(A_STR) > 18) {
199.  		if (ACURR(A_STR) > STR18(100))
200.  		    Sprintf(nb = eos(nb),"St:%2d ",ACURR(A_STR)-100);
201.  		else if (ACURR(A_STR) < STR18(100))
202.  		    Sprintf(nb = eos(nb), "St:18/%02d ",ACURR(A_STR)-18);
203.  		else
204.  		    Sprintf(nb = eos(nb),"St:18/** ");
205.  	} else
206.  		Sprintf(nb = eos(nb), "St:%-1d ",ACURR(A_STR));
207.  	Sprintf(nb = eos(nb),
208.  		"Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
209.  		ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), ACURR(A_CHA));
210.  	Sprintf(nb = eos(nb), (u.ualign.type == A_CHAOTIC) ? "  Chaotic" :
211.  			(u.ualign.type == A_NEUTRAL) ? "  Neutral" : "  Lawful");
212.  #ifdef SCORE_ON_BOTL
213.  	if (flags.showscore)
214.  	    Sprintf(nb = eos(nb), " S:%ld", botl_score());
215.  #endif
216.  	curs(WIN_STATUS, 1, 0);
217.  	putstr(WIN_STATUS, 0, newbot1);
218.  }
219.  
220.  /* provide the name of the current level for display by various ports */
221.  int
222.  describe_level(buf)
223.  char *buf;
224.  {
225.  	int ret = 1;
226.  
227.  	/* TODO:	Add in dungeon name */
228.  	if (Is_knox(&u.uz))
229.  		Sprintf(buf, "%s ", dungeons[u.uz.dnum].dname);
230.  	else if (In_quest(&u.uz))
231.  		Sprintf(buf, "Home %d ", dunlev(&u.uz));
232.  	else if (In_endgame(&u.uz))
233.  		Sprintf(buf,
234.  			Is_astralevel(&u.uz) ? "Astral Plane " : "End Game ");
235.  	else {
236.  		/* ports with more room may expand this one */
237.  		Sprintf(buf, "Dlvl:%-2d ", depth(&u.uz));
238.  		ret = 0;
239.  	}
240.  	return ret;
241.  }
242.  
243.  STATIC_OVL void
244.  bot2()
245.  {
246.  	char  newbot2[MAXCO];
247.  	register char *nb;
248.  	int hp, hpmax;
249.  	int cap = near_capacity();
250.  
251.  	hp = Upolyd ? u.mh : u.uhp;
252.  	hpmax = Upolyd ? u.mhmax : u.uhpmax;
253.  
254.  	if(hp < 0) hp = 0;
255.  	(void) describe_level(newbot2);
256.  	Sprintf(nb = eos(newbot2),
257.  		"%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", oc_syms[GOLD_CLASS],
258.  #ifndef GOLDOBJ
259.  		u.ugold,
260.  #else
261.  		money_cnt(invent),
262.  #endif
263.  		hp, hpmax, u.uen, u.uenmax, u.uac);
264.  
265.  	if (Upolyd)
266.  		Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
267.  #ifdef EXP_ON_BOTL
268.  	else if(flags.showexp)
269.  		Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel,u.uexp);
270.  #endif
271.  	else
272.  		Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
273.  
274.  	if(flags.time)
275.  	    Sprintf(nb = eos(nb), " T:%ld", moves);
276.  	if(strcmp(hu_stat[u.uhs], "        ")) {
277.  		Sprintf(nb = eos(nb), " ");
278.  		Strcat(newbot2, hu_stat[u.uhs]);
279.  	}
280.  	if(Confusion)	   Sprintf(nb = eos(nb), " Conf");
281.  	if(Sick) {
282.  		if (u.usick_type & SICK_VOMITABLE)
283.  			   Sprintf(nb = eos(nb), " FoodPois");
284.  		if (u.usick_type & SICK_NONVOMITABLE)
285.  			   Sprintf(nb = eos(nb), " Ill");
286.  	}
287.  	if(Blind)	   Sprintf(nb = eos(nb), " Blind");
288.  	if(Stunned)	   Sprintf(nb = eos(nb), " Stun");
289.  	if(Hallucination)  Sprintf(nb = eos(nb), " Hallu");
290.  	if(Slimed)         Sprintf(nb = eos(nb), " Slime");
291.  	if(cap > UNENCUMBERED)
292.  		Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
293.  	curs(WIN_STATUS, 1, 1);
294.  	putstr(WIN_STATUS, 0, newbot2);
295.  }
296.  
297.  void
298.  bot()
299.  {
300.  	bot1();
301.  	bot2();
302.  	flags.botl = flags.botlx = 0;
303.  }
304.  
305.  #endif /* OVL0 */
306.  
307.  /*botl.c*/