Source:NetHack 3.4.0/attrib.c

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

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)attrib.c	3.4	2000/05/17	*/ 2.   /*	Copyright 1988, 1989, 1990, 1992, M. Stephenson		  */ 3.   /* NetHack may be freely redistributed. See license for details. */ 4.     5.    /*  attribute modification routines. */ 6.     7.    #include "hack.h"  8.    #include "artifact.h"  9. 10.  /* #define DEBUG */	/* uncomment for debugging info */ 11.   12.   #ifdef OVLB 13.   14.   	/* part of the output on gain or loss of attribute */ 15.  static 16.  const char	*plusattr[] = { 17.  	"strong", "smart", "wise", "agile", "tough", "charismatic" 18.  },  19.   		*minusattr[] = { 20.  	"weak", "stupid", "foolish", "clumsy", "fragile", "repulsive" 21.  };  22.    23.    24.   static 25.  const struct innate { 26.  	schar	ulevel; 27.  	long	*ability; 28.  	const char *gainstr, *losestr; 29.  }	arc_abil[] = { {	 1, &(HStealth), "", "" }, 30.  		     {   1, &(HFast), "", "" }, 31.  		     {  10, &(HSearching), "perceptive", "" }, 32.  		     {	 0, 0, 0, 0 } },  33.    34.   	bar_abil[] = { {	 1, &(HPoison_resistance), "", "" }, 35.  		     {   7, &(HFast), "quick", "slow" }, 36.  		     {  15, &(HStealth), "stealthy", "" }, 37.  		     {	 0, 0, 0, 0 } },  38.    39.   	cav_abil[] = { {	 7, &(HFast), "quick", "slow" }, 40.  		     {	15, &(HWarning), "sensitive", "" }, 41.  		     {	 0, 0, 0, 0 } },  42.    43.   	hea_abil[] = { {	 1, &(HPoison_resistance), "", "" }, 44.  		     {	15, &(HWarning), "sensitive", "" }, 45.  		     {	 0, 0, 0, 0 } },  46.    47.   	kni_abil[] = { {	 7, &(HFast), "quick", "slow" }, 48.  		     {	 0, 0, 0, 0 } },  49.    50.   	mon_abil[] = { {   1, &(HFast), "", "" }, 51.  		     {   1, &(HSleep_resistance), "", "" }, 52.  		     {   1, &(HSee_invisible), "", "" }, 53.  		     {   3, &(HPoison_resistance), "healthy", "" }, 54.  		     {   5, &(HStealth), "stealthy", "" }, 55.  		     {   7, &(HWarning), "sensitive", "" }, 56.  		     {   9, &(HSearching), "perceptive", "unaware" }, 57.  		     {  11, &(HFire_resistance), "cool", "warmer" }, 58.  		     {  13, &(HCold_resistance), "warm", "cooler" }, 59.  		     {  15, &(HShock_resistance), "insulated", "conductive" }, 60.  		     {  17, &(HTeleport_control), "controlled","uncontrolled" }, 61.  		     {   0, 0, 0, 0 } },  62.    63.   	pri_abil[] = { {	15, &(HWarning), "sensitive", "" }, 64.  		     {  20, &(HFire_resistance), "cool", "warmer" }, 65.  		     {	 0, 0, 0, 0 } },  66.    67.   	ran_abil[] = { {   1, &(HSearching), "", "" }, 68.  		     {	 7, &(HStealth), "stealthy", "" }, 69.  		     {	15, &(HSee_invisible), "", "" }, 70.  		     {	 0, 0, 0, 0 } },  71.    72.   	rog_abil[] = { {	 1, &(HStealth), "", ""  }, 73.  		     {  10, &(HSearching), "perceptive", "" }, 74.  		     {	 0, 0, 0, 0 } },  75.    76.   	sam_abil[] = { {	 1, &(HFast), "", "" }, 77.  		     {  15, &(HStealth), "stealthy", "" }, 78.  		     {	 0, 0, 0, 0 } },  79.    80.   	tou_abil[] = { {	10, &(HSearching), "perceptive", "" }, 81.  		     {	20, &(HPoison_resistance), "hardy", "" }, 82.  		     {	 0, 0, 0, 0 } },  83.    84.   	val_abil[] = { {	 1, &(HCold_resistance), "", "" }, 85.  		     {	 1, &(HStealth), "", "" }, 86.  		     {   7, &(HFast), "quick", "slow" }, 87.  		     {	 0, 0, 0, 0 } },  88.    89.   	wiz_abil[] = { {	15, &(HWarning), "sensitive", "" }, 90.  		     {  17, &(HTeleport_control), "controlled","uncontrolled" }, 91.  		     {	 0, 0, 0, 0 } },  92.    93.   	/* Intrinsics conferred by race */ 94.  	elf_abil[] = { {	4, &(HSleep_resistance), "awake", "tired" }, 95.  		     {	 0, 0, 0, 0 } },  96.    97.   	orc_abil[] = { {	1, &(HPoison_resistance), "", "" }, 98.  		     {	 0, 0, 0, 0 } };  99.    100.  static long next_check = 600L;	/* arbitrary first setting */ 101. STATIC_DCL void NDECL(exerper); 102.  103.  /* adjust an attribute; return TRUE if change is made, FALSE otherwise */ 104. boolean 105. adjattrib(ndx, incr, msgflg) 106. 	int	ndx, incr; 107. 	int	msgflg;	    /* positive => no message, zero => message, and */ 108. {			    /* negative => conditional (msg if change made) */ 109. 	if (Fixed_abil || !incr) return FALSE; 110.  111.  	if ((ndx == A_INT || ndx == A_WIS)  112.  				&& uarmh && uarmh->otyp == DUNCE_CAP) { 113. 		if (msgflg == 0) 114. 		    Your("cap constricts briefly, then relaxes again."); 115. 		return FALSE; 116. 	}  117.   118.  	if (incr > 0) { 119. 	    if ((AMAX(ndx) >= ATTRMAX(ndx)) && (ACURR(ndx) >= AMAX(ndx))) { 120. 		if (msgflg == 0 && flags.verbose) 121. 		    pline("You're already as %s as you can get.",  122.  			  plusattr[ndx]); 123. 		ABASE(ndx) = AMAX(ndx) = ATTRMAX(ndx); /* just in case */ 124. 		return FALSE; 125. 	    }  126.   127.  	    ABASE(ndx) += incr; 128. 	    if(ABASE(ndx) > AMAX(ndx)) { 129. 		incr = ABASE(ndx) - AMAX(ndx); 130. 		AMAX(ndx) += incr; 131. 		if(AMAX(ndx) > ATTRMAX(ndx)) 132. 		    AMAX(ndx) = ATTRMAX(ndx); 133. 		ABASE(ndx) = AMAX(ndx); 134. 	    }  135.  	} else { 136. 	    if (ABASE(ndx) <= ATTRMIN(ndx)) { 137. 		if (msgflg == 0 && flags.verbose) 138. 		    pline("You're already as %s as you can get.",  139.  			  minusattr[ndx]); 140. 		ABASE(ndx) = ATTRMIN(ndx); /* just in case */ 141. 		return FALSE; 142. 	    }  143.   144.  	    ABASE(ndx) += incr; 145. 	    if(ABASE(ndx) < ATTRMIN(ndx)) { 146. 		incr = ABASE(ndx) - ATTRMIN(ndx); 147. 		ABASE(ndx) = ATTRMIN(ndx); 148. 		AMAX(ndx) += incr; 149. 		if(AMAX(ndx) < ATTRMIN(ndx)) 150. 		    AMAX(ndx) = ATTRMIN(ndx); 151. 	    }  152.  	}  153.  	if (msgflg <= 0) 154. 	    You_feel("%s%s!",  155.  		  (incr > 1 || incr < -1) ? "very ": "",  156.  		  (incr > 0) ? plusattr[ndx] : minusattr[ndx]); 157. 	flags.botl = 1; 158. 	if (moves > 1 && (ndx == A_STR || ndx == A_CON)) 159. 		(void)encumber_msg; 160. 	return TRUE; 161. }  162.   163.  void 164. gainstr(otmp, incr) 165. 	register struct obj *otmp; 166. 	register int incr; 167. {  168.  	int num = 1; 169.  170.  	if(incr) num = incr; 171. 	else { 172. 	    if(ABASE(A_STR) < 18) num = (rn2(4) ? 1 : rnd(6) ); 173. 	    else if (ABASE(A_STR) < STR18(85)) num = rnd(10); 174. 	}  175.  	(void) adjattrib(A_STR, (otmp && otmp->cursed) ? -num : num, TRUE); 176. }  177.   178.  void 179. losestr(num)	/* may kill you; cause may be poison or monster like 'a' */ 180. 	register int num; 181. {  182.  	int ustr = ABASE(A_STR) - num; 183.  184.  	while(ustr < 3) { 185. 	    ++ustr; 186. 	    --num; 187. 	    if (Upolyd) { 188. 		u.mh -= 6; 189. 		u.mhmax -= 6; 190. 	    } else { 191. 		u.uhp -= 6; 192. 		u.uhpmax -= 6; 193. 	    }  194.  	}  195.  	(void) adjattrib(A_STR, -num, TRUE); 196. }  197.   198.  void 199. change_luck(n) 200. 	register schar n;  201. { 202.  	u.uluck += n;  203. if (u.uluck < 0 && u.uluck < LUCKMIN)	u.uluck = LUCKMIN; 204. 	if (u.uluck > 0 && u.uluck > LUCKMAX)	u.uluck = LUCKMAX; 205. }  206.   207.  int 208. stone_luck(parameter) 209. boolean parameter; /* So I can't think up of a good name. So sue me. --KAA */ 210. {  211.  	register struct obj *otmp; 212. 	register long bonchance = 0; 213.  214.  	for(otmp = invent; otmp; otmp=otmp->nobj) 215. 	    if (otmp->otyp == LUCKSTONE  216.  		|| (otmp->oartifact && spec_ability(otmp, SPFX_LUCK))) { 217. 		if (otmp->cursed) bonchance -= otmp->quan; 218. 		else if (otmp->blessed) bonchance += otmp->quan; 219. 		else if (parameter) bonchance += otmp->quan; 220. 	    }  221.   222.  	return sgn((int)bonchance); 223. }  224.   225.  /* there has just been an inventory change affecting a luck-granting item */ 226. void 227. set_moreluck 228. {  229.  	int luckbon = stone_luck(TRUE); 230.  231.  	if (!luckbon && !carrying(LUCKSTONE)) u.moreluck = 0; 232. 	else if (luckbon >= 0) u.moreluck = LUCKADD; 233. 	else u.moreluck = -LUCKADD; 234. }  235.   236.  #endif /* OVLB */ 237. #ifdef OVL1 238.  239.  void 240. restore_attrib 241. {  242.  	int	i; 243.  244.  	for(i = 0; i < A_MAX; i++) {	/* all temporary losses/gains */ 245.  246.  	   if(ATEMP(i) && ATIME(i)) { 247. 		if(!(--(ATIME(i)))) { /* countdown for change */ 248. 		    ATEMP(i) += ATEMP(i) > 0 ? -1 : 1; 249.   250.  		    if(ATEMP(i)) /* reset timer */ 251. 			ATIME(i) = 100 / ACURR(A_CON); 252. 		}  253.  	    }  254.  	}  255.  	(void)encumber_msg; 256. }  257.   258.  #endif /* OVL1 */ 259. #ifdef OVLB 260.  261.  #define AVAL	50		/* tune value for exercise gains */ 262.  263.  void 264. exercise(i, inc_or_dec) 265. int	i; 266. boolean	inc_or_dec; 267. {  268.  #ifdef DEBUG 269. 	pline("Exercise:"); 270. #endif 271. 	if (i == A_INT || i == A_CHA) return;	/* can't exercise these */ 272.  273.  	/* no physical exercise while polymorphed; the body's temporary */ 274. 	if (Upolyd && i != A_WIS) return; 275.  276.  	if(abs(AEXE(i)) < AVAL) { 277. 		/*  278.  		 *	Law of diminishing returns (Part I): 279. 		 *  280.  		 *	Gain is harder at higher attribute values. 281. 		 *	79% at "3" --> 0% at "18" 282. 		 *	Loss is even at all levels (50%). 283. 		 *  284.  		 *	Note: *YES* ACURR is the right one to use. 285. 		 */  286.  		AEXE(i) += (inc_or_dec) ? (rn2(19) > ACURR(i)) : -rn2(2); 287. #ifdef DEBUG 288. 		pline("%s, %s AEXE = %d",  289.  			(i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" :  290.  			(i == A_DEX) ? "Dex" : "Con",  291.  			(inc_or_dec) ? "inc" : "dec", AEXE(i)); 292. #endif 293. 	}  294.  	if (moves > 0 && (i == A_STR || i == A_CON)) (void)encumber_msg; 295. }  296.   297.  /* hunger values - from eat.c */ 298. #define SATIATED	0 299. #define NOT_HUNGRY	1 300. #define HUNGRY		2 301. #define WEAK		3 302. #define FAINTING	4 303. #define FAINTED		5 304. #define STARVED		6 305.  306.  STATIC_OVL void 307. exerper 308. {  309.  	if(!(moves % 10)) { 310. 		/* Hunger Checks */ 311.  312.  		int hs = (u.uhunger > 1000) ? SATIATED : 313. 			 (u.uhunger > 150) ? NOT_HUNGRY : 314. 			 (u.uhunger > 50) ? HUNGRY : 315. 			 (u.uhunger > 0) ? WEAK : FAINTING; 316.  317.  #ifdef DEBUG 318. 		pline("exerper: Hunger checks"); 319. #endif 320. 		switch (hs) { 321. 		    case SATIATED:	exercise(A_DEX, FALSE); break; 322. 		    case NOT_HUNGRY:	exercise(A_CON, TRUE); break; 323. 		    case WEAK:		exercise(A_STR, FALSE); break; 324. 		    case FAINTING: 325. 		    case FAINTED:	exercise(A_CON, FALSE); break; 326. 		}  327.   328.  		/* Encumberance Checks */ 329. #ifdef DEBUG 330. 		pline("exerper: Encumber checks"); 331. #endif 332. 		switch (near_capacity) { 333. 		    case MOD_ENCUMBER:	exercise(A_STR, TRUE); break; 334. 		    case HVY_ENCUMBER:	exercise(A_STR, TRUE); 335. 					exercise(A_DEX, FALSE); break; 336. 		    case EXT_ENCUMBER:	exercise(A_DEX, FALSE); 337. 					exercise(A_CON, FALSE); break; 338. 		}  339.   340.  	}  341.   342.  	/* status checks */ 343. 	if(!(moves % 5)) { 344. #ifdef DEBUG 345. 		pline("exerper: Status checks"); 346. #endif 347. 		if ((HClairvoyant & (INTRINSIC|TIMEOUT)) &&  348.  			!BClairvoyant)                      exercise(A_WIS, TRUE); 349. 		if (HRegeneration)			exercise(A_STR, TRUE); 350.  351.  		if(Sick || Vomiting)     exercise(A_CON, FALSE); 352. 		if(Confusion || Hallucination)		exercise(A_WIS, FALSE); 353. 		if((Wounded_legs 354. #ifdef STEED 355. 		    && !u.usteed 356. #endif 357. 			    ) || Fumbling || HStun)	exercise(A_DEX, FALSE); 358. 	}  359.  }  360.   361.  void 362. exerchk 363. {  364.  	int	i, mod_val; 365.  366.  	/*	Check out the periodic accumulations */ 367. 	exerper; 368.  369.  #ifdef DEBUG 370. 	if(moves >= next_check) 371. 		pline("exerchk: ready to test. multi = %d.", multi); 372. #endif 373. 	/*	Are we ready for a test? */ 374.  	if(moves >= next_check && !multi) { 375. #ifdef DEBUG 376. 	    pline("exerchk: testing."); 377. #endif 378. 	    /*  379.  	     *	Law of diminishing returns (Part II): 380. 	     *  381.  	     *	The effects of "exercise" and "abuse" wear 382. 	     *	off over time. Even if you *don't* get an 383. *	increase/decrease, you lose some of the 384. 	     *	accumulated effects. 385. 	     */  386.  	    for(i = 0; i < A_MAX; AEXE(i++) /= 2) { 387.  388.  		if(ABASE(i) >= 18 || !AEXE(i)) continue; 389. 		if(i == A_INT || i == A_CHA) continue;/* can't exercise these */ 390.  391.  #ifdef DEBUG 392. 		pline("exerchk: testing %s (%d).",  393.  			(i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" :  394.  			(i == A_DEX) ? "Dex" : "Con", AEXE(i)); 395. #endif 396. 		/*  397.  		 *	Law of diminishing returns (Part III): 398. 		 *  399.  		 *	You don't *always* gain by exercising. 400. 		 *	[MRS 92/10/28 - Treat Wisdom specially for balance.] 401. 		 */  402.  		if(rn2(AVAL) > ((i != A_WIS) ? abs(AEXE(i)*2/3) : abs(AEXE(i)))) 403. 		    continue; 404. 		mod_val = sgn(AEXE(i)); 405.  406.  #ifdef DEBUG 407. 		pline("exerchk: changing %d.", i); 408. #endif 409. 		if(adjattrib(i, mod_val, -1)) { 410. #ifdef DEBUG 411. 		    pline("exerchk: changed %d.", i); 412. #endif 413. 		    /* if you actually changed an attrib - zero accumulation */ 414. 		    AEXE(i) = 0; 415. 		    /* then print an explanation */ 416. 		    switch(i) { 417. 		    case A_STR: You((mod_val >0) ?  418.  				    "must have been exercising." :  419.  				    "must have been abusing your body."); 420. 				break; 421. 		    case A_WIS: You((mod_val >0) ?  422.  				    "must have been very observant." :  423.  				    "haven't been paying attention."); 424. 				break; 425. 		    case A_DEX: You((mod_val >0) ?  426.  				    "must have been working on your reflexes." :  427.  				    "haven't been working on reflexes lately."); 428. 				break; 429. 		    case A_CON: You((mod_val >0) ?  430.  				    "must be leading a healthy life-style." :  431.  				    "haven't been watching your health."); 432. 				break; 433. 		    }  434.  		}  435.  	    }  436.  	    next_check += rn1(200,800); 437. #ifdef DEBUG 438. 	    pline("exerchk: next check at %ld.", next_check); 439. #endif 440. 	}  441.  }  442.   443.  /* next_check will otherwise have its initial 600L after a game restore */ 444. void 445. reset_attribute_clock 446. {  447.  	if (moves > 600L) next_check = moves + rn1(50,800); 448. }  449.   450.   451.  void 452. init_attr(np) 453. 	register int	np; 454. {  455.  	register int	i, x, tryct; 456.  457.   458.  	for(i = 0; i < A_MAX; i++) { 459. 	    ABASE(i) = AMAX(i) = urole.attrbase[i]; 460. 	    ATEMP(i) = ATIME(i) = 0; 461. 	    np -= urole.attrbase[i]; 462. 	}  463.   464.  	tryct = 0; 465. 	while(np > 0 && tryct < 100) { 466.  467.  	    x = rn2(100); 468. 	    for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++) ; 469. 	    if(i >= A_MAX) continue; /* impossible */ 470.  471.  	    if(ABASE(i) >= ATTRMAX(i)) { 472.  473.  		tryct++; 474. 		continue; 475. 	    }  476.  	    tryct = 0; 477. 	    ABASE(i)++; 478. 	    AMAX(i)++; 479. 	    np--; 480. 	}  481.   482.  	tryct = 0; 483. 	while(np < 0 && tryct < 100) {		/* for redistribution */ 484.  485.  	    x = rn2(100); 486. 	    for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++) ; 487. 	    if(i >= A_MAX) continue; /* impossible */ 488.  489.  	    if(ABASE(i) <= ATTRMIN(i)) { 490.  491.  		tryct++; 492. 		continue; 493. 	    }  494.  	    tryct = 0; 495. 	    ABASE(i)--; 496. 	    AMAX(i)--; 497. 	    np++; 498. 	}  499.  }  500.   501.  void 502. redist_attr 503. {  504.  	register int i, tmp; 505.  506.  	for(i = 0; i < A_MAX; i++) { 507. 	    if (i==A_INT || i==A_WIS) continue; 508. 		/* Polymorphing doesn't change your mind */ 509. 	    tmp = AMAX(i); 510. 	    AMAX(i) += (rn2(5)-2); 511. 	    if (AMAX(i) > ATTRMAX(i)) AMAX(i) = ATTRMAX(i); 512. 	    if (AMAX(i) < ATTRMIN(i)) AMAX(i) = ATTRMIN(i); 513. 	    ABASE(i) = ABASE(i) * AMAX(i) / tmp; 514. 	    /* ABASE(i) > ATTRMAX(i) is impossible */ 515. 	    if (ABASE(i) < ATTRMIN(i)) ABASE(i) = ATTRMIN(i); 516. 	}  517.  	(void)encumber_msg; 518. }  519.   520.  void 521. adjabil(oldlevel,newlevel) 522. int oldlevel, newlevel; 523. {  524.  	register const struct innate *abil, *rabil; 525. 	long mask = FROMEXPER; 526.  527.   528.  	switch (Role_switch) { 529. 	case PM_ARCHEOLOGIST:   abil = arc_abil;	break; 530. 	case PM_BARBARIAN:      abil = bar_abil;	break; 531. 	case PM_CAVEMAN:        abil = cav_abil;	break; 532. 	case PM_HEALER:         abil = hea_abil;	break; 533. 	case PM_KNIGHT:         abil = kni_abil;	break; 534. 	case PM_MONK:           abil = mon_abil;	break; 535. 	case PM_PRIEST:         abil = pri_abil;	break; 536. 	case PM_RANGER:         abil = ran_abil;	break; 537. 	case PM_ROGUE:          abil = rog_abil;	break; 538. 	case PM_SAMURAI:        abil = sam_abil;	break; 539. #ifdef TOURIST 540. 	case PM_TOURIST:        abil = tou_abil;	break; 541. #endif 542. 	case PM_VALKYRIE:       abil = val_abil;	break; 543. 	case PM_WIZARD:         abil = wiz_abil;	break; 544. 	default:                abil = 0;		break; 545. 	}  546.   547.  	switch (Race_switch) { 548. 	case PM_ELF:            rabil = elf_abil;	break; 549. 	case PM_ORC:            rabil = orc_abil;	break; 550. 	case PM_HUMAN: 551. 	case PM_DWARF: 552. 	case PM_GNOME: 553. 	default:                rabil = 0;		break; 554. 	}  555.   556.  	while (abil || rabil) { 557. 	    /* Have we finished with the intrinsics list? */ 558.  	    if (!abil || !abil->ability) { 559. 	    	/* Try the race intrinsics */ 560. 	    	if (!rabil || !rabil->ability) break; 561. 	    	abil = rabil; 562. 	    	rabil = 0; 563. 	    	mask = FROMRACE; 564. 	    }  565.   566.  		if(oldlevel < abil->ulevel && newlevel >= abil->ulevel) { 567. 			/* Abilities gained at level 1 can never be lost 568. 			 * via level loss, only via means that remove _any_ 569. 			 * sort of ability. A "gain" of such an ability from 570. 			 * an outside source is devoid of meaning, so we set 571. 			 * FROMOUTSIDE to avoid such gains. 572. 			 */  573.  			if (abil->ulevel == 1) 574. 				*(abil->ability) |= (mask|FROMOUTSIDE); 575. 			else 576. 				*(abil->ability) |= mask; 577. 			if(!(*(abil->ability) & INTRINSIC & ~mask)) { 578. 			    if(*(abil->gainstr)) 579. 				You_feel("%s!", abil->gainstr); 580. 			}  581.  		} else if (oldlevel >= abil->ulevel && newlevel < abil->ulevel) { 582. 			*(abil->ability) &= ~mask; 583. 			if(!(*(abil->ability) & INTRINSIC)) { 584. 			    if(*(abil->losestr)) 585. 				You_feel("%s!", abil->losestr); 586. 			    else if(*(abil->gainstr)) 587. 				You_feel("less %s!", abil->gainstr); 588. 			}  589.  		}  590.  	    abil++; 591. 	}  592.   593.  	if (oldlevel > 0) { 594. 	    if (newlevel > oldlevel) 595. 		add_weapon_skill(newlevel - oldlevel); 596. 	    else 597. 		lose_weapon_skill(oldlevel - newlevel); 598. 	}  599.  }  600.   601.   602.  int 603. newhp 604. {  605.  	int	hp, conplus; 606.  607.   608.  	if (u.ulevel == 0) { 609. 	    /* Initialize hit points */ 610. 	    hp = urole.hpadv.infix + urace.hpadv.infix; 611. 	    if (urole.hpadv.inrnd > 0) hp += rnd(urole.hpadv.inrnd); 612. 	    if (urace.hpadv.inrnd > 0) hp += rnd(urace.hpadv.inrnd); 613.  614.  	    /* Initialize alignment stuff */ 615. 	    u.ualign.type = aligns[flags.initalign].value; 616. 	    u.ualign.record = urole.initrecord; 617.  618.  		return hp; 619. 	} else { 620. 	    if (u.ulevel < urole.xlev) { 621. 	    	hp = urole.hpadv.lofix + urace.hpadv.lofix; 622. 	    	if (urole.hpadv.lornd > 0) hp += rnd(urole.hpadv.lornd); 623. 	    	if (urace.hpadv.lornd > 0) hp += rnd(urace.hpadv.lornd); 624. 	    } else { 625. 	    	hp = urole.hpadv.hifix + urace.hpadv.hifix; 626. 	    	if (urole.hpadv.hirnd > 0) hp += rnd(urole.hpadv.hirnd); 627. 	    	if (urace.hpadv.hirnd > 0) hp += rnd(urace.hpadv.hirnd); 628. 	    }  629.  	}  630.   631.  	if (ACURR(A_CON) <= 3) conplus = -2; 632. 	else if (ACURR(A_CON) <= 6) conplus = -1; 633. 	else if (ACURR(A_CON) <= 14) conplus = 0; 634. 	else if (ACURR(A_CON) <= 16) conplus = 1; 635. 	else if (ACURR(A_CON) == 17) conplus = 2; 636. 	else if (ACURR(A_CON) == 18) conplus = 3; 637. 	else conplus = 4; 638. 	  639.  	hp += conplus; 640. 	return((hp <= 0) ? 1 : hp); 641. }  642.   643.  #endif /* OVLB */ 644. #ifdef OVL0 645.  646.  schar 647. acurr(x) 648. int x;  649. { 650.  	register int tmp = (u.abon.a[x] + u.atemp.a[x] + u.acurr.a[x]); 651.  652.  	if (x == A_STR) { 653. 		if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER) return(125); 654. #ifdef WIN32_BUG 655. 		else return(x=((tmp >= 125) ? 125 : (tmp <= 3) ? 3 : tmp)); 656. #else 657. 		else return((schar)((tmp >= 125) ? 125 : (tmp <= 3) ? 3 : tmp)); 658. #endif 659. 	} else if (x == A_CHA) { 660. 		if (tmp < 18 && (youmonst.data->mlet == S_NYMPH || 661. 		    u.umonnum==PM_SUCCUBUS || u.umonnum == PM_INCUBUS)) 662. 		    return 18; 663. 	} else if (x == A_INT || x == A_WIS) { 664. 		/* yes, this may raise int/wis if player is sufficiently 665. 		 * stupid. there are lower levels of cognition than "dunce". 666. 		 */  667.  		if (uarmh && uarmh->otyp == DUNCE_CAP) return(6); 668. 	}  669.  #ifdef WIN32_BUG 670. 	return(x=((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp)); 671. #else 672. 	return((schar)((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp)); 673. #endif 674. }  675.   676.  /* condense clumsy ACURR(A_STR) value into value that fits into game formulas 677.  */  678.  schar 679. acurrstr 680. {  681.  	register int str = ACURR(A_STR); 682.  683.  	if (str <= 18) return((schar)str); 684. 	if (str <= 121) return((schar)(19 + str / 50)); /* map to 19-21 */ 685. 	else return((schar)(str - 100)); 686. }  687.   688.  #endif /* OVL0 */ 689. #ifdef OVL2 690.  691.  /* avoid possible problems with alignment overflow, and provide a centralized 692.  * location for any future alignment limits 693.  */  694.  void 695. adjalign(n) 696. register int n;  697. { 698.  	register int newalign = u.ualign.record + n;  699. 700. 	if(n < 0) { 701. 		if(newalign < u.ualign.record) 702. 			u.ualign.record = newalign; 703. 	} else 704. 		if(newalign > u.ualign.record) { 705. 			u.ualign.record = newalign; 706. 			if(u.ualign.record > ALIGNLIM) 707. 				u.ualign.record = ALIGNLIM; 708. 		}  709.  }  710.   711.  #endif /* OVL2 */ 712.  713.  /*attrib.c*/