Source:NetHack 5.0.0/src/botl.c
Jump to navigation
Jump to search
Below is the full text to botl.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/botl.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 botl.c $NHDT-Date: 1769839231 2026/01/30 22:00:31 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.277 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Michael Allison, 2006. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. extern const char *const hu_stat[]; /* defined in eat.c */ 9. 10. /* also used in insight.c */ 11. const char *const enc_stat[] = { 12. "", "Burdened", "Stressed", 13. "Strained", "Overtaxed", "Overloaded" 14. }; 15. 16. staticfn const char *rank(void); 17. staticfn void bot_via_windowport(void); 18. staticfn void stat_update_time(void); 19. 20. char * 21. get_strength_str(void) 22. { 23. static char buf[32]; 24. int st = ACURR(A_STR); 25. 26. if (st > 18) { 27. if (st > STR18(100)) 28. Sprintf(buf, "%2d", st - 100); 29. else if (st < STR18(100)) 30. Sprintf(buf, "18/%02d", st - 18); 31. else 32. Sprintf(buf, "18/**"); 33. } else 34. Sprintf(buf, "%-1d", st); 35. 36. return buf; 37. } 38. 39. void 40. check_gold_symbol(void) 41. { 42. nhsym goldch = gs.showsyms[COIN_CLASS + SYM_OFF_O]; 43. 44. iflags.invis_goldsym = (goldch <= (nhsym) ' '); 45. } 46. 47. char * 48. do_statusline1(void) 49. { 50. static char newbot1[BUFSZ]; 51. char *nb; 52. int i, j; 53. 54. if (suppress_map_output()) 55. return strcpy(newbot1, ""); 56. 57. Strcpy(newbot1, svp.plname); 58. if ('a' <= newbot1[0] && newbot1[0] <= 'z') 59. newbot1[0] += 'A' - 'a'; 60. newbot1[BOTL_NSIZ] = 0; 61. Sprintf(nb = eos(newbot1), " the "); 62. 63. if (Upolyd) { 64. char mbot[BUFSZ]; 65. int k = 0; 66. 67. Strcpy(mbot, pmname(&mons[u.umonnum], Ugender)); 68. while (mbot[k] != 0) { 69. if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k] 70. && mbot[k] <= 'z') 71. mbot[k] += 'A' - 'a'; 72. k++; 73. } 74. Strcpy(nb = eos(nb), mbot); 75. } else { 76. Strcpy(nb = eos(nb), rank()); 77. } 78. 79. Sprintf(nb = eos(nb), " "); 80. i = gm.mrank_sz + 15; 81. j = (int) ((nb + 2) - newbot1); /* strlen(newbot1) but less computation */ 82. if ((i - j) > 0) 83. Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */ 84. 85. Sprintf(nb = eos(nb), "St:%s Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d", 86. get_strength_str(), 87. ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), 88. ACURR(A_CHA)); 89. Sprintf(nb = eos(nb), "%s", 90. (u.ualign.type == A_CHAOTIC) ? " Chaotic" 91. : (u.ualign.type == A_NEUTRAL) ? " Neutral" 92. : " Lawful"); 93. #ifdef SCORE_ON_BOTL 94. if (flags.showscore) 95. Sprintf(nb = eos(nb), " S:%ld", botl_score()); 96. #endif 97. return newbot1; 98. } 99. 100. char * 101. do_statusline2(void) 102. { 103. static char newbot2[BUFSZ], /* MAXCO: botl.h */ 104. /* dungeon location (and gold), hero health (HP, PW, AC), 105. experience (HD if poly'd, else Exp level and maybe Exp points), 106. time (in moves), varying number of status conditions */ 107. dloc[QBUFSZ], hlth[QBUFSZ], expr[QBUFSZ], 108. tmmv[QBUFSZ], cond[QBUFSZ], vers[QBUFSZ]; 109. char *nb; 110. size_t dln, dx, hln, xln, tln, cln, vrn; 111. int hp, hpmax, cap; 112. long money; 113. 114. if (suppress_map_output()) 115. return strcpy(newbot2, ""); 116. 117. /* 118. * Various min(x,9999)'s are to avoid having excessive values 119. * violate the field width assumptions in botl.h and should not 120. * impact normal play. Particularly 64-bit long for gold which 121. * could require many more digits if someone figures out a way 122. * to get and carry a really large (or negative) amount of it. 123. * Turn counter is also long, but we'll risk that. 124. */ 125. 126. /* dungeon location plus gold */ 127. (void) describe_level(dloc, 1); /* includes at least one trailing space */ 128. if ((money = money_cnt(gi.invent)) < 0L) 129. money = 0L; /* ought to issue impossible() and then discard gold */ 130. Sprintf(eos(dloc), "%s:%-2ld", /* strongest hero can lift ~300000 gold */ 131. (iflags.in_dumplog || iflags.invis_goldsym) ? "$" 132. : encglyph(objnum_to_glyph(GOLD_PIECE)), 133. min(money, 999999L)); 134. dln = strlen(dloc); 135. /* '$' encoded as \GXXXXNNNN is 9 chars longer than display will need */ 136. dx = strstri(dloc, "\\G") ? 9 : 0; 137. 138. /* health and armor class (has trailing space for AC 0..9) */ 139. hp = Upolyd ? u.mh : u.uhp; 140. hpmax = Upolyd ? u.mhmax : u.uhpmax; 141. if (hp < 0) 142. hp = 0; 143. Sprintf(hlth, "HP:%d(%d) Pw:%d(%d) AC:%-2d", 144. min(hp, 9999), min(hpmax, 9999), 145. min(u.uen, 9999), min(u.uenmax, 9999), u.uac); 146. hln = strlen(hlth); 147. 148. /* experience */ 149. if (Upolyd) 150. Sprintf(expr, "HD:%d", mons[u.umonnum].mlevel); 151. else if (flags.showexp) 152. Sprintf(expr, "Xp:%d/%-1ld", u.ulevel, u.uexp); 153. else 154. Sprintf(expr, "Xp:%d", u.ulevel); 155. xln = strlen(expr); 156. 157. /* time/move counter */ 158. if (flags.time) 159. Sprintf(tmmv, "T:%ld", svm.moves); 160. else 161. tmmv[0] = '\0'; 162. tln = strlen(tmmv); 163. 164. /* status conditions; worst ones first */ 165. cond[0] = '\0'; /* once non-empty, cond will have a leading space */ 166. nb = cond; 167. /* 168. * Stoned, Slimed, Strangled, and both types of Sick are all fatal 169. * unless remedied before timeout expires. Should we order them by 170. * shortest time left? [Probably not worth the effort, since it's 171. * unusual for more than one of them to apply at a time.] 172. */ 173. if (Stoned) 174. Strcpy(nb = eos(nb), " Stone"); 175. if (Slimed) 176. Strcpy(nb = eos(nb), " Slime"); 177. if (Strangled) 178. Strcpy(nb = eos(nb), " Strngl"); 179. if (Sick) { 180. if (u.usick_type & SICK_VOMITABLE) 181. Strcpy(nb = eos(nb), " FoodPois"); 182. if (u.usick_type & SICK_NONVOMITABLE) 183. Strcpy(nb = eos(nb), " TermIll"); 184. } 185. if (u.uhs != NOT_HUNGRY) 186. Sprintf(nb = eos(nb), " %s", hu_stat[u.uhs]); 187. if ((cap = near_capacity()) > UNENCUMBERED) 188. Sprintf(nb = eos(nb), " %s", enc_stat[cap]); 189. if (Blind) 190. Strcpy(nb = eos(nb), " Blind"); 191. if (Deaf) 192. Strcpy(nb = eos(nb), " Deaf"); 193. if (Stunned) 194. Strcpy(nb = eos(nb), " Stun"); 195. if (Confusion) 196. Strcpy(nb = eos(nb), " Conf"); 197. if (Hallucination) 198. Strcpy(nb = eos(nb), " Hallu"); 199. /* levitation and flying are mutually exclusive; riding is not */ 200. if (Levitation) 201. Strcpy(nb = eos(nb), " Lev"); 202. if (Flying) 203. Strcpy(nb = eos(nb), " Fly"); 204. if (u.usteed) 205. Strcpy(nb = eos(nb), " Ride"); 206. cln = strlen(cond); 207. 208. /* version on status line, with leading space */ 209. if (flags.showvers) 210. (void) status_version(vers, sizeof vers, TRUE); 211. else 212. vers[0] = '\0'; 213. vrn = strlen(vers); 214. 215. /* 216. * Put the pieces together. If they all fit, keep the traditional 217. * sequence. Otherwise, move least important parts to the end in 218. * case the interface side of things has to truncate. Note that 219. * dloc[] contains '$' encoded in ten character sequence \GXXXXNNNN 220. * so we want to test its display length rather than buffer length. 221. * 222. * We don't have an actual display limit here, so have to go by the 223. * width of the map. Since we're reordering rather than truncating, 224. * wider displays can still show wider status than the map if the 225. * interface supports that. 226. */ 227. if ((dln - dx) + 1 + hln + 1 + xln + 1 + tln + 1 + cln + vrn <= COLNO) { 228. Snprintf(newbot2, sizeof newbot2, "%s %s %s %s %s%s", dloc, hlth, 229. expr, tmmv, cond, vers); 230. } else { 231. if (dln + 1 + hln + 1 + xln + 1 + tln + 1 + cln + vrn > MAXCO) { 232. panic("bot2: second status line exceeds MAXCO (%u > %d)", 233. (unsigned) (dln + 1 + hln + 1 + xln + 1 + tln + 1 + cln 234. + vrn), 235. MAXCO); 236. } else if ((dln - dx) + 1 + hln + 1 + xln + 1 + cln <= COLNO) { 237. Snprintf(newbot2, sizeof newbot2, "%s %s %s %s %s%s", dloc, hlth, 238. expr, cond, tmmv, vers); 239. } else if ((dln - dx) + 1 + hln + 1 + cln <= COLNO) { 240. Snprintf(newbot2, sizeof newbot2, "%s %s %s %s %s%s", dloc, hlth, 241. cond, expr, tmmv, vers); 242. } else { 243. Snprintf(newbot2, sizeof newbot2, "%s %s %s %s %s%s", hlth, cond, 244. dloc, expr, tmmv, vers); 245. } 246. /* only two or three consecutive spaces available to squeeze out */ 247. mungspaces(newbot2); 248. } 249. return newbot2; 250. } 251. 252. void 253. bot(void) 254. { 255. if (gb.bot_disabled) 256. return; 257. /* dosave() flags completion by setting u.uhp to -1; suppress_map_output() 258. covers program_state.restoring and is used for status as well as map */ 259. if (u.uhp != -1 && gy.youmonst.data 260. && iflags.status_updates && !suppress_map_output()) { 261. if (VIA_WINDOWPORT()) { 262. bot_via_windowport(); 263. } else { 264. curs(WIN_STATUS, 1, 0); 265. putstr(WIN_STATUS, 0, do_statusline1()); 266. curs(WIN_STATUS, 1, 1); 267. putmixed(WIN_STATUS, 0, do_statusline2()); 268. } 269. } 270. disp.botl = disp.botlx = disp.time_botl = FALSE; 271. } 272. 273. /* special purpose status update: move counter ('time' status) only */ 274. void 275. timebot(void) 276. { 277. if (gb.bot_disabled) 278. return; 279. /* we're called when disp.time_botl is set and general disp.botl 280. is clear; disp.time_botl gets set whenever svm.moves changes value 281. so there's no benefit in tracking previous value to decide whether 282. to skip update; suppress_map_output() handles program_state.restoring 283. and program_state.done_hup (tty hangup => no further output at all) 284. and we use it for maybe skipping status as well as for the map */ 285. if (flags.time && iflags.status_updates && !suppress_map_output()) { 286. if (VIA_WINDOWPORT()) { 287. stat_update_time(); 288. } else { 289. /* old status display updates everything */ 290. bot(); 291. } 292. } 293. disp.time_botl = FALSE; 294. } 295. 296. /* convert experience level (1..30) to rank index (0..8) */ 297. int 298. xlev_to_rank(int xlev) 299. { 300. /* 301. * 1..2 => 0 302. * 3..5 => 1 303. * 6..9 => 2 304. * 10..13 => 3 305. * ... 306. * 26..29 => 7 307. * 30 => 8 308. * Conversion is precise but only partially reversible. 309. */ 310. return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8; 311. } 312. 313. /* convert rank index (0..8) to experience level (1..30) */ 314. int 315. rank_to_xlev(int rank) 316. { 317. /* 318. * 0 => 1..2 319. * 1 => 3..5 320. * 2 => 6..9 321. * 3 => 10..13 322. * ... 323. * 7 => 26..29 324. * 8 => 30 325. * We return the low end of each range. 326. */ 327. return (rank < 1) ? 1 : (rank < 2) ? 3 328. : (rank < 8) ? ((rank * 4) - 2) : 30; 329. } 330. 331. const char * 332. rank_of(int lev, short monnum, boolean female) 333. { 334. const struct Role *role; 335. int i; 336. 337. /* Find the role */ 338. for (role = roles; role->name.m; role++) 339. if (monnum == role->mnum) 340. break; 341. if (!role->name.m) 342. role = &gu.urole; 343. 344. /* Find the rank */ 345. for (i = xlev_to_rank((int) lev); i >= 0; i--) { 346. if (female && role->rank[i].f) 347. return role->rank[i].f; 348. if (role->rank[i].m) 349. return role->rank[i].m; 350. } 351. 352. /* Try the role name, instead */ 353. if (female && role->name.f) 354. return role->name.f; 355. else if (role->name.m) 356. return role->name.m; 357. return "Player"; 358. } 359. 360. staticfn const char * 361. rank(void) 362. { 363. return rank_of(u.ulevel, Role_switch, flags.female); 364. } 365. 366. int 367. title_to_mon( 368. const char *str, 369. int *rank_indx, 370. int *title_length) 371. { 372. int i, j; 373. 374. /* Loop through each of the roles */ 375. for (i = 0; roles[i].name.m; i++) { 376. /* loop through each of the rank titles for role #i */ 377. for (j = 0; j < 9; j++) { 378. if (roles[i].rank[j].m 379. && str_start_is(str, roles[i].rank[j].m, TRUE)) { 380. if (rank_indx) 381. *rank_indx = j; 382. if (title_length) 383. *title_length = Strlen(roles[i].rank[j].m); 384. return roles[i].mnum; 385. } 386. if (roles[i].rank[j].f 387. && str_start_is(str, roles[i].rank[j].f, TRUE)) { 388. if (rank_indx) 389. *rank_indx = j; 390. if (title_length) 391. *title_length = Strlen(roles[i].rank[j].f); 392. return roles[i].mnum; 393. } 394. } 395. } 396. if (title_length) 397. *title_length = 0; 398. return NON_PM; 399. } 400. 401. void 402. max_rank_sz(void) 403. { 404. int i; 405. size_t r, maxr = 0; 406. 407. for (i = 0; i < 9; i++) { 408. if (gu.urole.rank[i].m && (r = strlen(gu.urole.rank[i].m)) > maxr) 409. maxr = r; 410. if (gu.urole.rank[i].f && (r = strlen(gu.urole.rank[i].f)) > maxr) 411. maxr = r; 412. } 413. gm.mrank_sz = (int) maxr; 414. return; 415. } 416. 417. #ifdef SCORE_ON_BOTL 418. long 419. botl_score(void) 420. { 421. long deepest = (long) deepest_lev_reached(FALSE); 422. long umoney, depthbonus; 423. 424. /* hidden_gold(False): only gold in containers whose contents are known */ 425. umoney = money_cnt(gi.invent) + hidden_gold(FALSE); 426. /* don't include initial gold; don't impose penalty if it's all gone */ 427. if ((umoney -= u.umoney0) < 0L) 428. umoney = 0L; 429. depthbonus = (50L * (deepest - 1L)) 430. + ((deepest > 30L) ? 10000L 431. : (deepest > 20L) ? (1000L * (deepest - 20L)) 432. : 0L); 433. /* neither umoney nor depthbonus can grow unusually big (gold due to 434. weight); u.urexp might */ 435. return nowrap_add(u.urexp, umoney + depthbonus); 436. } 437. #endif /* SCORE_ON_BOTL */ 438. 439. /* provide the name of the current level for display by various ports */ 440. int 441. describe_level( 442. char *buf, /* output buffer */ 443. int dflgs) /* 1: append trailing space; 2: include dungeon branch name */ 444. { 445. boolean addspace = (dflgs & 1) != 0, /* (used to be unconditional) */ 446. addbranch = (dflgs & 2) != 0; /* False: status, True: livelog */ 447. int ret = 1; 448. 449. if (Is_knox(&u.uz)) { 450. Sprintf(buf, "%s", svd.dungeons[u.uz.dnum].dname); 451. addbranch = FALSE; 452. } else if (In_quest(&u.uz)) { 453. Sprintf(buf, "Home %d", dunlev(&u.uz)); 454. } else if (In_endgame(&u.uz)) { 455. /* [3.6.2: this used to be "Astral Plane" or generic "End Game"] */ 456. (void) endgamelevelname(buf, depth(&u.uz)); 457. if (!addbranch) 458. (void) strsubst(buf, "Plane of ", ""); /* just keep <element> */ 459. addbranch = FALSE; 460. } else { 461. /* ports with more room may expand this one */ 462. if (!addbranch) 463. Sprintf(buf, "%s:%-2d", /* "Dlvl:n" (grep fodder) */ 464. In_tutorial(&u.uz) ? "Tutorial" : "Dlvl", depth(&u.uz)); 465. else 466. Sprintf(buf, "level %d", depth(&u.uz)); 467. ret = 0; 468. } 469. if (addbranch) { 470. Sprintf(eos(buf), ", %s", svd.dungeons[u.uz.dnum].dname); 471. (void) strsubst(buf, "The ", "the "); 472. } 473. if (addspace) 474. Strcat(buf, " "); 475. return ret; 476. } 477. 478. /* weapon description for status lines; started as a terser version of 479. what ^X shows but has diverged to some extent */ 480. char * 481. weapon_status(char *outbuf) 482. { 483. const char *res = 0; 484. 485. *outbuf = '\0'; /* lint suppression */ 486. if (!uwep) { 487. /* no weapon; gloves imply hands; humanoid also implies hands; 488. otherwise make no assumptions */ 489. res = uarmg ? "Empty-hnd" /* empty handed means "gloves only" */ 490. : humanoid(gy.youmonst.data) ? "Bare-hnds" /* bare hands */ 491. : "No-weapon"; 492. } else if (u.twoweap) { 493. /* two-weaponing implies hands and a weapon or wep-tool 494. (not other odd stuff) in each hand */ 495. res = "Dual-weps"; 496. /* note: dual wielding two lances doesn't produce double joust */ 497. if (u.usteed && (weapon_type(uwep) == P_LANCE 498. || weapon_type(uswapwep) == P_LANCE)) 499. res = "Dual+joust"; /* lance behaves specially when mounted */ 500. } else { 501. /* report most weapons by their skill class (so a katana will be 502. described as a long sword, for instance; mattock and hook are 503. exceptions), or wielded non-weapon item by its object class */ 504. char *p; 505. int skill = weapon_type(uwep); 506. 507. if (u.usteed && skill == P_LANCE) { 508. /* lance behaves specially when hero is mounted */ 509. res = "joust"; 510. } else if (uwep->otyp == AKLYS) { 511. /* aklys behaves specially when thrown while wielded, so 512. give it a distinct name instead of skill name of "club"; 513. [maybe FIXME?] for the time being 514. use real name even if 'obj' is undiscovered "thonged club" */ 515. res = "aklys"; 516. } else if (is_sword(uwep)) { 517. /* simplify short short/broad sword/long sword/two-handed sword 518. (similar to messages when dropped due to slippery fingers) */ 519. res = "sword"; 520. } else { 521. /* shorten several */ 522. switch (skill) { 523. case P_QUARTERSTAFF: 524. res = "staff"; 525. break; 526. case P_MORNING_STAR: 527. res = "mrng-star"; /* still pretty long */ 528. break; 529. case P_POLEARMS: 530. res = "pole"; 531. break; 532. case P_UNICORN_HORN: 533. res = "unihorn"; 534. break; 535. default: 536. res = weapon_descr(uwep); 537. /* [should this be moved into weapon_descr()?] */ 538. if (!strcmpi(res, "food") && uwep->otyp == CREAM_PIE) 539. res = "pie"; 540. break; 541. } 542. } 543. 544. if ((uwep->oclass == WEAPON_CLASS || is_weptool(uwep)) 545. && bimanual(uwep) && *res != '2' && strncmpi(res, "two", 3)) 546. Strcat(outbuf, "2H-"); 547. Strcpy(p = eos(outbuf), res), res = outbuf; 548. *p = highc(*p); 549. /* avoid embedded spaces since its designed to appear as part 550. of a space-separated status line */ 551. (void) strNsubst(outbuf, " ", "-", 0); 552. } 553. 554. return (outbuf == res) ? outbuf : strcpy(outbuf, res); 555. } 556. 557. /* armor description for status lines */ 558. char * 559. armor_status(char *armbuf) 560. { 561. int n = !!uarmg + !!uarmc + !!uarm + !!uarmu + !!uarmh + !!uarmf + !!uarms; 562. 563. /* 564. * FIXME: ^X needs to provide non-abbreviated version of this info. 565. * At present it just reports the "no armor" case. 566. */ 567. if (n == 0) { /* no armor */ 568. Strcpy(armbuf, "naked"); 569. } else if (n == 1) { /* just one piece; spell it out */ 570. Strcpy(armbuf, uarmg ? "gloves" 571. : uarmc ? "cloak" 572. : uarm ? "suit" 573. : uarmu ? "shirt" 574. : uarmh ? helm_simple_name(uarmh) /* hat|helm */ 575. : uarmf ? "boots" 576. : uarms ? "shield" 577. : ""); /* not possible */ 578. } else { /* more than one piece */ 579. char *p = armbuf; 580. 581. /* gloves first since this is expected to follow weapon_status(); 582. cloak next since it tends to provide the most protection 583. aside from raw AC */ 584. if (uarmg) 585. *p++ = 'G'; /* gloves */ 586. if (uarmc) 587. *p++ = 'C'; /* cloak */ 588. if (uarm) 589. *p++ = 'A'; /* suit but 's' is for shield */ 590. if (uarmu) 591. *p++ = 'U'; /* underwear? => shirt */ 592. if (uarmh) 593. *p++ = 'H'; /* hat/helm */ 594. if (uarmf) 595. *p++ = 'B'; /* footwear => boots */ 596. if (uarms) 597. *p++ = 'S'; /* shield */ 598. *p = '\0'; 599. } 600. /* 601. * Add a hint about MC by appending a plus sign if that's augmented. 602. * Bug: we should modfiy magical_negation() to return extra info and 603. * call it to scan whole inventory looking for sources of protection. 604. * This is a hack for efficiency to avoid that during status updates. 605. */ 606. if ((uright && uright->otyp == RIN_PROTECTION) 607. || (uleft && uleft->otyp == RIN_PROTECTION) 608. || (uamul && uamul->otyp == AMULET_OF_GUARDING) 609. || (uarmc && uarmc->otyp == CLOAK_OF_PROTECTION) 610. || (uarmh && uarmh->oartifact == ART_MITRE_OF_HOLINESS) 611. || (uwep && uwep->oartifact == ART_TSURUGI_OF_MURAMASA)) 612. (void) strkitten(armbuf, '+'); 613. 614. return upstart(armbuf); 615. } 616. 617. /* =======================================================================*/ 618. /* statusnew routines */ 619. /* =======================================================================*/ 620. 621. /* structure that tracks the status details in the core */ 622. 623. #ifdef STATUS_HILITES 624. #endif /* STATUS_HILITES */ 625. 626. staticfn boolean eval_notify_windowport_field(int, boolean *, int); 627. staticfn void evaluate_and_notify_windowport(boolean *, int); 628. staticfn void init_blstats(void); 629. staticfn int compare_blstats(struct istat_s *, struct istat_s *); 630. staticfn char *anything_to_s(char *, anything *, int); 631. staticfn int percentage(struct istat_s *, struct istat_s *); 632. staticfn int exp_percentage(void); 633. staticfn int QSORTCALLBACK cond_cmp(const genericptr, const genericptr); 634. staticfn int QSORTCALLBACK menualpha_cmp(const genericptr, const genericptr); 635. 636. #ifdef STATUS_HILITES 637. staticfn void s_to_anything(anything *, char *, int); 638. staticfn enum statusfields fldname_to_bl_indx(const char *); 639. staticfn boolean hilite_reset_needed(struct istat_s *, long); 640. staticfn boolean noneoftheabove(const char *); 641. staticfn struct hilite_s *get_hilite(int, int, genericptr_t, int, int, int *); 642. staticfn void split_clridx(int, int *, int *); 643. staticfn boolean is_ltgt_percentnumber(const char *); 644. staticfn boolean has_ltgt_percentnumber(const char *); 645. staticfn int splitsubfields(char *, char ***, int); 646. staticfn boolean is_fld_arrayvalues(const char *, const char *const *, 647. int, int, int *); 648. staticfn int query_arrayvalue(const char *, const char *const *, int, int); 649. staticfn void status_hilite_add_threshold(int, struct hilite_s *); 650. staticfn boolean parse_status_hl2(char (*)[QBUFSZ], boolean); 651. staticfn unsigned long query_conditions(void); 652. staticfn char *conditionbitmask2str(unsigned long); 653. staticfn unsigned long match_str2conditionbitmask(const char *); 654. staticfn unsigned long str2conditionbitmask(char *); 655. staticfn boolean parse_condition(char (*)[QBUFSZ], int); 656. staticfn char *hlattr2attrname(int, char *, size_t); 657. staticfn void status_hilite_linestr_add(int, struct hilite_s *, unsigned long, 658. const char *); 659. staticfn void status_hilite_linestr_done(void); 660. staticfn int status_hilite_linestr_countfield(int); 661. staticfn void status_hilite_linestr_gather_conditions(void); 662. staticfn void status_hilite_linestr_gather(void); 663. staticfn char *status_hilite2str(struct hilite_s *); 664. staticfn int status_hilite_menu_choose_field(void); 665. staticfn int status_hilite_menu_choose_behavior(int); 666. staticfn int status_hilite_menu_choose_updownboth(int, const char *, boolean, 667. boolean); 668. staticfn boolean status_hilite_menu_add(int); 669. staticfn boolean status_hilite_remove(int); 670. staticfn boolean status_hilite_menu_fld(int); 671. staticfn void status_hilites_viewall(void); 672. 673. #define has_hilite(i) (gb.blstats[0][(i)].thresholds) 674. /* TH_UPDOWN encompasses specific 'up' and 'down' also general 'changed' */ 675. #define Is_Temp_Hilite(rule) ((rule) && (rule)->behavior == BL_TH_UPDOWN) 676. 677. /* pointers to current hilite rule and list of this field's defined rules */ 678. #define INIT_THRESH , (struct hilite_s *) 0, (struct hilite_s *) 0 679. #else /* !STATUS_HILITES */ 680. #define INIT_THRESH /*empty*/ 681. #endif 682. 683. #define INIT_BLSTAT(name, fmtstr, anytyp, wid, fld) \ 684. { name, fmtstr, 0L, FALSE, FALSE, 0, anytyp, \ 685. { (genericptr_t) 0 }, { (genericptr_t) 0 }, (char *) 0, \ 686. wid, -1, fld INIT_THRESH } 687. #define INIT_BLSTATP(name, fmtstr, anytyp, wid, maxfld, fld) \ 688. { name, fmtstr, 0L, FALSE, TRUE, 0, anytyp, \ 689. { (genericptr_t) 0 }, { (genericptr_t) 0 }, (char *) 0, \ 690. wid, maxfld, fld INIT_THRESH } 691. 692. /* 693. * If entries are added to this, botl.h will require updating too. 694. * 695. * 'max' values of BL_XP and BL_EXP get special handling since the 696. * percentage involved isn't a direct 100*current/maximum calculation. 697. * 698. * long int fields are given a buffer size of 30 which is guaranteed to 699. * be big enough for short prefix followed by a 20+ digit 64-bit long 700. * even though the actual values will be much smaller. The gold field 701. * is even bigger due to its encoded dollar sign prefix. 702. */ 703. static struct istat_s initblstats[MAXBLSTATS] = { 704. INIT_BLSTAT("title", "%s", ANY_STR, MAXVALWIDTH, BL_TITLE), 705. INIT_BLSTAT("strength", " St:%s", ANY_INT, 10, BL_STR), 706. INIT_BLSTAT("dexterity", " Dx:%s", ANY_INT, 10, BL_DX), 707. INIT_BLSTAT("constitution", " Co:%s", ANY_INT, 10, BL_CO), 708. INIT_BLSTAT("intelligence", " In:%s", ANY_INT, 10, BL_IN), 709. INIT_BLSTAT("wisdom", " Wi:%s", ANY_INT, 10, BL_WI), 710. INIT_BLSTAT("charisma", " Ch:%s", ANY_INT, 10, BL_CH), 711. INIT_BLSTAT("alignment", " %s", ANY_STR, 20, BL_ALIGN), 712. INIT_BLSTAT("score", " S:%s", ANY_LONG, 30, BL_SCORE), 713. INIT_BLSTAT("carrying-capacity", " %s", ANY_INT, 20, BL_CAP), 714. INIT_BLSTAT("gold", " %s", ANY_LONG, 40, BL_GOLD), 715. INIT_BLSTATP("power", " Pw:%s", ANY_INT, 10, BL_ENEMAX, BL_ENE), 716. INIT_BLSTAT("power-max", "(%s)", ANY_INT, 10, BL_ENEMAX), 717. INIT_BLSTATP("experience-level", " Xp:%s", ANY_INT, 10, BL_EXP, BL_XP), 718. INIT_BLSTAT("armor-class", " AC:%s", ANY_INT, 10, BL_AC), 719. INIT_BLSTAT("HD", " HD:%s", ANY_INT, 10, BL_HD), 720. INIT_BLSTAT("time", " T:%s", ANY_LONG, 30, BL_TIME), 721. /* hunger used to be 'ANY_UINT'; see note below in bot_via_windowport() */ 722. INIT_BLSTAT("hunger", " %s", ANY_INT, 20, BL_HUNGER), 723. INIT_BLSTATP("hitpoints", " HP:%s", ANY_INT, 10, BL_HPMAX, BL_HP), 724. INIT_BLSTAT("hitpoints-max", "(%s)", ANY_INT, 10, BL_HPMAX), 725. INIT_BLSTAT("dungeon-level", "%s", ANY_STR, MAXVALWIDTH, BL_LEVELDESC), 726. INIT_BLSTATP("experience", "/%s", ANY_LONG, 30, BL_EXP, BL_EXP), 727. INIT_BLSTAT("condition", "%s", ANY_MASK32, 0, BL_CONDITION), 728. /* optional; once set it doesn't change unless 'showvers' option is 729. toggled or player modifies the 'versinfo' option; 730. available mostly for screenshots or someone looking over shoulder; 731. blstat[][BL_VERS] is actually an int copy of flags.versinfo (0...7) */ 732. INIT_BLSTAT("version", " %s", ANY_STR, MAXVALWIDTH, BL_VERS), 733. /* weapon and armor are constructed strings with no particular numeric 734. equivalent */ 735. INIT_BLSTAT("weapon", " %s", ANY_STR, 20, BL_WEAPON), 736. INIT_BLSTAT("armor", " %s", ANY_STR, 20, BL_ARMOR), 737. /* terrain is tracked by a number but designating it as type 'int' 738. isn't useful; using type 'string' allows highlighting based on text 739. matching which is potentially useful */ 740. INIT_BLSTAT("terrain", " %s", ANY_STR, 20, BL_TERRAIN), 741. }; 742. 743. #undef INIT_BLSTATP 744. #undef INIT_BLSTAT 745. #undef INIT_THRESH 746. 747. #ifdef STATUS_HILITES 748. 749. static const struct condmap condition_aliases[] = { 750. { "strangled", BL_MASK_STRNGL }, 751. { "all", BL_MASK_BAREH | BL_MASK_BLIND | BL_MASK_BUSY 752. | BL_MASK_CONF | BL_MASK_DEAF | BL_MASK_ELF_IRON 753. | BL_MASK_FLY | BL_MASK_FOODPOIS | BL_MASK_GLOWHANDS 754. | BL_MASK_GRAB | BL_MASK_HALLU | BL_MASK_HELD 755. | BL_MASK_ICY | BL_MASK_INLAVA | BL_MASK_LEV 756. | BL_MASK_PARLYZ | BL_MASK_RIDE | BL_MASK_SLEEPING 757. | BL_MASK_SLIME | BL_MASK_SLIPPERY | BL_MASK_STONE 758. | BL_MASK_STRNGL | BL_MASK_STUN | BL_MASK_SUBMERGED 759. | BL_MASK_TERMILL | BL_MASK_TETHERED 760. | BL_MASK_TRAPPED | BL_MASK_UNCONSC 761. | BL_MASK_WOUNDEDL | BL_MASK_HOLDING }, 762. { "major_troubles", BL_MASK_FOODPOIS | BL_MASK_GRAB | BL_MASK_INLAVA 763. | BL_MASK_SLIME | BL_MASK_STONE | BL_MASK_STRNGL 764. | BL_MASK_TERMILL }, 765. { "minor_troubles", BL_MASK_BLIND | BL_MASK_CONF | BL_MASK_DEAF 766. | BL_MASK_HALLU | BL_MASK_PARLYZ | BL_MASK_SUBMERGED 767. | BL_MASK_STUN }, 768. { "movement", BL_MASK_LEV | BL_MASK_FLY | BL_MASK_RIDE }, 769. { "opt_in", BL_MASK_BAREH | BL_MASK_BUSY | BL_MASK_GLOWHANDS 770. | BL_MASK_HELD | BL_MASK_ICY | BL_MASK_PARLYZ 771. | BL_MASK_SLEEPING | BL_MASK_SLIPPERY 772. | BL_MASK_SUBMERGED | BL_MASK_TETHERED 773. | BL_MASK_TRAPPED 774. | BL_MASK_UNCONSC | BL_MASK_WOUNDEDL 775. | BL_MASK_HOLDING }, 776. }; 777. 778. #endif /* STATUS_HILITES */ 779. 780. /* condition names and their abbreviations are used by windowport code */ 781. const struct conditions_t conditions[] = { 782. /* ranking, mask, identifier, txt1, txt2, txt3 */ 783. { 20, BL_MASK_BAREH, bl_bareh, { "Bare", "Bar", "Bh" } }, 784. { 10, BL_MASK_BLIND, bl_blind, { "Blind", "Blnd", "Bl" } }, 785. { 20, BL_MASK_BUSY, bl_busy, { "Busy", "Bsy", "By" } }, 786. { 10, BL_MASK_CONF, bl_conf, { "Conf", "Cnf", "Cf" } }, 787. { 10, BL_MASK_DEAF, bl_deaf, { "Deaf", "Def", "Df" } }, 788. { 15, BL_MASK_ELF_IRON, bl_elf_iron, { "Iron", "Irn", "Fe" } }, 789. { 10, BL_MASK_FLY, bl_fly, { "Fly", "Fly", "Fl" } }, 790. { 6, BL_MASK_FOODPOIS, bl_foodpois, { "FoodPois", "Fpois", "Poi" } }, 791. { 20, BL_MASK_GLOWHANDS, bl_glowhands, { "Glow", "Glo", "Gl" } }, 792. { 2, BL_MASK_GRAB, bl_grab, { "Grab", "Grb", "Gr" } }, 793. { 10, BL_MASK_HALLU, bl_hallu, { "Hallu", "Hal", "Hl" } }, 794. { 20, BL_MASK_HELD, bl_held, { "Held", "Hld", "Hd" } }, 795. { 20, BL_MASK_ICY, bl_icy, { "Icy", "Icy", "Ic" } }, 796. { 8, BL_MASK_INLAVA, bl_inlava, { "InLava", "Lav", "La" } }, 797. { 10, BL_MASK_LEV, bl_lev, { "Lev", "Lev", "Lv" } }, 798. { 20, BL_MASK_PARLYZ, bl_parlyz, { "Parlyz", "Para", "Par" } }, 799. { 10, BL_MASK_RIDE, bl_ride, { "Ride", "Rid", "Rd" } }, 800. { 20, BL_MASK_SLEEPING, bl_sleeping, { "Zzz", "Zzz", "Zz" } }, 801. { 6, BL_MASK_SLIME, bl_slime, { "Slime", "Slim", "Slm" } }, 802. { 20, BL_MASK_SLIPPERY, bl_slippery, { "Slip", "Slp", "Sl" } }, 803. { 6, BL_MASK_STONE, bl_stone, { "Stone", "Ston", "Sto" } }, 804. { 4, BL_MASK_STRNGL, bl_strngl, { "Strngl", "Stngl", "Str" } }, 805. { 10, BL_MASK_STUN, bl_stun, { "Stun", "Stun", "St" } }, 806. { 15, BL_MASK_SUBMERGED, bl_submerged, { "Submrg", "Subm", "Sm" } }, 807. { 6, BL_MASK_TERMILL, bl_termill, { "TermIll", "Ill", "Ill" } }, 808. { 20, BL_MASK_TETHERED, bl_tethered, { "Teth", "Tth", "Te" } }, 809. { 20, BL_MASK_TRAPPED, bl_trapped, { "Trap", "Trp", "Tr" } }, 810. { 20, BL_MASK_UNCONSC, bl_unconsc, { "Out", "Out", "KO" } }, 811. { 20, BL_MASK_WOUNDEDL, bl_woundedl, { "WLegs", "Leg", "Lg" } }, 812. { 20, BL_MASK_HOLDING, bl_holding, { "UHold", "UHld", "UHd" } }, 813. }; 814. 815. /* [perhaps these should all be opt_out with default of 'in'; 816. otherwise some players may never learn about them] */ 817. struct condtests_t condtests[CONDITION_COUNT] = { 818. /* id, useropt, opt_in or out, enabled, configchoice, testresult; 819. default value for enabled is !opt_in but can get changed via options */ 820. { bl_bareh, "barehanded", opt_in, FALSE, FALSE, FALSE }, 821. { bl_blind, "blind", opt_out, TRUE, FALSE, FALSE }, 822. { bl_busy, "busy", opt_in, FALSE, FALSE, FALSE }, 823. { bl_conf, "conf", opt_out, TRUE, FALSE, FALSE }, 824. { bl_deaf, "deaf", opt_out, TRUE, FALSE, FALSE }, 825. { bl_elf_iron, "iron", opt_out, TRUE, FALSE, FALSE }, 826. { bl_fly, "fly", opt_out, TRUE, FALSE, FALSE }, 827. { bl_foodpois, "foodPois", opt_out, TRUE, FALSE, FALSE }, 828. { bl_glowhands, "glowhands", opt_in, FALSE, FALSE, FALSE }, 829. { bl_grab, "grab", opt_out, TRUE, FALSE, FALSE }, 830. { bl_hallu, "hallucinat", opt_out, TRUE, FALSE, FALSE }, 831. { bl_held, "held", opt_in, FALSE, FALSE, FALSE }, 832. { bl_icy, "ice", opt_in, FALSE, FALSE, FALSE }, 833. { bl_inlava, "lava", opt_out, TRUE, FALSE, FALSE }, 834. { bl_lev, "levitate", opt_out, TRUE, FALSE, FALSE }, 835. { bl_parlyz, "paralyzed", opt_in, FALSE, FALSE, FALSE }, 836. { bl_ride, "ride", opt_out, TRUE, FALSE, FALSE }, 837. { bl_sleeping, "sleep", opt_in, FALSE, FALSE, FALSE }, 838. { bl_slime, "slime", opt_out, TRUE, FALSE, FALSE }, 839. { bl_slippery, "slip", opt_in, FALSE, FALSE, FALSE }, 840. { bl_stone, "stone", opt_out, TRUE, FALSE, FALSE }, 841. { bl_strngl, "strngl", opt_out, TRUE, FALSE, FALSE }, 842. { bl_stun, "stun", opt_out, TRUE, FALSE, FALSE }, 843. { bl_submerged, "submerged", opt_in, FALSE, FALSE, FALSE }, 844. { bl_termill, "termIll", opt_out, TRUE, FALSE, FALSE }, 845. { bl_tethered, "tethered", opt_in, FALSE, FALSE, FALSE }, 846. { bl_trapped, "trap", opt_in, FALSE, FALSE, FALSE }, 847. { bl_unconsc, "unconscious", opt_in, FALSE, FALSE, FALSE }, 848. { bl_woundedl, "woundedlegs", opt_in, FALSE, FALSE, FALSE }, 849. { bl_holding, "holding", opt_in, FALSE, FALSE, FALSE }, 850. }; 851. /* condition indexing */ 852. int cond_idx[CONDITION_COUNT] = { 0 }; 853. 854. static const char c_Wall[] = "Wall"; 855. /* 856. * Terrain descriptions for flags.terrainstatus; simplified from 857. * def_syms[].name and indexed by iflags.terrain_typ; should be 858. * kept in sync with rm.h types and the first half of def_syms[]. 859. * The extra pseudo-types are specified by classify_terrain() 860. * when it sets up iflags.terrain_typ. Walls and a few of the 861. * others can only occur when hero has the Passes_walls ability. 862. */ 863. const char *terrain_descr[] = { 864. /* 0*/ "Stone", /* stone */ 865. c_Wall, /* vwall */ 866. c_Wall, /* hwall */ 867. c_Wall, /* tlcorner */ 868. c_Wall, /* trcorner */ 869. c_Wall, /* blcorner */ 870. c_Wall, /* brcorner */ 871. c_Wall, /* crosswall */ 872. c_Wall, /* tuwall */ 873. c_Wall, /* tdwall */ 874. /*10*/ c_Wall, /* tlwall */ 875. c_Wall, /* trwall */ 876. "Portcullis", /* dbwall, closed drawbridge 'door' */ 877. "Tree", 878. c_Wall, /* sdoor: secret door */ 879. "Stone", /* scorr: secret corridor */ 880. "Pool", /* pool or non-moat water; can be boiled away */ 881. "Moat", /* water that can't be boiled away */ 882. "Water", /* water on Water level; can't be boiled or frozen */ 883. "(gap)", /* drawbridge_up; replaced by whatever is under */ 884. /*20*/ "Lava", /* lavapool */ 885. "LavaWall", /* lava that extends to ceiling */ 886. "Bars", /* ironbars */ 887. "Doorway", /* doorless or broken door; diagonal movement is ok */ 888. "Corridor", /* replaced by "Floor" */ 889. "Room", /* also replaced by "Floor" */ 890. "Stairs", 891. "Ladder", 892. "Fountain", 893. "Throne", 894. /*30*/ "Sink", 895. "Grave", 896. "Altar", 897. "Ice", 898. "Bridge", /* drawbridge_down, span across moat/ice/lava/floor */ 899. "Air", /* open air on Air level or bubble on Water level */ 900. "Cloud", /* [part of] a cloud or Air level */ 901. /* 902. */ 903. /*37*/ "", /* MAX_TYPE; skipped ratther than overloaded */ 904. /*38*/ c_Wall, /* MATCH_WALL for special levels; shouldn't happen */ 905. /* 906. * additional terrain names that aren't simple levl[][].typ values 907. */ 908. /*39*/ "Floor", /* substituted for room or corridor */ 909. /*40*/ "Ground", /* 'room' on Earth level */ 910. "Open-door", /* open (not broken or doorless) */ 911. "Shut-door", /* closed or locked (or trapped) */ 912. "Swamp", /* Juiblex level */ 913. "Submerged", /* under water */ 914. "Sea", /* moat terrain on Medusa's level: "shallow sea" */ 915. "WaterWall", /* water that extends to the ceiling */ 916. }; 917. 918. /* cache-related */ 919. static boolean cache_avail[3] = { FALSE, FALSE, FALSE }; 920. static boolean cache_reslt[3] = { FALSE, FALSE, FALSE }; 921. static const char *cache_nomovemsg = NULL, *cache_multi_reason = NULL; 922. 923. #define cond_cache_prepA() \ 924. do { \ 925. boolean clear_cache = FALSE, refresh_cache = FALSE; \ 926. \ 927. if (gm.multi < 0) { \ 928. if (gn.nomovemsg || gm.multi_reason) { \ 929. if (cache_nomovemsg != gn.nomovemsg) \ 930. refresh_cache = TRUE; \ 931. if (cache_multi_reason != gm.multi_reason) \ 932. refresh_cache = TRUE; \ 933. } else { \ 934. clear_cache = TRUE; \ 935. } \ 936. } else { \ 937. clear_cache = TRUE; \ 938. } \ 939. if (clear_cache) { \ 940. cache_nomovemsg = (const char *) 0; \ 941. cache_multi_reason = (const char *) 0; \ 942. } \ 943. if (refresh_cache) { \ 944. cache_nomovemsg = gn.nomovemsg; \ 945. cache_multi_reason = gm.multi_reason; \ 946. } \ 947. if (clear_cache || refresh_cache) { \ 948. cache_reslt[0] = cache_avail[0] = FALSE; \ 949. cache_reslt[1] = cache_avail[1] = FALSE; \ 950. } \ 951. } while (0) 952. 953. /* we don't put this next declaration in #ifdef STATUS_HILITES. 954. * In the absence of STATUS_HILITES, each array 955. * element will be 0 however, and quite meaningless, 956. * but we need to pass the first array element as 957. * the final argument of status_update, with or 958. * without STATUS_HILITES. 959. */ 960. 961. staticfn void 962. bot_via_windowport(void) 963. { 964. char buf[BUFSZ]; 965. const char *titl; 966. char *nb; 967. int i, idx, cap; 968. long money; 969. 970. if (!gb.blinit) 971. panic("bot before init."); 972. 973. /* toggle from previous iteration */ 974. idx = 1 - gn.now_or_before_idx; /* 0 -> 1, 1 -> 0 */ 975. gn.now_or_before_idx = idx; 976. 977. /* clear the "value set" indicators */ 978. (void) memset((genericptr_t) gv.valset, 0, MAXBLSTATS * sizeof (boolean)); 979. 980. /* 981. * Note: min(x,9999) - we enforce the same maximum on hp, maxhp, 982. * pw, maxpw, and gold as basic status formatting so that the two 983. * modes of status display don't produce different information. 984. */ 985. 986. /* 987. * Player name and title. 988. */ 989. Strcpy(nb = buf, svp.plname); 990. nb[0] = highc(nb[0]); 991. titl = !Upolyd ? rank() : pmname(&mons[u.umonnum], Ugender); 992. i = (int) (strlen(buf) + sizeof " the " + strlen(titl) - sizeof ""); 993. /* if "Name the Rank/monster" is too long, we truncate the name but 994. always keep at least BOTL_NSIZ characters of it; when hitpointbar is 995. enabled, anything beyond 30 (long monster name) will be truncated */ 996. if (i > 30) { 997. i = 30 - (int) (sizeof " the " + strlen(titl) - sizeof ""); 998. nb[max(i, BOTL_NSIZ)] = '\0'; 999. } 1000. Strcpy(nb = eos(nb), " the "); 1001. Strcpy(nb = eos(nb), titl); 1002. if (Upolyd) { /* when poly'd, capitalize monster name */ 1003. for (i = 0; nb[i]; i++) 1004. if (i == 0 || nb[i - 1] == ' ') 1005. nb[i] = highc(nb[i]); 1006. } 1007. Sprintf(gb.blstats[idx][BL_TITLE].val, "%-30s", buf); 1008. gv.valset[BL_TITLE] = TRUE; /* indicate val already set */ 1009. 1010. /* Strength */ 1011. gb.blstats[idx][BL_STR].a.a_int = ACURR(A_STR); 1012. Strcpy(gb.blstats[idx][BL_STR].val, get_strength_str()); 1013. gv.valset[BL_STR] = TRUE; /* indicate val already set */ 1014. 1015. /* Dexterity, constitution, intelligence, wisdom, charisma. */ 1016. gb.blstats[idx][BL_DX].a.a_int = ACURR(A_DEX); 1017. gb.blstats[idx][BL_CO].a.a_int = ACURR(A_CON); 1018. gb.blstats[idx][BL_IN].a.a_int = ACURR(A_INT); 1019. gb.blstats[idx][BL_WI].a.a_int = ACURR(A_WIS); 1020. gb.blstats[idx][BL_CH].a.a_int = ACURR(A_CHA); 1021. 1022. /* Alignment */ 1023. Strcpy(gb.blstats[idx][BL_ALIGN].val, (u.ualign.type == A_CHAOTIC) 1024. ? "Chaotic" 1025. : (u.ualign.type == A_NEUTRAL) 1026. ? "Neutral" 1027. : "Lawful"); 1028. 1029. /* Score */ 1030. gb.blstats[idx][BL_SCORE].a.a_long = 1031. #ifdef SCORE_ON_BOTL 1032. flags.showscore ? botl_score() : 1033. #endif 1034. 0L; 1035. 1036. /* Hit points */ 1037. i = Upolyd ? u.mh : u.uhp; 1038. if (i < 0) /* gameover sets u.uhp to -1 */ 1039. i = 0; 1040. gb.blstats[idx][BL_HP].rawval.a_int = i; 1041. gb.blstats[idx][BL_HP].a.a_int = min(i, 9999); 1042. i = Upolyd ? u.mhmax : u.uhpmax; 1043. gb.blstats[idx][BL_HPMAX].rawval.a_int = i; 1044. gb.blstats[idx][BL_HPMAX].a.a_int = min(i, 9999); 1045. 1046. /* Dungeon level. */ 1047. (void) describe_level(gb.blstats[idx][BL_LEVELDESC].val, 1); 1048. gv.valset[BL_LEVELDESC] = TRUE; /* indicate val already set */ 1049. 1050. /* Gold */ 1051. if ((money = money_cnt(gi.invent)) < 0L) 1052. money = 0L; /* ought to issue impossible() and then discard gold */ 1053. gb.blstats[idx][BL_GOLD].rawval.a_long = money; 1054. gb.blstats[idx][BL_GOLD].a.a_long = min(money, 999999L); 1055. /* 1056. * The tty port needs to display the current symbol for gold 1057. * as a field header, so to accommodate that we pass gold with 1058. * that already included. If a window port needs to use the text 1059. * gold amount without the leading "$:" the port will have to 1060. * skip past ':' to the value pointer it was passed in status_update() 1061. * for the BL_GOLD case. 1062. * 1063. * Another quirk of BL_GOLD is that the field display may have 1064. * changed if a new symbol set was loaded, or we entered or left 1065. * the rogue level. 1066. * 1067. * The currency prefix is encoded as ten character \GXXXXNNNN 1068. * sequence. 1069. */ 1070. Sprintf(gb.blstats[idx][BL_GOLD].val, "%s:%ld", 1071. (iflags.in_dumplog || iflags.invis_goldsym) ? "$" 1072. : encglyph(objnum_to_glyph(GOLD_PIECE)), 1073. gb.blstats[idx][BL_GOLD].a.a_long); 1074. gv.valset[BL_GOLD] = TRUE; /* indicate val already set */ 1075. 1076. /* Power (magical energy) */ 1077. gb.blstats[idx][BL_ENE].rawval.a_int = u.uen; 1078. gb.blstats[idx][BL_ENE].a.a_int = min(u.uen, 9999); 1079. gb.blstats[idx][BL_ENEMAX].rawval.a_int = u.uenmax; 1080. gb.blstats[idx][BL_ENEMAX].a.a_int = min(u.uenmax, 9999); 1081. 1082. /* Armor class */ 1083. gb.blstats[idx][BL_AC].a.a_int = u.uac; 1084. 1085. /* Monster level (if Upolyd) */ 1086. gb.blstats[idx][BL_HD].a.a_int = Upolyd ? (int) mons[u.umonnum].mlevel : 0; 1087. 1088. /* Experience */ 1089. gb.blstats[idx][BL_XP].a.a_int = u.ulevel; 1090. gb.blstats[idx][BL_EXP].a.a_long = u.uexp; 1091. 1092. /* Time (moves) */ 1093. gb.blstats[idx][BL_TIME].a.a_long = svm.moves; 1094. 1095. /* Hunger */ 1096. /* note: u.uhs is unsigned, and 3.6.1's STATUS_HILITE defined 1097. BL_HUNGER to be ANY_UINT, but that was the only non-int/non-long 1098. numeric field so it's far simpler to treat it as plain int and 1099. not need ANY_UINT handling at all */ 1100. gb.blstats[idx][BL_HUNGER].a.a_int = (int) u.uhs; 1101. Strcpy(gb.blstats[idx][BL_HUNGER].val, 1102. (u.uhs != NOT_HUNGRY) ? hu_stat[u.uhs] : ""); 1103. gv.valset[BL_HUNGER] = TRUE; 1104. 1105. /* Carrying capacity */ 1106. cap = near_capacity(); 1107. gb.blstats[idx][BL_CAP].a.a_int = cap; 1108. Strcpy(gb.blstats[idx][BL_CAP].val, 1109. (cap > UNENCUMBERED) ? enc_stat[cap] : ""); 1110. gv.valset[BL_CAP] = TRUE; 1111. 1112. /* Version; unchanging unless player toggles 'showvers' option or 1113. modifies 'versinfo' option; toggling showvers off will clear it */ 1114. if (gb.blstats[idx][BL_VERS].a.a_int != (int) flags.versinfo) { 1115. gb.blstats[idx][BL_VERS].a.a_int = (int) flags.versinfo; 1116. gv.valset[BL_VERS] = FALSE; 1117. } 1118. if (!gv.valset[BL_VERS]) { 1119. (void) status_version(gb.blstats[idx][BL_VERS].val, 1120. gb.blstats[idx][BL_VERS].valwidth, FALSE); 1121. gv.valset[BL_VERS] = TRUE; 1122. } 1123. 1124. /* Conditions */ 1125. 1126. gb.blstats[idx][BL_CONDITION].a.a_ulong = 0L; 1127. 1128. /* 1129. * Avoid anything that does string comparisons in here because this 1130. * is called *extremely* often, for every screen update and the same 1131. * string comparisons would be repeated, thus contributing toward 1132. * performance degradation. If it is essential that string comparisons 1133. * are needed for a particular condition, consider adding a caching 1134. * mechanism to limit the string comparisons to the first occurrence 1135. * for that cache lifetime. There is caching of that nature done for 1136. * unconsc (1) and parlyz (2) because the suggested way of being able 1137. * to distinguish unconsc, parlyz, sleeping, and busy involves multiple 1138. * string comparisons. 1139. * 1140. * [Rebuttal: it's called a lot for Windows and MS-DOS because their 1141. * sample run-time configuration file enables 'time' (move counter). 1142. * The optimization to bypass full status update when only 'time' 1143. * has changed (via timebot(), only effective for VIA_WINDOWPORT() 1144. * configurations) should ameliorate that.] 1145. */ 1146. 1147. #define test_if_enabled(c) if (condtests[(c)].enabled) condtests[(c)].test 1148. 1149. condtests[bl_foodpois].test = condtests[bl_termill].test = FALSE; 1150. if (Sick) { 1151. test_if_enabled(bl_foodpois) = (u.usick_type & SICK_VOMITABLE) != 0; 1152. test_if_enabled(bl_termill) = (u.usick_type & SICK_NONVOMITABLE) != 0; 1153. } 1154. condtests[bl_inlava].test = condtests[bl_tethered].test 1155. = condtests[bl_trapped].test = FALSE; 1156. if (u.utrap) { 1157. test_if_enabled(bl_inlava) = (u.utraptype == TT_LAVA); 1158. test_if_enabled(bl_tethered) = (u.utraptype == TT_BURIEDBALL); 1159. /* if in-lava or tethered is disabled and the condition applies, 1160. lump it in with trapped */ 1161. test_if_enabled(bl_trapped) = (!condtests[bl_inlava].test 1162. && !condtests[bl_tethered].test); 1163. } 1164. condtests[bl_grab].test = condtests[bl_held].test 1165. #if 0 1166. = condtests[bl_engulfed].test 1167. #endif 1168. = condtests[bl_holding].test = FALSE; 1169. if (u.ustuck) { 1170. /* it is possible for a hero in sticks() form to be swallowed, 1171. so swallowed needs to be checked first; it is not possible for 1172. a hero in sticks() form to be held--sticky hero does the holding 1173. even if u.ustuck is also a holder */ 1174. if (u.uswallow) { 1175. /* engulfed/swallowed isn't currently a tracked status condition; 1176. "held" might look odd for it but seems better than blank */ 1177. #if 0 1178. test_if_enabled(bl_engulfed) = TRUE; 1179. #else 1180. test_if_enabled(bl_held) = TRUE; 1181. #endif 1182. } else if (Upolyd && sticks(gy.youmonst.data)) { 1183. test_if_enabled(bl_holding) = TRUE; 1184. } else { 1185. /* grab == hero is held by sea monster and about to be drowned; 1186. held == hero is held by something else and can't move away */ 1187. test_if_enabled(bl_grab) = (u.ustuck->data->mlet == S_EEL); 1188. test_if_enabled(bl_held) = !condtests[bl_grab].test; 1189. } 1190. } 1191. condtests[bl_blind].test = (Blind) ? TRUE : FALSE; 1192. condtests[bl_conf].test = (Confusion) ? TRUE : FALSE; 1193. condtests[bl_deaf].test = (Deaf) ? TRUE : FALSE; 1194. condtests[bl_fly].test = (Flying) ? TRUE : FALSE; 1195. condtests[bl_glowhands].test = (u.umconf) ? TRUE : FALSE; 1196. condtests[bl_hallu].test = (Hallucination) ? TRUE : FALSE; 1197. condtests[bl_lev].test = (Levitation) ? TRUE : FALSE; 1198. condtests[bl_ride].test = (u.usteed) ? TRUE : FALSE; 1199. condtests[bl_slime].test = (Slimed) ? TRUE : FALSE; 1200. condtests[bl_stone].test = (Stoned) ? TRUE : FALSE; 1201. condtests[bl_strngl].test = (Strangled) ? TRUE : FALSE; 1202. condtests[bl_stun].test = (Stunned) ? TRUE : FALSE; 1203. condtests[bl_submerged].test = (Underwater) ? TRUE : FALSE; 1204. test_if_enabled(bl_elf_iron) = (FALSE); 1205. test_if_enabled(bl_bareh) = (!uarmg && !uwep); 1206. test_if_enabled(bl_icy) = (levl[u.ux][u.uy].typ == ICE); 1207. test_if_enabled(bl_slippery) = (Glib) ? TRUE : FALSE; 1208. test_if_enabled(bl_woundedl) = (Wounded_legs) ? TRUE : FALSE; 1209. 1210. if (gm.multi < 0) { 1211. cond_cache_prepA(); 1212. if (condtests[bl_unconsc].enabled 1213. && cache_nomovemsg && !cache_avail[0]) { 1214. cache_reslt[0] = (!u.usleep && unconscious()); 1215. cache_avail[0] = TRUE; 1216. } 1217. if (condtests[bl_parlyz].enabled 1218. && cache_multi_reason && !cache_avail[1]) { 1219. cache_reslt[1] = (!strncmp(cache_multi_reason, "paralyzed", 9) 1220. || !strncmp(cache_multi_reason, "frozen", 6)); 1221. cache_avail[1] = TRUE; 1222. } 1223. if (cache_avail[0] && cache_reslt[0]) { 1224. condtests[bl_unconsc].test = cache_reslt[0]; 1225. } else if (cache_avail[1] && cache_reslt[1]) { 1226. condtests[bl_parlyz].test = cache_reslt[1]; 1227. } else if (condtests[bl_sleeping].enabled && u.usleep) { 1228. condtests[bl_sleeping].test = TRUE; 1229. } else if (condtests[bl_busy].enabled) { 1230. condtests[bl_busy].test = TRUE; 1231. } 1232. } else { 1233. condtests[bl_unconsc].test = condtests[bl_parlyz].test = 1234. condtests[bl_sleeping].test = condtests[bl_busy].test = FALSE; 1235. } 1236. 1237. #define cond_setbit(c) \ 1238. gb.blstats[idx][BL_CONDITION].a.a_ulong |= conditions[(c)].mask 1239. 1240. for (i = 0; i < CONDITION_COUNT; ++i) { 1241. if (condtests[i].enabled 1242. /* && i != bl_holding */ /* uncomment to suppress UHold */ 1243. && condtests[i].test) 1244. cond_setbit(i); 1245. } 1246. #undef cond_bitset 1247. 1248. /* 1249. * Optionally displayed weapon(s), armor, and terrain. 1250. */ 1251. if (flags.weaponstatus) 1252. (void) weapon_status(gb.blstats[idx][BL_WEAPON].val); 1253. else 1254. *gb.blstats[idx][BL_WEAPON].val = '\0'; 1255. 1256. if (flags.armorstatus) 1257. (void) armor_status(gb.blstats[idx][BL_ARMOR].val); 1258. else 1259. *gb.blstats[idx][BL_ARMOR].val = '\0'; 1260. 1261. if (flags.terrainstatus) { 1262. if (iflags.terrain_typ == MAX_TYPE) 1263. classify_terrain(); 1264. i = iflags.terrain_typ; 1265. if (gb.blstats[idx][BL_TERRAIN].a.a_int != i) { 1266. Strcpy(gb.blstats[idx][BL_TERRAIN].val, terrain_descr[i]); 1267. gb.blstats[idx][BL_TERRAIN].a.a_int = i; 1268. } 1269. } else { 1270. *gb.blstats[idx][BL_TERRAIN].val = '\0'; 1271. /* MAX_TYPE is "none of the above" for levl[][].typ */ 1272. gb.blstats[idx][BL_TERRAIN].a.a_int = MAX_TYPE; 1273. } 1274. gv.valset[BL_TERRAIN] = TRUE; 1275. 1276. /* now request rendering */ 1277. evaluate_and_notify_windowport(gv.valset, idx); 1278. #undef test_if_enabled 1279. } 1280. 1281. #undef cond_cache_prepA 1282. 1283. /* update just the status lines' 'time' field */ 1284. staticfn void 1285. stat_update_time(void) 1286. { 1287. int idx = gn.now_or_before_idx; /* no 0/1 toggle */ 1288. int fld = BL_TIME; 1289. 1290. /* Time (moves) */ 1291. gb.blstats[idx][fld].a.a_long = svm.moves; 1292. gv.valset[fld] = FALSE; 1293. 1294. eval_notify_windowport_field(fld, gv.valset, idx); 1295. if ((windowprocs.wincap2 & WC2_FLUSH_STATUS) != 0L) 1296. status_update(BL_FLUSH, (genericptr_t) 0, 0, 0, 1297. NO_COLOR, (unsigned long *) 0); 1298. return; 1299. } 1300. 1301. /* deal with player's choice to change processing of a condition */ 1302. void 1303. condopt(int idx, boolean *addr, boolean negated) 1304. { 1305. int i; 1306. 1307. /* sanity check */ 1308. if ((idx < 0 || idx >= CONDITION_COUNT) 1309. || (addr && addr != &condtests[idx].choice)) 1310. return; 1311. 1312. if (!addr) { 1313. /* special: indicates a request to init so 1314. set the choice values to match the defaults */ 1315. gc.condmenu_sortorder = 0; 1316. for (i = 0; i < CONDITION_COUNT; ++i) { 1317. cond_idx[i] = i; 1318. condtests[i].choice = condtests[i].enabled; 1319. } 1320. qsort((genericptr_t) cond_idx, CONDITION_COUNT, 1321. sizeof cond_idx[0], cond_cmp); 1322. } else { 1323. /* (addr == &condtests[idx].choice) */ 1324. condtests[idx].enabled = negated ? FALSE : TRUE; 1325. condtests[idx].choice = condtests[idx].enabled; 1326. /* avoid lingering false positives if test is no longer run */ 1327. condtests[idx].test = FALSE; 1328. } 1329. } 1330. 1331. /* qsort callback routine for sorting the condition index */ 1332. staticfn int QSORTCALLBACK 1333. cond_cmp(const genericptr vptr1, const genericptr vptr2) 1334. { 1335. int indx1 = *(int *) vptr1, indx2 = *(int *) vptr2, 1336. c1 = conditions[indx1].ranking, c2 = conditions[indx2].ranking; 1337. 1338. if (c1 != c2) 1339. return c1 - c2; 1340. /* tie-breaker - visible alpha by name */ 1341. return strcmpi(condtests[indx1].useroption, condtests[indx2].useroption); 1342. } 1343. 1344. /* qsort callback routine for alphabetical sorting of index */ 1345. staticfn int QSORTCALLBACK 1346. menualpha_cmp(const genericptr vptr1, const genericptr vptr2) 1347. { 1348. int indx1 = *(int *) vptr1, indx2 = *(int *) vptr2; 1349. 1350. return strcmpi(condtests[indx1].useroption, condtests[indx2].useroption); 1351. } 1352. 1353. int 1354. parse_cond_option(boolean negated, char *opts) 1355. { 1356. int i, sl; 1357. const char *compareto, *uniqpart, prefix[] = "cond_"; 1358. 1359. if (!opts || strlen(opts) <= sizeof prefix - 1) 1360. return 2; 1361. uniqpart = opts + (sizeof prefix - 1); 1362. for (i = 0; i < CONDITION_COUNT; ++i) { 1363. compareto = condtests[i].useroption; 1364. sl = Strlen(compareto); 1365. if (match_optname(uniqpart, compareto, (sl >= 4) ? 4 : sl, FALSE)) { 1366. condopt(i, &condtests[i].choice, negated); 1367. return 0; 1368. } 1369. } 1370. return 1; /* !0 indicates error */ 1371. } 1372. 1373. /* display a menu of all available status condition options and let player 1374. toggled them on or off; returns True iff any changes are made */ 1375. boolean 1376. cond_menu(void) 1377. { 1378. static const char *const menutitle[2] = { 1379. "alphabetically", "by ranking" 1380. }; 1381. int i, res, idx = 0; 1382. int sequence[CONDITION_COUNT]; 1383. winid tmpwin; 1384. anything any; 1385. menu_item *picks = (menu_item *) 0; 1386. char mbuf[QBUFSZ]; 1387. boolean showmenu = TRUE; 1388. int clr = NO_COLOR; 1389. boolean changed = FALSE; 1390. 1391. do { 1392. for (i = 0; i < CONDITION_COUNT; ++i) { 1393. sequence[i] = i; 1394. } 1395. qsort((genericptr_t) sequence, CONDITION_COUNT, 1396. sizeof sequence[0], 1397. (gc.condmenu_sortorder) ? cond_cmp : menualpha_cmp); 1398. 1399. tmpwin = create_nhwindow(NHW_MENU); 1400. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 1401. 1402. any = cg.zeroany; 1403. any.a_int = 1; 1404. Sprintf(mbuf, "change sort order from \"%s\" to \"%s\"", 1405. menutitle[gc.condmenu_sortorder], 1406. menutitle[1 - gc.condmenu_sortorder]); 1407. add_menu(tmpwin, &nul_glyphinfo, &any, 'S', 0, ATR_NONE, 1408. clr, mbuf, MENU_ITEMFLAGS_SKIPINVERT); 1409. any = cg.zeroany; 1410. Sprintf(mbuf, "sorted %s", menutitle[gc.condmenu_sortorder]); 1411. add_menu_heading(tmpwin, mbuf); 1412. for (i = 0; i < SIZE(condtests); i++) { 1413. idx = sequence[i]; 1414. Sprintf(mbuf, "cond_%-14s", condtests[idx].useroption); 1415. any = cg.zeroany; 1416. any.a_int = idx + 2; /* avoid zero and the sort change pick */ 1417. condtests[idx].choice = FALSE; 1418. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, mbuf, 1419. condtests[idx].enabled 1420. ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE); 1421. } 1422. 1423. end_menu(tmpwin, "Choose status conditions to toggle"); 1424. 1425. res = select_menu(tmpwin, PICK_ANY, &picks); 1426. destroy_nhwindow(tmpwin); 1427. showmenu = FALSE; 1428. if (res > 0) { 1429. for (i = 0; i < res; i++) { 1430. idx = picks[i].item.a_int; 1431. if (idx == 1) { 1432. /* sort change requested */ 1433. gc.condmenu_sortorder = 1 - gc.condmenu_sortorder; 1434. showmenu = TRUE; 1435. break; /* for loop */ 1436. } else { 1437. idx -= 2; 1438. condtests[idx].choice = TRUE; 1439. } 1440. } 1441. free((genericptr_t) picks); 1442. } 1443. } while (showmenu); 1444. 1445. if (res >= 0) { 1446. for (i = 0; i < CONDITION_COUNT; ++i) 1447. if (condtests[i].enabled != condtests[i].choice) { 1448. condtests[i].enabled = condtests[i].choice; 1449. condtests[idx].test = FALSE; 1450. disp.botl = changed = TRUE; 1451. } 1452. } 1453. return changed; 1454. } 1455. 1456. /* called by all_options_conds() to get value for next cond_xyz option 1457. so that #saveoptions can collect it and write the set into new RC file. 1458. returns zero-length string if the option is the default value. */ 1459. boolean 1460. opt_next_cond(int indx, char *outbuf) 1461. { 1462. *outbuf = '\0'; 1463. if (indx >= CONDITION_COUNT) 1464. return FALSE; 1465. 1466. /* 1467. * The entries are returned in internal order which requires the 1468. * least code. It would be easy to sort them into alphabetic order 1469. * (just sort all over again for every requested entry: 1470. * int i, sequence[CONDITION_COUNT] 1471. * for (i = 0; i < CONDITION_COUNT; ++i) sequence[i] = i; 1472. * qsort(sequence, ..., menualpha_cmp); 1473. * indx = sequence[indx]; 1474. * Sprintf(outbuf, ...); 1475. * with no need to hang on to 'sequence[]' between calls). 1476. * 1477. * But using 'severity order' isn't feasible unless the player has 1478. * used 'mO' on conditions in this session. Even then, they would 1479. * revert to the default order (whether internal or alphabetical) 1480. * if #saveoptions got used in some later session where doset() 1481. * wasn't used to choose their preferred order. 1482. */ 1483. 1484. if ((condtests[indx].opt == opt_in && condtests[indx].enabled) 1485. || (condtests[indx].opt == opt_out && !condtests[indx].enabled)) { 1486. Sprintf(outbuf, "%scond_%s", condtests[indx].enabled ? "" : "!", 1487. condtests[indx].useroption); 1488. } 1489. return TRUE; 1490. } 1491. 1492. staticfn boolean 1493. eval_notify_windowport_field( 1494. int fld, 1495. boolean *valsetlist, 1496. int idx) 1497. { 1498. static int oldrndencode = 0; 1499. static nhsym oldgoldsym = 0; 1500. int pc, chg, color = NO_COLOR; 1501. unsigned anytype; 1502. boolean updated = FALSE, reset; 1503. struct istat_s *curr, *prev; 1504. enum statusfields fldmax; 1505. 1506. /* 1507. * Now pass the changed values to window port. 1508. */ 1509. anytype = gb.blstats[idx][fld].anytype; 1510. curr = &gb.blstats[idx][fld]; 1511. prev = &gb.blstats[1 - idx][fld]; 1512. color = NO_COLOR; 1513. 1514. chg = gu.update_all ? 0 : compare_blstats(prev, curr); 1515. /* 1516. * TODO: 1517. * Dynamically update 'percent_matters' as rules are added or 1518. * removed to track whether any of them are percentage rules. 1519. * Then there'll be no need to assume that non-Null 'thresholds' 1520. * means that percentages need to be kept up to date. 1521. * [Affects exp_percent_changing() too.] 1522. */ 1523. if (((chg || gu.update_all || fld == BL_XP) 1524. && curr->percent_matters 1525. #ifdef STATUS_HILITES 1526. && curr->thresholds 1527. #endif 1528. ) 1529. /* when 'hitpointbar' is On, percent matters even if HP 1530. hasn't changed and has no percentage rules (in case HPmax 1531. has changed when HP hasn't, where we ordinarily wouldn't 1532. update HP so would miss an update of the hitpoint bar) */ 1533. || (fld == BL_HP && iflags.wc2_hitpointbar)) { 1534. fldmax = curr->idxmax; 1535. pc = (fldmax == BL_EXP) ? exp_percentage() 1536. : (fldmax >= 0 && fldmax < MAXBLSTATS) 1537. ? percentage(curr, &gb.blstats[idx][fldmax]) 1538. : 0; /* bullet proofing; can't get here */ 1539. if (pc != prev->percent_value) 1540. chg = (pc < prev->percent_value) ? -1 : 1; 1541. curr->percent_value = pc; 1542. } else { 1543. pc = 0; 1544. } 1545. 1546. /* Temporary? hack: moveloop()'s prolog for a new game sets 1547. * svc.context.rndencode after the status window has been init'd, 1548. * so $:0 has already been encoded and cached by the window 1549. * port. Without this hack, gold's \G sequence won't be 1550. * recognized and ends up being displayed as-is for 'gu.update_all'. 1551. * 1552. * Also, even if svc.context.rndencode hasn't changed and the 1553. * gold amount itself hasn't changed, the glyph portion of the 1554. * encoding may have changed if a new symset was put into effect. 1555. * 1556. * \GXXXXNNNN:25 1557. * XXXX = the svc.context.rndencode portion 1558. * NNNN = the glyph portion 1559. * 25 = the gold amount 1560. * 1561. * Setting 'chg = 2' is enough to render the field properly, but 1562. * not to honor an initial highlight, so force 'gu.update_all = TRUE'. 1563. */ 1564. if (fld == BL_GOLD 1565. && (svc.context.rndencode != oldrndencode 1566. || gs.showsyms[COIN_CLASS + SYM_OFF_O] != oldgoldsym)) { 1567. gu.update_all = TRUE; /* chg = 2; */ 1568. oldrndencode = svc.context.rndencode; 1569. oldgoldsym = gs.showsyms[COIN_CLASS + SYM_OFF_O]; 1570. } 1571. 1572. reset = FALSE; 1573. #ifdef STATUS_HILITES 1574. if (gu.update_all) { 1575. chg = 0; 1576. curr->time = prev->time = 0L; 1577. } else if (!chg && curr->time) { 1578. reset = hilite_reset_needed(prev, gb.bl_hilite_moves); 1579. if (reset) 1580. curr->time = prev->time = 0L; 1581. } 1582. #endif 1583. 1584. if (gu.update_all || chg || reset) { 1585. if (!valsetlist[fld]) 1586. (void) anything_to_s(curr->val, &curr->a, anytype); 1587. 1588. if (anytype != ANY_MASK32) { 1589. #ifdef STATUS_HILITES 1590. if (chg || *curr->val) { 1591. /* if Xp percentage changed, we set 'chg' to 1 above; 1592. reset that if the Xp value hasn't actually changed 1593. or possibly went down rather than up (level loss) */ 1594. if (chg == 1 && fld == BL_XP) 1595. chg = compare_blstats(prev, curr); 1596. 1597. curr->hilite_rule = get_hilite(idx, fld, 1598. (genericptr_t) &curr->a, 1599. chg, pc, &color); 1600. prev->hilite_rule = curr->hilite_rule; 1601. if (chg == 2) { 1602. color = NO_COLOR; 1603. chg = 0; 1604. } 1605. } 1606. #endif /* STATUS_HILITES */ 1607. status_update(fld, (genericptr_t) curr->val, 1608. chg, pc, color, (unsigned long *) 0); 1609. } else { 1610. /* Color for conditions is done through gc.cond_hilites[] */ 1611. status_update(fld, (genericptr_t) &curr->a.a_ulong, 1612. chg, pc, color, gc.cond_hilites); 1613. } 1614. curr->chg = prev->chg = TRUE; 1615. updated = TRUE; 1616. } 1617. return updated; 1618. } 1619. 1620. staticfn void 1621. evaluate_and_notify_windowport( 1622. boolean *valsetlist, 1623. int idx) 1624. { 1625. int i, fld, updated = 0; 1626. 1627. /* 1628. * Now pass the changed values to window port. 1629. */ 1630. for (i = 0; i < MAXBLSTATS; i++) { 1631. fld = initblstats[i].fld; 1632. if (((fld == BL_SCORE) && !flags.showscore) 1633. || ((fld == BL_EXP) && !flags.showexp) 1634. || ((fld == BL_TIME) && !flags.time) 1635. || ((fld == BL_HD) && !Upolyd) 1636. || ((fld == BL_XP || fld == BL_EXP) && Upolyd) 1637. || ((fld == BL_VERS) && !flags.showvers) 1638. || ((fld == BL_TERRAIN) && !flags.terrainstatus) 1639. || ((fld == BL_WEAPON) && !flags.weaponstatus) 1640. || ((fld == BL_ARMOR) && !flags.armorstatus) 1641. ) { 1642. continue; 1643. } 1644. if (eval_notify_windowport_field(fld, valsetlist, idx)) 1645. updated++; 1646. } 1647. /* 1648. * Notes: 1649. * 1. It is possible to get here, with nothing having been pushed 1650. * to the window port, when none of the info has changed. 1651. * 1652. * 2. Some window ports are also known to optimize by only drawing 1653. * fields that have changed since the previous update. 1654. * 1655. * In both of those situations, we need to force updates to 1656. * all of the fields when disp.botlx is set. The tty port in 1657. * particular has a problem if that isn't done, since the core sets 1658. * disp.botlx when a menu or text display obliterates the status 1659. * line. 1660. * 1661. * For those situations, to trigger the full update of every field 1662. * whether changed or not, call status_update() with BL_RESET. 1663. * 1664. * For regular processing and to notify the window port that a 1665. * bot() round has finished and it's time to trigger a flush of 1666. * all buffered changes received thus far but not reflected in 1667. * the display, call status_update() with BL_FLUSH. 1668. * 1669. */ 1670. if (disp.botlx && (windowprocs.wincap2 & WC2_RESET_STATUS) != 0L) 1671. status_update(BL_RESET, (genericptr_t) 0, 0, 0, 1672. NO_COLOR, (unsigned long *) 0); 1673. else if ((updated || disp.botlx) 1674. && (windowprocs.wincap2 & WC2_FLUSH_STATUS) != 0L) 1675. status_update(BL_FLUSH, (genericptr_t) 0, 0, 0, 1676. NO_COLOR, (unsigned long *) 0); 1677. 1678. disp.botl = disp.botlx = disp.time_botl = FALSE; 1679. gu.update_all = FALSE; 1680. } 1681. 1682. void 1683. status_initialize( 1684. boolean reassessment) /* True: just recheck fields without other init */ 1685. { 1686. enum statusfields fld; 1687. boolean fldenabl; 1688. int i; 1689. const char *fieldfmt, *fieldname; 1690. 1691. if (!reassessment) { 1692. if (gb.blinit) 1693. impossible("2nd status_initialize with full init."); 1694. init_blstats(); 1695. (*windowprocs.win_status_init)(); 1696. gb.blinit = TRUE; 1697. } else if (!gb.blinit) { 1698. panic("status 'reassess' before init"); 1699. } 1700. for (i = 0; i < MAXBLSTATS; ++i) { 1701. fld = initblstats[i].fld; 1702. fldenabl = (fld == BL_SCORE) ? flags.showscore 1703. : (fld == BL_TIME) ? flags.time 1704. : (fld == BL_EXP) ? (boolean) (flags.showexp && !Upolyd) 1705. : (fld == BL_XP) ? (boolean) !Upolyd 1706. : (fld == BL_HD) ? (boolean) Upolyd 1707. : (fld == BL_VERS) ? flags.showvers 1708. : (fld == BL_WEAPON) ? flags.weaponstatus 1709. : (fld == BL_ARMOR) ? flags.armorstatus 1710. : (fld == BL_TERRAIN) ? flags.terrainstatus 1711. : TRUE; 1712. 1713. fieldname = initblstats[i].fldname; 1714. fieldfmt = (fld == BL_TITLE && iflags.wc2_hitpointbar) ? "%-30.30s" 1715. : initblstats[i].fldfmt; 1716. status_enablefield(fld, fieldname, fieldfmt, fldenabl); 1717. } 1718. gu.update_all = TRUE; 1719. disp.botlx = TRUE; 1720. } 1721. 1722. void 1723. status_finish(void) 1724. { 1725. int i; 1726. 1727. /* call the window port cleanup routine first */ 1728. if (windowprocs.win_status_finish) 1729. (*windowprocs.win_status_finish)(); 1730. 1731. /* free memory that we alloc'd now */ 1732. for (i = 0; i < MAXBLSTATS; ++i) { 1733. if (gb.blstats[0][i].val) 1734. free((genericptr_t) gb.blstats[0][i].val), 1735. gb.blstats[0][i].val = (char *) NULL; 1736. if (gb.blstats[1][i].val) 1737. free((genericptr_t) gb.blstats[1][i].val), 1738. gb.blstats[1][i].val = (char *) NULL; 1739. #ifdef STATUS_HILITES 1740. /* pointer to an entry in thresholds list; Null it out since 1741. that list is about to go away */ 1742. gb.blstats[0][i].hilite_rule = gb.blstats[1][i].hilite_rule = 0; 1743. if (gb.blstats[0][i].thresholds) { 1744. struct hilite_s *temp, *next; 1745. 1746. for (temp = gb.blstats[0][i].thresholds; temp; temp = next) { 1747. next = temp->next; 1748. free((genericptr_t) temp); 1749. } 1750. gb.blstats[0][i].thresholds 1751. = gb.blstats[1][i].thresholds 1752. = (struct hilite_s *) NULL; 1753. } 1754. #endif /* STATUS_HILITES */ 1755. } 1756. } 1757. 1758. staticfn void 1759. init_blstats(void) 1760. { 1761. static boolean initalready = FALSE; 1762. int i, j; 1763. 1764. if (initalready) { 1765. impossible("init_blstats called more than once."); 1766. return; 1767. } 1768. for (i = 0; i <= 1; ++i) { 1769. for (j = 0; j < MAXBLSTATS; ++j) { 1770. #ifdef STATUS_HILITES 1771. struct hilite_s *keep_hilite_chain = gb.blstats[i][j].thresholds; 1772. #endif 1773. 1774. gb.blstats[i][j] = initblstats[j]; 1775. gb.blstats[i][j].a = cg.zeroany; 1776. if (gb.blstats[i][j].valwidth) { 1777. gb.blstats[i][j].val 1778. = (char *) alloc(gb.blstats[i][j].valwidth); 1779. gb.blstats[i][j].val[0] = '\0'; 1780. } else 1781. gb.blstats[i][j].val = (char *) 0; 1782. #ifdef STATUS_HILITES 1783. gb.blstats[i][j].thresholds = keep_hilite_chain; 1784. #endif 1785. } 1786. } 1787. initalready = TRUE; 1788. } 1789. 1790. /* 1791. * This compares the previous stat with the current stat, 1792. * and returns one of the following results based on that: 1793. * 1794. * if prev_value < new_value (stat went up, increased) 1795. * return 1 1796. * 1797. * if prev_value > new_value (stat went down, decreased) 1798. * return -1 1799. * 1800. * if prev_value == new_value (stat stayed the same) 1801. * return 0 1802. * 1803. * Special cases: 1804. * - for bitmasks, 0 = stayed the same, 1 = changed 1805. * - for strings, 0 = stayed the same, 1 = changed 1806. * 1807. */ 1808. staticfn int 1809. compare_blstats(struct istat_s *bl1, struct istat_s *bl2) 1810. { 1811. anything *a1, *a2; 1812. boolean use_rawval; 1813. int anytype, fld, result = 0; 1814. 1815. if (!bl1 || !bl2) { 1816. panic("compare_blstat: bad istat pointer %s, %s", 1817. fmt_ptr((genericptr_t) bl1), fmt_ptr((genericptr_t) bl2)); 1818. } 1819. 1820. anytype = bl1->anytype; 1821. if ((!bl1->a.a_void || !bl2->a.a_void) 1822. && (anytype == ANY_IPTR || anytype == ANY_UPTR 1823. || anytype == ANY_LPTR || anytype == ANY_ULPTR)) { 1824. panic("compare_blstat: invalid pointer %s, %s", 1825. fmt_ptr((genericptr_t) bl1->a.a_void), 1826. fmt_ptr((genericptr_t) bl2->a.a_void)); 1827. } 1828. /* cheat; terrain is highlighted as a string but we have a handy int 1829. reflecting its value to use when checking for changes */ 1830. if (bl1->fld == BL_TERRAIN) 1831. anytype = ANY_INT; 1832. 1833. fld = bl1->fld; 1834. use_rawval = (fld == BL_HP || fld == BL_HPMAX 1835. || fld == BL_ENE || fld == BL_ENEMAX 1836. || fld == BL_GOLD); 1837. a1 = use_rawval ? &bl1->rawval : &bl1->a; 1838. a2 = use_rawval ? &bl2->rawval : &bl2->a; 1839. 1840. switch (anytype) { 1841. case ANY_INT: 1842. result = (a1->a_int < a2->a_int) ? 1 1843. : (a1->a_int > a2->a_int) ? -1 : 0; 1844. break; 1845. case ANY_IPTR: 1846. result = (*a1->a_iptr < *a2->a_iptr) ? 1 1847. : (*a1->a_iptr > *a2->a_iptr) ? -1 : 0; 1848. break; 1849. case ANY_LONG: 1850. result = (a1->a_long < a2->a_long) ? 1 1851. : (a1->a_long > a2->a_long) ? -1 : 0; 1852. break; 1853. case ANY_LPTR: 1854. result = (*a1->a_lptr < *a2->a_lptr) ? 1 1855. : (*a1->a_lptr > *a2->a_lptr) ? -1 : 0; 1856. break; 1857. case ANY_UINT: 1858. result = (a1->a_uint < a2->a_uint) ? 1 1859. : (a1->a_uint > a2->a_uint) ? -1 : 0; 1860. break; 1861. case ANY_UPTR: 1862. result = (*a1->a_uptr < *a2->a_uptr) ? 1 1863. : (*a1->a_uptr > *a2->a_uptr) ? -1 : 0; 1864. break; 1865. case ANY_ULONG: 1866. result = (a1->a_ulong < a2->a_ulong) ? 1 1867. : (a1->a_ulong > a2->a_ulong) ? -1 : 0; 1868. break; 1869. case ANY_ULPTR: 1870. result = (*a1->a_ulptr < *a2->a_ulptr) ? 1 1871. : (*a1->a_ulptr > *a2->a_ulptr) ? -1 : 0; 1872. break; 1873. case ANY_STR: 1874. result = sgn(strcmp(bl1->val, bl2->val)); 1875. break; 1876. case ANY_MASK32: 1877. result = (a1->a_ulong != a2->a_ulong); 1878. break; 1879. default: 1880. result = 1; 1881. } 1882. return result; 1883. } 1884. 1885. staticfn char * 1886. anything_to_s(char *buf, anything *a, int anytype) 1887. { 1888. if (!buf) 1889. return (char *) 0; 1890. 1891. switch (anytype) { 1892. case ANY_ULONG: 1893. Sprintf(buf, "%lu", a->a_ulong); 1894. break; 1895. case ANY_MASK32: 1896. Sprintf(buf, "%lx", a->a_ulong); 1897. break; 1898. case ANY_LONG: 1899. Sprintf(buf, "%ld", a->a_long); 1900. break; 1901. case ANY_INT: 1902. Sprintf(buf, "%d", a->a_int); 1903. break; 1904. case ANY_UINT: 1905. Sprintf(buf, "%u", a->a_uint); 1906. break; 1907. case ANY_IPTR: 1908. Sprintf(buf, "%d", *a->a_iptr); 1909. break; 1910. case ANY_LPTR: 1911. Sprintf(buf, "%ld", *a->a_lptr); 1912. break; 1913. case ANY_ULPTR: 1914. Sprintf(buf, "%lu", *a->a_ulptr); 1915. break; 1916. case ANY_UPTR: 1917. Sprintf(buf, "%u", *a->a_uptr); 1918. break; 1919. case ANY_STR: /* do nothing */ 1920. ; 1921. break; 1922. default: 1923. buf[0] = '\0'; 1924. } 1925. return buf; 1926. } 1927. 1928. #ifdef STATUS_HILITES 1929. staticfn void 1930. s_to_anything(anything *a, char *buf, int anytype) 1931. { 1932. if (!buf || !a) 1933. return; 1934. 1935. switch (anytype) { 1936. case ANY_LONG: 1937. a->a_long = atol(buf); 1938. break; 1939. case ANY_INT: 1940. a->a_int = atoi(buf); 1941. break; 1942. case ANY_UINT: 1943. a->a_uint = (unsigned) atoi(buf); 1944. break; 1945. case ANY_ULONG: 1946. a->a_ulong = (unsigned long) atol(buf); 1947. break; 1948. case ANY_IPTR: 1949. if (a->a_iptr) 1950. *a->a_iptr = atoi(buf); 1951. break; 1952. case ANY_UPTR: 1953. if (a->a_uptr) 1954. *a->a_uptr = (unsigned) atoi(buf); 1955. break; 1956. case ANY_LPTR: 1957. if (a->a_lptr) 1958. *a->a_lptr = atol(buf); 1959. break; 1960. case ANY_ULPTR: 1961. if (a->a_ulptr) 1962. *a->a_ulptr = (unsigned long) atol(buf); 1963. break; 1964. case ANY_MASK32: 1965. a->a_ulong = (unsigned long) atol(buf); 1966. break; 1967. default: 1968. a->a_void = 0; 1969. break; 1970. } 1971. return; 1972. } 1973. #endif /* STATUS_HILITES */ 1974. 1975. /* integer percentage is 100 * bl->a / maxbl->a */ 1976. staticfn int 1977. percentage(struct istat_s *bl, struct istat_s *maxbl) 1978. { 1979. int result = 0; 1980. int anytype; 1981. int ival, mval; 1982. long lval; 1983. unsigned uval; 1984. unsigned long ulval; 1985. int fld; 1986. boolean use_rawval; 1987. 1988. if (!bl || !maxbl) { 1989. impossible("percentage: bad istat pointer %s, %s", 1990. fmt_ptr((genericptr_t) bl), fmt_ptr((genericptr_t) maxbl)); 1991. return 0; 1992. } 1993. 1994. fld = bl->fld; 1995. use_rawval = (fld == BL_HP || fld == BL_ENE); 1996. ival = 0, lval = 0L, uval = 0U, ulval = 0UL; 1997. anytype = bl->anytype; 1998. if (maxbl->a.a_void) { 1999. switch (anytype) { 2000. case ANY_INT: 2001. /* HP and energy are int so this is the only case that cares 2002. about 'rawval'; for them, we use that rather than their 2003. potentially truncated (to 9999) display value */ 2004. ival = use_rawval ? bl->rawval.a_int : bl->a.a_int; 2005. mval = use_rawval ? maxbl->rawval.a_int : maxbl->a.a_int; 2006. result = ((100 * ival) / mval); 2007. break; 2008. case ANY_LONG: 2009. lval = bl->a.a_long; 2010. result = (int) ((100L * lval) / maxbl->a.a_long); 2011. break; 2012. case ANY_UINT: 2013. uval = bl->a.a_uint; 2014. result = (int) ((100U * uval) / maxbl->a.a_uint); 2015. break; 2016. case ANY_ULONG: 2017. ulval = bl->a.a_ulong; 2018. result = (int) ((100UL * ulval) / maxbl->a.a_ulong); 2019. break; 2020. case ANY_IPTR: 2021. ival = *bl->a.a_iptr; 2022. result = ((100 * ival) / (*maxbl->a.a_iptr)); 2023. break; 2024. case ANY_LPTR: 2025. lval = *bl->a.a_lptr; 2026. result = (int) ((100L * lval) / (*maxbl->a.a_lptr)); 2027. break; 2028. case ANY_UPTR: 2029. uval = *bl->a.a_uptr; 2030. result = (int) ((100U * uval) / (*maxbl->a.a_uptr)); 2031. break; 2032. case ANY_ULPTR: 2033. ulval = *bl->a.a_ulptr; 2034. result = (int) ((100UL * ulval) / (*maxbl->a.a_ulptr)); 2035. break; 2036. } 2037. } 2038. /* don't let truncation from integer division produce a zero result 2039. from a non-zero input; note: if we ever change to something like 2040. ((((1000 * val) / max) + 5) / 10) for a rounded result, we'll 2041. also need to check for and convert false 100 to 99 */ 2042. if (result == 0 2043. && (ival != 0 || lval != 0L || uval != 0U || ulval != 0UL)) 2044. result = 1; 2045. 2046. return result; 2047. } 2048. 2049. /* percentage for both xp (level) and exp (points) is the percentage for 2050. (curr_exp - this_level_start) in (next_level_start - this_level_start) */ 2051. staticfn int 2052. exp_percentage(void) 2053. { 2054. int res = 0; 2055. 2056. if (u.ulevel < 30) { 2057. long exp_val, nxt_exp_val, curlvlstart; 2058. 2059. curlvlstart = newuexp(u.ulevel - 1); 2060. exp_val = u.uexp - curlvlstart; 2061. nxt_exp_val = newuexp(u.ulevel) - curlvlstart; 2062. if (exp_val == nxt_exp_val - 1L) { 2063. /* 2064. * Full 100% is unattainable since hero gains a level 2065. * and the threshold for next level increases, but treat 2066. * (next_level_start - 1 point) as a special case. It's a 2067. * key value after being level drained so is something that 2068. * some players would like to be able to highlight distinctly. 2069. */ 2070. res = 100; 2071. } else { 2072. struct istat_s curval, maxval; 2073. 2074. curval.anytype = maxval.anytype = ANY_LONG; 2075. curval.a = maxval.a = cg.zeroany; 2076. curval.a.a_long = exp_val; 2077. maxval.a.a_long = nxt_exp_val; 2078. curval.fld = maxval.fld = BL_EXP; /* (neither BL_HP nor BL_ENE) */ 2079. /* maximum delta between levels is 10000000; calculation of 2080. 100 * (10000000 - N) / 10000000 fits within 32-bit long */ 2081. res = percentage(&curval, &maxval); 2082. } 2083. } 2084. return res; 2085. } 2086. 2087. /* experience points have changed but experience level hasn't; decide whether 2088. botl update is needed for a different percentage highlight rule for Xp */ 2089. boolean 2090. exp_percent_changing(void) 2091. { 2092. int pc; 2093. anything a; 2094. #ifdef STATUS_HILITES 2095. int color_dummy; 2096. struct hilite_s *rule; 2097. #endif 2098. struct istat_s *curr; 2099. 2100. /* if status update is already requested, skip this processing */ 2101. if (!disp.botl) { 2102. /* 2103. * Status update is warranted iff percent integer changes and the new 2104. * percentage results in a different highlighting rule being selected. 2105. */ 2106. curr = &gb.blstats[gn.now_or_before_idx][BL_XP]; 2107. /* TODO: [see eval_notify_windowport_field() about percent_matters 2108. and the check against 'thresholds'] */ 2109. if (curr->percent_matters 2110. #ifdef STATUS_HILITES 2111. && curr->thresholds 2112. #endif 2113. && (pc = exp_percentage()) != curr->percent_value) { 2114. a = cg.zeroany; 2115. a.a_int = (int) u.ulevel; 2116. #ifdef STATUS_HILITES 2117. rule = get_hilite(gn.now_or_before_idx, BL_XP, 2118. (genericptr_t) &a, 0, pc, &color_dummy); 2119. if (rule != curr->hilite_rule) 2120. return TRUE; /* caller should set 'disp.botl' to True */ 2121. #endif 2122. } 2123. } 2124. return FALSE; 2125. } 2126. 2127. /* callback so that interface can get capacity index rather than trying 2128. to reconstruct that from the encumbrance string or asking the general 2129. core what the value is */ 2130. int 2131. stat_cap_indx(void) 2132. { 2133. int cap; 2134. 2135. #ifdef STATUS_HILITES 2136. cap = gb.blstats[gn.now_or_before_idx][BL_CAP].a.a_int; 2137. #else 2138. cap = near_capacity(); 2139. #endif 2140. return cap; 2141. } 2142. 2143. /* callback so that interface can get hunger index rather than trying to 2144. reconstruct that from the hunger string or dipping into core internals */ 2145. int 2146. stat_hunger_indx(void) 2147. { 2148. int uhs; 2149. 2150. #ifdef STATUS_HILITES 2151. uhs = gb.blstats[gn.now_or_before_idx][BL_HUNGER].a.a_int; 2152. #else 2153. uhs = (int) u.uhs; 2154. #endif 2155. return uhs; 2156. } 2157. 2158. /* used by X11 for "tty status" even when STATUS_HILITES is disabled */ 2159. const char * 2160. bl_idx_to_fldname(int idx) 2161. { 2162. if (idx >= 0 && idx < MAXBLSTATS) 2163. return initblstats[idx].fldname; 2164. return (const char *) 0; 2165. } 2166. 2167. /* used when rendering hitpointbar; inoutbuf[] has been padded with 2168. trailing spaces; replace pairs of spaces with pairs of space+dash */ 2169. void 2170. repad_with_dashes(char *inoutbuf) 2171. { 2172. char *p = eos(inoutbuf); 2173. 2174. while (p >= inoutbuf + 2 && p[-1] == ' ' && p[-2] == ' ') { 2175. p[-1] = '-'; 2176. p -= 2; 2177. } 2178. } 2179. 2180. #ifdef STATUS_HILITES 2181. 2182. /****************************************************************************/ 2183. /* Core status hiliting support */ 2184. /****************************************************************************/ 2185. 2186. static const struct fieldid_t { 2187. const char *fieldname; 2188. enum statusfields fldid; 2189. } fieldids_alias[] = { 2190. { "characteristics", BL_CHARACTERISTICS }, 2191. { "encumbrance", BL_CAP }, 2192. { "experience-points", BL_EXP }, 2193. { "dx", BL_DX }, 2194. { "co", BL_CO }, 2195. { "con", BL_CO }, 2196. { "points", BL_SCORE }, 2197. { "cap", BL_CAP }, 2198. { "pw", BL_ENE }, 2199. { "pw-max", BL_ENEMAX }, 2200. { "xl", BL_XP }, 2201. { "xplvl", BL_XP }, 2202. { "ac", BL_AC }, 2203. { "hit-dice", BL_HD }, 2204. { "turns", BL_TIME }, 2205. { "hp", BL_HP }, 2206. { "hp-max", BL_HPMAX }, 2207. { "dgn", BL_LEVELDESC }, 2208. { "xp", BL_EXP }, 2209. { "exp", BL_EXP }, 2210. { "flags", BL_CONDITION }, 2211. { NULL, BL_FLUSH } 2212. }; 2213. 2214. /* format arguments */ 2215. static const char threshold_value[] = "hilite_status threshold ", 2216. is_out_of_range[] = " is out of range"; 2217. 2218. 2219. /* field name to bottom line index */ 2220. staticfn enum statusfields 2221. fldname_to_bl_indx(const char *name) 2222. { 2223. int i, nmatches = 0, fld = 0; 2224. 2225. if (name && *name) { 2226. /* check matches to canonical names */ 2227. for (i = 0; i < SIZE(initblstats); i++) 2228. if (fuzzymatch(initblstats[i].fldname, name, " -_", TRUE)) { 2229. fld = initblstats[i].fld; 2230. nmatches++; 2231. } 2232. if (!nmatches) { 2233. /* check aliases */ 2234. for (i = 0; fieldids_alias[i].fieldname; i++) 2235. if (fuzzymatch(fieldids_alias[i].fieldname, name, 2236. " -_", TRUE)) { 2237. fld = fieldids_alias[i].fldid; 2238. nmatches++; 2239. } 2240. } 2241. if (!nmatches) { 2242. /* check partial matches to canonical names */ 2243. int len = (int) strlen(name); 2244. 2245. for (i = 0; i < SIZE(initblstats); i++) 2246. if (!strncmpi(name, initblstats[i].fldname, len)) { 2247. fld = initblstats[i].fld; 2248. nmatches++; 2249. } 2250. } 2251. 2252. } 2253. return (nmatches == 1) ? fld : BL_FLUSH; 2254. } 2255. 2256. staticfn boolean 2257. hilite_reset_needed( 2258. struct istat_s *bl_p, 2259. long augmented_time) /* no longer augmented; it once encoded fractional 2260. * amounts for multiple moves within same turn */ 2261. { 2262. /* 2263. * This 'multi' handling may need some tuning... 2264. */ 2265. if (gm.multi) 2266. return FALSE; 2267. 2268. if (!Is_Temp_Hilite(bl_p->hilite_rule)) 2269. return FALSE; 2270. 2271. if (bl_p->time == 0 || bl_p->time >= augmented_time) 2272. return FALSE; 2273. 2274. return TRUE; 2275. } 2276. 2277. /* called from moveloop(); sets context.botl if temp hilites have timed out */ 2278. void 2279. status_eval_next_unhilite(void) 2280. { 2281. int i; 2282. struct istat_s *curr; 2283. long next_unhilite, this_unhilite; 2284. 2285. gb.bl_hilite_moves = svm.moves; /* simplified; at one point we used to 2286. * try to encode fractional amounts for 2287. * multiple moves within same turn */ 2288. /* figure out whether an unhilight needs to be performed now */ 2289. next_unhilite = 0L; 2290. for (i = 0; i < MAXBLSTATS; ++i) { 2291. curr = &gb.blstats[0][i]; /* blstats[0][*].time==blstats[1][*].time */ 2292. 2293. if (curr->chg) { 2294. struct istat_s *prev = &gb.blstats[1][i]; 2295. 2296. if (Is_Temp_Hilite(curr->hilite_rule)) 2297. curr->time = (gb.bl_hilite_moves + iflags.hilite_delta); 2298. else 2299. curr->time = 0L; 2300. prev->time = curr->time; 2301. 2302. curr->chg = prev->chg = FALSE; 2303. disp.botl = TRUE; 2304. } 2305. if (disp.botl) 2306. continue; /* just process other gb.blstats[][].time and .chg */ 2307. 2308. this_unhilite = curr->time; 2309. if (this_unhilite > 0L 2310. && (next_unhilite == 0L || this_unhilite < next_unhilite) 2311. && hilite_reset_needed(curr, this_unhilite + 1L)) { 2312. next_unhilite = this_unhilite; 2313. if (next_unhilite < gb.bl_hilite_moves) 2314. disp.botl = TRUE; 2315. } 2316. } 2317. } 2318. 2319. /* called by options handling when 'statushilites' value is changed */ 2320. void 2321. reset_status_hilites(void) 2322. { 2323. if (iflags.hilite_delta) { 2324. int i; 2325. 2326. for (i = 0; i < MAXBLSTATS; ++i) 2327. gb.blstats[0][i].time = gb.blstats[1][i].time = 0L; 2328. gu.update_all = TRUE; 2329. } 2330. disp.botlx = TRUE; 2331. } 2332. 2333. /* test whether the text from a title rule matches the string for 2334. title-while-polymorphed in the 'textmatch' menu */ 2335. staticfn boolean 2336. noneoftheabove(const char *hl_text) 2337. { 2338. if (fuzzymatch(hl_text, "none of the above", "\" -_", TRUE) 2339. || fuzzymatch(hl_text, "(polymorphed)", "\"()", TRUE) 2340. || fuzzymatch(hl_text, "none of the above (polymorphed)", 2341. "\" -_()", TRUE)) 2342. return TRUE; 2343. return FALSE; 2344. } 2345. 2346. /* 2347. * get_hilite 2348. * 2349. * Returns, based on the value and the direction it is moving, 2350. * the highlight rule that applies to the specified field. 2351. * 2352. * Provide get_hilite() with the following to work with: 2353. * actual value vp 2354. * useful for BL_TH_VAL_ABSOLUTE 2355. * indicator of down, up, or the same (-1, 1, 0) chg 2356. * useful for BL_TH_UPDOWN or change detection 2357. * percentage (current value percentage of max value) pc 2358. * useful for BL_TH_VAL_PERCENTAGE 2359. * 2360. * Get back: 2361. * pointer to rule that applies; Null if no rule does. 2362. */ 2363. staticfn struct hilite_s * 2364. get_hilite( 2365. int idx, int fldidx, 2366. genericptr_t vp, 2367. int chg, int pc, 2368. int *colorptr) 2369. { 2370. struct hilite_s *hl, *rule = 0; 2371. anything *value = (anything *) vp; 2372. char *txtstr; 2373. 2374. if (fldidx < 0 || fldidx >= MAXBLSTATS) 2375. return (struct hilite_s *) 0; 2376. 2377. if (has_hilite(fldidx)) { 2378. int dt; 2379. /* there are hilites set here */ 2380. int max_pc = -1, min_pc = 101; 2381. /* LARGEST_INT isn't INT_MAX; it fits within 16 bits, but that 2382. value is big enough to handle all 'int' status fields */ 2383. int max_ival = -LARGEST_INT, min_ival = LARGEST_INT; 2384. /* LONG_MAX comes from <limits.h> which might not be available for 2385. ancient configurations; we don't need LONG_MIN */ 2386. long max_lval = -LONG_MAX, min_lval = LONG_MAX; 2387. boolean exactmatch = FALSE, updown = FALSE, changed = FALSE, 2388. perc_or_abs = FALSE, crit_hp = FALSE; 2389. 2390. /* min_/max_ are used to track best fit */ 2391. for (hl = gb.blstats[0][fldidx].thresholds; hl; hl = hl->next) { 2392. dt = initblstats[fldidx].anytype; /* only needed for 'absolute' */ 2393. /* for HP, if we already have a critical-hp rule then we ignore 2394. other HP rules unless we hit another critical-hp one (last 2395. one found wins); critical-hp takes precedence over temporary 2396. HP highlights, otherwise a hero with regeneration and an up 2397. or changed rule for HP would always show that up or changed 2398. highlight even when within the critical-hp threshold because 2399. the value will go up by at least one on every move */ 2400. if (crit_hp && hl->behavior != BL_TH_CRITICALHP) 2401. continue; 2402. /* if we've already matched a temporary highlight, it takes 2403. precedence over all persistent ones; we still process 2404. updown rules to get the last one which qualifies */ 2405. if ((updown || changed) && hl->behavior != BL_TH_UPDOWN) 2406. continue; 2407. /* among persistent highlights, if a 'percentage' or 'absolute' 2408. rule has been matched, it takes precedence over 'always' */ 2409. if (perc_or_abs && hl->behavior == BL_TH_ALWAYS_HILITE) 2410. continue; 2411. 2412. switch (hl->behavior) { 2413. case BL_TH_VAL_PERCENTAGE: /* percent values are always ANY_INT */ 2414. if (hl->rel == EQ_VALUE && pc == hl->value.a_int) { 2415. rule = hl; 2416. min_pc = max_pc = hl->value.a_int; 2417. exactmatch = perc_or_abs = TRUE; 2418. } else if (exactmatch) { 2419. ; /* already found best fit, skip lt,ge,&c */ 2420. } else if (hl->rel == LT_VALUE 2421. && (pc < hl->value.a_int) 2422. && (hl->value.a_int <= min_pc)) { 2423. rule = hl; 2424. min_pc = hl->value.a_int; 2425. perc_or_abs = TRUE; 2426. } else if (hl->rel == LE_VALUE 2427. && (pc <= hl->value.a_int) 2428. && (hl->value.a_int <= min_pc)) { 2429. rule = hl; 2430. min_pc = hl->value.a_int; 2431. perc_or_abs = TRUE; 2432. } else if (hl->rel == GT_VALUE 2433. && (pc > hl->value.a_int) 2434. && (hl->value.a_int >= max_pc)) { 2435. rule = hl; 2436. max_pc = hl->value.a_int; 2437. perc_or_abs = TRUE; 2438. } else if (hl->rel == GE_VALUE 2439. && (pc >= hl->value.a_int) 2440. && (hl->value.a_int >= max_pc)) { 2441. rule = hl; 2442. max_pc = hl->value.a_int; 2443. perc_or_abs = TRUE; 2444. } 2445. break; 2446. case BL_TH_UPDOWN: /* uses 'chg' (set by caller), not 'dt' */ 2447. /* specific 'up' or 'down' takes precedence over general 2448. 'changed' regardless of their order in the rule set */ 2449. if (chg < 0 && hl->rel == LT_VALUE) { 2450. rule = hl; 2451. updown = TRUE; 2452. } else if (chg > 0 && hl->rel == GT_VALUE) { 2453. rule = hl; 2454. updown = TRUE; 2455. } else if (chg != 0 && hl->rel == EQ_VALUE && !updown) { 2456. rule = hl; 2457. changed = TRUE; 2458. } 2459. break; 2460. case BL_TH_VAL_ABSOLUTE: /* either ANY_INT or ANY_LONG */ 2461. /* 2462. * The int and long variations here are identical aside from 2463. * union field and min_/max_ variable names. If you change 2464. * one, be sure to make a corresponding change in the other. 2465. */ 2466. if (dt == ANY_INT) { 2467. if (hl->rel == EQ_VALUE 2468. && hl->value.a_int == value->a_int) { 2469. rule = hl; 2470. min_ival = max_ival = hl->value.a_int; 2471. exactmatch = perc_or_abs = TRUE; 2472. } else if (exactmatch) { 2473. ; /* already found best fit, skip lt,ge,&c */ 2474. } else if (hl->rel == LT_VALUE 2475. && (value->a_int < hl->value.a_int) 2476. && (hl->value.a_int <= min_ival)) { 2477. rule = hl; 2478. min_ival = hl->value.a_int; 2479. perc_or_abs = TRUE; 2480. } else if (hl->rel == LE_VALUE 2481. && (value->a_int <= hl->value.a_int) 2482. && (hl->value.a_int <= min_ival)) { 2483. rule = hl; 2484. min_ival = hl->value.a_int; 2485. perc_or_abs = TRUE; 2486. } else if (hl->rel == GT_VALUE 2487. && (value->a_int > hl->value.a_int) 2488. && (hl->value.a_int >= max_ival)) { 2489. rule = hl; 2490. max_ival = hl->value.a_int; 2491. perc_or_abs = TRUE; 2492. } else if (hl->rel == GE_VALUE 2493. && (value->a_int >= hl->value.a_int) 2494. && (hl->value.a_int >= max_ival)) { 2495. rule = hl; 2496. max_ival = hl->value.a_int; 2497. perc_or_abs = TRUE; 2498. } 2499. } else { /* ANY_LONG */ 2500. if (hl->rel == EQ_VALUE 2501. && hl->value.a_long == value->a_long) { 2502. rule = hl; 2503. min_lval = max_lval = hl->value.a_long; 2504. exactmatch = perc_or_abs = TRUE; 2505. } else if (exactmatch) { 2506. ; /* already found best fit, skip lt,ge,&c */ 2507. } else if (hl->rel == LT_VALUE 2508. && (value->a_long < hl->value.a_long) 2509. && (hl->value.a_long <= min_lval)) { 2510. rule = hl; 2511. min_lval = hl->value.a_long; 2512. perc_or_abs = TRUE; 2513. } else if (hl->rel == LE_VALUE 2514. && (value->a_long <= hl->value.a_long) 2515. && (hl->value.a_long <= min_lval)) { 2516. rule = hl; 2517. min_lval = hl->value.a_long; 2518. perc_or_abs = TRUE; 2519. } else if (hl->rel == GT_VALUE 2520. && (value->a_long > hl->value.a_long) 2521. && (hl->value.a_long >= max_lval)) { 2522. rule = hl; 2523. max_lval = hl->value.a_long; 2524. perc_or_abs = TRUE; 2525. } else if (hl->rel == GE_VALUE 2526. && (value->a_long >= hl->value.a_long) 2527. && (hl->value.a_long >= max_lval)) { 2528. rule = hl; 2529. max_lval = hl->value.a_long; 2530. perc_or_abs = TRUE; 2531. } 2532. } 2533. break; 2534. case BL_TH_TEXTMATCH: /* ANY_STR */ 2535. txtstr = gb.blstats[idx][fldidx].val; 2536. if (fldidx == BL_TITLE) 2537. /* "<name> the <rank-title>", skip past "<name> the " */ 2538. txtstr += strlen(svp.plname) + sizeof " the " - sizeof ""; 2539. if (hl->rel == TXT_VALUE && hl->textmatch[0]) { 2540. if (fuzzymatch(hl->textmatch, txtstr, "\" -_", TRUE)) { 2541. rule = hl; 2542. exactmatch = TRUE; 2543. } else if (exactmatch) { 2544. ; /* already found best fit, skip "noneoftheabove" */ 2545. } else if (fldidx == BL_TITLE 2546. && Upolyd && noneoftheabove(hl->textmatch)) { 2547. rule = hl; 2548. } 2549. } 2550. break; 2551. case BL_TH_ALWAYS_HILITE: 2552. rule = hl; 2553. break; 2554. case BL_TH_CRITICALHP: 2555. if (fldidx == BL_HP && critically_low_hp(FALSE)) { 2556. rule = hl; 2557. crit_hp = TRUE; 2558. updown = changed = perc_or_abs = FALSE; 2559. } 2560. break; 2561. case BL_TH_NONE: 2562. break; 2563. default: 2564. break; 2565. } 2566. } 2567. } 2568. *colorptr = rule ? rule->coloridx : NO_COLOR; 2569. return rule; 2570. } 2571. 2572. #undef has_hilite 2573. #undef Is_Temp_Hilite 2574. 2575. staticfn void 2576. split_clridx(int idx, int *coloridx, int *attrib) 2577. { 2578. if (coloridx) 2579. *coloridx = idx & 0x00FF; 2580. if (attrib) 2581. *attrib = (idx >> 8) & 0x00FF; 2582. } 2583. 2584. /* 2585. * This is the parser for the hilite options. 2586. * 2587. * parse_status_hl1() separates each hilite entry into 2588. * a set of field threshold/action component strings, 2589. * then calls parse_status_hl2() to parse further 2590. * and configure the hilite. 2591. */ 2592. boolean 2593. parse_status_hl1(char *op, boolean from_configfile) 2594. { 2595. #define MAX_THRESH 21 2596. char hsbuf[MAX_THRESH][QBUFSZ]; 2597. boolean rslt, badopt = FALSE; 2598. int i, fldnum, ccount = 0; 2599. char c; 2600. 2601. fldnum = 0; 2602. for (i = 0; i < MAX_THRESH; ++i) { 2603. hsbuf[i][0] = '\0'; 2604. } 2605. while (*op && fldnum < MAX_THRESH && ccount < (QBUFSZ - 2)) { 2606. c = lowc(*op); 2607. if (c == ' ') { 2608. if (fldnum >= 1) { 2609. if (fldnum == 1 && strcmpi(hsbuf[0], "title") == 0) { 2610. /* spaces are allowed in title */ 2611. hsbuf[fldnum][ccount++] = c; 2612. hsbuf[fldnum][ccount] = '\0'; 2613. op++; 2614. continue; 2615. } 2616. rslt = parse_status_hl2(hsbuf, from_configfile); 2617. if (!rslt) { 2618. badopt = TRUE; 2619. break; 2620. } 2621. } 2622. for (i = 0; i < MAX_THRESH; ++i) { 2623. hsbuf[i][0] = '\0'; 2624. } 2625. fldnum = 0; 2626. ccount = 0; 2627. } else if (c == '/') { 2628. fldnum++; 2629. ccount = 0; 2630. } else { 2631. hsbuf[fldnum][ccount++] = c; 2632. hsbuf[fldnum][ccount] = '\0'; 2633. } 2634. op++; 2635. } 2636. if (fldnum >= 1 && !badopt) { 2637. rslt = parse_status_hl2(hsbuf, from_configfile); 2638. if (!rslt) 2639. badopt = TRUE; 2640. } 2641. if (badopt) 2642. return FALSE; 2643. /* make sure highlighting is On; use short duration for temp highlights */ 2644. if (!iflags.hilite_delta) 2645. iflags.hilite_delta = 3L; 2646. return TRUE; 2647. #undef MAX_THRESH 2648. } 2649. 2650. /* is str in the format of "[<>]?=?[-+]?[0-9]+%?" regex */ 2651. staticfn boolean 2652. is_ltgt_percentnumber(const char *str) 2653. { 2654. const char *s = str; 2655. 2656. if (*s == '<' || *s == '>') 2657. s++; 2658. if (*s == '=') 2659. s++; 2660. if (*s == '-' || *s == '+') 2661. s++; 2662. if (!digit(*s)) 2663. return FALSE; 2664. while (digit(*s)) 2665. s++; 2666. if (*s == '%') 2667. s++; 2668. return (*s == '\0'); 2669. } 2670. 2671. /* does str only contain "<>=-+0-9%" chars */ 2672. staticfn boolean 2673. has_ltgt_percentnumber(const char *str) 2674. { 2675. const char *s = str; 2676. 2677. while (*s) { 2678. if (!strchr("<>=-+0123456789%", *s)) 2679. return FALSE; 2680. s++; 2681. } 2682. return TRUE; 2683. } 2684. 2685. /* splitsubfields(): splits str in place into '+' or '&' separated strings. 2686. returns number of strings, or -1 if more than maxsf or MAX_SUBFIELDS */ 2687. staticfn int 2688. splitsubfields(char *str, char ***sfarr, int maxsf) 2689. { 2690. #define MAX_SUBFIELDS 16 2691. static char *subfields[MAX_SUBFIELDS]; 2692. char *st = (char *) 0; 2693. int sf = 0; 2694. 2695. if (!str) 2696. return 0; 2697. for (sf = 0; sf < MAX_SUBFIELDS; ++sf) 2698. subfields[sf] = (char *) 0; 2699. 2700. maxsf = (maxsf == 0) ? MAX_SUBFIELDS : min(maxsf, MAX_SUBFIELDS); 2701. 2702. if (strchr(str, '+') || strchr(str, '&')) { 2703. char *c = str; 2704. 2705. sf = 0; 2706. st = c; 2707. while (*c && sf < maxsf) { 2708. if (*c == '&' || *c == '+') { 2709. *c = '\0'; 2710. subfields[sf] = st; 2711. st = c+1; 2712. sf++; 2713. } 2714. c++; 2715. } 2716. if (sf >= maxsf - 1) 2717. return -1; 2718. if (!*c && c != st) 2719. subfields[sf++] = st; 2720. } else { 2721. sf = 1; 2722. subfields[0] = str; 2723. } 2724. *sfarr = subfields; 2725. return sf; 2726. #undef MAX_SUBFIELDS 2727. } 2728. 2729. staticfn boolean 2730. is_fld_arrayvalues( 2731. const char *str, 2732. const char *const *arr, 2733. int arrmin, int arrmax, 2734. int *retidx) 2735. { 2736. int i; 2737. 2738. for (i = arrmin; i < arrmax; i++) 2739. if (!strcmpi(str, arr[i])) { 2740. *retidx = i; 2741. return TRUE; 2742. } 2743. return FALSE; 2744. } 2745. 2746. staticfn int 2747. query_arrayvalue( 2748. const char *querystr, 2749. const char *const *arr, 2750. int arrmin, int arrmax) 2751. { 2752. int i, res, ret = arrmin - 1; 2753. winid tmpwin; 2754. anything any; 2755. menu_item *picks = (menu_item *) 0; 2756. int adj = (arrmin > 0) ? 1 : arrmax; 2757. int clr = NO_COLOR; 2758. 2759. tmpwin = create_nhwindow(NHW_MENU); 2760. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 2761. 2762. for (i = arrmin; i < arrmax; i++) { 2763. if (!arr[i]) /* the array of hunger status values has a gap ...*/ 2764. continue; /*... set to Null between Satiated and Hungry */ 2765. any = cg.zeroany; 2766. any.a_int = i + adj; 2767. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 2768. clr, arr[i], MENU_ITEMFLAGS_NONE); 2769. } 2770. 2771. end_menu(tmpwin, querystr); 2772. 2773. res = select_menu(tmpwin, PICK_ONE, &picks); 2774. destroy_nhwindow(tmpwin); 2775. if (res > 0) { 2776. ret = picks->item.a_int - adj; 2777. free((genericptr_t) picks); 2778. } 2779. 2780. return ret; 2781. } 2782. 2783. staticfn void 2784. status_hilite_add_threshold(int fld, struct hilite_s *hilite) 2785. { 2786. struct hilite_s *new_hilite, *old_hilite; 2787. 2788. if (!hilite) 2789. return; 2790. 2791. /* alloc and initialize a new hilite_s struct */ 2792. new_hilite = (struct hilite_s *) alloc(sizeof (struct hilite_s)); 2793. *new_hilite = *hilite; /* copy struct */ 2794. 2795. new_hilite->set = TRUE; 2796. new_hilite->fld = fld; 2797. new_hilite->next = (struct hilite_s *) 0; 2798. /* insert new entry at the end of the list */ 2799. if (!gb.blstats[0][fld].thresholds) { 2800. gb.blstats[0][fld].thresholds = new_hilite; 2801. } else { 2802. for (old_hilite = gb.blstats[0][fld].thresholds; old_hilite->next; 2803. old_hilite = old_hilite->next) 2804. continue; 2805. old_hilite->next = new_hilite; 2806. } 2807. /* sort_hilites(fld) */ 2808. 2809. /* current and prev must both point at the same hilites */ 2810. gb.blstats[1][fld].thresholds = gb.blstats[0][fld].thresholds; 2811. } 2812. 2813. staticfn boolean 2814. parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile) 2815. { 2816. static const char *const aligntxt[] = { "chaotic", "neutral", "lawful" }; 2817. /* hu_stat[] from eat.c has trailing spaces which foul up comparisons; 2818. for the "not hungry" case, there's no text hence no way to highlight */ 2819. static const char *const hutxt[] = { 2820. "Satiated", "", "Hungry", "Weak", "Fainting", "Fainted", "Starved" 2821. }; 2822. char *tmp, *how; 2823. int sidx = 0, i = -1, dt = ANY_INVALID; 2824. int coloridx = -1, successes = 0; 2825. int disp_attrib = 0; 2826. boolean percent, changed, numeric, down, up, 2827. grt, lt, gte, le, eq, txtval, always, criticalhp; 2828. const char *txt; 2829. enum statusfields fld = BL_FLUSH; 2830. struct hilite_s hilite; 2831. char tmpbuf[BUFSZ]; 2832. 2833. /* Examples: 2834. 3.6.1: 2835. OPTION=hilite_status: hitpoints/<10%/red 2836. OPTION=hilite_status: hitpoints/<10%/red/<5%/purple/1/red&blink+inverse 2837. OPTION=hilite_status: experience/down/red/up/green 2838. OPTION=hilite_status: cap/strained/yellow/overtaxed/orange 2839. OPTION=hilite_status: title/always/blue 2840. OPTION=hilite_status: title/blue 2841. */ 2842. 2843. /* field name to statusfield */ 2844. fld = fldname_to_bl_indx(s[sidx]); 2845. 2846. if (fld == BL_CHARACTERISTICS) { 2847. boolean res = FALSE; 2848. 2849. /* recursively set each of strength, dexterity, constitution, &c */ 2850. for (fld = BL_STR; fld <= BL_CH; fld++) { 2851. Strcpy(s[sidx], initblstats[fld].fldname); 2852. res = parse_status_hl2(s, from_configfile); 2853. if (!res) 2854. return FALSE; 2855. } 2856. return TRUE; 2857. } 2858. if (fld == BL_FLUSH) { 2859. config_error_add("Unknown status field '%s'", s[sidx]); 2860. return FALSE; 2861. } 2862. if (fld == BL_CONDITION) 2863. return parse_condition(s, sidx); 2864. 2865. ++sidx; 2866. while (s[sidx][0]) { 2867. char buf[BUFSZ], **subfields; 2868. int sf = 0; /* subfield count */ 2869. int kidx; 2870. 2871. txt = (const char *) 0; 2872. percent = numeric = always = FALSE; 2873. down = up = changed = FALSE; 2874. criticalhp = FALSE; 2875. grt = gte = eq = le = lt = txtval = FALSE; 2876. #if 0 2877. /* threshold value - return on empty string */ 2878. if (!s[sidx][0]) 2879. return TRUE; 2880. #endif 2881. memset((genericptr_t) &hilite, 0, sizeof (struct hilite_s)); 2882. hilite.set = FALSE; /* mark it "unset" */ 2883. hilite.fld = fld; 2884. 2885. if (*s[sidx + 1] == '\0' || !strcmpi(s[sidx], "always")) { 2886. /* "field/always/color" OR "field/color" */ 2887. always = TRUE; 2888. if (*s[sidx + 1] == '\0') 2889. sidx--; 2890. } else if (!strcmpi(s[sidx], "up") || !strcmpi(s[sidx], "down")) { 2891. if (initblstats[fld].anytype == ANY_STR) 2892. /* ordered string comparison is supported but LT/GT for 2893. the string fields (title, dungeon-level, alignment) 2894. is pointless; treat 'up' or 'down' for string fields 2895. as 'changed' rather than rejecting them outright */ 2896. ; 2897. else if (!strcmpi(s[sidx], "down")) 2898. down = TRUE; 2899. else 2900. up = TRUE; 2901. changed = TRUE; 2902. } else if (fld == BL_CAP 2903. && is_fld_arrayvalues(s[sidx], enc_stat, 2904. SLT_ENCUMBER, OVERLOADED + 1, 2905. &kidx)) { 2906. txt = enc_stat[kidx]; 2907. txtval = TRUE; 2908. } else if (fld == BL_ALIGN 2909. && is_fld_arrayvalues(s[sidx], aligntxt, 0, 3, &kidx)) { 2910. txt = aligntxt[kidx]; 2911. txtval = TRUE; 2912. } else if (fld == BL_HUNGER 2913. && is_fld_arrayvalues(s[sidx], hutxt, 2914. SATIATED, STARVED + 1, &kidx)) { 2915. txt = hu_stat[kidx]; /* store hu_stat[] val, not hutxt[] */ 2916. txtval = TRUE; 2917. } else if (!strcmpi(s[sidx], "changed")) { 2918. changed = TRUE; 2919. } else if (fld == BL_HP && !strcmpi(s[sidx], "criticalhp")) { 2920. criticalhp = TRUE; 2921. } else if (is_ltgt_percentnumber(s[sidx])) { 2922. const char *op; 2923. 2924. tmp = s[sidx]; /* is_ltgt_() guarantees [<>]?=?[-+]?[0-9]+%? */ 2925. if (strchr(tmp, '%')) 2926. percent = TRUE; 2927. if (*tmp == '<') { 2928. if (tmp[1] == '=') 2929. le = TRUE; 2930. else 2931. lt = TRUE; 2932. } else if (*tmp == '>') { 2933. if (tmp[1] == '=') 2934. gte = TRUE; 2935. else 2936. grt = TRUE; 2937. } 2938. /* '%', '<', '>' have served their purpose, '=' is either 2939. part of '<' or '>' or optional for '=N', unary '+' is 2940. just decorative, so get rid of them, leaving -?[0-9]+ */ 2941. tmp = stripchars(tmpbuf, "%<>=+", tmp); 2942. numeric = TRUE; 2943. dt = percent ? ANY_INT : initblstats[fld].anytype; 2944. (void) s_to_anything(&hilite.value, tmp, dt); 2945. 2946. op = grt ? ">" : gte ? ">=" : lt ? "<" : le ? "<=" : "="; 2947. if (dt == ANY_INT 2948. /* AC is the only field where negative values make sense but 2949. accept >-1 for other fields; reject <0 for non-AC */ 2950. && (hilite.value.a_int 2951. < ((fld == BL_AC) ? -128 : grt ? -1 : lt ? 1 : 0) 2952. /* percentages have another more comprehensive check below */ 2953. || hilite.value.a_int > (percent ? (lt ? 101 : 100) 2954. : LARGEST_INT))) { 2955. config_error_add("%s'%s%d%s'%s", threshold_value, 2956. op, hilite.value.a_int, percent ? "%" : "", 2957. is_out_of_range); 2958. return FALSE; 2959. } else if (dt == ANY_LONG 2960. && hilite.value.a_long < (grt ? -1L : lt ? 1L : 0L)) { 2961. config_error_add("%s'%s%ld'%s", threshold_value, 2962. op, hilite.value.a_long, is_out_of_range); 2963. return FALSE; 2964. } 2965. } else if (initblstats[fld].anytype == ANY_STR) { 2966. txt = s[sidx]; 2967. txtval = TRUE; 2968. } else { 2969. config_error_add(has_ltgt_percentnumber(s[sidx]) 2970. ? "Wrong format '%s', expected a threshold number or percent" 2971. : "Unknown behavior '%s'", 2972. s[sidx]); 2973. return FALSE; 2974. } 2975. 2976. /* relationships {LT_VALUE, LE_VALUE, EQ_VALUE, GE_VALUE, GT_VALUE} */ 2977. if (grt || up) 2978. hilite.rel = GT_VALUE; 2979. else if (lt || down) 2980. hilite.rel = LT_VALUE; 2981. else if (gte) 2982. hilite.rel = GE_VALUE; 2983. else if (le) 2984. hilite.rel = LE_VALUE; 2985. else if (eq || percent || numeric || changed) 2986. hilite.rel = EQ_VALUE; 2987. else if (txtval) 2988. hilite.rel = TXT_VALUE; 2989. else 2990. hilite.rel = LT_VALUE; 2991. 2992. if (initblstats[fld].anytype == ANY_STR && (percent || numeric)) { 2993. config_error_add("Field '%s' does not support numeric values", 2994. initblstats[fld].fldname); 2995. return FALSE; 2996. } 2997. 2998. if (percent) { 2999. if (initblstats[fld].idxmax < 0) { 3000. config_error_add("Cannot use percent with '%s'", 3001. initblstats[fld].fldname); 3002. return FALSE; 3003. } else if ((hilite.value.a_int < -1) 3004. || (hilite.value.a_int == -1 3005. && hilite.value.a_int != GT_VALUE) 3006. || (hilite.value.a_int == 0 3007. && hilite.rel == LT_VALUE) 3008. || (hilite.value.a_int == 100 3009. && hilite.rel == GT_VALUE) 3010. || (hilite.value.a_int == 101 3011. && hilite.value.a_int != LT_VALUE) 3012. || (hilite.value.a_int > 101)) { 3013. config_error_add( 3014. "hilite_status: invalid percentage value '%s%d%%'", 3015. (hilite.rel == LT_VALUE) ? "<" 3016. : (hilite.rel == LE_VALUE) ? "<=" 3017. : (hilite.rel == GT_VALUE) ? ">" 3018. : (hilite.rel == GE_VALUE) ? ">=" 3019. : "=", 3020. hilite.value.a_int); 3021. return FALSE; 3022. } 3023. } 3024. 3025. /* actions */ 3026. sidx++; 3027. how = s[sidx]; 3028. if (!how) { 3029. if (!successes) 3030. return FALSE; 3031. } 3032. coloridx = -1; 3033. Strcpy(buf, how); 3034. sf = splitsubfields(buf, &subfields, 0); 3035. 3036. if (sf < 1) 3037. return FALSE; 3038. 3039. disp_attrib = HL_UNDEF; 3040. 3041. for (i = 0; i < sf; ++i) { 3042. int a = match_str2attr(subfields[i], FALSE); 3043. 3044. if (a == ATR_BOLD) 3045. disp_attrib |= HL_BOLD; 3046. else if (a == ATR_DIM) 3047. disp_attrib |= HL_DIM; 3048. else if (a == ATR_ITALIC) 3049. disp_attrib |= HL_ITALIC; 3050. else if (a == ATR_ULINE) 3051. disp_attrib |= HL_ULINE; 3052. else if (a == ATR_BLINK) 3053. disp_attrib |= HL_BLINK; 3054. else if (a == ATR_INVERSE) 3055. disp_attrib |= HL_INVERSE; 3056. else if (a == ATR_NONE) 3057. disp_attrib = HL_NONE; 3058. else { 3059. int c = match_str2clr(subfields[i], FALSE); 3060. 3061. if (c >= CLR_MAX || coloridx != -1) { 3062. config_error_add("bad color '%d %d'", c, coloridx); 3063. return FALSE; 3064. } 3065. coloridx = c; 3066. } 3067. } 3068. if (coloridx == -1) 3069. coloridx = NO_COLOR; 3070. 3071. /* Assign the values */ 3072. hilite.coloridx = coloridx | (disp_attrib << 8); 3073. 3074. if (always) 3075. hilite.behavior = BL_TH_ALWAYS_HILITE; 3076. else if (percent) 3077. hilite.behavior = BL_TH_VAL_PERCENTAGE; 3078. else if (changed) 3079. hilite.behavior = BL_TH_UPDOWN; 3080. else if (numeric) 3081. hilite.behavior = BL_TH_VAL_ABSOLUTE; 3082. else if (txtval) 3083. hilite.behavior = BL_TH_TEXTMATCH; 3084. else if (hilite.value.a_void) 3085. hilite.behavior = BL_TH_VAL_ABSOLUTE; 3086. else if (criticalhp) 3087. hilite.behavior = BL_TH_CRITICALHP; 3088. else 3089. hilite.behavior = BL_TH_NONE; 3090. 3091. hilite.anytype = dt; 3092. 3093. if (hilite.behavior == BL_TH_TEXTMATCH && txt) { 3094. (void) strncpy(hilite.textmatch, txt, sizeof hilite.textmatch); 3095. hilite.textmatch[sizeof hilite.textmatch - 1] = '\0'; 3096. (void) trimspaces(hilite.textmatch); 3097. } 3098. 3099. status_hilite_add_threshold(fld, &hilite); 3100. 3101. successes++; 3102. sidx++; 3103. } 3104. 3105. return (successes > 0); 3106. } 3107. 3108. staticfn unsigned long 3109. query_conditions(void) 3110. { 3111. int i,res; 3112. unsigned long ret = 0UL; 3113. winid tmpwin; 3114. anything any; 3115. menu_item *picks = (menu_item *) 0; 3116. int clr = NO_COLOR; 3117. 3118. tmpwin = create_nhwindow(NHW_MENU); 3119. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 3120. 3121. for (i = 0; i < SIZE(conditions); i++) { 3122. any = cg.zeroany; 3123. any.a_ulong = conditions[i].mask; 3124. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 3125. clr, conditions[i].text[0], MENU_ITEMFLAGS_NONE); 3126. } 3127. 3128. end_menu(tmpwin, "Choose status conditions"); 3129. 3130. res = select_menu(tmpwin, PICK_ANY, &picks); 3131. destroy_nhwindow(tmpwin); 3132. if (res > 0) { 3133. for (i = 0; i < res; i++) 3134. ret |= picks[i].item.a_ulong; 3135. free((genericptr_t) picks); 3136. } 3137. return ret; 3138. } 3139. 3140. staticfn char * 3141. conditionbitmask2str(unsigned long ul) 3142. { 3143. static char buf[BUFSZ]; 3144. int i; 3145. boolean first = TRUE; 3146. const char *alias = (char *) 0; 3147. 3148. 3149. buf[0] = '\0'; 3150. if (!ul) 3151. return buf; 3152. 3153. for (i = 1; i < SIZE(condition_aliases); i++) 3154. if (condition_aliases[i].bitmask == ul) 3155. alias = condition_aliases[i].id; 3156. 3157. for (i = 0; i < SIZE(conditions); i++) 3158. if ((conditions[i].mask & ul) != 0UL) { 3159. Sprintf(eos(buf), "%s%s", (first) ? "" : "+", 3160. conditions[i].text[0]); 3161. first = FALSE; 3162. } 3163. 3164. if (!first && alias) 3165. Sprintf(buf, "%s", alias); 3166. 3167. return buf; 3168. } 3169. 3170. staticfn unsigned long 3171. match_str2conditionbitmask(const char *str) 3172. { 3173. int i, nmatches = 0; 3174. unsigned long mask = 0UL; 3175. 3176. if (str && *str) { 3177. /* check matches to canonical names */ 3178. for (i = 0; i < SIZE(conditions); i++) 3179. if (fuzzymatch(conditions[i].text[0], str, " -_", TRUE)) { 3180. mask |= conditions[i].mask; 3181. nmatches++; 3182. } 3183. 3184. if (!nmatches) { 3185. /* check aliases */ 3186. for (i = 0; i < SIZE(condition_aliases); i++) 3187. if (fuzzymatch(condition_aliases[i].id, str, " -_", TRUE)) { 3188. mask |= condition_aliases[i].bitmask; 3189. nmatches++; 3190. } 3191. } 3192. 3193. if (!nmatches) { 3194. /* check partial matches to aliases */ 3195. int len = (int) strlen(str); 3196. 3197. for (i = 0; i < SIZE(condition_aliases); i++) 3198. if (!strncmpi(str, condition_aliases[i].id, len)) { 3199. mask |= condition_aliases[i].bitmask; 3200. nmatches++; 3201. } 3202. } 3203. } 3204. 3205. return mask; 3206. } 3207. 3208. staticfn unsigned long 3209. str2conditionbitmask(char *str) 3210. { 3211. unsigned long conditions_bitmask = 0UL; 3212. char **subfields; 3213. int i, sf; 3214. 3215. sf = splitsubfields(str, &subfields, SIZE(conditions)); 3216. 3217. if (sf < 1) 3218. return 0UL; 3219. 3220. for (i = 0; i < sf; ++i) { 3221. unsigned long bm = match_str2conditionbitmask(subfields[i]); 3222. 3223. if (!bm) { 3224. config_error_add("Unknown condition '%s'", subfields[i]); 3225. return 0UL; 3226. } 3227. conditions_bitmask |= bm; 3228. } 3229. return conditions_bitmask; 3230. } 3231. 3232. staticfn boolean 3233. parse_condition(char (*s)[QBUFSZ], int sidx) 3234. { 3235. int i; 3236. int coloridx = NO_COLOR; 3237. char *tmp, *how; 3238. unsigned long conditions_bitmask = 0UL; 3239. boolean result = FALSE; 3240. 3241. if (!s) 3242. return FALSE; 3243. 3244. /*3.6.1: 3245. OPTION=hilite_status: condition/stone+slime+foodPois/red&inverse */ 3246. 3247. /* 3248. * TODO? 3249. * It would be simpler to treat each condition (also hunger state 3250. * and encumbrance level) as if it were a separate field. That 3251. * way they could have either or both 'changed' temporary rule and 3252. * 'always' persistent rule and wouldn't need convoluted access to 3253. * the intended color and attributes. 3254. */ 3255. 3256. sidx++; 3257. if (!s[sidx][0]) { 3258. config_error_add("Missing condition(s)"); 3259. return FALSE; 3260. } 3261. while (s[sidx][0]) { 3262. int sf = 0; /* subfield count */ 3263. char buf[BUFSZ], **subfields; 3264. 3265. tmp = s[sidx]; 3266. Strcpy(buf, tmp); 3267. conditions_bitmask = str2conditionbitmask(buf); 3268. 3269. if (!conditions_bitmask) 3270. return FALSE; 3271. 3272. /* 3273. * We have the conditions_bitmask with bits set for 3274. * each ailment we want in a particular color and/or 3275. * attribute, but we need to assign it to an array of 3276. * bitmasks indexed by the color chosen 3277. * (0 to (CLR_MAX - 1)) 3278. * and/or attributes chosen 3279. * (HL_ATTCLR_NONE to (BL_ATTCLR_MAX - 1)) 3280. * We still have to parse the colors and attributes out. 3281. */ 3282. 3283. /* actions */ 3284. sidx++; 3285. how = s[sidx]; 3286. if (!how || !*how) { 3287. config_error_add("Missing color+attribute"); 3288. return FALSE; 3289. } 3290. 3291. Strcpy(buf, how); 3292. sf = splitsubfields(buf, &subfields, 0); 3293. 3294. /* 3295. * conditions_bitmask now has bits set representing 3296. * the conditions that player wants represented, but 3297. * now we parse out *how* they will be represented. 3298. * 3299. * Only 1 colour is allowed, but potentially multiple 3300. * attributes are allowed. 3301. * 3302. * We have the following additional array offsets to 3303. * use for storing the attributes beyond the end of 3304. * the color indexes, all of which are less than CLR_MAX. 3305. * 3306. */ 3307. 3308. for (i = 0; i < sf; ++i) { 3309. int a = match_str2attr(subfields[i], FALSE); 3310. 3311. if (a == ATR_BOLD) 3312. gc.cond_hilites[HL_ATTCLR_BOLD] |= conditions_bitmask; 3313. else if (a == ATR_DIM) 3314. gc.cond_hilites[HL_ATTCLR_DIM] |= conditions_bitmask; 3315. else if (a == ATR_ITALIC) 3316. gc.cond_hilites[HL_ATTCLR_ITALIC] |= conditions_bitmask; 3317. else if (a == ATR_ULINE) 3318. gc.cond_hilites[HL_ATTCLR_ULINE] |= conditions_bitmask; 3319. else if (a == ATR_BLINK) 3320. gc.cond_hilites[HL_ATTCLR_BLINK] |= conditions_bitmask; 3321. else if (a == ATR_INVERSE) 3322. gc.cond_hilites[HL_ATTCLR_INVERSE] |= conditions_bitmask; 3323. else if (a == ATR_NONE) { 3324. gc.cond_hilites[HL_ATTCLR_BOLD] &= ~conditions_bitmask; 3325. gc.cond_hilites[HL_ATTCLR_DIM] &= ~conditions_bitmask; 3326. gc.cond_hilites[HL_ATTCLR_ITALIC] &= ~conditions_bitmask; 3327. gc.cond_hilites[HL_ATTCLR_ULINE] &= ~conditions_bitmask; 3328. gc.cond_hilites[HL_ATTCLR_BLINK] &= ~conditions_bitmask; 3329. gc.cond_hilites[HL_ATTCLR_INVERSE] &= ~conditions_bitmask; 3330. } else { 3331. int k = match_str2clr(subfields[i], FALSE); 3332. 3333. if (k >= CLR_MAX) { 3334. config_error_add("bad color %d", k); 3335. return FALSE; 3336. } 3337. coloridx = k; 3338. } 3339. } 3340. /* set the bits in the appropriate member of the 3341. condition array according to color chosen as index */ 3342. 3343. gc.cond_hilites[coloridx] |= conditions_bitmask; 3344. result = TRUE; 3345. sidx++; 3346. } 3347. return result; 3348. } 3349. 3350. void 3351. clear_status_hilites(void) 3352. { 3353. int i; 3354. 3355. for (i = 0; i < MAXBLSTATS; ++i) { 3356. struct hilite_s *temp, *next; 3357. 3358. for (temp = gb.blstats[0][i].thresholds; temp; temp = next) { 3359. next = temp->next; 3360. free(temp); 3361. } 3362. gb.blstats[0][i].thresholds = gb.blstats[1][i].thresholds = 0; 3363. /* pointer into thresholds list, now stale */ 3364. gb.blstats[0][i].hilite_rule = gb.blstats[1][i].hilite_rule = 0; 3365. } 3366. } 3367. 3368. staticfn char * 3369. hlattr2attrname(int attrib, char *buf, size_t bufsz) 3370. { 3371. if (attrib && buf) { 3372. char attbuf[BUFSZ]; 3373. int first = 0; 3374. size_t k; 3375. 3376. attbuf[0] = '\0'; 3377. if (attrib == HL_NONE) { 3378. Strcpy(buf, "normal"); 3379. return buf; 3380. } 3381. 3382. if (attrib & HL_BOLD) 3383. Strcat(attbuf, first++ ? "+bold" : "bold"); 3384. if (attrib & HL_DIM) 3385. Strcat(attbuf, first++ ? "+dim" : "dim"); 3386. if (attrib & HL_ITALIC) 3387. Strcat(attbuf, first++ ? "+italic" : "italic"); 3388. if (attrib & HL_ULINE) 3389. Strcat(attbuf, first++ ? "+underline" : "underline"); 3390. if (attrib & HL_BLINK) 3391. Strcat(attbuf, first++ ? "+blink" : "blink"); 3392. if (attrib & HL_INVERSE) 3393. Strcat(attbuf, first++ ? "+inverse" : "inverse"); 3394. 3395. k = strlen(attbuf); 3396. if (k < (size_t)(bufsz - 1)) 3397. Strcpy(buf, attbuf); 3398. return buf; 3399. } 3400. return (char *) 0; 3401. } 3402. 3403. struct _status_hilite_line_str { 3404. int id; 3405. int fld; 3406. struct hilite_s *hl; 3407. unsigned long mask; 3408. char str[BUFSZ]; 3409. struct _status_hilite_line_str *next; 3410. }; 3411. 3412. /* these don't need to be in 'struct g' */ 3413. static struct _status_hilite_line_str *status_hilite_str = 0; 3414. static int status_hilite_str_id = 0; 3415. 3416. staticfn void 3417. status_hilite_linestr_add( 3418. int fld, 3419. struct hilite_s *hl, 3420. unsigned long mask, 3421. const char *str) 3422. { 3423. struct _status_hilite_line_str *tmp, *nxt; 3424. 3425. tmp = (struct _status_hilite_line_str *) alloc(sizeof *tmp); 3426. (void) memset(tmp, 0, sizeof *tmp); 3427. tmp->next = (struct _status_hilite_line_str *) 0; 3428. 3429. tmp->id = ++status_hilite_str_id; 3430. tmp->fld = fld; 3431. tmp->hl = hl; 3432. tmp->mask = mask; 3433. if (fld == BL_TITLE) 3434. Strcpy(tmp->str, str); 3435. else 3436. (void) stripchars(tmp->str, " ", str); 3437. 3438. if ((nxt = status_hilite_str) != 0) { 3439. while (nxt->next) 3440. nxt = nxt->next; 3441. nxt->next = tmp; 3442. } else { 3443. status_hilite_str = tmp; 3444. } 3445. } 3446. 3447. staticfn void 3448. status_hilite_linestr_done(void) 3449. { 3450. struct _status_hilite_line_str *nxt, *tmp = status_hilite_str; 3451. 3452. while (tmp) { 3453. nxt = tmp->next; 3454. free(tmp); 3455. tmp = nxt; 3456. } 3457. status_hilite_str = (struct _status_hilite_line_str *) 0; 3458. status_hilite_str_id = 0; 3459. } 3460. 3461. staticfn int 3462. status_hilite_linestr_countfield(int fld) 3463. { 3464. struct _status_hilite_line_str *tmp; 3465. boolean countall = (fld == BL_FLUSH); 3466. int count = 0; 3467. 3468. for (tmp = status_hilite_str; tmp; tmp = tmp->next) { 3469. if (countall || tmp->fld == fld) 3470. count++; 3471. } 3472. return count; 3473. } 3474. 3475. /* used by options handling, doset(options.c) */ 3476. int 3477. count_status_hilites(void) 3478. { 3479. int count; 3480. 3481. status_hilite_linestr_gather(); 3482. count = status_hilite_linestr_countfield(BL_FLUSH); 3483. status_hilite_linestr_done(); 3484. return count; 3485. } 3486. 3487. staticfn void 3488. status_hilite_linestr_gather_conditions(void) 3489. { 3490. int i; 3491. struct _cond_map { 3492. unsigned long bm; 3493. unsigned int clratr; 3494. } cond_maps[SIZE(conditions)]; 3495. 3496. (void) memset(cond_maps, 0, 3497. SIZE(conditions) * sizeof (struct _cond_map)); 3498. 3499. for (i = 0; i < SIZE(conditions); i++) { 3500. int clr = NO_COLOR; 3501. int atr = HL_NONE; 3502. int j; 3503. 3504. for (j = 0; j < CLR_MAX; j++) 3505. if (gc.cond_hilites[j] & conditions[i].mask) { 3506. clr = j; 3507. break; 3508. } 3509. if (gc.cond_hilites[HL_ATTCLR_BOLD] & conditions[i].mask) 3510. atr |= HL_BOLD; 3511. if (gc.cond_hilites[HL_ATTCLR_DIM] & conditions[i].mask) 3512. atr |= HL_DIM; 3513. if (gc.cond_hilites[HL_ATTCLR_ITALIC] & conditions[i].mask) 3514. atr |= HL_ITALIC; 3515. if (gc.cond_hilites[HL_ATTCLR_ULINE] & conditions[i].mask) 3516. atr |= HL_ULINE; 3517. if (gc.cond_hilites[HL_ATTCLR_BLINK] & conditions[i].mask) 3518. atr |= HL_BLINK; 3519. if (gc.cond_hilites[HL_ATTCLR_INVERSE] & conditions[i].mask) 3520. atr |= HL_INVERSE; 3521. if (atr != HL_NONE) 3522. atr &= ~HL_NONE; 3523. 3524. if (clr != NO_COLOR || atr != HL_NONE) { 3525. unsigned int ca = clr | (atr << 8); 3526. boolean added_condmap = FALSE; 3527. 3528. for (j = 0; j < SIZE(conditions); j++) 3529. if (cond_maps[j].clratr == ca) { 3530. cond_maps[j].bm |= conditions[i].mask; 3531. added_condmap = TRUE; 3532. break; 3533. } 3534. if (!added_condmap) { 3535. for (j = 0; j < SIZE(conditions); j++) 3536. if (!cond_maps[j].bm) { 3537. cond_maps[j].bm = conditions[i].mask; 3538. cond_maps[j].clratr = ca; 3539. break; 3540. } 3541. } 3542. } 3543. } 3544. 3545. for (i = 0; i < SIZE(conditions); i++) 3546. if (cond_maps[i].bm) { 3547. int clr = NO_COLOR, atr = HL_NONE; 3548. 3549. split_clridx(cond_maps[i].clratr, &clr, &atr); 3550. if (clr != NO_COLOR || atr != HL_NONE) { 3551. char clrbuf[BUFSZ]; 3552. char attrbuf[BUFSZ]; 3553. char condbuf[BUFSZ]; 3554. char *tmpattr; 3555. 3556. (void) strNsubst(strcpy(clrbuf, clr2colorname(clr)), 3557. " ", "-", 0); 3558. tmpattr = hlattr2attrname(atr, attrbuf, BUFSZ); 3559. if (tmpattr) 3560. Sprintf(eos(clrbuf), "&%s", tmpattr); 3561. Snprintf(condbuf, sizeof(condbuf), "condition/%s/%s", 3562. conditionbitmask2str(cond_maps[i].bm), clrbuf); 3563. status_hilite_linestr_add(BL_CONDITION, 0, 3564. cond_maps[i].bm, condbuf); 3565. } 3566. } 3567. } 3568. 3569. staticfn void 3570. status_hilite_linestr_gather(void) 3571. { 3572. int i; 3573. struct hilite_s *hl; 3574. 3575. status_hilite_linestr_done(); 3576. 3577. for (i = 0; i < MAXBLSTATS; i++) { 3578. hl = gb.blstats[0][i].thresholds; 3579. while (hl) { 3580. status_hilite_linestr_add(i, hl, 0UL, status_hilite2str(hl)); 3581. hl = hl->next; 3582. } 3583. } 3584. 3585. status_hilite_linestr_gather_conditions(); 3586. } 3587. 3588. 3589. staticfn char * 3590. status_hilite2str(struct hilite_s *hl) 3591. { 3592. static char buf[BUFSZ]; 3593. int clr = NO_COLOR, attr = ATR_NONE; 3594. char behavebuf[BUFSZ]; 3595. char clrbuf[BUFSZ]; 3596. char attrbuf[BUFSZ]; 3597. char *tmpattr; 3598. const char *op; 3599. 3600. if (!hl) 3601. return (char *) 0; 3602. 3603. behavebuf[0] = '\0'; 3604. clrbuf[0] = '\0'; 3605. op = (hl->rel == LT_VALUE) ? "<" 3606. : (hl->rel == LE_VALUE) ? "<=" 3607. : (hl->rel == GT_VALUE) ? ">" 3608. : (hl->rel == GE_VALUE) ? ">=" 3609. : (hl->rel == EQ_VALUE) ? "=" 3610. : 0; 3611. 3612. switch (hl->behavior) { 3613. case BL_TH_VAL_PERCENTAGE: 3614. if (op) 3615. Sprintf(behavebuf, "%s%d%%", op, hl->value.a_int); 3616. else 3617. impossible("hl->behavior=percentage, rel error"); 3618. break; 3619. case BL_TH_UPDOWN: 3620. if (hl->rel == LT_VALUE) 3621. Sprintf(behavebuf, "down"); 3622. else if (hl->rel == GT_VALUE) 3623. Sprintf(behavebuf, "up"); 3624. else if (hl->rel == EQ_VALUE) 3625. Sprintf(behavebuf, "changed"); 3626. else 3627. impossible("hl->behavior=updown, rel error"); 3628. break; 3629. case BL_TH_VAL_ABSOLUTE: 3630. if (op) 3631. Sprintf(behavebuf, "%s%d", op, hl->value.a_int); 3632. else 3633. impossible("hl->behavior=absolute, rel error"); 3634. break; 3635. case BL_TH_TEXTMATCH: 3636. if (hl->rel == TXT_VALUE && hl->textmatch[0]) 3637. Sprintf(behavebuf, "%s", hl->textmatch); 3638. else 3639. impossible("hl->behavior=textmatch, rel or textmatch error"); 3640. break; 3641. case BL_TH_CONDITION: 3642. if (hl->rel == EQ_VALUE) 3643. Sprintf(behavebuf, "%s", conditionbitmask2str(hl->value.a_ulong)); 3644. else 3645. impossible("hl->behavior=condition, rel error"); 3646. break; 3647. case BL_TH_ALWAYS_HILITE: 3648. Sprintf(behavebuf, "always"); 3649. break; 3650. case BL_TH_CRITICALHP: 3651. Sprintf(behavebuf, "criticalhp"); 3652. break; 3653. case BL_TH_NONE: 3654. break; 3655. default: 3656. break; 3657. } 3658. 3659. split_clridx(hl->coloridx, &clr, &attr); 3660. (void) strNsubst(strcpy(clrbuf, clr2colorname(clr)), " ", "-", 0); 3661. if (attr != HL_UNDEF) { 3662. if ((tmpattr = hlattr2attrname(attr, attrbuf, BUFSZ)) != 0) 3663. Sprintf(eos(clrbuf), "&%s", tmpattr); 3664. } 3665. Snprintf(buf, sizeof(buf), "%s/%s/%s", initblstats[hl->fld].fldname, 3666. behavebuf, clrbuf); 3667. 3668. return buf; 3669. } 3670. 3671. staticfn int 3672. status_hilite_menu_choose_field(void) 3673. { 3674. winid tmpwin; 3675. int i, res, fld = BL_FLUSH; 3676. anything any; 3677. menu_item *picks = (menu_item *) 0; 3678. int clr = NO_COLOR; 3679. 3680. tmpwin = create_nhwindow(NHW_MENU); 3681. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 3682. 3683. for (i = 0; i < MAXBLSTATS; i++) { 3684. #ifndef SCORE_ON_BOTL 3685. if (initblstats[i].fld == BL_SCORE 3686. && !gb.blstats[0][BL_SCORE].thresholds) 3687. continue; 3688. #endif 3689. any = cg.zeroany; 3690. any.a_int = (i + 1); 3691. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 3692. clr, initblstats[i].fldname, MENU_ITEMFLAGS_NONE); 3693. } 3694. 3695. end_menu(tmpwin, "Select a hilite field:"); 3696. 3697. res = select_menu(tmpwin, PICK_ONE, &picks); 3698. destroy_nhwindow(tmpwin); 3699. if (res > 0) { 3700. fld = picks->item.a_int - 1; 3701. free((genericptr_t) picks); 3702. } 3703. return fld; 3704. } 3705. 3706. staticfn int 3707. status_hilite_menu_choose_behavior(int fld) 3708. { 3709. winid tmpwin; 3710. int res = 0, beh = BL_TH_NONE-1; 3711. anything any; 3712. menu_item *picks = (menu_item *) 0; 3713. char buf[BUFSZ]; 3714. int at; 3715. int onlybeh = BL_TH_NONE, nopts = 0; 3716. int clr = NO_COLOR; 3717. 3718. if (fld < 0 || fld >= MAXBLSTATS) 3719. return BL_TH_NONE; 3720. 3721. at = initblstats[fld].anytype; 3722. 3723. tmpwin = create_nhwindow(NHW_MENU); 3724. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 3725. 3726. if (fld != BL_CONDITION) { 3727. any = cg.zeroany; 3728. any.a_int = onlybeh = BL_TH_ALWAYS_HILITE; 3729. Sprintf(buf, "Always highlight %s", initblstats[fld].fldname); 3730. add_menu(tmpwin, &nul_glyphinfo, &any, 'a', 0, ATR_NONE, 3731. clr, buf, MENU_ITEMFLAGS_NONE); 3732. nopts++; 3733. } 3734. 3735. if (fld == BL_CONDITION) { 3736. any = cg.zeroany; 3737. any.a_int = onlybeh = BL_TH_CONDITION; 3738. add_menu(tmpwin, &nul_glyphinfo, &any, 'b', 0, ATR_NONE, 3739. clr, "Bitmask of conditions", MENU_ITEMFLAGS_NONE); 3740. nopts++; 3741. } 3742. 3743. if (fld != BL_CONDITION && fld != BL_VERS) { 3744. any = cg.zeroany; 3745. any.a_int = onlybeh = BL_TH_UPDOWN; 3746. Sprintf(buf, "%s value changes", initblstats[fld].fldname); 3747. add_menu(tmpwin, &nul_glyphinfo, &any, 'c', 0, ATR_NONE, 3748. clr, buf, MENU_ITEMFLAGS_NONE); 3749. nopts++; 3750. } 3751. 3752. if (fld != BL_CAP && fld != BL_HUNGER 3753. && (at == ANY_INT || at == ANY_LONG)) { 3754. any = cg.zeroany; 3755. any.a_int = onlybeh = BL_TH_VAL_ABSOLUTE; 3756. add_menu(tmpwin, &nul_glyphinfo, &any, 'n', 0, ATR_NONE, 3757. clr, "Number threshold", MENU_ITEMFLAGS_NONE); 3758. nopts++; 3759. } 3760. 3761. if (initblstats[fld].idxmax >= 0) { 3762. any = cg.zeroany; 3763. any.a_int = onlybeh = BL_TH_VAL_PERCENTAGE; 3764. add_menu(tmpwin, &nul_glyphinfo, &any, 'p', 0, ATR_NONE, 3765. clr, "Percentage threshold", MENU_ITEMFLAGS_NONE); 3766. nopts++; 3767. } 3768. 3769. if (fld == BL_HP) { 3770. any = cg.zeroany; 3771. any.a_int = onlybeh = BL_TH_CRITICALHP; 3772. Sprintf(buf, "Highlight critically low %s", 3773. initblstats[fld].fldname); 3774. add_menu(tmpwin, &nul_glyphinfo, &any, 'C', 0, ATR_NONE, 3775. clr, buf, MENU_ITEMFLAGS_NONE); 3776. nopts++; 3777. } 3778. 3779. if (initblstats[fld].anytype == ANY_STR 3780. || fld == BL_CAP || fld == BL_HUNGER) { 3781. any = cg.zeroany; 3782. any.a_int = onlybeh = BL_TH_TEXTMATCH; 3783. Sprintf(buf, "%s text match", initblstats[fld].fldname); 3784. add_menu(tmpwin, &nul_glyphinfo, &any, 't', 0, ATR_NONE, 3785. clr, buf, MENU_ITEMFLAGS_NONE); 3786. nopts++; 3787. } 3788. 3789. Sprintf(buf, "Select %s field hilite behavior:", 3790. initblstats[fld].fldname); 3791. end_menu(tmpwin, buf); 3792. 3793. if (nopts > 1) { 3794. res = select_menu(tmpwin, PICK_ONE, &picks); 3795. if (res == 0) /* none chosen*/ 3796. beh = BL_TH_NONE; 3797. else if (res == -1) /* menu cancelled */ 3798. beh = (BL_TH_NONE - 1); 3799. } else if (onlybeh != BL_TH_NONE) { 3800. beh = onlybeh; 3801. } 3802. destroy_nhwindow(tmpwin); 3803. if (res > 0) { 3804. beh = picks->item.a_int; 3805. free((genericptr_t) picks); 3806. } 3807. return beh; 3808. } 3809. 3810. staticfn int 3811. status_hilite_menu_choose_updownboth( 3812. int fld, 3813. const char *str, 3814. boolean ltok, boolean gtok) 3815. { 3816. int res, ret = NO_LTEQGT; 3817. winid tmpwin; 3818. char buf[BUFSZ]; 3819. anything any; 3820. menu_item *picks = (menu_item *) 0; 3821. int clr = NO_COLOR; 3822. 3823. tmpwin = create_nhwindow(NHW_MENU); 3824. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 3825. 3826. if (ltok) { 3827. if (str) 3828. Sprintf(buf, "%s than %s", 3829. (fld == BL_AC) ? "Better (lower)" : "Less", str); 3830. else 3831. Sprintf(buf, "Value goes down"); 3832. any = cg.zeroany; 3833. any.a_int = 10 + LT_VALUE; 3834. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 3835. clr, buf, MENU_ITEMFLAGS_NONE); 3836. 3837. if (str) { 3838. Sprintf(buf, "%s or %s", 3839. str, (fld == BL_AC) ? "better (lower)" : "less"); 3840. any = cg.zeroany; 3841. any.a_int = 10 + LE_VALUE; 3842. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 3843. clr, buf, MENU_ITEMFLAGS_NONE); 3844. } 3845. } 3846. 3847. if (str) 3848. Sprintf(buf, "Exactly %s", str); 3849. else 3850. Sprintf(buf, "Value changes"); 3851. any = cg.zeroany; 3852. any.a_int = 10 + EQ_VALUE; 3853. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 3854. clr, buf, MENU_ITEMFLAGS_NONE); 3855. 3856. if (gtok) { 3857. if (str) { 3858. Sprintf(buf, "%s or %s", 3859. str, (fld == BL_AC) ? "worse (higher)" : "more"); 3860. any = cg.zeroany; 3861. any.a_int = 10 + GE_VALUE; 3862. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 3863. clr, buf, MENU_ITEMFLAGS_NONE); 3864. } 3865. 3866. if (str) 3867. Sprintf(buf, "%s than %s", 3868. (fld == BL_AC) ? "Worse (higher)" : "More", str); 3869. else 3870. Sprintf(buf, "Value goes up"); 3871. any = cg.zeroany; 3872. any.a_int = 10 + GT_VALUE; 3873. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, 3874. buf, MENU_ITEMFLAGS_NONE); 3875. } 3876. Sprintf(buf, "Select field %s value:", initblstats[fld].fldname); 3877. end_menu(tmpwin, buf); 3878. 3879. res = select_menu(tmpwin, PICK_ONE, &picks); 3880. destroy_nhwindow(tmpwin); 3881. if (res > 0) { 3882. ret = picks->item.a_int - 10; 3883. free((genericptr_t) picks); 3884. } 3885. 3886. return ret; 3887. } 3888. 3889. staticfn boolean 3890. status_hilite_menu_add(int origfld) 3891. { 3892. int fld; 3893. int behavior; 3894. int lt_gt_eq; 3895. int clr = NO_COLOR, atr = HL_UNDEF; 3896. struct hilite_s hilite; 3897. unsigned long cond = 0UL; 3898. char colorqry[BUFSZ]; 3899. char attrqry[BUFSZ]; 3900. int retry = 0; 3901. 3902. choose_field: 3903. fld = origfld; 3904. if (fld == BL_FLUSH) { 3905. fld = status_hilite_menu_choose_field(); 3906. /* isn't this redundant given what follows? */ 3907. if (fld == BL_FLUSH) 3908. return FALSE; 3909. } 3910. 3911. if (fld == BL_FLUSH) 3912. return FALSE; 3913. 3914. colorqry[0] = '\0'; 3915. attrqry[0] = '\0'; 3916. 3917. memset((genericptr_t) &hilite, 0, sizeof (struct hilite_s)); 3918. hilite.next = (struct hilite_s *) 0; 3919. hilite.set = FALSE; /* mark it "unset" */ 3920. hilite.fld = fld; 3921. 3922. choose_behavior: 3923. behavior = status_hilite_menu_choose_behavior(fld); 3924. 3925. if (behavior == (BL_TH_NONE - 1)) { 3926. return FALSE; 3927. } else if (behavior == BL_TH_NONE) { 3928. if (origfld == BL_FLUSH) 3929. goto choose_field; 3930. return FALSE; 3931. } 3932. 3933. hilite.behavior = behavior; 3934. 3935. choose_value: 3936. if (retry++ > 5) { 3937. pline("That's enough tries."); 3938. return FALSE; 3939. } 3940. if (behavior == BL_TH_VAL_PERCENTAGE 3941. || behavior == BL_TH_VAL_ABSOLUTE) { 3942. char inbuf[BUFSZ], buf[BUFSZ]; 3943. anything aval; 3944. int val, dt; 3945. boolean gotnum = FALSE, percent = (behavior == BL_TH_VAL_PERCENTAGE); 3946. char *inp, *numstart; 3947. const char *op; 3948. 3949. lt_gt_eq = NO_LTEQGT; /* not set up yet */ 3950. inbuf[0] = '\0'; 3951. Sprintf(buf, "Enter %svalue for %s threshold:", 3952. percent ? "percentage " : "", 3953. initblstats[fld].fldname); 3954. getlin(buf, inbuf); 3955. if (inbuf[0] == '\0' || inbuf[0] == '\033') 3956. goto choose_behavior; 3957. 3958. inp = numstart = trimspaces(inbuf); 3959. if (!*inp) 3960. goto choose_behavior; 3961. 3962. /* allow user to enter "<50%" or ">50" or just "50" 3963. or <=50% or >=50 or =50 */ 3964. if (*inp == '>' || *inp == '<' || *inp == '=') { 3965. lt_gt_eq = (*inp == '>') ? ((inp[1] == '=') ? GE_VALUE : GT_VALUE) 3966. : (*inp == '<') ? ((inp[1] == '=') ? LE_VALUE : LT_VALUE) 3967. : EQ_VALUE; 3968. *inp++ = ' '; 3969. numstart++; 3970. if (lt_gt_eq == GE_VALUE || lt_gt_eq == LE_VALUE) { 3971. *inp++ = ' '; 3972. numstart++; 3973. } 3974. } 3975. if (*inp == '-') { 3976. inp++; 3977. } else if (*inp == '+') { 3978. *inp++ = ' '; 3979. numstart++; 3980. } 3981. while (digit(*inp)) { 3982. inp++; 3983. gotnum = TRUE; 3984. } 3985. if (*inp == '%') { 3986. if (!percent) { 3987. pline("Not expecting a percentage."); 3988. goto choose_behavior; 3989. } 3990. *inp = '\0'; /* strip '%' [this accepts trailing junk!] */ 3991. } else if (*inp) { 3992. /* some random characters */ 3993. pline("\"%s\" is not a recognized number.", inp); 3994. goto choose_value; 3995. } 3996. if (!gotnum) { 3997. pline("Is that an invisible number?"); 3998. goto choose_value; 3999. } 4000. op = (lt_gt_eq == LT_VALUE) ? "<" 4001. : (lt_gt_eq == LE_VALUE) ? "<=" 4002. : (lt_gt_eq == GT_VALUE) ? ">" 4003. : (lt_gt_eq == GE_VALUE) ? ">=" 4004. : (lt_gt_eq == EQ_VALUE) ? "=" 4005. : ""; /* didn't specify lt_gt_eq with number */ 4006. 4007. aval = cg.zeroany; 4008. dt = percent ? ANY_INT : initblstats[fld].anytype; 4009. (void) s_to_anything(&aval, numstart, dt); 4010. 4011. if (percent) { 4012. val = aval.a_int; 4013. if (initblstats[fld].idxmax == -1) { 4014. pline("Field '%s' does not support percentage values.", 4015. initblstats[fld].fldname); 4016. behavior = BL_TH_VAL_ABSOLUTE; 4017. goto choose_value; 4018. } 4019. /* if player only specified a number then lt_gt_eq isn't set 4020. up yet and the >-1 and <101 exceptions can't be honored; 4021. deliberate use of those should be uncommon enough for 4022. that to be palatable; for 0 and 100, choose_updown_both() 4023. will prevent useless operations */ 4024. if ((val < 0 && (val != -1 || lt_gt_eq != GT_VALUE)) 4025. || (val == 0 && lt_gt_eq == LT_VALUE) 4026. || (val == 100 && lt_gt_eq == GT_VALUE) 4027. || (val > 100 && (val != 101 || lt_gt_eq != LT_VALUE))) { 4028. pline("'%s%d%%' is not a valid percent value.", op, val); 4029. goto choose_value; 4030. } 4031. /* restore suffix for use in color and attribute prompts */ 4032. if (!strchr(numstart, '%')) 4033. Strcat(numstart, "%"); 4034. 4035. /* reject negative values except for AC and >-1; reject 0 for < */ 4036. } else if (dt == ANY_INT 4037. && (aval.a_int < ((fld == BL_AC) ? -128 4038. : (lt_gt_eq == GT_VALUE) ? -1 4039. : (lt_gt_eq == LT_VALUE) ? 1 : 0))) { 4040. pline("%s'%s%d'%s", threshold_value, 4041. op, aval.a_int, is_out_of_range); 4042. goto choose_value; 4043. } else if (dt == ANY_LONG 4044. && (aval.a_long < ((lt_gt_eq == GT_VALUE) ? -1L 4045. : (lt_gt_eq == LT_VALUE) ? 1L : 0L))) { 4046. pline("%s'%s%ld'%s", threshold_value, 4047. op, aval.a_long, is_out_of_range); 4048. goto choose_value; 4049. } 4050. 4051. if (lt_gt_eq == NO_LTEQGT) { 4052. boolean ltok = ((dt == ANY_INT) 4053. ? (aval.a_int > 0 || fld == BL_AC) 4054. : (aval.a_long > 0L)), 4055. gtok = (!percent || aval.a_long < 100); 4056. 4057. lt_gt_eq = status_hilite_menu_choose_updownboth(fld, inbuf, 4058. ltok, gtok); 4059. if (lt_gt_eq == NO_LTEQGT) 4060. goto choose_value; 4061. } 4062. 4063. Sprintf(colorqry, "Choose a color for when %s is %s%s%s:", 4064. initblstats[fld].fldname, 4065. (lt_gt_eq == LT_VALUE) ? "less than " 4066. : (lt_gt_eq == GT_VALUE) ? "more than " 4067. : "", 4068. numstart, 4069. (lt_gt_eq == LE_VALUE) ? " or less" 4070. : (lt_gt_eq == GE_VALUE) ? " or more" 4071. : ""); 4072. Sprintf(attrqry, "Choose attribute for when %s is %s%s%s:", 4073. initblstats[fld].fldname, 4074. (lt_gt_eq == LT_VALUE) ? "less than " 4075. : (lt_gt_eq == GT_VALUE) ? "more than " 4076. : "", 4077. numstart, 4078. (lt_gt_eq == LE_VALUE) ? " or less" 4079. : (lt_gt_eq == GE_VALUE) ? " or more" 4080. : ""); 4081. 4082. hilite.rel = lt_gt_eq; 4083. hilite.value = aval; 4084. } else if (behavior == BL_TH_UPDOWN) { 4085. if (initblstats[fld].anytype != ANY_STR) { 4086. boolean ltok = (fld != BL_TIME), gtok = TRUE; 4087. 4088. lt_gt_eq = status_hilite_menu_choose_updownboth(fld, (char *) 0, 4089. ltok, gtok); 4090. if (lt_gt_eq == NO_LTEQGT) 4091. goto choose_behavior; 4092. } else { /* ANY_STR */ 4093. /* player picked '<field> value changes' in outer menu; 4094. ordered string comparison is supported but LT/GT for the 4095. string status fields (title, dungeon level, alignment) 4096. is pointless; rather than calling ..._choose_updownboth() 4097. with ltok==False plus gtok=False and having a menu with a 4098. single choice, skip it altogether and just use 'changed' */ 4099. lt_gt_eq = EQ_VALUE; 4100. } 4101. Sprintf(colorqry, "Choose a color for when %s %s:", 4102. initblstats[fld].fldname, 4103. (lt_gt_eq == EQ_VALUE) ? "changes" 4104. : (lt_gt_eq == LT_VALUE) ? "decreases" 4105. : "increases"); 4106. Sprintf(attrqry, "Choose attribute for when %s %s:", 4107. initblstats[fld].fldname, 4108. (lt_gt_eq == EQ_VALUE) ? "changes" 4109. : (lt_gt_eq == LT_VALUE) ? "decreases" 4110. : "increases"); 4111. hilite.rel = lt_gt_eq; 4112. } else if (behavior == BL_TH_CONDITION) { 4113. cond = query_conditions(); 4114. if (!cond) { 4115. if (origfld == BL_FLUSH) 4116. goto choose_field; 4117. return FALSE; 4118. } 4119. Snprintf(colorqry, sizeof(colorqry), 4120. "Choose a color for conditions %s:", 4121. conditionbitmask2str(cond)); 4122. Snprintf(attrqry, sizeof(attrqry), 4123. "Choose attribute for conditions %s:", 4124. conditionbitmask2str(cond)); 4125. } else if (behavior == BL_TH_TEXTMATCH) { 4126. char qry_buf[BUFSZ]; 4127. 4128. Sprintf(qry_buf, "%s %s text value to match:", 4129. (fld == BL_CAP 4130. || fld == BL_ALIGN 4131. || fld == BL_HUNGER 4132. || fld == BL_TITLE) ? "Choose" : "Enter", 4133. initblstats[fld].fldname); 4134. if (fld == BL_CAP) { 4135. int rv = query_arrayvalue(qry_buf, 4136. enc_stat, 4137. SLT_ENCUMBER, OVERLOADED + 1); 4138. 4139. if (rv < SLT_ENCUMBER) 4140. goto choose_behavior; 4141. 4142. hilite.rel = TXT_VALUE; 4143. Strcpy(hilite.textmatch, enc_stat[rv]); 4144. } else if (fld == BL_ALIGN) { 4145. static const char *const aligntxt[] = { 4146. "chaotic", "neutral", "lawful" 4147. }; 4148. int rv = query_arrayvalue(qry_buf, 4149. aligntxt, 0, 2 + 1); 4150. 4151. if (rv < 0) 4152. goto choose_behavior; 4153. 4154. hilite.rel = TXT_VALUE; 4155. Strcpy(hilite.textmatch, aligntxt[rv]); 4156. } else if (fld == BL_HUNGER) { 4157. static const char *const hutxt[] = { 4158. "Satiated", (char *) 0, "Hungry", "Weak", 4159. "Fainting", "Fainted", "Starved" 4160. }; 4161. int rv = query_arrayvalue(qry_buf, hutxt, SATIATED, STARVED + 1); 4162. 4163. if (rv < SATIATED) 4164. goto choose_behavior; 4165. 4166. hilite.rel = TXT_VALUE; 4167. Strcpy(hilite.textmatch, hutxt[rv]); 4168. } else if (fld == BL_TITLE) { 4169. const char *rolelist[3 * 9 + 1]; 4170. char mbuf[MAXVALWIDTH], fbuf[MAXVALWIDTH], obuf[MAXVALWIDTH]; 4171. int i, j, rv; 4172. 4173. for (i = j = 0; i < 9; i++) { 4174. Sprintf(mbuf, "\"%s\"", gu.urole.rank[i].m); 4175. if (gu.urole.rank[i].f) { 4176. Sprintf(fbuf, "\"%s\"", gu.urole.rank[i].f); 4177. Snprintf(obuf, sizeof obuf, "%s or %s", 4178. flags.female ? fbuf : mbuf, 4179. flags.female ? mbuf : fbuf); 4180. } else { 4181. fbuf[0] = obuf[0] = '\0'; 4182. } 4183. if (flags.female) { 4184. if (*fbuf) 4185. rolelist[j++] = dupstr(fbuf); 4186. rolelist[j++] = dupstr(mbuf); 4187. if (*obuf) 4188. rolelist[j++] = dupstr(obuf); 4189. } else { 4190. rolelist[j++] = dupstr(mbuf); 4191. if (*fbuf) 4192. rolelist[j++] = dupstr(fbuf); 4193. if (*obuf) 4194. rolelist[j++] = dupstr(obuf); 4195. } 4196. } 4197. rolelist[j++] = dupstr("\"none of the above (polymorphed)\""); 4198. 4199. rv = query_arrayvalue(qry_buf, rolelist, 0, j); 4200. if (rv >= 0) { 4201. hilite.rel = TXT_VALUE; 4202. Strcpy(hilite.textmatch, rolelist[rv]); 4203. } 4204. for (i = 0; i < j; i++) 4205. free((genericptr_t) rolelist[i]), rolelist[i] = 0; 4206. if (rv < 0) 4207. goto choose_behavior; 4208. } else { 4209. char inbuf[BUFSZ]; 4210. 4211. inbuf[0] = '\0'; 4212. getlin(qry_buf, inbuf); 4213. if (inbuf[0] == '\0' || inbuf[0] == '\033') 4214. goto choose_behavior; 4215. 4216. hilite.rel = TXT_VALUE; 4217. if (strlen(inbuf) < sizeof hilite.textmatch) 4218. Strcpy(hilite.textmatch, inbuf); 4219. else 4220. return FALSE; 4221. } 4222. Sprintf(colorqry, "Choose a color for when %s is '%s':", 4223. initblstats[fld].fldname, hilite.textmatch); 4224. Sprintf(attrqry, "Choose attribute for when %s is '%s':", 4225. initblstats[fld].fldname, hilite.textmatch); 4226. } else if (behavior == BL_TH_ALWAYS_HILITE) { 4227. Sprintf(colorqry, "Choose a color to always hilite %s:", 4228. initblstats[fld].fldname); 4229. Sprintf(attrqry, "Choose attribute to always hilite %s:", 4230. initblstats[fld].fldname); 4231. } 4232. 4233. choose_color: 4234. clr = query_color(colorqry, NO_COLOR); 4235. if (clr == -1) { 4236. if (behavior != BL_TH_ALWAYS_HILITE) 4237. goto choose_value; 4238. else 4239. goto choose_behavior; 4240. } 4241. atr = query_attr(attrqry, ATR_NONE); 4242. if (atr == -1) 4243. goto choose_color; 4244. 4245. if (behavior == BL_TH_CONDITION) { 4246. char clrbuf[BUFSZ]; 4247. char attrbuf[BUFSZ]; 4248. char *tmpattr; 4249. 4250. if (atr & HL_BOLD) 4251. gc.cond_hilites[HL_ATTCLR_BOLD] |= cond; 4252. if (atr & HL_DIM) 4253. gc.cond_hilites[HL_ATTCLR_DIM] |= cond; 4254. if (atr & HL_ITALIC) 4255. gc.cond_hilites[HL_ATTCLR_ITALIC] |= cond; 4256. if (atr & HL_ULINE) 4257. gc.cond_hilites[HL_ATTCLR_ULINE] |= cond; 4258. if (atr & HL_BLINK) 4259. gc.cond_hilites[HL_ATTCLR_BLINK] |= cond; 4260. if (atr & HL_INVERSE) 4261. gc.cond_hilites[HL_ATTCLR_INVERSE] |= cond; 4262. if (atr == HL_NONE) { 4263. gc.cond_hilites[HL_ATTCLR_BOLD] &= ~cond; 4264. gc.cond_hilites[HL_ATTCLR_DIM] &= ~cond; 4265. gc.cond_hilites[HL_ATTCLR_ITALIC] &= ~cond; 4266. gc.cond_hilites[HL_ATTCLR_ULINE] &= ~cond; 4267. gc.cond_hilites[HL_ATTCLR_BLINK] &= ~cond; 4268. gc.cond_hilites[HL_ATTCLR_INVERSE] &= ~cond; 4269. } 4270. gc.cond_hilites[clr] |= cond; 4271. (void) strNsubst(strcpy(clrbuf, clr2colorname(clr)), " ", "-", 0); 4272. tmpattr = hlattr2attrname(atr, attrbuf, BUFSZ); 4273. if (tmpattr) 4274. Sprintf(eos(clrbuf), "&%s", tmpattr); 4275. pline("Added hilite condition/%s/%s", 4276. conditionbitmask2str(cond), clrbuf); 4277. } else { 4278. char *p, *q; 4279. 4280. hilite.coloridx = clr | (atr << 8); 4281. hilite.anytype = initblstats[fld].anytype; 4282. 4283. if (fld == BL_TITLE && (p = strstri(hilite.textmatch, " or ")) != 0) { 4284. /* split menu choice "male-rank or female-rank" into two distinct 4285. but otherwise identical rules, "male-rank" and "female-rank" */ 4286. *p = '\0'; /* chop off " or female-rank" */ 4287. /* new rule for male-rank */ 4288. status_hilite_add_threshold(fld, &hilite); 4289. pline("Added hilite %s", status_hilite2str(&hilite)); 4290. /* transfer female-rank to start of hilite.textmatch buffer */ 4291. p += sizeof " or " - sizeof ""; 4292. q = hilite.textmatch; 4293. while ((*q++ = *p++) != '\0') 4294. continue; 4295. /* proceed with normal addition of new rule */ 4296. } 4297. status_hilite_add_threshold(fld, &hilite); 4298. pline("Added hilite %s", status_hilite2str(&hilite)); 4299. } 4300. reset_status_hilites(); 4301. return TRUE; 4302. } 4303. 4304. staticfn boolean 4305. status_hilite_remove(int id) 4306. { 4307. struct _status_hilite_line_str *hlstr = status_hilite_str; 4308. 4309. while (hlstr && hlstr->id != id) { 4310. hlstr = hlstr->next; 4311. } 4312. 4313. if (!hlstr) 4314. return FALSE; 4315. 4316. if (hlstr->fld == BL_CONDITION) { 4317. int i; 4318. 4319. for (i = 0; i < CLR_MAX; i++) 4320. gc.cond_hilites[i] &= ~hlstr->mask; 4321. gc.cond_hilites[HL_ATTCLR_BOLD] &= ~hlstr->mask; 4322. gc.cond_hilites[HL_ATTCLR_DIM] &= ~hlstr->mask; 4323. gc.cond_hilites[HL_ATTCLR_ITALIC] &= ~hlstr->mask; 4324. gc.cond_hilites[HL_ATTCLR_ULINE] &= ~hlstr->mask; 4325. gc.cond_hilites[HL_ATTCLR_BLINK] &= ~hlstr->mask; 4326. gc.cond_hilites[HL_ATTCLR_INVERSE] &= ~hlstr->mask; 4327. return TRUE; 4328. } else { 4329. int fld = hlstr->fld; 4330. struct hilite_s *hl, *hlprev = (struct hilite_s *) 0; 4331. 4332. for (hl = gb.blstats[0][fld].thresholds; hl; hl = hl->next) { 4333. if (hlstr->hl == hl) { 4334. if (hlprev) { 4335. hlprev->next = hl->next; 4336. } else { 4337. gb.blstats[0][fld].thresholds = hl->next; 4338. gb.blstats[1][fld].thresholds 4339. = gb.blstats[0][fld].thresholds; 4340. } 4341. if (gb.blstats[0][fld].hilite_rule == hl) { 4342. gb.blstats[0][fld].hilite_rule 4343. = gb.blstats[1][fld].hilite_rule 4344. = (struct hilite_s *) 0; 4345. gb.blstats[0][fld].time = gb.blstats[1][fld].time = 0L; 4346. } 4347. free((genericptr_t) hl); 4348. return TRUE; 4349. } 4350. hlprev = hl; 4351. } 4352. } 4353. return FALSE; 4354. } 4355. 4356. staticfn boolean 4357. status_hilite_menu_fld(int fld) 4358. { 4359. winid tmpwin; 4360. int i, res; 4361. menu_item *picks = (menu_item *) 0; 4362. anything any; 4363. int count = status_hilite_linestr_countfield(fld); 4364. struct _status_hilite_line_str *hlstr; 4365. char buf[BUFSZ]; 4366. boolean acted; 4367. int clr = NO_COLOR; 4368. 4369. if (!count) { 4370. if (status_hilite_menu_add(fld)) { 4371. status_hilite_linestr_done(); 4372. status_hilite_linestr_gather(); 4373. count = status_hilite_linestr_countfield(fld); 4374. } else 4375. return FALSE; 4376. } 4377. 4378. tmpwin = create_nhwindow(NHW_MENU); 4379. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 4380. 4381. if (count) { 4382. hlstr = status_hilite_str; 4383. while (hlstr) { 4384. if (hlstr->fld == fld) { 4385. any = cg.zeroany; 4386. any.a_int = hlstr->id; 4387. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 4388. clr, hlstr->str, MENU_ITEMFLAGS_NONE); 4389. } 4390. hlstr = hlstr->next; 4391. } 4392. } else { 4393. Sprintf(buf, "No current hilites for %s", initblstats[fld].fldname); 4394. add_menu_str(tmpwin, buf); 4395. } 4396. 4397. /* separator line */ 4398. add_menu_str(tmpwin, ""); 4399. 4400. if (count) { 4401. any = cg.zeroany; 4402. any.a_int = -1; 4403. add_menu(tmpwin, &nul_glyphinfo, &any, 'X', 0, ATR_NONE, clr, 4404. "Remove selected hilites", MENU_ITEMFLAGS_NONE); 4405. } 4406. 4407. #ifndef SCORE_ON_BOTL 4408. if (fld == BL_SCORE) { 4409. /* suppress 'Z - Add a new hilite' for 'score' when SCORE_ON_BOTL 4410. is disabled; we wouldn't be called for 'score' unless it has 4411. hilite rules from the config file, so count must be positive 4412. (hence there's no risk that we're putting up an empty menu) */ 4413. ; 4414. } else 4415. #endif 4416. { 4417. any = cg.zeroany; 4418. any.a_int = -2; 4419. add_menu(tmpwin, &nul_glyphinfo, &any, 'Z', 0, ATR_NONE, 4420. clr, "Add new hilites", MENU_ITEMFLAGS_NONE); 4421. } 4422. 4423. Sprintf(buf, "Current %s hilites:", initblstats[fld].fldname); 4424. end_menu(tmpwin, buf); 4425. 4426. acted = FALSE; 4427. if ((res = select_menu(tmpwin, PICK_ANY, &picks)) > 0) { 4428. int idx; 4429. unsigned mode = 0; 4430. 4431. for (i = 0; i < res; i++) { 4432. idx = picks[i].item.a_int; 4433. if (idx == -1) 4434. mode |= 1; /* delete selected hilites */ 4435. else if (idx == -2) 4436. mode |= 2; /* create new hilites */ 4437. } 4438. if (mode & 1) { /* delete selected hilites */ 4439. for (i = 0; i < res; i++) { 4440. idx = picks[i].item.a_int; 4441. if (idx > 0 && status_hilite_remove(idx)) 4442. acted = TRUE; 4443. } 4444. } 4445. if (mode & 2) { /* create new hilites */ 4446. while (status_hilite_menu_add(fld)) 4447. acted = TRUE; 4448. } 4449. free((genericptr_t) picks), picks = 0; 4450. } 4451. destroy_nhwindow(tmpwin); 4452. return acted; 4453. } 4454. 4455. staticfn void 4456. status_hilites_viewall(void) 4457. { 4458. winid datawin; 4459. struct _status_hilite_line_str *hlstr = status_hilite_str; 4460. char buf[BUFSZ]; 4461. 4462. datawin = create_nhwindow(NHW_TEXT); 4463. 4464. while (hlstr) { 4465. Sprintf(buf, "OPTIONS=hilite_status: %.*s", 4466. (int) (BUFSZ - sizeof "OPTIONS=hilite_status: " - 1), 4467. hlstr->str); 4468. putstr(datawin, 0, buf); 4469. hlstr = hlstr->next; 4470. } 4471. 4472. display_nhwindow(datawin, FALSE); 4473. destroy_nhwindow(datawin); 4474. } 4475. 4476. void 4477. all_options_statushilites(strbuf_t *sbuf) 4478. { 4479. struct _status_hilite_line_str *hlstr; 4480. char buf[BUFSZ]; 4481. 4482. status_hilite_linestr_done(); 4483. status_hilite_linestr_gather(); 4484. 4485. hlstr = status_hilite_str; 4486. 4487. while (hlstr) { 4488. Sprintf(buf, "OPTIONS=hilite_status: %.*s\n", 4489. (int) (BUFSZ - sizeof "OPTIONS=hilite_status: " - 1), 4490. hlstr->str); 4491. strbuf_append(sbuf, buf); 4492. hlstr = hlstr->next; 4493. } 4494. status_hilite_linestr_done(); 4495. } 4496. 4497. boolean 4498. status_hilite_menu(void) 4499. { 4500. winid tmpwin; 4501. int i, fld, res; 4502. menu_item *picks = (menu_item *) 0; 4503. anything any; 4504. boolean redo; 4505. int countall; 4506. int clr = NO_COLOR; 4507. 4508. shlmenu_redo: 4509. redo = FALSE; 4510. 4511. tmpwin = create_nhwindow(NHW_MENU); 4512. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 4513. 4514. status_hilite_linestr_gather(); 4515. countall = status_hilite_linestr_countfield(BL_FLUSH); 4516. if (countall) { 4517. any = cg.zeroany; 4518. any.a_int = -1; 4519. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 4520. clr, "View all hilites in config format", 4521. MENU_ITEMFLAGS_NONE); 4522. 4523. add_menu_str(tmpwin, ""); 4524. } 4525. 4526. for (i = 0; i < MAXBLSTATS; i++) { 4527. int count; 4528. char buf[BUFSZ]; 4529. 4530. fld = initblstats[i].fld; 4531. count = status_hilite_linestr_countfield(fld); 4532. #ifndef SCORE_ON_BOTL 4533. /* config file might contain rules for highlighting 'score' 4534. even when SCORE_ON_BOTL is disabled; if so, 'O' command 4535. menus will show them and allow deletions but not additions, 4536. otherwise, it won't show 'score' at all */ 4537. if (fld == BL_SCORE && !count) 4538. continue; 4539. #endif 4540. any = cg.zeroany; 4541. any.a_int = fld + 1; 4542. Sprintf(buf, "%-18s", initblstats[i].fldname); 4543. if (count) 4544. Sprintf(eos(buf), " (%d defined)", count); 4545. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 4546. clr, buf, MENU_ITEMFLAGS_NONE); 4547. } 4548. 4549. end_menu(tmpwin, "Status hilites:"); 4550. if ((res = select_menu(tmpwin, PICK_ONE, &picks)) > 0) { 4551. fld = picks->item.a_int - 1; 4552. if (fld < 0) { 4553. status_hilites_viewall(); 4554. } else { 4555. if (status_hilite_menu_fld(fld)) 4556. reset_status_hilites(); 4557. } 4558. free((genericptr_t) picks), picks = (menu_item *) 0; 4559. redo = TRUE; 4560. } 4561. 4562. destroy_nhwindow(tmpwin); 4563. countall = status_hilite_linestr_countfield(BL_FLUSH); 4564. status_hilite_linestr_done(); 4565. 4566. /* fuzzer is unlikely to pick something useful within nested menus; 4567. limit it to one try */ 4568. if (redo && !iflags.debug_fuzzer) 4569. goto shlmenu_redo; 4570. 4571. /* hilite_delta=='statushilites' does double duty: it is the 4572. number of turns for temporary highlights to remain visible 4573. and also when non-zero it is the flag to enable highlighting */ 4574. if (countall > 0 && !iflags.hilite_delta) 4575. iflags.hilite_delta = 3L; 4576. 4577. return TRUE; 4578. } 4579. 4580. #endif /* STATUS_HILITES */ 4581. 4582. /*botl.c*/