Source:NetHack 3.4.3/src/botl.c

From NetHackWiki
(Redirected from Source:Ref/title to mon)
Jump to: navigation, search

Below is the full text to src/botl.c from NetHack 3.4.3. To link to a particular line, write [[botl.c#line123]], for example.

Top of file[edit]

  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. */

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. #include "hack.h"
  2.  
  3. #ifdef OVL0
  4. extern const char *hu_stat[];	/* defined in eat.c */
  5.  
  6. const char * const enc_stat[] = {
  7. 	"",
  8. 	"Burdened",
  9. 	"Stressed",
  10. 	"Strained",
  11. 	"Overtaxed",
  12. 	"Overloaded"
  13. };
  14.  
  15. STATIC_DCL void NDECL(bot1);
  16. STATIC_DCL void NDECL(bot2);
  17. #endif /* OVL0 */
  18.  
  19. /* MAXCO must hold longest uncompressed status line, and must be larger
  20. * than COLNO
  21. *
  22. * longest practical second status line at the moment is
  23. *	Astral Plane $:12345 HP:700(700) Pw:111(111) AC:-127 Xp:30/123456789
  24. *	T:123456 Satiated Conf FoodPois Ill Blind Stun Hallu Overloaded
  25. * -- or somewhat over 130 characters
  26. */
  27. #if COLNO <= 140
  28. #define MAXCO 160
  29. #else
  30. #define MAXCO (COLNO+20)
  31. #endif
  32.  
  33. #ifndef OVLB
  34. STATIC_DCL int mrank_sz;
  35. #else /* OVLB */
  36. STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */
  37. #endif /* OVLB */
  38.  
  39. STATIC_DCL const char *NDECL(rank);

xlev_to_rank[edit]

  1. #ifdef OVL1
  2.  
  3. /* convert experience level (1..30) to rank index (0..8) */
  4. int
  5. xlev_to_rank(xlev)
  6. int xlev;
  7. {
  8. 	return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8;
  9. }

The conversion produces the following result:

Rank 0 1 2
Level 1 to 2 3 to 5 6 to 9
Rank 3 4 5
Level 10 to 13 14 to 17 18 to 21
Rank 6 7 8
Level 22 to 25 26 to 29 30

rank_to_xlev[edit]

  1. #if 0	/* not currently needed */
  2. /* convert rank index (0..8) to experience level (1..30) */
  3. int
  4. rank_to_xlev(rank)
  5. int rank;
  6. {
  7. 	return (rank <= 0) ? 1 : (rank <= 8) ? ((rank * 4) - 2) : 30;
  8. }
  9. #endif

rank_of[edit]

  1. const char *
  2. rank_of(lev, monnum, female)
  3. 	int lev;
  4. 	short monnum;
  5. 	boolean female;
  6. {
  7. 	register struct Role *role;
  8. 	register int i;
  9.  
  10.  
  11. 	/* Find the role */
  12. 	for (role = (struct Role *) roles; role->name.m; role++)
  13. 	    if (monnum == role->malenum || monnum == role->femalenum)
  14. 	    	break;
  15. 	if (!role->name.m)
  16. 	    role = &urole;
  17.  
  18. 	/* Find the rank */
  19. 	for (i = xlev_to_rank((int)lev); i >= 0; i--) {
  20. 	    if (female && role->rank[i].f) return (role->rank[i].f);
  21. 	    if (role->rank[i].m) return (role->rank[i].m);
  22. 	}
  23.  
  24. 	/* Try the role name, instead */
  25. 	if (female && role->name.f) return (role->name.f);
  26. 	else if (role->name.m) return (role->name.m);
  27. 	return ("Player");
  28. }

rank[edit]

  1. STATIC_OVL const char *
  2. rank()
  3. {
  4. 	return(rank_of(u.ulevel, Role_switch, flags.female));
  5. }

title_to_mon[edit]

  1. int
  2. title_to_mon(str, rank_indx, title_length)
  3. const char *str;
  4. int *rank_indx, *title_length;
  5. {
  6. 	register int i, j;
  7.  
  8.  
  9. 	/* Loop through each of the roles */
  10. 	for (i = 0; roles[i].name.m; i++)
  11. 	    for (j = 0; j < 9; j++) {
  12. 	    	if (roles[i].rank[j].m && !strncmpi(str,
  13. 	    			roles[i].rank[j].m, strlen(roles[i].rank[j].m))) {
  14. 	    	    if (rank_indx) *rank_indx = j;
  15. 	    	    if (title_length) *title_length = strlen(roles[i].rank[j].m);
  16. 	    	    return roles[i].malenum;
  17. 	    	}
  18. 	    	if (roles[i].rank[j].f && !strncmpi(str,
  19. 	    			roles[i].rank[j].f, strlen(roles[i].rank[j].f))) {
  20. 	    	    if (rank_indx) *rank_indx = j;
  21. 	    	    if (title_length) *title_length = strlen(roles[i].rank[j].f);
  22. 	    	    return ((roles[i].femalenum != NON_PM) ?
  23. 	    	    		roles[i].femalenum : roles[i].malenum);
  24. 	    	}
  25. 	    }
  26. 	return NON_PM;
  27. }
  28.  
  29. #endif /* OVL1 */

max_rank_sz[edit]

  1. #ifdef OVLB
  2.  
  3. void
  4. max_rank_sz()
  5. {
  6. 	register int i, r, maxr = 0;
  7. 	for (i = 0; i < 9; i++) {
  8. 	    if (urole.rank[i].m && (r = strlen(urole.rank[i].m)) > maxr) maxr = r;
  9. 	    if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr) maxr = r;
  10. 	}
  11. 	mrank_sz = maxr;
  12. 	return;
  13. }
  14.  
  15. #endif /* OVLB */

botl_score[edit]

  1. #ifdef OVL0
  2.  
  3. #ifdef SCORE_ON_BOTL
  4. long
  5. botl_score()
  6. {
  7. int deepest = deepest_lev_reached(FALSE);
  8. #ifndef GOLDOBJ
  9. long ugold = u.ugold + hidden_gold();
  10.  
  11. if ((ugold -= u.ugold0) < 0L) ugold = 0L;
  12. return ugold + u.urexp + (long)(50 * (deepest - 1))
  13. #else
  14. long umoney = money_cnt(invent) + hidden_gold();
  15.  
  16. if ((umoney -= u.umoney0) < 0L) umoney = 0L;
  17. return umoney + u.urexp + (long)(50 * (deepest - 1))
  18. #endif
  19. 			  + (long)(deepest > 30 ? 10000 :
  20. 				   deepest > 20 ? 1000*(deepest - 20) : 0);
  21. }
  22. #endif

botl[edit]

  1. STATIC_OVL void
  2. bot1()
  3. {
  4. 	char newbot1[MAXCO];
  5. 	register char *nb;
  6. 	register int i,j;
  7.  
  8. 	Strcpy(newbot1, plname);
  9. 	if('a' <= newbot1[0] && newbot1[0] <= 'z') newbot1[0] += 'A'-'a';
  10. 	newbot1[10] = 0;
  11. 	Sprintf(nb = eos(newbot1)," the ");
  12.  
  13. 	if (Upolyd) {
  14. 		char mbot[BUFSZ];
  15. 		int k = 0;
  16.  
  17. 		Strcpy(mbot, mons[u.umonnum].mname);
  18. 		while(mbot[k] != 0) {
  19. 		    if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) &&
  20. 					'a' <= mbot[k] && mbot[k] <= 'z')
  21. 			mbot[k] += 'A' - 'a';
  22. 		    k++;
  23. 		}
  24. 		Sprintf(nb = eos(nb), mbot);
  25. 	} else
  26. 		Sprintf(nb = eos(nb), rank());
  27.  
  28. 	Sprintf(nb = eos(nb),"  ");
  29. 	i = mrank_sz + 15;
  30. 	j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */
  31. 	if((i - j) > 0)
  32. 		Sprintf(nb = eos(nb),"%*s", i-j, " ");	/* pad with spaces */
  33. 	if (ACURR(A_STR) > 18) {
  34. 		if (ACURR(A_STR) > STR18(100))
  35. 		    Sprintf(nb = eos(nb),"St:%2d ",ACURR(A_STR)-100);
  36. 		else if (ACURR(A_STR) < STR18(100))
  37. 		    Sprintf(nb = eos(nb), "St:18/%02d ",ACURR(A_STR)-18);
  38. 		else
  39. 		    Sprintf(nb = eos(nb),"St:18/** ");
  40. 	} else
  41. 		Sprintf(nb = eos(nb), "St:%-1d ",ACURR(A_STR));
  42. 	Sprintf(nb = eos(nb),
  43. 		"Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
  44. 		ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), ACURR(A_CHA));
  45. 	Sprintf(nb = eos(nb), (u.ualign.type == A_CHAOTIC) ? "  Chaotic" :
  46. 			(u.ualign.type == A_NEUTRAL) ? "  Neutral" : "  Lawful");
  47. #ifdef SCORE_ON_BOTL
  48. 	if (flags.showscore)
  49. 	    Sprintf(nb = eos(nb), " S:%ld", botl_score());
  50. #endif
  51. 	curs(WIN_STATUS, 1, 0);
  52. 	putstr(WIN_STATUS, 0, newbot1);
  53. }

describe_level[edit]

  1. /* provide the name of the current level for display by various ports */
  2. int
  3. describe_level(buf)
  4. char *buf;
  5. {
  6. 	int ret = 1;
  7.  
  8. 	/* TODO:	Add in dungeon name */
  9. 	if (Is_knox(&u.uz))
  10. 		Sprintf(buf, "%s ", dungeons[u.uz.dnum].dname);
  11. 	else if (In_quest(&u.uz))
  12. 		Sprintf(buf, "Home %d ", dunlev(&u.uz));
  13. 	else if (In_endgame(&u.uz))
  14. 		Sprintf(buf,
  15. 			Is_astralevel(&u.uz) ? "Astral Plane " : "End Game ");
  16. 	else {
  17. 		/* ports with more room may expand this one */
  18. 		Sprintf(buf, "Dlvl:%-2d ", depth(&u.uz));
  19. 		ret = 0;
  20. 	}
  21. 	return ret;
  22. }

bot2[edit]

  1. STATIC_OVL void
  2. bot2()
  3. {
  4. 	char  newbot2[MAXCO];
  5. 	register char *nb;
  6. 	int hp, hpmax;
  7. 	int cap = near_capacity();
  8.  
  9. 	hp = Upolyd ? u.mh : u.uhp;
  10. 	hpmax = Upolyd ? u.mhmax : u.uhpmax;
  11.  
  12. 	if(hp < 0) hp = 0;
  13. 	(void) describe_level(newbot2);
  14. 	Sprintf(nb = eos(newbot2),
  15. 		"%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", oc_syms[COIN_CLASS],
  16. #ifndef GOLDOBJ
  17. 		u.ugold,
  18. #else
  19. 		money_cnt(invent),
  20. #endif
  21. 		hp, hpmax, u.uen, u.uenmax, u.uac);
  22.  
  23. 	if (Upolyd)
  24. 		Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
  25. #ifdef EXP_ON_BOTL
  26. 	else if(flags.showexp)
  27. 		Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel,u.uexp);
  28. #endif
  29. 	else
  30. 		Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
  31.  
  32. 	if(flags.time)
  33. 	    Sprintf(nb = eos(nb), " T:%ld", moves);
  34. 	if(strcmp(hu_stat[u.uhs], "        ")) {
  35. 		Sprintf(nb = eos(nb), " ");
  36. 		Strcat(newbot2, hu_stat[u.uhs]);
  37. 	}
  38. 	if(Confusion)	   Sprintf(nb = eos(nb), " Conf");
  39. 	if(Sick) {
  40. 		if (u.usick_type & SICK_VOMITABLE)
  41. 			   Sprintf(nb = eos(nb), " FoodPois");
  42. 		if (u.usick_type & SICK_NONVOMITABLE)
  43. 			   Sprintf(nb = eos(nb), " Ill");
  44. 	}
  45. 	if(Blind)	   Sprintf(nb = eos(nb), " Blind");
  46. 	if(Stunned)	   Sprintf(nb = eos(nb), " Stun");
  47. 	if(Hallucination)  Sprintf(nb = eos(nb), " Hallu");
  48. 	if(Slimed)         Sprintf(nb = eos(nb), " Slime");
  49. 	if(cap > UNENCUMBERED)
  50. 		Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
  51. 	curs(WIN_STATUS, 1, 1);
  52. 	putstr(WIN_STATUS, 0, newbot2);
  53. }

bot[edit]

  1. void
  2. bot()
  3. {
  4. 	bot1();
  5. 	bot2();
  6. 	flags.botl = flags.botlx = 0;
  7. }
  8.  
  9. #endif /* OVL0 */
  10.  
  11. /*botl.c*/