Source:NetHack 5.0.0/src/attrib.c
Jump to navigation
Jump to search
Below is the full text to attrib.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/attrib.c#line12]], for example.
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. /* NetHack 5.0 attrib.c $NHDT-Date: 1777000050 2026/04/23 19:07:30 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.137 $ */ 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. 9. /* part of the output on gain or loss of attribute */ 10. static const char 11. *const plusattr[] = { "strong", "smart", "wise", 12. "agile", "tough", "charismatic" }, 13. *const minusattr[] = { "weak", "stupid", 14. "foolish", "clumsy", 15. "fragile", "repulsive" }; 16. /* also used by enlightenment in insight.c for non-abbreviated status info */ 17. extern const char *const attrname[6]; 18. 19. const char 20. *const attrname[] = { "strength", "intelligence", "wisdom", 21. "dexterity", "constitution", "charisma" }; 22. 23. static const struct innate { 24. schar ulevel; 25. long *ability; 26. const char *gainstr, *losestr; 27. } arc_abil[] = { { 1, &(HSearching), "", "" }, 28. { 5, &(HStealth), "stealthy", "" }, 29. { 10, &(HFast), "quick", "slow" }, 30. { 0, 0, 0, 0 } }, 31. 32. bar_abil[] = { { 1, &(HPoison_resistance), "", "" }, 33. { 7, &(HFast), "quick", "slow" }, 34. { 15, &(HStealth), "stealthy", "" }, 35. { 0, 0, 0, 0 } }, 36. 37. cav_abil[] = { { 7, &(HFast), "quick", "slow" }, 38. { 15, &(HWarning), "sensitive", "" }, 39. { 0, 0, 0, 0 } }, 40. 41. hea_abil[] = { { 1, &(HPoison_resistance), "", "" }, 42. { 15, &(HWarning), "sensitive", "" }, 43. { 0, 0, 0, 0 } }, 44. 45. kni_abil[] = { { 7, &(HFast), "quick", "slow" }, { 0, 0, 0, 0 } }, 46. 47. mon_abil[] = { { 1, &(HFast), "", "" }, 48. { 1, &(HSleep_resistance), "", "" }, 49. { 1, &(HSee_invisible), "", "" }, 50. { 3, &(HPoison_resistance), "healthy", "" }, 51. { 5, &(HStealth), "stealthy", "" }, 52. { 7, &(HWarning), "sensitive", "" }, 53. { 9, &(HSearching), "perceptive", "unaware" }, 54. { 11, &(HFire_resistance), "cool", "warmer" }, 55. { 13, &(HCold_resistance), "warm", "cooler" }, 56. { 15, &(HShock_resistance), "insulated", "conductive" }, 57. { 17, &(HTeleport_control), "controlled", "uncontrolled" }, 58. { 0, 0, 0, 0 } }, 59. 60. pri_abil[] = { { 15, &(HWarning), "sensitive", "" }, 61. { 20, &(HFire_resistance), "cool", "warmer" }, 62. { 0, 0, 0, 0 } }, 63. 64. ran_abil[] = { { 1, &(HSearching), "", "" }, 65. { 7, &(HStealth), "stealthy", "" }, 66. { 15, &(HSee_invisible), "", "" }, 67. { 0, 0, 0, 0 } }, 68. 69. rog_abil[] = { { 1, &(HStealth), "", "" }, 70. { 10, &(HSearching), "perceptive", "" }, 71. { 0, 0, 0, 0 } }, 72. 73. sam_abil[] = { { 1, &(HFast), "", "" }, 74. { 15, &(HStealth), "stealthy", "" }, 75. { 0, 0, 0, 0 } }, 76. 77. tou_abil[] = { { 10, &(HSearching), "perceptive", "" }, 78. { 20, &(HPoison_resistance), "hardy", "" }, 79. { 0, 0, 0, 0 } }, 80. 81. val_abil[] = { { 1, &(HCold_resistance), "", "" }, 82. { 3, &(HStealth), "stealthy", "" }, 83. { 7, &(HFast), "quick", "slow" }, 84. { 0, 0, 0, 0 } }, 85. 86. wiz_abil[] = { { 15, &(HWarning), "sensitive", "" }, 87. { 17, &(HTeleport_control), "controlled", "uncontrolled" }, 88. { 0, 0, 0, 0 } }, 89. 90. /* Intrinsics conferred by race */ 91. dwa_abil[] = { { 1, &HInfravision, "", "" }, 92. { 0, 0, 0, 0 } }, 93. 94. elf_abil[] = { { 1, &HInfravision, "", "" }, 95. { 4, &HSleep_resistance, "awake", "tired" }, 96. { 0, 0, 0, 0 } }, 97. 98. gno_abil[] = { { 1, &HInfravision, "", "" }, 99. { 0, 0, 0, 0 } }, 100. 101. orc_abil[] = { { 1, &HInfravision, "", "" }, 102. { 1, &HPoison_resistance, "", "" }, 103. { 0, 0, 0, 0 } }, 104. 105. hum_abil[] = { { 0, 0, 0, 0 } }; 106. 107. staticfn void exerper(void); 108. staticfn int rnd_attr(void); 109. staticfn int init_attr_role_redist(int, boolean); 110. staticfn void postadjabil(long *) NONNULLARG1; 111. staticfn const struct innate *role_abil(int); 112. staticfn const struct innate *check_innate_abil(long *, long); 113. staticfn int innately(long *); 114. 115. /* adjust an attribute; return TRUE if change is made, FALSE otherwise */ 116. boolean 117. adjattrib( 118. int ndx, /* which characteristic */ 119. int incr, /* amount of change */ 120. int msgflg) /* positive => no message, zero => message, and */ 121. { /* negative => conditional (msg if change made) */ 122. int old_acurr, old_abase, old_amax, decr; 123. boolean abonflg; 124. const char *attrstr; 125. 126. if (Fixed_abil || !incr) 127. return FALSE; 128. 129. if ((ndx == A_INT || ndx == A_WIS) && uarmh && uarmh->otyp == DUNCE_CAP) { 130. if (msgflg == 0) 131. Your("cap constricts briefly, then relaxes again."); 132. return FALSE; 133. } 134. 135. old_acurr = ACURR(ndx); 136. old_abase = ABASE(ndx); 137. old_amax = AMAX(ndx); 138. ABASE(ndx) += incr; /* when incr is negative, this reduces ABASE() */ 139. if (incr > 0) { 140. if (ABASE(ndx) > AMAX(ndx)) { 141. AMAX(ndx) = ABASE(ndx); 142. if (AMAX(ndx) > ATTRMAX(ndx)) 143. ABASE(ndx) = AMAX(ndx) = ATTRMAX(ndx); 144. } 145. attrstr = plusattr[ndx]; 146. abonflg = (ABON(ndx) < 0); 147. } else { /* incr is negative */ 148. if (ABASE(ndx) < ATTRMIN(ndx)) { 149. /* 150. * If base value has dropped so low that it is trying to be 151. * taken below the minimum, reduce max value (peak reached) 152. * instead. That means that restore ability and repeated 153. * applications of unicorn horn will not be able to recover 154. * all the lost value. As of 3.6.2, we only take away 155. * some (average half, possibly zero) of the excess from max 156. * instead of all of it, but without intervening recovery, it 157. * can still eventually drop to the minimum allowed. After 158. * that, it can't be recovered, only improved with new gains. 159. * 160. * This used to assign a new negative value to incr and then 161. * add it, but that could affect messages below, possibly 162. * making a large decrease be described as a small one. 163. * 164. * decr = rn2(-(ABASE - ATTRMIN) + 1); 165. */ 166. decr = rn2(ATTRMIN(ndx) - ABASE(ndx) + 1); 167. ABASE(ndx) = ATTRMIN(ndx); 168. AMAX(ndx) -= decr; 169. if (AMAX(ndx) < ATTRMIN(ndx)) 170. AMAX(ndx) = ATTRMIN(ndx); 171. } 172. attrstr = minusattr[ndx]; 173. abonflg = (ABON(ndx) > 0); 174. } 175. if (ACURR(ndx) == old_acurr) { 176. if (msgflg == 0 && flags.verbose) { 177. if (ABASE(ndx) == old_abase && AMAX(ndx) == old_amax) { 178. pline("You're %s as %s as you can get.", 179. abonflg ? "currently" : "already", attrstr); 180. } else { 181. /* current stayed the same but base value changed, or 182. base is at minimum and reduction caused max to drop */ 183. Your("innate %s has %s.", attrname[ndx], 184. (incr > 0) ? "improved" : "declined"); 185. } 186. } 187. return FALSE; 188. } 189. 190. /* Any successful change also resets abuse / exercise level */ 191. AEXE(ndx) = 0; 192. 193. disp.botl = TRUE; 194. if (msgflg <= 0) 195. You_feel("%s%s!", (incr > 1 || incr < -1) ? "very " : "", attrstr); 196. if (program_state.in_moveloop && (ndx == A_STR || ndx == A_CON)) 197. encumber_msg(); 198. return TRUE; 199. } 200. 201. /* strength gain */ 202. void 203. gainstr(struct obj *otmp, int incr, boolean givemsg) 204. { 205. int num = incr; 206. 207. if (!num) { 208. if (ABASE(A_STR) < 18) 209. num = (rn2(4) ? 1 : rnd(6)); 210. else if (ABASE(A_STR) < STR18(85)) 211. num = rnd(10); 212. else 213. num = 1; 214. } 215. (void) adjattrib(A_STR, (otmp && otmp->cursed) ? -num : num, 216. givemsg ? -1 : 1); 217. } 218. 219. /* strength loss, may kill you; cause may be poison or monster like 'a' */ 220. void 221. losestr(int num, const char *knam, schar k_format) 222. { 223. int uhpmin = minuhpmax(1), olduhpmax = u.uhpmax; 224. int ustr = ABASE(A_STR) - num, amt, dmg; 225. boolean waspolyd = Upolyd; 226. 227. if (num <= 0 || ABASE(A_STR) < ATTRMIN(A_STR)) { 228. impossible("losestr: %d - %d", ABASE(A_STR), num); 229. return; 230. } 231. dmg = 0; 232. while (ustr < ATTRMIN(A_STR)) { 233. ++ustr; 234. --num; 235. amt = rn1(4, 3); /* (0..(4-1))+3 => 3..6; used to use flat 6 here */ 236. dmg += amt; 237. } 238. if (dmg) { 239. /* in case damage is fatal and caller didn't supply killer reason */ 240. if (!knam || !*knam) { 241. knam = "terminal frailty"; 242. k_format = KILLED_BY; 243. } 244. losehp(dmg, knam, k_format); 245. 246. if (Upolyd) { 247. /* when still poly'd, reduce you-as-monst maxHP; never below 1 */ 248. setuhpmax(max(u.mhmax - dmg, 1), FALSE); /* acts as setmhmax() */ 249. } else if (!waspolyd) { 250. /* not polymorphed now and didn't rehumanize when taking damage; 251. reduce max HP, but not below uhpmin */ 252. if (u.uhpmax > uhpmin) 253. setuhpmax(max(u.uhpmax - dmg, uhpmin), FALSE); 254. } 255. disp.botl = TRUE; 256. } 257. #if 0 /* only possible if uhpmax was already less than uhpmin */ 258. if (!Upolyd && u.uhpmax < uhpmin) { 259. setuhpmax(min(olduhpmax, uhpmin), FALSE); 260. if (!Drain_resistance) 261. losexp(NULL); /* won't be fatal when no 'drainer' is supplied */ 262. } 263. #else 264. nhUse(olduhpmax); 265. #endif 266. /* 'num' could have been reduced to 0 in the minimum strength loop; 267. '(Upolyd || !waspolyd)' is True unless damage caused rehumanization */ 268. if (num > 0 && (Upolyd || !waspolyd)) 269. (void) adjattrib(A_STR, -num, 1); 270. } 271. 272. /* combined strength loss and damage from some poisons */ 273. void 274. poison_strdmg(int strloss, int dmg, const char *knam, schar k_format) 275. { 276. losestr(strloss, knam, k_format); 277. losehp(dmg, knam, k_format); 278. } 279. 280. static const struct poison_effect_message { 281. void (*delivery_func)(const char *, ...); 282. const char *effect_msg; 283. } poiseff[] = { 284. { You_feel, "weaker" }, /* A_STR */ 285. { Your, "brain is on fire" }, /* A_INT */ 286. { Your, "judgement is impaired" }, /* A_WIS */ 287. { Your, "muscles won't obey you" }, /* A_DEX */ 288. { You_feel, "very sick" }, /* A_CON */ 289. { You, "break out in hives" } /* A_CHA */ 290. }; 291. 292. /* feedback for attribute loss due to poisoning */ 293. void 294. poisontell(int typ, /* which attribute */ 295. boolean exclaim) /* emphasis */ 296. { 297. void (*func)(const char *, ...) = poiseff[typ].delivery_func; 298. const char *msg_txt = poiseff[typ].effect_msg; 299. 300. /* 301. * "You feel weaker" or "you feel very sick" aren't appropriate when 302. * wearing or wielding something (gauntlets of power, Ogresmasher) 303. * which forces the attribute to maintain its maximum value. 304. * Phrasing for other attributes which might have fixed values 305. * (dunce cap) is such that we don't need message fixups for them. 306. */ 307. if (typ == A_STR && ACURR(A_STR) == STR19(25)) 308. msg_txt = "innately weaker"; 309. else if (typ == A_CON && ACURR(A_CON) == 25) 310. msg_txt = "sick inside"; 311. 312. (*func)("%s%c", msg_txt, exclaim ? '!' : '.'); 313. } 314. 315. /* called when an attack or trap has poisoned hero (used to be in mon.c) */ 316. void 317. poisoned( 318. const char *reason, /* controls what messages we display */ 319. int typ, 320. const char *pkiller, /* for score+log file if fatal */ 321. int fatal, /* if fatal is 0, limit damage to adjattrib */ 322. boolean thrown_weapon) /* thrown weapons are less deadly */ 323. { 324. int i, loss, kprefix = KILLED_BY_AN; 325. boolean blast = !strcmp(reason, "blast"); 326. 327. /* inform player about being poisoned unless that's already been done; 328. "blast" has given a "blast of poison gas" message; "poison arrow", 329. "poison dart", etc have implicitly given poison messages too... */ 330. if (!blast && !strstri(reason, "poison")) { 331. boolean plural = (reason[strlen(reason) - 1] == 's') ? 1 : 0; 332. 333. /* avoid "The" Orcus's sting was poisoned... */ 334. pline("%s%s %s poisoned!", 335. isupper((uchar) *reason) ? "" : "The ", reason, 336. plural ? "were" : "was"); 337. } 338. if (Poison_resistance) { 339. if (blast) 340. shieldeff(u.ux, u.uy); 341. pline_The("poison doesn't seem to affect you."); 342. return; 343. } 344. 345. /* suppress killer prefix if it already has one */ 346. i = name_to_mon(pkiller, (int *) 0); 347. if (ismnum(i) && (mons[i].geno & G_UNIQ)) { 348. kprefix = KILLED_BY; 349. if (!type_is_pname(&mons[i])) 350. pkiller = the(pkiller); 351. } else if (!strncmpi(pkiller, "the ", 4) || !strncmpi(pkiller, "an ", 3) 352. || !strncmpi(pkiller, "a ", 2)) { 353. /*[ does this need a plural check too? ]*/ 354. kprefix = KILLED_BY; 355. } 356. 357. /* 358. * FIXME: 359. * this operates on u.uhp[max] even when hero is polymorphed.... 360. */ 361. 362. i = !fatal ? 1 : rn2(fatal + (thrown_weapon ? 20 : 0)); 363. if (i == 0 && typ != A_CHA) { 364. /* sometimes survivable instant kill */ 365. loss = 6 + d(4, 6); /* 6 + 4d6 => 10..34 */ 366. if (u.uhp <= loss) { 367. u.uhp = -1; 368. disp.botl = TRUE; 369. pline_The("poison was deadly..."); 370. } else { 371. /* survived, but with severe reaction */ 372. int olduhp = u.uhp, 373. newuhpmax = u.uhpmax - (loss / 2); 374. 375. setuhpmax(max(newuhpmax, minuhpmax(3)), TRUE); /*True: see FIXME*/ 376. loss = adjuhploss(loss, olduhp); 377. 378. losehp(loss, pkiller, kprefix); /* poison damage */ 379. if (adjattrib(A_CON, (typ != A_CON) ? -1 : -3, TRUE)) 380. poisontell(A_CON, TRUE); 381. if (typ != A_CON && adjattrib(typ, -3, 1)) 382. poisontell(typ, TRUE); 383. } 384. } else if (i > 5) { 385. boolean cloud = !strcmp(reason, "gas cloud"); 386. 387. /* HP damage; more likely--but less severe--with missiles */ 388. loss = thrown_weapon ? rnd(6) : rn1(10, 6); 389. if ((blast || cloud) && Half_gas_damage) /* worn towel */ 390. loss = (loss + 1) / 2; 391. losehp(loss, pkiller, kprefix); /* poison damage */ 392. } else { 393. /* attribute loss; if typ is A_STR, reduction in current and 394. maximum HP will occur once strength has dropped down to 3 */ 395. loss = (thrown_weapon || !fatal) ? 1 : d(2, 2); /* was rn1(3,3) */ 396. /* check that a stat change was made */ 397. if (adjattrib(typ, -loss, 1)) 398. poisontell(typ, TRUE); 399. } 400. 401. if (u.uhp < 1) { 402. svk.killer.format = kprefix; 403. Strcpy(svk.killer.name, pkiller); 404. /* "Poisoned by a poisoned ___" is redundant */ 405. done(strstri(pkiller, "poison") ? DIED : POISONING); 406. } 407. encumber_msg(); 408. } 409. 410. void 411. change_luck(schar n) 412. { 413. u.uluck += n; 414. if (u.uluck < 0 && u.uluck < LUCKMIN) 415. u.uluck = LUCKMIN; 416. if (u.uluck > 0 && u.uluck > LUCKMAX) 417. u.uluck = LUCKMAX; 418. } 419. 420. /* decide whether there are more blessed luckstones (plus luck-conferring 421. artifacts) than cursed ones; optionally combine uncursed with blessed */ 422. int 423. stone_luck(boolean include_uncursed) 424. { 425. struct obj *otmp; 426. long bonchance = 0; 427. 428. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 429. if (confers_luck(otmp)) { 430. if (otmp->cursed) 431. bonchance -= otmp->quan; 432. else if (otmp->blessed || include_uncursed) 433. bonchance += otmp->quan; 434. } 435. 436. return sgn((int) bonchance); 437. } 438. 439. /* there has just been an inventory change affecting a luck-granting item */ 440. void 441. set_moreluck(void) 442. { 443. int luckbon = stone_luck(TRUE); 444. 445. if (!luckbon && !carrying(LUCKSTONE)) 446. u.moreluck = 0; 447. else if (luckbon >= 0) 448. u.moreluck = LUCKADD; 449. else 450. u.moreluck = -LUCKADD; 451. } 452. 453. /* (not used) */ 454. void 455. restore_attrib(void) 456. { 457. int i, equilibrium;; 458. 459. /* 460. * Note: this used to get called by moveloop() on every turn but 461. * ATIME() is never set to non-zero anywhere so didn't do anything. 462. * Presumably it once supported something like potion of heroism 463. * which conferred temporary characteristics boost(s). 464. * 465. * ATEMP() is used for strength loss from hunger, which doesn't 466. * time out, and for dexterity loss from wounded legs, which has 467. * its own timeout routine. 468. */ 469. 470. for (i = 0; i < A_MAX; i++) { /* all temporary losses/gains */ 471. equilibrium = ((i == A_STR && u.uhs >= WEAK) 472. || (i == A_DEX && Wounded_legs)) ? -1 : 0; 473. if (ATEMP(i) != equilibrium && ATIME(i) != 0) { 474. if (!(--(ATIME(i)))) { /* countdown for change */ 475. ATEMP(i) += (ATEMP(i) > 0) ? -1 : 1; 476. disp.botl = TRUE; 477. if (ATEMP(i)) /* reset timer */ 478. ATIME(i) = 100 / ACURR(A_CON); 479. } 480. } 481. } 482. if (disp.botl) 483. encumber_msg(); 484. } 485. 486. #define AVAL 50 /* tune value for exercise gains */ 487. 488. void 489. exercise(int i, boolean inc_or_dec) 490. { 491. debugpline0("Exercise:"); 492. if (i == A_INT || i == A_CHA) 493. return; /* can't exercise these */ 494. 495. /* no physical exercise while polymorphed; the body's temporary */ 496. if (Upolyd && i != A_WIS) 497. return; 498. 499. if (abs(AEXE(i)) < AVAL) { 500. /* 501. * Law of diminishing returns (Part I): 502. * 503. * Gain is harder at higher attribute values. 504. * 79% at "3" --> 0% at "18" 505. * Loss is even at all levels (50%). 506. * 507. * Note: *YES* ACURR is the right one to use. 508. */ 509. AEXE(i) += (inc_or_dec) ? (rn2(19) > ACURR(i)) : -rn2(2); 510. debugpline3("%s, %s AEXE = %d", 511. (i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" : (i == A_DEX) 512. ? "Dex" 513. : "Con", 514. (inc_or_dec) ? "inc" : "dec", AEXE(i)); 515. } 516. if (svm.moves > 0 && (i == A_STR || i == A_CON)) 517. encumber_msg(); 518. } 519. 520. staticfn void 521. exerper(void) 522. { 523. if (!(svm.moves % 10)) { 524. /* Hunger Checks */ 525. int hs = (u.uhunger > 1000) ? SATIATED 526. : (u.uhunger > 150) ? NOT_HUNGRY 527. : (u.uhunger > 50) ? HUNGRY 528. : (u.uhunger > 0) ? WEAK 529. : FAINTING; 530. 531. debugpline0("exerper: Hunger checks"); 532. switch (hs) { 533. case SATIATED: 534. exercise(A_DEX, FALSE); 535. if (Role_if(PM_MONK)) 536. exercise(A_WIS, FALSE); 537. break; 538. case NOT_HUNGRY: 539. exercise(A_CON, TRUE); 540. break; 541. case WEAK: 542. exercise(A_STR, FALSE); 543. if (Role_if(PM_MONK)) /* fasting */ 544. exercise(A_WIS, TRUE); 545. break; 546. case FAINTING: 547. case FAINTED: 548. exercise(A_CON, FALSE); 549. break; 550. } 551. 552. /* Encumbrance Checks */ 553. debugpline0("exerper: Encumber checks"); 554. switch (near_capacity()) { 555. case MOD_ENCUMBER: 556. exercise(A_STR, TRUE); 557. break; 558. case HVY_ENCUMBER: 559. exercise(A_STR, TRUE); 560. exercise(A_DEX, FALSE); 561. break; 562. case EXT_ENCUMBER: 563. exercise(A_DEX, FALSE); 564. exercise(A_CON, FALSE); 565. break; 566. } 567. } 568. 569. /* status checks */ 570. if (!(svm.moves % 5)) { 571. debugpline0("exerper: Status checks"); 572. if ((HClairvoyant & (INTRINSIC | TIMEOUT)) && !BClairvoyant) 573. exercise(A_WIS, TRUE); 574. if (HRegeneration) 575. exercise(A_STR, TRUE); 576. 577. if (Sick || Vomiting) 578. exercise(A_CON, FALSE); 579. if (Confusion || Hallucination) 580. exercise(A_WIS, FALSE); 581. if ((Wounded_legs && !u.usteed) || Fumbling || HStun) 582. exercise(A_DEX, FALSE); 583. } 584. } 585. 586. /* exercise/abuse text (must be in attribute order, not botl order); 587. phrased as "You must have been [][0]." or "You haven't been [][1]." */ 588. static NEARDATA const char *const exertext[A_MAX][2] = { 589. { "exercising diligently", "exercising properly" }, /* Str */ 590. { 0, 0 }, /* Int */ 591. { "very observant", "paying attention" }, /* Wis */ 592. { "working on your reflexes", "working on reflexes lately" }, /* Dex */ 593. { "leading a healthy life-style", "watching your health" }, /* Con */ 594. { 0, 0 }, /* Cha */ 595. }; 596. 597. void 598. exerchk(void) 599. { 600. int i, ax, mod_val, lolim, hilim; 601. 602. /* Check out the periodic accumulations */ 603. exerper(); 604. 605. if (svm.moves >= svc.context.next_attrib_check) { 606. debugpline1("exerchk: ready to test. multi = %ld.", gm.multi); 607. } 608. /* Are we ready for a test? */ 609. if (svm.moves >= svc.context.next_attrib_check && !gm.multi) { 610. debugpline0("exerchk: testing."); 611. /* 612. * Law of diminishing returns (Part II): 613. * 614. * The effects of "exercise" and "abuse" wear 615. * off over time. Even if you *don't* get an 616. * increase/decrease, you lose some of the 617. * accumulated effects. 618. */ 619. for (i = 0; i < A_MAX; ++i) { 620. ax = AEXE(i); 621. /* nothing to do here if no exercise or abuse has occurred 622. (Int and Cha always fall into this category) */ 623. if (!ax) 624. continue; /* ok to skip nextattrib */ 625. 626. mod_val = sgn(ax); /* +1 or -1; used below */ 627. /* no further effect for exercise if at max or abuse if at min; 628. can't exceed 18 via exercise even if actual max is higher */ 629. lolim = ATTRMIN(i); /* usually 3; might be higher */ 630. hilim = ATTRMAX(i); /* usually 18; maybe lower or higher */ 631. if (hilim > 18) 632. hilim = 18; 633. if ((ax < 0) ? (ABASE(i) <= lolim) : (ABASE(i) >= hilim)) 634. goto nextattrib; 635. /* can't exercise non-Wisdom while polymorphed; previous 636. exercise/abuse gradually wears off without impact then */ 637. if (Upolyd && i != A_WIS) 638. goto nextattrib; 639. 640. debugpline2("exerchk: testing %s (%d).", 641. (i == A_STR) ? "Str" 642. : (i == A_INT) ? "Int?" 643. : (i == A_WIS) ? "Wis" 644. : (i == A_DEX) ? "Dex" 645. : (i == A_CON) ? "Con" 646. : (i == A_CHA) ? "Cha?" 647. : "???", 648. ax); 649. /* 650. * Law of diminishing returns (Part III): 651. * 652. * You don't *always* gain by exercising. 653. * [MRS 92/10/28 - Treat Wisdom specially for balance.] 654. */ 655. if (rn2(AVAL) > ((i != A_WIS) ? (abs(ax) * 2 / 3) : abs(ax))) 656. goto nextattrib; 657. 658. debugpline1("exerchk: changing %d.", i); 659. if (adjattrib(i, mod_val, -1)) { 660. debugpline1("exerchk: changed %d.", i); 661. /* if you actually changed an attrib - zero accumulation */ 662. AEXE(i) = ax = 0; 663. /* then print an explanation */ 664. You("%s %s.", 665. (mod_val > 0) ? "must have been" : "haven't been", 666. exertext[i][(mod_val > 0) ? 0 : 1]); 667. } 668. nextattrib: 669. /* this used to be ``AEXE(i) /= 2 but that would produce 670. platform-dependent rounding/truncation for negative vals */ 671. AEXE(i) = (abs(ax) / 2) * mod_val; 672. } 673. svc.context.next_attrib_check += rn1(200, 800); 674. debugpline1("exerchk: next check at %ld.", 675. svc.context.next_attrib_check); 676. } 677. } 678. 679. /* return random hero attribute (by role's attr distribution). 680. returns A_MAX if failed. */ 681. staticfn int 682. rnd_attr(void) 683. { 684. int i, x = rn2(100); 685. 686. /* 5.0: the x -= ... calculation used to have an off by 1 error that 687. resulted in the values being biased toward Str and away from Cha */ 688. for (i = 0; i < A_MAX; ++i) 689. if ((x -= gu.urole.attrdist[i]) < 0) 690. break; 691. return i; 692. } 693. 694. /* add or subtract np points from random attributes, 695. adjusting the base and maximum values of the attributes. 696. if subtracting, np must be negative. 697. returns the left over points. */ 698. staticfn int 699. init_attr_role_redist(int np, boolean addition) 700. { 701. int tryct = 0; 702. int adj = addition ? 1 : -1; 703. 704. while ((addition ? (np > 0) : (np < 0)) && tryct < 100) { 705. int i = rnd_attr(); 706. 707. if (i >= A_MAX 708. || (addition ? (ABASE(i) >= ATTRMAX(i)) 709. : (ABASE(i) <= ATTRMIN(i)))) { 710. tryct++; 711. continue; 712. } 713. tryct = 0; 714. ABASE(i) += adj; 715. AMAX(i) += adj; 716. np -= adj; 717. } 718. return np; 719. } 720. 721. /* allocate hero's initial characteristics */ 722. void 723. init_attr(int np) 724. { 725. int i; 726. 727. for (i = 0; i < A_MAX; i++) { 728. ABASE(i) = AMAX(i) = gu.urole.attrbase[i]; 729. ATEMP(i) = ATIME(i) = 0; 730. np -= gu.urole.attrbase[i]; 731. } 732. 733. /* distribute leftover points */ 734. np = init_attr_role_redist(np, TRUE); 735. /* if we went over, remove points */ 736. np = init_attr_role_redist(np, FALSE); 737. } 738. 739. void 740. redist_attr(void) 741. { 742. int i, tmp; 743. 744. for (i = 0; i < A_MAX; i++) { 745. if (i == A_INT || i == A_WIS) 746. continue; 747. /* Polymorphing doesn't change your mind */ 748. tmp = AMAX(i); 749. AMAX(i) += (rn2(5) - 2); 750. if (AMAX(i) > ATTRMAX(i)) 751. AMAX(i) = ATTRMAX(i); 752. if (AMAX(i) < ATTRMIN(i)) 753. AMAX(i) = ATTRMIN(i); 754. ABASE(i) = ABASE(i) * AMAX(i) / tmp; 755. /* ABASE(i) > ATTRMAX(i) is impossible */ 756. if (ABASE(i) < ATTRMIN(i)) 757. ABASE(i) = ATTRMIN(i); 758. } 759. /* encumber_msg(); -- caller needs to do this */ 760. } 761. 762. /* apply minor variation to attributes */ 763. void 764. vary_init_attr(void) 765. { 766. int i; 767. 768. for (i = 0; i < A_MAX; i++) 769. if (!rn2(20)) { 770. int xd = rn2(7) - 2; /* biased variation */ 771. 772. (void) adjattrib(i, xd, TRUE); 773. if (ABASE(i) < AMAX(i)) 774. AMAX(i) = ABASE(i); 775. } 776. } 777. 778. staticfn 779. void 780. postadjabil(long *ability) 781. { 782. if (!u.ulevel) /* initializing hero; don't attempt screen update yet */ 783. return; 784. if (ability == &(HWarning) || ability == &(HSee_invisible)) 785. see_monsters(); 786. } 787. 788. staticfn const struct innate * 789. role_abil(int r) 790. { 791. const struct { 792. short role; 793. const struct innate *abil; 794. } roleabils[] = { 795. { PM_ARCHEOLOGIST, arc_abil }, 796. { PM_BARBARIAN, bar_abil }, 797. { PM_CAVE_DWELLER, cav_abil }, 798. { PM_HEALER, hea_abil }, 799. { PM_KNIGHT, kni_abil }, 800. { PM_MONK, mon_abil }, 801. { PM_CLERIC, pri_abil }, 802. { PM_RANGER, ran_abil }, 803. { PM_ROGUE, rog_abil }, 804. { PM_SAMURAI, sam_abil }, 805. { PM_TOURIST, tou_abil }, 806. { PM_VALKYRIE, val_abil }, 807. { PM_WIZARD, wiz_abil }, 808. { 0, 0 } 809. }; 810. int i; 811. 812. for (i = 0; roleabils[i].abil && roleabils[i].role != r; i++) 813. continue; 814. return roleabils[i].abil; 815. } 816. 817. staticfn const struct innate * 818. check_innate_abil(long *ability, long frommask) 819. { 820. const struct innate *abil = 0; 821. 822. if (frommask == FROMEXPER) 823. abil = role_abil(Role_switch); 824. else if (frommask == FROMRACE) 825. switch (Race_switch) { 826. case PM_DWARF: 827. abil = dwa_abil; 828. break; 829. case PM_ELF: 830. abil = elf_abil; 831. break; 832. case PM_GNOME: 833. abil = gno_abil; 834. break; 835. case PM_ORC: 836. abil = orc_abil; 837. break; 838. case PM_HUMAN: 839. abil = hum_abil; 840. break; 841. default: 842. break; 843. } 844. 845. while (abil && abil->ability) { 846. if ((abil->ability == ability) && (u.ulevel >= abil->ulevel)) 847. return abil; 848. abil++; 849. } 850. return (struct innate *) 0; 851. } 852. 853. /* reasons for innate ability */ 854. #define FROM_NONE 0 855. #define FROM_ROLE 1 /* from experience at level 1 */ 856. #define FROM_RACE 2 857. #define FROM_INTR 3 /* intrinsically (eating some corpse or prayer reward) */ 858. #define FROM_EXP 4 /* from experience for some level > 1 */ 859. #define FROM_FORM 5 860. #define FROM_LYCN 6 861. 862. /* check whether particular ability has been obtained via innate attribute */ 863. staticfn int 864. innately(long *ability) 865. { 866. const struct innate *iptr; 867. 868. if ((iptr = check_innate_abil(ability, FROMEXPER)) != 0) 869. return (iptr->ulevel == 1) ? FROM_ROLE : FROM_EXP; 870. if ((iptr = check_innate_abil(ability, FROMRACE)) != 0) 871. return FROM_RACE; 872. if ((*ability & FROMOUTSIDE) != 0L) 873. return FROM_INTR; 874. if ((*ability & FROMFORM) != 0L) 875. return FROM_FORM; 876. return FROM_NONE; 877. } 878. 879. int 880. is_innate(int propidx) 881. { 882. int innateness; 883. 884. /* innately() would report FROM_FORM for this; caller wants specificity */ 885. if (propidx == DRAIN_RES && ismnum(u.ulycn)) 886. return FROM_LYCN; 887. if (propidx == FAST && Very_fast) 888. return FROM_NONE; /* can't become very fast innately */ 889. if ((innateness = innately(&u.uprops[propidx].intrinsic)) != FROM_NONE) 890. return innateness; 891. if (propidx == JUMPING && Role_if(PM_KNIGHT) 892. /* knight has intrinsic jumping, but extrinsic is more versatile so 893. ignore innateness if equipment is going to claim responsibility */ 894. && !u.uprops[propidx].extrinsic) 895. return FROM_ROLE; 896. if ((propidx == BLINDED && !haseyes(gy.youmonst.data)) 897. || (propidx == BLND_RES && (HBlnd_resist & FROMFORM) != 0)) 898. return FROM_FORM; 899. return FROM_NONE; 900. } 901. 902. DISABLE_WARNING_FORMAT_NONLITERAL 903. 904. char * 905. from_what( 906. int propidx) /* special cases can have negative values */ 907. { 908. static char buf[BUFSZ]; 909. 910. buf[0] = '\0'; 911. /* 912. * Restrict the source of the attributes just to debug mode for now 913. */ 914. if (wizard) { 915. static NEARDATA const char because_of[] = " because of %s"; 916. 917. if (propidx >= 0) { 918. char *p; 919. struct obj *obj = (struct obj *) 0; 920. int innateness = is_innate(propidx); 921. 922. /* 923. * Properties can be obtained from multiple sources and we 924. * try to pick the most significant one. Classification 925. * priority is not set in stone; current precedence is: 926. * "from the start" (from role or race at level 1), 927. * "from outside" (eating corpse, divine reward, blessed potion), 928. * "from experience" (from role or race at level 2+), 929. * "from current form" (while polymorphed), 930. * "from timed effect" (potion or spell), 931. * "from worn/wielded equipment" (Firebrand, elven boots, &c), 932. * "from carried equipment" (mainly quest artifacts). 933. * There are exceptions. Versatile jumping from spell or boots 934. * takes priority over knight's innate but limited jumping. 935. */ 936. if ((propidx == BLINDED && u.uroleplay.blind) 937. || (propidx == DEAF && u.uroleplay.deaf)) 938. Sprintf(buf, " from birth"); 939. else if (innateness == FROM_ROLE || innateness == FROM_RACE) 940. Strcpy(buf, " innately"); 941. else if (innateness == FROM_INTR) /* [].intrinsic & FROMOUTSIDE */ 942. Strcpy(buf, " intrinsically"); 943. else if (innateness == FROM_EXP) 944. Strcpy(buf, " because of your experience"); 945. else if (innateness == FROM_LYCN) 946. Strcpy(buf, " due to your lycanthropy"); 947. else if (innateness == FROM_FORM) 948. Strcpy(buf, " from your creature form"); 949. else if (propidx == FAST && Very_fast) 950. Sprintf(buf, because_of, 951. ((HFast & TIMEOUT) != 0L) ? "a potion or spell" 952. : ((EFast & W_ARMF) != 0L && uarmf->dknown 953. && objects[uarmf->otyp].oc_name_known) 954. ? ysimple_name(uarmf) /* speed boots */ 955. : EFast ? "worn equipment" 956. : something); 957. else if (wizard 958. && (obj = what_gives(&u.uprops[propidx].extrinsic)) != 0) 959. Sprintf(buf, because_of, obj->oartifact 960. ? bare_artifactname(obj) 961. : ysimple_name(obj)); 962. else if (propidx == BLINDED && Blindfolded_only) 963. Sprintf(buf, because_of, ysimple_name(ublindf)); 964. else if (propidx == BLINDED && u.ucreamed 965. && BlindedTimeout == (long) u.ucreamed 966. && !EBlinded && !(HBlinded & ~TIMEOUT)) 967. Sprintf(buf, "due to goop covering your %s", 968. body_part(FACE)); 969. 970. /* remove some verbosity and/or redundancy */ 971. if ((p = strstri(buf, " pair of ")) != 0) 972. copynchars(p + 1, p + 9, BUFSZ); /* overlapping buffers ok */ 973. else if (propidx == STRANGLED 974. && (p = strstri(buf, " of strangulation")) != 0) 975. *p = '\0'; 976. 977. } else { /* negative property index */ 978. /* if more blocking capabilities get implemented we'll need to 979. replace this with what_blocks() comparable to what_gives() */ 980. switch (-propidx) { 981. case BLINDED: 982. /* wearing the Eyes of the Overworld overrides blindness */ 983. if (BBlinded && is_art(ublindf, ART_EYES_OF_THE_OVERWORLD)) 984. Sprintf(buf, because_of, bare_artifactname(ublindf)); 985. break; 986. case INVIS: 987. if (u.uprops[INVIS].blocked & W_ARMC) 988. Sprintf(buf, because_of, 989. ysimple_name(uarmc)); /* mummy wrapping */ 990. break; 991. case CLAIRVOYANT: 992. if (wizard && (u.uprops[CLAIRVOYANT].blocked & W_ARMH)) 993. Sprintf(buf, because_of, 994. ysimple_name(uarmh)); /* cornuthaum */ 995. break; 996. } 997. } 998. 999. } /*wizard*/ 1000. return buf; 1001. } 1002. 1003. RESTORE_WARNING_FORMAT_NONLITERAL 1004. 1005. void 1006. adjabil(int oldlevel, int newlevel) 1007. { 1008. const struct innate *abil, *rabil; 1009. long prevabil, mask = FROMEXPER; 1010. 1011. abil = role_abil(Role_switch); 1012. 1013. switch (Race_switch) { 1014. case PM_ELF: 1015. rabil = elf_abil; 1016. break; 1017. case PM_ORC: 1018. rabil = orc_abil; 1019. break; 1020. case PM_HUMAN: 1021. case PM_DWARF: 1022. case PM_GNOME: 1023. default: 1024. rabil = 0; 1025. break; 1026. } 1027. 1028. while (abil || rabil) { 1029. /* Have we finished with the intrinsics list? */ 1030. if (!abil || !abil->ability) { 1031. /* Try the race intrinsics */ 1032. if (!rabil || !rabil->ability) 1033. break; 1034. abil = rabil; 1035. rabil = 0; 1036. mask = FROMRACE; 1037. } 1038. prevabil = *(abil->ability); 1039. if (oldlevel < abil->ulevel && newlevel >= abil->ulevel) { 1040. /* Abilities gained at level 1 can never be lost 1041. * via level loss, only via means that remove _any_ 1042. * sort of ability. A "gain" of such an ability from 1043. * an outside source is devoid of meaning, so we set 1044. * FROMOUTSIDE to avoid such gains. 1045. */ 1046. if (abil->ulevel == 1) 1047. *(abil->ability) |= (mask | FROMOUTSIDE); 1048. else 1049. *(abil->ability) |= mask; 1050. if (!(*(abil->ability) & INTRINSIC & ~mask)) { 1051. if (*(abil->gainstr)) 1052. You_feel("%s!", abil->gainstr); 1053. } 1054. } else if (oldlevel >= abil->ulevel && newlevel < abil->ulevel) { 1055. *(abil->ability) &= ~mask; 1056. if (!(*(abil->ability) & INTRINSIC)) { 1057. if (*(abil->losestr)) 1058. You_feel("%s!", abil->losestr); 1059. else if (*(abil->gainstr)) 1060. You_feel("less %s!", abil->gainstr); 1061. } 1062. } 1063. if (prevabil != *(abil->ability)) /* it changed */ 1064. postadjabil(abil->ability); 1065. abil++; 1066. } 1067. 1068. if (oldlevel > 0) { 1069. if (newlevel > oldlevel) 1070. add_weapon_skill(newlevel - oldlevel); 1071. else 1072. lose_weapon_skill(oldlevel - newlevel); 1073. } 1074. } 1075. 1076. /* called when gaining a level (before u.ulevel gets incremented); 1077. also called with u.ulevel==0 during hero initialization or for 1078. re-init if hero turns into a "new man/woman/elf/&c" */ 1079. int 1080. newhp(void) 1081. { 1082. int hp, conplus; 1083. 1084. if (u.ulevel == 0) { 1085. /* Initialize hit points */ 1086. hp = gu.urole.hpadv.infix + gu.urace.hpadv.infix; 1087. if (gu.urole.hpadv.inrnd > 0) 1088. hp += rnd(gu.urole.hpadv.inrnd); 1089. if (gu.urace.hpadv.inrnd > 0) 1090. hp += rnd(gu.urace.hpadv.inrnd); 1091. if (svm.moves == 0) { /* initial hero; skip for polyself to new man */ 1092. /* Initialize alignment stuff */ 1093. u.ualign.type = aligns[flags.initalign].value; 1094. u.ualign.record = gu.urole.initrecord; 1095. } 1096. /* no Con adjustment for initial hit points */ 1097. } else { 1098. if (u.ulevel < gu.urole.xlev) { 1099. hp = gu.urole.hpadv.lofix + gu.urace.hpadv.lofix; 1100. if (gu.urole.hpadv.lornd > 0) 1101. hp += rnd(gu.urole.hpadv.lornd); 1102. if (gu.urace.hpadv.lornd > 0) 1103. hp += rnd(gu.urace.hpadv.lornd); 1104. } else { 1105. hp = gu.urole.hpadv.hifix + gu.urace.hpadv.hifix; 1106. if (gu.urole.hpadv.hirnd > 0) 1107. hp += rnd(gu.urole.hpadv.hirnd); 1108. if (gu.urace.hpadv.hirnd > 0) 1109. hp += rnd(gu.urace.hpadv.hirnd); 1110. } 1111. if (ACURR(A_CON) <= 3) 1112. conplus = -2; 1113. else if (ACURR(A_CON) <= 6) 1114. conplus = -1; 1115. else if (ACURR(A_CON) <= 14) 1116. conplus = 0; 1117. else if (ACURR(A_CON) <= 16) 1118. conplus = 1; 1119. else if (ACURR(A_CON) == 17) 1120. conplus = 2; 1121. else if (ACURR(A_CON) == 18) 1122. conplus = 3; 1123. else 1124. conplus = 4; 1125. hp += conplus; 1126. } 1127. if (hp <= 0) 1128. hp = 1; 1129. if (u.ulevel < MAXULEV) { 1130. /* remember increment; future level drain could take it away again */ 1131. u.uhpinc[u.ulevel] = (xint16) hp; 1132. } else { 1133. /* after level 30, throttle hit point gains from extra experience; 1134. once max reaches 1200, further increments will be just 1 more */ 1135. char lim = 5 - u.uhpmax / 300; 1136. 1137. lim = max(lim, 1); 1138. if (hp > lim) 1139. hp = lim; 1140. } 1141. return hp; 1142. } 1143. 1144. /* minimum value for uhpmax is ulevel but for life-saving it is always at 1145. least 10 if ulevel is less than that */ 1146. int 1147. minuhpmax(int altmin) 1148. { 1149. if (altmin < 1) 1150. altmin = 1; 1151. return max(u.ulevel, altmin); 1152. } 1153. 1154. /* update u.uhpmax or u.mhmax and values of other things that depend upon 1155. whichever of them is relevant */ 1156. void 1157. setuhpmax(int newmax, boolean even_when_polyd) 1158. { 1159. if (!Upolyd || even_when_polyd) { 1160. if (newmax != u.uhpmax) { 1161. u.uhpmax = newmax; 1162. if (u.uhpmax > u.uhppeak) 1163. u.uhppeak = u.uhpmax; 1164. disp.botl = TRUE; 1165. } 1166. if (u.uhp > u.uhpmax) 1167. u.uhp = u.uhpmax, disp.botl = TRUE; 1168. } else { /* Upolyd */ 1169. if (newmax != u.mhmax) { 1170. u.mhmax = newmax; 1171. disp.botl = TRUE; 1172. } 1173. if (u.mh > u.mhmax) 1174. u.mh = u.mhmax, disp.botl = TRUE; 1175. } 1176. } 1177. 1178. /* called after setuhpmax() when damage is pending; 1179. if uhpmax (or mhmax) has been reduced, it might have caused uhp (or mh) 1180. to be reduced too; if so, recalculate pending loss to account for that */ 1181. int 1182. adjuhploss( 1183. int loss, /* pending hp loss */ 1184. int olduhp) /* does double duty as oldmh when Upolyd */ 1185. { 1186. if (!Upolyd) { 1187. if (u.uhp < olduhp) 1188. loss -= (olduhp - u.uhp); 1189. } else { 1190. if (u.mh < olduhp) 1191. loss -= (olduhp - u.mh); 1192. } 1193. return max(loss, 1); 1194. } 1195. 1196. /* return the current effective value of a specific characteristic 1197. (the 'a' in 'acurr()' comes from outdated use of "attribute" for the 1198. six Str/Dex/&c characteristics; likewise for u.abon, u.atemp, u.acurr) */ 1199. schar 1200. acurr(int chridx) 1201. { 1202. int tmp, result = 0; /* 'result' will always be reset to positive value */ 1203. 1204. assert(chridx >= 0 && chridx < A_MAX); 1205. tmp = u.abon.a[chridx] + u.atemp.a[chridx] + u.acurr.a[chridx]; 1206. 1207. /* for Strength: 3 <= result <= 125; 1208. for all others: 3 <= result <= 25 */ 1209. if (chridx == A_STR) { 1210. /* strength value is encoded: 3..18 normal, 19..118 for 18/xx (with 1211. 1 <= xx <= 100), and 119..125 for other characteristics' 19..25; 1212. STR18(x) yields 18 + x (intended for 0 <= x <= 100; not used here); 1213. STR19(y) yields 100 + y (intended for 19 <= y <= 25) */ 1214. if (tmp >= STR19(25) || (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER)) 1215. result = STR19(25); /* 125 */ 1216. else 1217. /* need non-zero here to avoid 'if(result==0)' below because 1218. that doesn't deal with Str encoding; the cap of 25 applied 1219. there would limit Str to 18/07 [18 + 7] */ 1220. result = max(tmp, 3); 1221. } else if (chridx == A_CHA) { 1222. if (tmp < 18 && (gy.youmonst.data->mlet == S_NYMPH 1223. || u.umonnum == PM_AMOROUS_DEMON)) 1224. result = 18; 1225. } else if (chridx == A_CON) { 1226. if (u_wield_art(ART_OGRESMASHER)) 1227. result = 25; 1228. } else if (chridx == A_INT || chridx == A_WIS) { 1229. /* Yes, this may raise Int and/or Wis if hero is sufficiently 1230. stupid. There are lower levels of cognition than "dunce". */ 1231. if (uarmh && uarmh->otyp == DUNCE_CAP) 1232. result = 6; 1233. } else if (chridx == A_DEX) { 1234. ; /* there aren't any special cases for dexterity */ 1235. } 1236. 1237. if (result == 0) /* none of the special cases applied */ 1238. result = (tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp; 1239. 1240. return (schar) result; 1241. } 1242. 1243. /* condense clumsy ACURR(A_STR) value into value that fits into formulas */ 1244. schar 1245. acurrstr(void) 1246. { 1247. int str = ACURR(A_STR), /* 3..125 after massaging by acurr() */ 1248. result; /* 3..25 */ 1249. 1250. if (str <= STR18(0)) /* <= 18; max(,3) here is redundant */ 1251. result = max(str, 3); /* 3..18 */ 1252. else if (str <= STR19(21)) /* <= 121 */ 1253. /* this converts 1254. 18/01..18/31 into 19, 1255. 18/32..18/81 into 20, 1256. 18/82..18/100 and 19..21 into 21 */ 1257. result = 19 + str / 50; /* map to 19..21 */ 1258. else /* convert 122..125; min(,125) here is redundant */ 1259. result = min(str, 125) - 100; /* 22..25 */ 1260. 1261. return (schar) result; 1262. } 1263. 1264. /* when wearing (or taking off) an unID'd item, this routine is used 1265. to distinguish between observable +0 result and no-visible-effect 1266. due to an attribute not being able to exceed maximum or minimum */ 1267. boolean 1268. extremeattr( 1269. int attrindx) /* does attrindx's value match its max or min? */ 1270. { 1271. /* Fixed_abil and racial MINATTR/MAXATTR aren't relevant here */ 1272. int lolimit = 3, hilimit = 25, curval = ACURR(attrindx); 1273. 1274. /* upper limit for Str is 25 but its value is encoded differently */ 1275. if (attrindx == A_STR) { 1276. hilimit = STR19(25); /* 125 */ 1277. /* lower limit for Str can also be 25 */ 1278. if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER) 1279. lolimit = hilimit; 1280. } else if (attrindx == A_CON) { 1281. if (u_wield_art(ART_OGRESMASHER)) 1282. lolimit = hilimit; 1283. } 1284. /* this exception is hypothetical; the only other worn item affecting 1285. Int or Wis is another helmet so can't be in use at the same time */ 1286. if (attrindx == A_INT || attrindx == A_WIS) { 1287. if (uarmh && uarmh->otyp == DUNCE_CAP) 1288. hilimit = lolimit = 6; 1289. } 1290. 1291. /* are we currently at either limit? */ 1292. return (curval == lolimit || curval == hilimit) ? TRUE : FALSE; 1293. } 1294. 1295. /* avoid possible problems with alignment overflow, and provide a centralized 1296. location for any future alignment limits */ 1297. void 1298. adjalign(int n) 1299. { 1300. int newalign = u.ualign.record + n; 1301. 1302. if (n < 0) { 1303. unsigned newabuse = u.ualign.abuse - n; 1304. 1305. if (newalign < u.ualign.record) 1306. u.ualign.record = newalign; 1307. if (newabuse > u.ualign.abuse) { 1308. u.ualign.abuse = newabuse; 1309. adj_erinys(newabuse); 1310. } 1311. } else if (newalign > u.ualign.record) { 1312. u.ualign.record = newalign; 1313. if (u.ualign.record > ALIGNLIM) 1314. u.ualign.record = (int)ALIGNLIM; 1315. } 1316. } 1317. 1318. /* change hero's alignment type, possibly losing use of artifacts */ 1319. void 1320. uchangealign( 1321. int newalign, 1322. int reason) /* A_CG_CONVERT, A_CG_HELM_ON, or A_CG_HELM_OFF */ 1323. { 1324. aligntyp oldalign = u.ualign.type; 1325. 1326. u.ublessed = 0; /* lose divine protection */ 1327. /* You/Your/pline message with call flush_screen(), triggering bot(), 1328. so the actual data change needs to come before the message */ 1329. disp.botl = TRUE; /* status line needs updating */ 1330. if (reason == A_CG_CONVERT) { 1331. /* conversion via altar */ 1332. livelog_printf(LL_ALIGNMENT, "permanently converted to %s", 1333. aligns[1 - newalign].adj); 1334. u.ualignbase[A_CURRENT] = (aligntyp) newalign; 1335. /* worn helm of opposite alignment might block change */ 1336. if (!uarmh || uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT) 1337. u.ualign.type = u.ualignbase[A_CURRENT]; 1338. You("have a %ssense of a new direction.", 1339. (u.ualign.type != oldalign) ? "sudden " : ""); 1340. } else { 1341. /* putting on or taking off a helm of opposite alignment */ 1342. u.ualign.type = (aligntyp) newalign; 1343. if (reason == A_CG_HELM_ON) { 1344. adjalign(-7); /* for abuse -- record will be cleared shortly */ 1345. Your("mind oscillates %s.", Hallucination ? "wildly" : "briefly"); 1346. make_confused(rn1(2, 3), FALSE); 1347. if (Is_astralevel(&u.uz) || ((unsigned) rn2(50) < u.ualign.abuse)) 1348. summon_furies(Is_astralevel(&u.uz) ? 0 : 1); 1349. /* don't livelog taking it back off */ 1350. livelog_printf(LL_ALIGNMENT, "used a helm to turn %s", 1351. aligns[1 - newalign].adj); 1352. } else if (reason == A_CG_HELM_OFF) { 1353. Your("mind is %s.", Hallucination 1354. ? "much of a muchness" 1355. : "back in sync with your body"); 1356. } 1357. } 1358. if (u.ualign.type != oldalign) { 1359. u.ualign.record = 0; /* slate is wiped clean */ 1360. retouch_equipment(0); 1361. } 1362. } 1363. 1364. /*attrib.c*/