Source:NetHack 3.4.3/src/attrib.c

From NetHackWiki
(Redirected from Source:Ref/set moreluck)
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)attrib.c	3.4	2002/10/07	*/
  2. /*	Copyright 1988, 1989, 1990, 1992, M. Stephenson		  */
  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. /*  attribute modification routines. */
  2.  
  3. #include "hack.h"
  4.  
  5. /* #define DEBUG */	/* uncomment for debugging info */
  6.  
  7. #ifdef OVLB
  8.  
  9. 	/* part of the output on gain or loss of attribute */
  10. static
  11. const char	* const plusattr[] = {
  12. 	"strong", "smart", "wise", "agile", "tough", "charismatic"
  13. },
  14. 		* const minusattr[] = {
  15. 	"weak", "stupid", "foolish", "clumsy", "fragile", "repulsive"
  16. };

innate[edit]

  1. static
  2. const struct innate {
  3. 	schar	ulevel;
  4. 	long	*ability;
  5. 	const char *gainstr, *losestr;
  6. }	arc_abil[] = { {	 1, &(HStealth), "", "" },
  7. 		     {   1, &(HFast), "", "" },
  8. 		     {  10, &(HSearching), "perceptive", "" },
  9. 		     {	 0, 0, 0, 0 } },
  10.  
  11. 	bar_abil[] = { {	 1, &(HPoison_resistance), "", "" },
  12. 		     {   7, &(HFast), "quick", "slow" },
  13. 		     {  15, &(HStealth), "stealthy", "" },
  14. 		     {	 0, 0, 0, 0 } },
  15.  
  16. 	cav_abil[] = { {	 7, &(HFast), "quick", "slow" },
  17. 		     {	15, &(HWarning), "sensitive", "" },
  18. 		     {	 0, 0, 0, 0 } },
  19.  
  20. 	hea_abil[] = { {	 1, &(HPoison_resistance), "", "" },
  21. 		     {	15, &(HWarning), "sensitive", "" },
  22. 		     {	 0, 0, 0, 0 } },
  23.  
  24. 	kni_abil[] = { {	 7, &(HFast), "quick", "slow" },
  25. 		     {	 0, 0, 0, 0 } },
  26.  
  27. 	mon_abil[] = { {   1, &(HFast), "", "" },
  28. 		     {   1, &(HSleep_resistance), "", "" },
  29. 		     {   1, &(HSee_invisible), "", "" },
  30. 		     {   3, &(HPoison_resistance), "healthy", "" },
  31. 		     {   5, &(HStealth), "stealthy", "" },
  32. 		     {   7, &(HWarning), "sensitive", "" },
  33. 		     {   9, &(HSearching), "perceptive", "unaware" },
  34. 		     {  11, &(HFire_resistance), "cool", "warmer" },
  35. 		     {  13, &(HCold_resistance), "warm", "cooler" },
  36. 		     {  15, &(HShock_resistance), "insulated", "conductive" },
  37. 		     {  17, &(HTeleport_control), "controlled","uncontrolled" },
  38. 		     {   0, 0, 0, 0 } },
  39.  
  40. 	pri_abil[] = { {	15, &(HWarning), "sensitive", "" },
  41. 		     {  20, &(HFire_resistance), "cool", "warmer" },
  42. 		     {	 0, 0, 0, 0 } },
  43.  
  44. 	ran_abil[] = { {   1, &(HSearching), "", "" },
  45. 		     {	 7, &(HStealth), "stealthy", "" },
  46. 		     {	15, &(HSee_invisible), "", "" },
  47. 		     {	 0, 0, 0, 0 } },
  48.  
  49. 	rog_abil[] = { {	 1, &(HStealth), "", ""  },
  50. 		     {  10, &(HSearching), "perceptive", "" },
  51. 		     {	 0, 0, 0, 0 } },
  52.  
  53. 	sam_abil[] = { {	 1, &(HFast), "", "" },
  54. 		     {  15, &(HStealth), "stealthy", "" },
  55. 		     {	 0, 0, 0, 0 } },
  56.  
  57. 	tou_abil[] = { {	10, &(HSearching), "perceptive", "" },
  58. 		     {	20, &(HPoison_resistance), "hardy", "" },
  59. 		     {	 0, 0, 0, 0 } },
  60.  
  61. 	val_abil[] = { {	 1, &(HCold_resistance), "", "" },
  62. 		     {	 1, &(HStealth), "", "" },
  63. 		     {   7, &(HFast), "quick", "slow" },
  64. 		     {	 0, 0, 0, 0 } },
  65.  
  66. 	wiz_abil[] = { {	15, &(HWarning), "sensitive", "" },
  67. 		     {  17, &(HTeleport_control), "controlled","uncontrolled" },
  68. 		     {	 0, 0, 0, 0 } },
  69.  
  70. 	/* Intrinsics conferred by race */
  71. 	elf_abil[] = { {	4, &(HSleep_resistance), "awake", "tired" },
  72. 		     {	 0, 0, 0, 0 } },
  73.  
  74. 	orc_abil[] = { {	1, &(HPoison_resistance), "", "" },
  75. 		     {	 0, 0, 0, 0 } };
  76.  
  77. static long next_check = 600L;	/* arbitrary first setting */
  78. STATIC_DCL void NDECL(exerper);
  79. STATIC_DCL void FDECL(postadjabil, (long *));

adjattrib[edit]

  1. /* adjust an attribute; return TRUE if change is made, FALSE otherwise */
  2. boolean
  3. adjattrib(ndx, incr, msgflg)
  4. 	int	ndx, incr;
  5. 	int	msgflg;	    /* positive => no message, zero => message, and */
  6. {			    /* negative => conditional (msg if change made) */
  7. 	if (Fixed_abil || !incr) return FALSE;
  8.  
  9. 	if ((ndx == A_INT || ndx == A_WIS)
  10. 				&& uarmh && uarmh->otyp == DUNCE_CAP) {
  11. 		if (msgflg == 0)
  12. 		    Your("cap constricts briefly, then relaxes again.");
  13. 		return FALSE;
  14. 	}
  15.  
  16. 	if (incr > 0) {
  17. 	    if ((AMAX(ndx) >= ATTRMAX(ndx)) && (ACURR(ndx) >= AMAX(ndx))) {
  18. 		if (msgflg == 0 && flags.verbose)
  19. 		    pline("You're already as %s as you can get.",
  20. 			  plusattr[ndx]);
  21. 		ABASE(ndx) = AMAX(ndx) = ATTRMAX(ndx); /* just in case */
  22. 		return FALSE;
  23. 	    }
  24.  
  25. 	    ABASE(ndx) += incr;
  26. 	    if(ABASE(ndx) > AMAX(ndx)) {
  27. 		incr = ABASE(ndx) - AMAX(ndx);
  28. 		AMAX(ndx) += incr;
  29. 		if(AMAX(ndx) > ATTRMAX(ndx))
  30. 		    AMAX(ndx) = ATTRMAX(ndx);
  31. 		ABASE(ndx) = AMAX(ndx);
  32. 	    }
  33. 	} else {
  34. 	    if (ABASE(ndx) <= ATTRMIN(ndx)) {
  35. 		if (msgflg == 0 && flags.verbose)
  36. 		    pline("You're already as %s as you can get.",
  37. 			  minusattr[ndx]);
  38. 		ABASE(ndx) = ATTRMIN(ndx); /* just in case */
  39. 		return FALSE;
  40. 	    }
  41.  
  42. 	    ABASE(ndx) += incr;
  43. 	    if(ABASE(ndx) < ATTRMIN(ndx)) {
  44. 		incr = ABASE(ndx) - ATTRMIN(ndx);
  45. 		ABASE(ndx) = ATTRMIN(ndx);
  46. 		AMAX(ndx) += incr;
  47. 		if(AMAX(ndx) < ATTRMIN(ndx))
  48. 		    AMAX(ndx) = ATTRMIN(ndx);
  49. 	    }
  50. 	}
  51. 	if (msgflg <= 0)
  52. 	    You_feel("%s%s!",
  53. 		  (incr > 1 || incr < -1) ? "very ": "",
  54. 		  (incr > 0) ? plusattr[ndx] : minusattr[ndx]);
  55. 	flags.botl = 1;
  56. 	if (moves > 1 && (ndx == A_STR || ndx == A_CON))
  57. 		(void)encumber_msg();
  58. 	return TRUE;
  59. }

gainstr[edit]

  1. void
  2. gainstr(otmp, incr)
  3. 	register struct obj *otmp;
  4. 	register int incr;
  5. {
  6. 	int num = 1;
  7.  
  8. 	if(incr) num = incr;
  9. 	else {
  10. 	    if(ABASE(A_STR) < 18) num = (rn2(4) ? 1 : rnd(6) );
  11. 	    else if (ABASE(A_STR) < STR18(85)) num = rnd(10);
  12. 	}
  13. 	(void) adjattrib(A_STR, (otmp && otmp->cursed) ? -num : num, TRUE);
  14. }

losestr[edit]

  1. void
  2. losestr(num)	/* may kill you; cause may be poison or monster like 'a' */
  3. 	register int num;
  4. {
  5. 	int ustr = ABASE(A_STR) - num;
  6.  
  7. 	while(ustr < 3) {
  8. 	    ++ustr;
  9. 	    --num;
  10. 	    if (Upolyd) {
  11. 		u.mh -= 6;
  12. 		u.mhmax -= 6;
  13. 	    } else {
  14. 		u.uhp -= 6;
  15. 		u.uhpmax -= 6;
  16. 	    }
  17. 	}
  18. 	(void) adjattrib(A_STR, -num, TRUE);
  19. }

change_luck[edit]

  1. void
  2. change_luck(n)
  3. 	register schar n;
  4. {
  5. 	u.uluck += n;
  6. 	if (u.uluck < 0 && u.uluck < LUCKMIN)	u.uluck = LUCKMIN;
  7. 	if (u.uluck > 0 && u.uluck > LUCKMAX)	u.uluck = LUCKMAX;
  8. }

stone_luck[edit]

  1. int
  2. stone_luck(parameter)
  3. boolean parameter; /* So I can't think up of a good name.  So sue me. --KAA */
  4. {
  5. 	register struct obj *otmp;
  6. 	register long bonchance = 0;
  7.  
  8. 	for (otmp = invent; otmp; otmp = otmp->nobj)
  9. 	    if (confers_luck(otmp)) {
  10. 		if (otmp->cursed) bonchance -= otmp->quan;
  11. 		else if (otmp->blessed) bonchance += otmp->quan;
  12. 		else if (parameter) bonchance += otmp->quan;
  13. 	    }
  14.  
  15. 	return sgn((int)bonchance);
  16. }

set_moreluck[edit]

  1. /* there has just been an inventory change affecting a luck-granting item */
  2. void
  3. set_moreluck()
  4. {
  5. 	int luckbon = stone_luck(TRUE);
  6.  
  7. 	if (!luckbon && !carrying(LUCKSTONE)) u.moreluck = 0;
  8. 	else if (luckbon >= 0) u.moreluck = LUCKADD;
  9. 	else u.moreluck = -LUCKADD;
  10. }
  11.  
  12. #endif /* OVLB */

restore_attrib[edit]

  1. #ifdef OVL1
  2.  
  3. void
  4. restore_attrib()
  5. {
  6. 	int	i;
  7.  
  8. 	for(i = 0; i < A_MAX; i++) {	/* all temporary losses/gains */
  9.  
  10. 	   if(ATEMP(i) && ATIME(i)) {
  11. 		if(!(--(ATIME(i)))) { /* countdown for change */
  12. 		    ATEMP(i) += ATEMP(i) > 0 ? -1 : 1;
  13.  
  14. 		    if(ATEMP(i)) /* reset timer */
  15. 			ATIME(i) = 100 / ACURR(A_CON);
  16. 		}
  17. 	    }
  18. 	}
  19. 	(void)encumber_msg();
  20. }
  21.  
  22. #endif /* OVL1 */

exercise[edit]

  1. #ifdef OVLB
  2.  
  3. #define AVAL	50		/* tune value for exercise gains */
  4.  
  5. void
  6. exercise(i, inc_or_dec)
  7. int	i;
  8. boolean	inc_or_dec;
  9. {
  10. #ifdef DEBUG
  11. 	pline("Exercise:");
  12. #endif
  13. 	if (i == A_INT || i == A_CHA) return;	/* can't exercise these */
  14.  
  15. 	/* no physical exercise while polymorphed; the body's temporary */
  16. 	if (Upolyd && i != A_WIS) return;
  17.  
  18. 	if(abs(AEXE(i)) < AVAL) {
  19. 		/*
  20. 		 *	Law of diminishing returns (Part I):
  21. 		 *
  22. 		 *	Gain is harder at higher attribute values.
  23. 		 *	79% at "3" --> 0% at "18"
  24. 		 *	Loss is even at all levels (50%).
  25. 		 *
  26. 		 *	Note: *YES* ACURR is the right one to use.
  27. 		 */
  28. 		AEXE(i) += (inc_or_dec) ? (rn2(19) > ACURR(i)) : -rn2(2);
  29. #ifdef DEBUG
  30. 		pline("%s, %s AEXE = %d",
  31. 			(i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" :
  32. 			(i == A_DEX) ? "Dex" : "Con",
  33. 			(inc_or_dec) ? "inc" : "dec", AEXE(i));
  34. #endif
  35. 	}
  36. 	if (moves > 0 && (i == A_STR || i == A_CON)) (void)encumber_msg();
  37. }

exercise() is called whenever one of Hero's attributes is being exercised. This means there's a change that attribute will go up or down. Takes two parameters, first is the attribute to exercise (A_STR, A_WIS, A_DEX or A_CON) and the second is TRUE if it should go up or FALSE if down.

exerper[edit]

  1. /* hunger values - from eat.c */
  2. #define SATIATED	0
  3. #define NOT_HUNGRY	1
  4. #define HUNGRY		2
  5. #define WEAK		3
  6. #define FAINTING	4
  7. #define FAINTED		5
  8. #define STARVED		6
  9.  
  10. STATIC_OVL void
  11. exerper()
  12. {
  13. 	if(!(moves % 10)) {
  14. 		/* Hunger Checks */
  15.  
  16. 		int hs = (u.uhunger > 1000) ? SATIATED :
  17. 			 (u.uhunger > 150) ? NOT_HUNGRY :
  18. 			 (u.uhunger > 50) ? HUNGRY :
  19. 			 (u.uhunger > 0) ? WEAK : FAINTING;
  20.  
  21. #ifdef DEBUG
  22. 		pline("exerper: Hunger checks");
  23. #endif
  24. 		switch (hs) {
  25. 		    case SATIATED:	exercise(A_DEX, FALSE);
  26. 					if (Role_if(PM_MONK))
  27. 					    exercise(A_WIS, FALSE);
  28. 					break;
  29. 		    case NOT_HUNGRY:	exercise(A_CON, TRUE); break;
  30. 		    case WEAK:		exercise(A_STR, FALSE);
  31. 					if (Role_if(PM_MONK))	/* fasting */
  32. 					    exercise(A_WIS, TRUE);
  33. 					break;
  34. 		    case FAINTING:
  35. 		    case FAINTED:	exercise(A_CON, FALSE); break;
  36. 		}
  37.  
  38. 		/* Encumberance Checks */
  39. #ifdef DEBUG
  40. 		pline("exerper: Encumber checks");
  41. #endif
  42. 		switch (near_capacity()) {
  43. 		    case MOD_ENCUMBER:	exercise(A_STR, TRUE); break;
  44. 		    case HVY_ENCUMBER:	exercise(A_STR, TRUE);
  45. 					exercise(A_DEX, FALSE); break;
  46. 		    case EXT_ENCUMBER:	exercise(A_DEX, FALSE);
  47. 					exercise(A_CON, FALSE); break;
  48. 		}
  49.  
  50. 	}
  51.  
  52. 	/* status checks */
  53. 	if(!(moves % 5)) {
  54. #ifdef DEBUG
  55. 		pline("exerper: Status checks");
  56. #endif
  57. 		if ((HClairvoyant & (INTRINSIC|TIMEOUT)) &&
  58. 			!BClairvoyant)                      exercise(A_WIS, TRUE);
  59. 		if (HRegeneration)			exercise(A_STR, TRUE);
  60.  
  61. 		if(Sick || Vomiting)     exercise(A_CON, FALSE);
  62. 		if(Confusion || Hallucination)		exercise(A_WIS, FALSE);
  63. 		if((Wounded_legs 
  64. #ifdef STEED
  65. 		    && !u.usteed
  66. #endif
  67. 			    ) || Fumbling || HStun)	exercise(A_DEX, FALSE);
  68. 	}
  69. }

exerchk[edit]

  1. void
  2. exerchk()
  3. {
  4. 	int	i, mod_val;
  5.  
  6. 	/*	Check out the periodic accumulations */
  7. 	exerper();
  8.  
  9. #ifdef DEBUG
  10. 	if(moves >= next_check)
  11. 		pline("exerchk: ready to test. multi = %d.", multi);
  12. #endif
  13. 	/*	Are we ready for a test?	*/
  14. 	if(moves >= next_check && !multi) {
  15. #ifdef DEBUG
  16. 	    pline("exerchk: testing.");
  17. #endif
  18. 	    /*
  19. 	     *	Law of diminishing returns (Part II):
  20. 	     *
  21. 	     *	The effects of "exercise" and "abuse" wear
  22. 	     *	off over time.  Even if you *don't* get an
  23. 	     *	increase/decrease, you lose some of the
  24. 	     *	accumulated effects.
  25. 	     */
  26. 	    for(i = 0; i < A_MAX; AEXE(i++) /= 2) {
  27.  
  28. 		if(ABASE(i) >= 18 || !AEXE(i)) continue;
  29. 		if(i == A_INT || i == A_CHA) continue;/* can't exercise these */
  30.  
  31. #ifdef DEBUG
  32. 		pline("exerchk: testing %s (%d).",
  33. 			(i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" :
  34. 			(i == A_DEX) ? "Dex" : "Con", AEXE(i));
  35. #endif
  36. 		/*
  37. 		 *	Law of diminishing returns (Part III):
  38. 		 *
  39. 		 *	You don't *always* gain by exercising.
  40. 		 *	[MRS 92/10/28 - Treat Wisdom specially for balance.]
  41. 		 */
  42. 		if(rn2(AVAL) > ((i != A_WIS) ? abs(AEXE(i)*2/3) : abs(AEXE(i))))
  43. 		    continue;
  44. 		mod_val = sgn(AEXE(i));
  45.  
  46. #ifdef DEBUG
  47. 		pline("exerchk: changing %d.", i);
  48. #endif
  49. 		if(adjattrib(i, mod_val, -1)) {
  50. #ifdef DEBUG
  51. 		    pline("exerchk: changed %d.", i);
  52. #endif
  53. 		    /* if you actually changed an attrib - zero accumulation */
  54. 		    AEXE(i) = 0;
  55. 		    /* then print an explanation */
  56. 		    switch(i) {
  57. 		    case A_STR: You((mod_val >0) ?
  58. 				    "must have been exercising." :
  59. 				    "must have been abusing your body.");
  60. 				break;
  61. 		    case A_WIS: You((mod_val >0) ?
  62. 				    "must have been very observant." :
  63. 				    "haven't been paying attention.");
  64. 				break;
  65. 		    case A_DEX: You((mod_val >0) ?
  66. 				    "must have been working on your reflexes." :
  67. 				    "haven't been working on reflexes lately.");
  68. 				break;
  69. 		    case A_CON: You((mod_val >0) ?
  70. 				    "must be leading a healthy life-style." :
  71. 				    "haven't been watching your health.");
  72. 				break;
  73. 		    }
  74. 		}
  75. 	    }
  76. 	    next_check += rn1(200,800);
  77. #ifdef DEBUG
  78. 	    pline("exerchk: next check at %ld.", next_check);
  79. #endif
  80. 	}
  81. }

reset_attribute_clock[edit]

  1. /* next_check will otherwise have its initial 600L after a game restore */
  2. void
  3. reset_attribute_clock()
  4. {
  5. 	if (moves > 600L) next_check = moves + rn1(50,800);
  6. }

init_attr[edit]

  1. void
  2. init_attr(np)
  3. 	register int	np;
  4. {
  5. 	register int	i, x, tryct;
  6.  
  7.  
  8. 	for(i = 0; i < A_MAX; i++) {
  9. 	    ABASE(i) = AMAX(i) = urole.attrbase[i];
  10. 	    ATEMP(i) = ATIME(i) = 0;
  11. 	    np -= urole.attrbase[i];
  12. 	}
  13.  
  14. 	tryct = 0;
  15. 	while(np > 0 && tryct < 100) {
  16.  
  17. 	    x = rn2(100);
  18. 	    for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++) ;
  19. 	    if(i >= A_MAX) continue; /* impossible */
  20.  
  21. 	    if(ABASE(i) >= ATTRMAX(i)) {
  22.  
  23. 		tryct++;
  24. 		continue;
  25. 	    }
  26. 	    tryct = 0;
  27. 	    ABASE(i)++;
  28. 	    AMAX(i)++;
  29. 	    np--;
  30. 	}
  31.  
  32. 	tryct = 0;
  33. 	while(np < 0 && tryct < 100) {		/* for redistribution */
  34.  
  35. 	    x = rn2(100);
  36. 	    for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++) ;
  37. 	    if(i >= A_MAX) continue; /* impossible */
  38.  
  39. 	    if(ABASE(i) <= ATTRMIN(i)) {
  40.  
  41. 		tryct++;
  42. 		continue;
  43. 	    }
  44. 	    tryct = 0;
  45. 	    ABASE(i)--;
  46. 	    AMAX(i)--;
  47. 	    np++;
  48. 	}
  49. }

redist_attr[edit]

  1. void
  2. redist_attr()
  3. {
  4. 	register int i, tmp;
  5.  
  6. 	for(i = 0; i < A_MAX; i++) {
  7. 	    if (i==A_INT || i==A_WIS) continue;
  8. 		/* Polymorphing doesn't change your mind */
  9. 	    tmp = AMAX(i);
  10. 	    AMAX(i) += (rn2(5)-2);
  11. 	    if (AMAX(i) > ATTRMAX(i)) AMAX(i) = ATTRMAX(i);
  12. 	    if (AMAX(i) < ATTRMIN(i)) AMAX(i) = ATTRMIN(i);
  13. 	    ABASE(i) = ABASE(i) * AMAX(i) / tmp;
  14. 	    /* ABASE(i) > ATTRMAX(i) is impossible */
  15. 	    if (ABASE(i) < ATTRMIN(i)) ABASE(i) = ATTRMIN(i);
  16. 	}
  17. 	(void)encumber_msg();
  18. }

postadjabil[edit]

  1. STATIC_OVL
  2. void
  3. postadjabil(ability)
  4. long *ability;
  5. {
  6. 	if (!ability) return;
  7. 	if (ability == &(HWarning) || ability == &(HSee_invisible))
  8. 		see_monsters();
  9. }

adjabil[edit]

  1. void
  2. adjabil(oldlevel,newlevel)
  3. int oldlevel, newlevel;
  4. {
  5. 	register const struct innate *abil, *rabil;
  6. 	long mask = FROMEXPER;
  7.  
  8.  
  9. 	switch (Role_switch) {
  10. 	case PM_ARCHEOLOGIST:   abil = arc_abil;	break;
  11. 	case PM_BARBARIAN:      abil = bar_abil;	break;
  12. 	case PM_CAVEMAN:        abil = cav_abil;	break;
  13. 	case PM_HEALER:         abil = hea_abil;	break;
  14. 	case PM_KNIGHT:         abil = kni_abil;	break;
  15. 	case PM_MONK:           abil = mon_abil;	break;
  16. 	case PM_PRIEST:         abil = pri_abil;	break;
  17. 	case PM_RANGER:         abil = ran_abil;	break;
  18. 	case PM_ROGUE:          abil = rog_abil;	break;
  19. 	case PM_SAMURAI:        abil = sam_abil;	break;
  20. #ifdef TOURIST
  21. 	case PM_TOURIST:        abil = tou_abil;	break;
  22. #endif
  23. 	case PM_VALKYRIE:       abil = val_abil;	break;
  24. 	case PM_WIZARD:         abil = wiz_abil;	break;
  25. 	default:                abil = 0;		break;
  26. 	}
  27.  
  28. 	switch (Race_switch) {
  29. 	case PM_ELF:            rabil = elf_abil;	break;
  30. 	case PM_ORC:            rabil = orc_abil;	break;
  31. 	case PM_HUMAN:
  32. 	case PM_DWARF:
  33. 	case PM_GNOME:
  34. 	default:                rabil = 0;		break;
  35. 	}
  36.  
  37. 	while (abil || rabil) {
  38. 	    long prevabil;
  39. 	    /* Have we finished with the intrinsics list? */
  40. 	    if (!abil || !abil->ability) {
  41. 	    	/* Try the race intrinsics */
  42. 	    	if (!rabil || !rabil->ability) break;
  43. 	    	abil = rabil;
  44. 	    	rabil = 0;
  45. 	    	mask = FROMRACE;
  46. 	    }
  47. 		prevabil = *(abil->ability);
  48. 		if(oldlevel < abil->ulevel && newlevel >= abil->ulevel) {
  49. 			/* Abilities gained at level 1 can never be lost
  50. 			 * via level loss, only via means that remove _any_
  51. 			 * sort of ability.  A "gain" of such an ability from
  52. 			 * an outside source is devoid of meaning, so we set
  53. 			 * FROMOUTSIDE to avoid such gains.
  54. 			 */
  55. 			if (abil->ulevel == 1)
  56. 				*(abil->ability) |= (mask|FROMOUTSIDE);
  57. 			else
  58. 				*(abil->ability) |= mask;
  59. 			if(!(*(abil->ability) & INTRINSIC & ~mask)) {
  60. 			    if(*(abil->gainstr))
  61. 				You_feel("%s!", abil->gainstr);
  62. 			}
  63. 		} else if (oldlevel >= abil->ulevel && newlevel < abil->ulevel) {
  64. 			*(abil->ability) &= ~mask;
  65. 			if(!(*(abil->ability) & INTRINSIC)) {
  66. 			    if(*(abil->losestr))
  67. 				You_feel("%s!", abil->losestr);
  68. 			    else if(*(abil->gainstr))
  69. 				You_feel("less %s!", abil->gainstr);
  70. 			}
  71. 		}
  72. 	    if (prevabil != *(abil->ability))	/* it changed */
  73. 		postadjabil(abil->ability);
  74. 	    abil++;
  75. 	}
  76.  
  77. 	if (oldlevel > 0) {
  78. 	    if (newlevel > oldlevel)
  79. 		add_weapon_skill(newlevel - oldlevel);
  80. 	    else
  81. 		lose_weapon_skill(oldlevel - newlevel);
  82. 	}
  83. }

newhp[edit]

  1. int
  2. newhp()
  3. {
  4. 	int	hp, conplus;
  5.  
  6.  
  7. 	if (u.ulevel == 0) {
  8. 	    /* Initialize hit points */
  9. 	    hp = urole.hpadv.infix + urace.hpadv.infix;
  10. 	    if (urole.hpadv.inrnd > 0) hp += rnd(urole.hpadv.inrnd);
  11. 	    if (urace.hpadv.inrnd > 0) hp += rnd(urace.hpadv.inrnd);
  12.  
  13. 	    /* Initialize alignment stuff */
  14. 	    u.ualign.type = aligns[flags.initalign].value;
  15. 	    u.ualign.record = urole.initrecord;
  16.  
  17. 		return hp;
  18. 	} else {
  19. 	    if (u.ulevel < urole.xlev) {
  20. 	    	hp = urole.hpadv.lofix + urace.hpadv.lofix;
  21. 	    	if (urole.hpadv.lornd > 0) hp += rnd(urole.hpadv.lornd);
  22. 	    	if (urace.hpadv.lornd > 0) hp += rnd(urace.hpadv.lornd);
  23. 	    } else {
  24. 	    	hp = urole.hpadv.hifix + urace.hpadv.hifix;
  25. 	    	if (urole.hpadv.hirnd > 0) hp += rnd(urole.hpadv.hirnd);
  26. 	    	if (urace.hpadv.hirnd > 0) hp += rnd(urace.hpadv.hirnd);
  27. 	    }
  28. 	}
  29.  
  30. 	if (ACURR(A_CON) <= 3) conplus = -2;
  31. 	else if (ACURR(A_CON) <= 6) conplus = -1;
  32. 	else if (ACURR(A_CON) <= 14) conplus = 0;
  33. 	else if (ACURR(A_CON) <= 16) conplus = 1;
  34. 	else if (ACURR(A_CON) == 17) conplus = 2;
  35. 	else if (ACURR(A_CON) == 18) conplus = 3;
  36. 	else conplus = 4;
  37.  
  38. 	hp += conplus;
  39. 	return((hp <= 0) ? 1 : hp);
  40. }
  41.  
  42. #endif /* OVLB */

acurr[edit]

  1. #ifdef OVL0
  2.  
  3. schar
  4. acurr(x)
  5. int x;
  6. {
  7. 	register int tmp = (u.abon.a[x] + u.atemp.a[x] + u.acurr.a[x]);
  8.  
  9. 	if (x == A_STR) {
  10. 		if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER) return(125);
  11. #ifdef WIN32_BUG
  12. 		else return(x=((tmp >= 125) ? 125 : (tmp <= 3) ? 3 : tmp));
  13. #else
  14. 		else return((schar)((tmp >= 125) ? 125 : (tmp <= 3) ? 3 : tmp));
  15. #endif
  16. 	} else if (x == A_CHA) {
  17. 		if (tmp < 18 && (youmonst.data->mlet == S_NYMPH ||
  18. 		    u.umonnum==PM_SUCCUBUS || u.umonnum == PM_INCUBUS))
  19. 		    return 18;
  20. 	} else if (x == A_INT || x == A_WIS) {
  21. 		/* yes, this may raise int/wis if player is sufficiently
  22. 		 * stupid.  there are lower levels of cognition than "dunce".
  23. 		 */
  24. 		if (uarmh && uarmh->otyp == DUNCE_CAP) return(6);
  25. 	}
  26. #ifdef WIN32_BUG
  27. 	return(x=((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp));
  28. #else
  29. 	return((schar)((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp));
  30. #endif
  31. }

acurrstr[edit]

  1. /* condense clumsy ACURR(A_STR) value into value that fits into game formulas
  2. */
  3. schar
  4. acurrstr()
  5. {
  6. 	register int str = ACURR(A_STR);
  7.  
  8. 	if (str <= 18) return((schar)str);
  9. 	if (str <= 121) return((schar)(19 + str / 50)); /* map to 19-21 */
  10. 	else return((schar)(str - 100));
  11. }
  12.  
  13. #endif /* OVL0 */

adjalign[edit]

  1. #ifdef OVL2
  2.  
  3. /* avoid possible problems with alignment overflow, and provide a centralized
  4. * location for any future alignment limits
  5. */
  6. void
  7. adjalign(n)
  8. register int n;
  9. {
  10. 	register int newalign = u.ualign.record + n;
  11.  
  12. 	if(n < 0) {
  13. 		if(newalign < u.ualign.record)
  14. 			u.ualign.record = newalign;
  15. 	} else
  16. 		if(newalign > u.ualign.record) {
  17. 			u.ualign.record = newalign;
  18. 			if(u.ualign.record > ALIGNLIM)
  19. 				u.ualign.record = ALIGNLIM;
  20. 		}
  21. }
  22.  
  23. #endif /* OVL2 */
  24.  
  25. /*attrib.c*/