1 /* NetHack 3.6 botl.c $NHDT-Date: 1447978683 2015/11/20 00:18:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.69 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
8 extern const char *hu_stat[]; /* defined in eat.c */
11 const char *const enc_stat[] = { "", "Burdened", "Stressed",
12 "Strained", "Overtaxed", "Overloaded" };
14 const char *const enc_stat[] = { "", "
\82æ
\82ë
\82ß
\82«", "
\88³
\94\97",
15 "
\8cÀ
\8aE", "
\89×
\8fd", "
\92´
\89ß"};
18 STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */
19 STATIC_DCL const char *NDECL(rank);
21 #ifndef STATUS_VIA_WINDOWPORT
23 STATIC_DCL void NDECL(bot1);
24 STATIC_DCL void NDECL(bot2);
33 Strcpy(newbot1, plname);
34 if ('a' <= newbot1[0] && newbot1[0] <= 'z')
35 newbot1[0] += 'A' - 'a';
37 if(is_kanji1(newbot1, 9))
42 Sprintf(nb = eos(newbot1), " the ");
44 Sprintf(nb = eos(newbot1)," ");
50 Strcpy(mbot, mons[u.umonnum].mname);
51 while (mbot[k] != 0) {
52 if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
57 Strcpy(nb = eos(nb), mbot);
59 Strcpy(nb = eos(nb), rank());
61 Sprintf(nb = eos(nb), " ");
63 j = (int) ((nb + 2) - newbot1); /* strlen(newbot1) but less computation */
65 Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */
66 if (ACURR(A_STR) > 18) {
67 if (ACURR(A_STR) > STR18(100))
69 Sprintf(nb = eos(nb), "St:%2d ", ACURR(A_STR) - 100);
71 Sprintf(nb = eos(nb), "
\8b:%2d ", ACURR(A_STR) - 100);
72 else if (ACURR(A_STR) < STR18(100))
74 Sprintf(nb = eos(nb), "St:18/%02d ", ACURR(A_STR) - 18);
76 Sprintf(nb = eos(nb), "
\8b:18/%02d ", ACURR(A_STR) - 18);
79 Sprintf(nb = eos(nb), "St:18/** ");
81 Sprintf(nb = eos(nb), "
\8b:18/** ");
84 Sprintf(nb = eos(nb), "St:%-1d ", ACURR(A_STR));
86 Sprintf(nb = eos(nb), "
\8b:%-1d ", ACURR(A_STR));
88 Sprintf(nb = eos(nb), "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
90 Sprintf(nb = eos(nb), "
\91\81:%-1d
\91Ï:%-1d
\92m:%-1d
\8c«:%-1d
\96£:%-1d ",
91 ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS),
95 (u.ualign.type == A_CHAOTIC)
97 : (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful");
100 (u.ualign.type == A_CHAOTIC)
102 : (u.ualign.type == A_NEUTRAL) ? "
\92\86\97§" : "
\92\81\8f\98");
107 Sprintf(nb = eos(nb), " S:%ld", botl_score());
109 Sprintf(nb = eos(nb), "%ld
\93_", botl_score());
111 curs(WIN_STATUS, 1, 0);
112 putstr(WIN_STATUS, 0, newbot1);
121 int cap = near_capacity();
123 hp = Upolyd ? u.mh : u.uhp;
124 hpmax = Upolyd ? u.mhmax : u.uhpmax;
128 (void) describe_level(newbot2);
130 Sprintf(nb = eos(newbot2), "%s:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d",
132 Sprintf(nb = eos(newbot2), "%s:%-2ld
\91Ì:%d(%d)
\96\82:%d(%d)
\8aZ:%-2d",
133 encglyph(objnum_to_glyph(GOLD_PIECE)), money_cnt(invent), hp,
134 hpmax, u.uen, u.uenmax, u.uac);
137 Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
138 else if (flags.showexp)
140 Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel, u.uexp);
142 Sprintf(nb = eos(nb), "
\8co
\8c±:%u/%-1ld", u.ulevel,u.uexp);
145 Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
147 Sprintf(nb = eos(nb), "
\8co
\8c±:%u", u.ulevel);
151 Sprintf(nb = eos(nb), " T:%ld", moves);
153 Sprintf(nb = eos(nb), "
\95à:%ld", moves);
154 if (strcmp(hu_stat[u.uhs], " ")) {
155 Sprintf(nb = eos(nb), " ");
156 Strcat(newbot2, hu_stat[u.uhs]);
160 Sprintf(nb = eos(nb), " Conf");
162 Sprintf(nb = eos(nb), "
\8d¬
\97\90");
164 if (u.usick_type & SICK_VOMITABLE)
166 Sprintf(nb = eos(nb), " FoodPois");
168 Sprintf(nb = eos(nb), "
\90H
\93Å");
169 if (u.usick_type & SICK_NONVOMITABLE)
171 Sprintf(nb = eos(nb), " Ill");
173 Sprintf(nb = eos(nb), "
\95a
\8bC");
177 Sprintf(nb = eos(nb), " Blind");
179 Sprintf(nb = eos(nb), "
\96Ó
\96Ú");
182 Sprintf(nb = eos(nb), " Stun");
184 Sprintf(nb = eos(nb), " á¿
\9dò");
187 Sprintf(nb = eos(nb), " Hallu");
189 Sprintf(nb = eos(nb), "
\8c¶
\8ao");
192 Sprintf(nb = eos(nb), " Slime");
194 Sprintf(nb = eos(nb), "
\82Ç
\82ë
\82Ç
\82ë");
195 if (cap > UNENCUMBERED)
196 Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
197 curs(WIN_STATUS, 1, 1);
198 putmixed(WIN_STATUS, 0, newbot2);
208 context.botl = context.botlx = 0;
211 #endif /* !STATUS_VIA_WINDOWPORT */
213 /* convert experience level (1..30) to rank index (0..8) */
218 return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8;
221 #if 0 /* not currently needed */
222 /* convert rank index (0..8) to experience level (1..30) */
227 return (rank <= 0) ? 1 : (rank <= 8) ? ((rank * 4) - 2) : 30;
232 rank_of(lev, monnum, female)
237 register const struct Role *role;
241 for (role = roles; role->name.m; role++)
242 if (monnum == role->malenum || monnum == role->femalenum)
248 for (i = xlev_to_rank((int) lev); i >= 0; i--) {
249 if (female && role->rank[i].f)
250 return role->rank[i].f;
252 return role->rank[i].m;
255 /* Try the role name, instead */
256 if (female && role->name.f)
258 else if (role->name.m)
263 STATIC_OVL const char *
266 return rank_of(u.ulevel, Role_switch, flags.female);
270 title_to_mon(str, rank_indx, title_length)
272 int *rank_indx, *title_length;
276 /* Loop through each of the roles */
277 for (i = 0; roles[i].name.m; i++)
278 for (j = 0; j < 9; j++) {
279 if (roles[i].rank[j].m
280 && !strncmpi(str, roles[i].rank[j].m,
281 strlen(roles[i].rank[j].m))) {
285 *title_length = strlen(roles[i].rank[j].m);
286 return roles[i].malenum;
288 if (roles[i].rank[j].f
289 && !strncmpi(str, roles[i].rank[j].f,
290 strlen(roles[i].rank[j].f))) {
294 *title_length = strlen(roles[i].rank[j].f);
295 return (roles[i].femalenum != NON_PM) ? roles[i].femalenum
305 register int i, r, maxr = 0;
306 for (i = 0; i < 9; i++) {
307 if (urole.rank[i].m && (r = strlen(urole.rank[i].m)) > maxr)
309 if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr)
320 long deepest = deepest_lev_reached(FALSE);
323 utotal = money_cnt(invent) + hidden_gold();
324 if ((utotal -= u.umoney0) < 0L)
326 utotal += u.urexp + (50 * (deepest - 1))
327 + (deepest > 30 ? 10000 : deepest > 20 ? 1000 * (deepest - 20) : 0);
328 if (utotal < u.urexp)
329 utotal = LONG_MAX; /* wrap around */
332 #endif /* SCORE_ON_BOTL */
334 /* provide the name of the current level for display by various ports */
341 /* TODO: Add in dungeon name */
343 Sprintf(buf, "%s ", dungeons[u.uz.dnum].dname);
344 else if (In_quest(&u.uz))
346 Sprintf(buf, "Home %d ", dunlev(&u.uz));
348 Sprintf(buf, "
\8cÌ
\8b½ %d ", dunlev(&u.uz));
349 else if (In_endgame(&u.uz))
351 Sprintf(buf, Is_astralevel(&u.uz) ? "Astral Plane " : "End Game ");
353 Sprintf(buf, Is_astralevel(&u.uz) ? "
\90¸
\97ì
\8aE " : "
\8dÅ
\8fI
\8e\8e\97û ");
355 /* ports with more room may expand this one */
357 Sprintf(buf, "Dlvl:%-2d ", depth(&u.uz));
359 Sprintf(buf, "
\92n
\89º:%-2d ", depth(&u.uz));
365 #ifdef STATUS_VIA_WINDOWPORT
366 /* =======================================================================*/
368 /* structure that tracks the status details in the core */
375 enum statusfields idxmax;
376 enum statusfields fld;
380 STATIC_DCL void NDECL(init_blstats);
381 STATIC_DCL char *FDECL(anything_to_s, (char *, anything *, int));
382 STATIC_DCL void FDECL(s_to_anything, (anything *, char *, int));
383 STATIC_OVL int FDECL(percentage, (struct istat_s *, struct istat_s *));
384 STATIC_OVL int FDECL(compare_blstats, (struct istat_s *, struct istat_s *));
386 #ifdef STATUS_HILITES
387 STATIC_DCL boolean FDECL(assign_hilite, (char *, char *, char *, char *,
389 STATIC_DCL const char *FDECL(clridx_to_s, (char *, int));
392 /* If entries are added to this, botl.h will require updating too */
393 STATIC_DCL struct istat_s initblstats[MAXBLSTATS] = {
394 { 0L, ANY_STR, { (genericptr_t) 0 }, (char *) 0, 80, 0, BL_TITLE},
395 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_STR},
396 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_DX},
397 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_CO},
398 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_IN},
399 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_WI},
400 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_CH},
401 { 0L, ANY_STR, { (genericptr_t) 0 }, (char *) 0, 40, 0, BL_ALIGN},
402 { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 20, 0, BL_SCORE},
403 { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 20, 0, BL_CAP},
404 { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 30, 0, BL_GOLD},
405 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, BL_ENEMAX, BL_ENE},
406 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_ENEMAX},
407 { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_XP},
408 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_AC},
409 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_HD},
410 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 20, 0, BL_TIME},
411 { 0L, ANY_UINT, { (genericptr_t) 0 }, (char *) 0, 40, 0, BL_HUNGER},
412 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, BL_HPMAX, BL_HP},
413 { 0L, ANY_INT, { (genericptr_t) 0 }, (char *) 0, 10, 0, BL_HPMAX},
414 { 0L, ANY_STR, { (genericptr_t) 0 }, (char *) 0, 80, 0, BL_LEVELDESC},
415 { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 20, 0, BL_EXP},
417 { (genericptr_t) 0 }, (char *) 0, 0, 0, BL_CONDITION}
420 static struct fieldid_t {
421 const char *fieldname;
422 enum statusfields fldid;
425 {"strength", BL_STR},
426 {"dexterity", BL_DX},
427 {"constitution", BL_CO},
428 {"intelligence", BL_IN},
431 {"alignment", BL_ALIGN},
433 {"carrying-capacity", BL_CAP},
436 {"power-max", BL_ENEMAX},
437 {"experience-level", BL_XP},
438 {"armor-class", BL_AC},
441 {"hunger", BL_HUNGER},
442 {"hitpoints", BL_HP},
443 {"hitpoints-max", BL_HPMAX},
444 {"dungeon-level", BL_LEVELDESC},
445 {"experience", BL_EXP},
446 {"condition", BL_CONDITION},
449 struct istat_s blstats[2][MAXBLSTATS];
450 static boolean blinit = FALSE, update_all = FALSE;
457 static int idx = 0, idx_p, idxmax;
458 boolean updated = FALSE;
461 struct istat_s *curr, *prev;
462 boolean valset[MAXBLSTATS], chgval = FALSE;
465 panic("bot before init.");
466 if (!youmonst.data) {
467 context.botl = context.botlx = 0;
472 cap = near_capacity();
474 idx = 1 - idx; /* 0 -> 1, 1 -> 0 */
476 /* clear the "value set" indicators */
477 (void) memset((genericptr_t) valset, 0, MAXBLSTATS * sizeof(boolean));
480 * Player name and title.
484 if ('a' <= buf[0] && buf[0] <= 'z')
487 Sprintf(nb = eos(buf), " the ");
492 Strcpy(mbot, mons[u.umonnum].mname);
493 while (mbot[k] != 0) {
494 if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
496 mbot[k] += 'A' - 'a';
499 Sprintf1(nb = eos(nb), mbot);
501 Sprintf1(nb = eos(nb), rank());
502 Sprintf(blstats[idx][BL_TITLE].val, "%-29s", buf);
503 valset[BL_TITLE] = TRUE; /* indicate val already set */
508 blstats[idx][BL_STR].a.a_int = ACURR(A_STR);
509 if (ACURR(A_STR) > 18) {
510 if (ACURR(A_STR) > STR18(100))
511 Sprintf(buf, "%2d", ACURR(A_STR) - 100);
512 else if (ACURR(A_STR) < STR18(100))
513 Sprintf(buf, "18/%02d", ACURR(A_STR) - 18);
515 Sprintf(buf, "18/**");
517 Sprintf(buf, "%-1d", ACURR(A_STR));
518 Strcpy(blstats[idx][BL_STR].val, buf);
519 valset[BL_STR] = TRUE; /* indicate val already set */
521 /* Dexterity, constitution, intelligence, wisdom, charisma. */
523 blstats[idx][BL_DX].a.a_int = ACURR(A_DEX);
524 blstats[idx][BL_CO].a.a_int = ACURR(A_CON);
525 blstats[idx][BL_IN].a.a_int = ACURR(A_INT);
526 blstats[idx][BL_WI].a.a_int = ACURR(A_WIS);
527 blstats[idx][BL_CH].a.a_int = ACURR(A_CHA);
531 Strcpy(blstats[idx][BL_ALIGN].val,
532 (u.ualign.type == A_CHAOTIC)
534 : (u.ualign.type == A_NEUTRAL) ? "Neutral" : "Lawful");
538 blstats[idx][BL_SCORE].a.a_long =
546 blstats[idx][BL_HP].a.a_int = Upolyd ? u.mh : u.uhp;
547 blstats[idx][BL_HPMAX].a.a_int = Upolyd ? u.mhmax : u.uhpmax;
548 if (blstats[idx][BL_HP].a.a_int < 0)
549 blstats[idx][BL_HP].a.a_int = 0;
553 (void) describe_level(blstats[idx][BL_LEVELDESC].val);
554 valset[BL_LEVELDESC] = TRUE; /* indicate val already set */
558 blstats[idx][BL_GOLD].a.a_long = money_cnt(invent);
560 * The tty port needs to display the current symbol for gold
561 * as a field header, so to accommodate that we pass gold with
562 * that already included. If a window port needs to use the text
563 * gold amount without the leading "$:" the port will have to
564 * add 2 to the value pointer it was passed in status_update()
565 * for the BL_GOLD case.
567 * Another quirk of BL_GOLD is that the field display may have
568 * changed if a new symbol set was loaded, or we entered or left
572 Sprintf(blstats[idx][BL_GOLD].val, "%s:%ld",
573 encglyph(objnum_to_glyph(GOLD_PIECE)),
574 blstats[idx][BL_GOLD].a.a_long);
575 valset[BL_GOLD] = TRUE; /* indicate val already set */
577 /* Power (magical energy) */
579 blstats[idx][BL_ENE].a.a_int = u.uen;
580 blstats[idx][BL_ENEMAX].a.a_int = u.uenmax;
584 blstats[idx][BL_AC].a.a_int = u.uac;
586 /* Monster level (if Upolyd) */
589 blstats[idx][BL_HD].a.a_int = mons[u.umonnum].mlevel;
591 blstats[idx][BL_HD].a.a_int = 0;
595 blstats[idx][BL_XP].a.a_int = u.ulevel;
596 blstats[idx][BL_EXP].a.a_int = u.uexp;
600 blstats[idx][BL_TIME].a.a_long = moves;
604 blstats[idx][BL_HUNGER].a.a_uint = u.uhs;
605 *(blstats[idx][BL_HUNGER].val) = '\0';
606 if (strcmp(hu_stat[u.uhs], " ") != 0)
607 Strcpy(blstats[idx][BL_HUNGER].val, hu_stat[u.uhs]);
608 valset[BL_HUNGER] = TRUE;
610 /* Carrying capacity */
612 *(blstats[idx][BL_CAP].val) = '\0';
613 blstats[idx][BL_CAP].a.a_int = cap;
614 if (cap > UNENCUMBERED)
615 Strcpy(blstats[idx][BL_CAP].val, enc_stat[cap]);
616 valset[BL_CAP] = TRUE;
621 blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_BLIND;
623 blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_BLIND;
626 blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_CONF;
628 blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_CONF;
630 if (Sick && u.usick_type & SICK_VOMITABLE)
631 blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FOODPOIS;
633 blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_FOODPOIS;
635 if (Sick && u.usick_type & SICK_NONVOMITABLE)
636 blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_ILL;
638 blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_ILL;
641 blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_HALLU;
643 blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_HALLU;
646 blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STUNNED;
648 blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_STUNNED;
651 blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_SLIMED;
653 blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_SLIMED;
656 * Now pass the changed values to window port.
658 for (i = 0; i < MAXBLSTATS; i++) {
659 if (((i == BL_SCORE) && !flags.showscore)
660 || ((i == BL_EXP) && !flags.showexp)
661 || ((i == BL_TIME) && !flags.time)
662 || ((i == BL_HD) && !Upolyd)
663 || ((i == BL_XP || i == BL_EXP) && Upolyd))
665 anytype = blstats[idx][i].anytype;
666 curr = &blstats[idx][i];
667 prev = &blstats[idx_p][i];
669 if (update_all || ((chg = compare_blstats(prev, curr)) != 0)
670 || ((chgval = (valset[i] && strcmp(blstats[idx][i].val,
671 blstats[idx_p][i].val)))
673 idxmax = blstats[idx][i].idxmax;
674 pc = (idxmax) ? percentage(curr, &blstats[idx][idxmax]) : 0;
676 (void) anything_to_s(curr->val, &curr->a, anytype);
677 if (anytype != ANY_MASK32) {
678 status_update(i, (genericptr_t) curr->val,
679 valset[i] ? chgval : chg, pc);
682 /* send pointer to mask */
683 (genericptr_t) &curr->a.a_ulong, chg, 0);
689 * It is possible to get here, with nothing having been pushed
690 * to the window port, when none of the info has changed. In that
691 * case, we need to force a call to status_update() when
692 * context.botlx is set. The tty port in particular has a problem
693 * if that isn't done, since it sets context.botlx when a menu or
694 * text display obliterates the status line.
696 * To work around it, we call status_update() with fictitious
697 * index of BL_FLUSH (-1).
699 if (context.botlx && !updated)
700 status_update(BL_FLUSH, (genericptr_t) 0, 0, 0);
702 context.botl = context.botlx = 0;
707 status_initialize(reassessment)
709 reassessment; /* TRUE = just reassess fields w/o other initialization*/
712 const char *fieldfmt = (const char *)0;
713 const char *fieldname = (const char *)0;
717 (*windowprocs.win_status_init)();
719 #ifdef STATUS_HILITES
720 status_notify_windowport(TRUE);
723 for (i = 0; i < MAXBLSTATS; ++i) {
724 enum statusfields fld = initblstats[i].fld;
730 status_enablefield(fld, fieldname, fieldfmt, TRUE);
734 fieldname = "strength";
735 status_enablefield(fld, fieldname, fieldfmt, TRUE);
739 fieldname = "dexterity";
740 status_enablefield(fld, fieldname, fieldfmt, TRUE);
744 fieldname = "constitution";
745 status_enablefield(fld, fieldname, fieldfmt, TRUE);
749 fieldname = "intelligence";
750 status_enablefield(fld, fieldname, fieldfmt, TRUE);
754 fieldname = "wisdom";
755 status_enablefield(fld, fieldname, fieldfmt, TRUE);
759 fieldname = "charisma";
760 status_enablefield(fld, fieldname, fieldfmt, TRUE);
764 fieldname = "alignment";
765 status_enablefield(fld, fieldname, fieldfmt, TRUE);
770 status_enablefield(fld, fieldname, fieldfmt,
771 (!flags.showscore) ? FALSE : TRUE);
775 fieldname = "carrying-capacity";
776 status_enablefield(fld, fieldname, fieldfmt, TRUE);
781 status_enablefield(fld, fieldname, fieldfmt, TRUE);
786 status_enablefield(fld, fieldname, fieldfmt, TRUE);
790 fieldname = "power-max";
791 status_enablefield(fld, fieldname, fieldfmt, TRUE);
795 fieldname = "experience-level";
796 status_enablefield(fld, fieldname, fieldfmt,
797 (Upolyd) ? FALSE : TRUE);
801 fieldname = "armor-class";
802 status_enablefield(fld, fieldname, fieldfmt, TRUE);
807 status_enablefield(fld, fieldname, fieldfmt,
808 (!Upolyd) ? FALSE : TRUE);
813 status_enablefield(fld, fieldname, fieldfmt,
814 (!flags.time) ? FALSE : TRUE);
818 fieldname = "hunger";
819 status_enablefield(fld, fieldname, fieldfmt, TRUE);
823 fieldname = "hitpoints";
824 status_enablefield(fld, fieldname, fieldfmt, TRUE);
828 fieldname = "hitpoint-max";
829 status_enablefield(fld, fieldname, fieldfmt, TRUE);
833 fieldname = "dungeon-level";
834 status_enablefield(fld, fieldname, fieldfmt, TRUE);
838 fieldname = "experience";
839 status_enablefield(fld, fieldname, fieldfmt,
840 (!flags.showexp || Upolyd) ? FALSE : TRUE);
844 fieldname = "condition";
845 status_enablefield(fld, fieldname, fieldfmt, TRUE);
860 /* call the window port cleanup routine first */
861 (*windowprocs.win_status_finish)();
863 /* free memory that we alloc'd now */
864 for (i = 0; i < MAXBLSTATS; ++i) {
865 if (blstats[0][i].val)
866 free((genericptr_t) blstats[0][i].val);
867 if (blstats[1][i].val)
868 free((genericptr_t) blstats[1][i].val);
875 static boolean initalready = FALSE;
879 impossible("init_blstats called more than once.");
884 for (i = BEFORE; i <= NOW; ++i) {
885 for (j = 0; j < MAXBLSTATS; ++j) {
886 blstats[i][j] = initblstats[j];
887 blstats[i][j].a = zeroany;
888 if (blstats[i][j].valwidth) {
889 blstats[i][j].val = (char *) alloc(blstats[i][j].valwidth);
890 blstats[i][j].val[0] = '\0';
892 blstats[i][j].val = (char *) 0;
898 anything_to_s(buf, a, anytype)
908 Sprintf(buf, "%lu", a->a_ulong);
911 Sprintf(buf, "%lx", a->a_ulong);
914 Sprintf(buf, "%ld", a->a_long);
917 Sprintf(buf, "%d", a->a_int);
920 Sprintf(buf, "%u", a->a_uint);
923 Sprintf(buf, "%d", *a->a_iptr);
926 Sprintf(buf, "%ld", *a->a_lptr);
929 Sprintf(buf, "%lu", *a->a_ulptr);
932 Sprintf(buf, "%u", *a->a_uptr);
934 case ANY_STR: /* do nothing */
944 s_to_anything(a, buf, anytype)
954 a->a_long = atol(buf);
957 a->a_int = atoi(buf);
960 a->a_uint = (unsigned) atoi(buf);
963 a->a_ulong = (unsigned long) atol(buf);
967 *a->a_iptr = atoi(buf);
971 *a->a_uptr = (unsigned) atoi(buf);
975 *a->a_lptr = atol(buf);
979 *a->a_ulptr = (unsigned long) atol(buf);
982 a->a_ulong = (unsigned long) atol(buf);
992 compare_blstats(bl1, bl2)
993 struct istat_s *bl1, *bl2;
995 int anytype, result = 0;
998 panic("compare_blstat: bad istat pointer %s, %s",
999 fmt_ptr((genericptr_t) bl1), fmt_ptr((genericptr_t) bl2));
1002 anytype = bl1->anytype;
1003 if ((!bl1->a.a_void || !bl2->a.a_void)
1004 && (anytype == ANY_IPTR || anytype == ANY_UPTR || anytype == ANY_LPTR
1005 || anytype == ANY_ULPTR)) {
1006 panic("compare_blstat: invalid pointer %s, %s",
1007 fmt_ptr((genericptr_t) bl1->a.a_void),
1008 fmt_ptr((genericptr_t) bl2->a.a_void));
1013 result = (bl1->a.a_int < bl2->a.a_int)
1015 : (bl1->a.a_int > bl2->a.a_int) ? -1 : 0;
1018 result = (*bl1->a.a_iptr < *bl2->a.a_iptr)
1020 : (*bl1->a.a_iptr > *bl2->a.a_iptr) ? -1 : 0;
1023 result = (bl1->a.a_long < bl2->a.a_long)
1025 : (bl1->a.a_long > bl2->a.a_long) ? -1 : 0;
1028 result = (*bl1->a.a_lptr < *bl2->a.a_lptr)
1030 : (*bl1->a.a_lptr > *bl2->a.a_lptr) ? -1 : 0;
1033 result = (bl1->a.a_uint < bl2->a.a_uint)
1035 : (bl1->a.a_uint > bl2->a.a_uint) ? -1 : 0;
1038 result = (*bl1->a.a_uptr < *bl2->a.a_uptr)
1040 : (*bl1->a.a_uptr > *bl2->a.a_uptr) ? -1 : 0;
1043 result = (bl1->a.a_ulong < bl2->a.a_ulong)
1045 : (bl1->a.a_ulong > bl2->a.a_ulong) ? -1 : 0;
1048 result = (*bl1->a.a_ulptr < *bl2->a.a_ulptr)
1050 : (*bl1->a.a_ulptr > *bl2->a.a_ulptr) ? -1 : 0;
1053 if (strcmp(bl1->val, bl2->val) == 0)
1059 if (bl1->a.a_ulong == bl2->a.a_ulong)
1071 percentage(bl, maxbl)
1072 struct istat_s *bl, *maxbl;
1077 if (!bl || !maxbl) {
1078 impossible("percentage: bad istat pointer %s, %s",
1079 fmt_ptr((genericptr_t) bl), fmt_ptr((genericptr_t) maxbl));
1083 anytype = bl->anytype;
1084 if (maxbl->a.a_void) {
1087 result = ((100 * bl->a.a_int) / maxbl->a.a_int);
1090 result = (int) ((100L * bl->a.a_long) / maxbl->a.a_long);
1093 result = (int) ((100U * bl->a.a_uint) / maxbl->a.a_uint);
1096 result = (int) ((100UL * bl->a.a_ulong) / maxbl->a.a_ulong);
1099 result = ((100 * (*bl->a.a_iptr)) / (*maxbl->a.a_iptr));
1102 result = (int) ((100L * (*bl->a.a_lptr)) / (*maxbl->a.a_lptr));
1105 result = (int) ((100U * (*bl->a.a_uptr)) / (*maxbl->a.a_uptr));
1108 result = (int) ((100UL * (*bl->a.a_ulptr)) / (*maxbl->a.a_ulptr));
1116 #ifdef STATUS_HILITES
1118 /****************************************************************************/
1119 /* Core status hiliting support */
1120 /****************************************************************************/
1130 struct hilite_s status_hilites[MAXBLSTATS];
1133 * This is the parser for the hilite options
1135 * OPTION=hilite_status: hitpoints/10%/red/normal
1137 * set_hilite_status() separates each hilite entry into its 4 component
1138 * strings, then calls assign_hilite() to make the adjustments.
1141 set_status_hilites(op, from_configfile)
1143 boolean from_configfile;
1145 char hsbuf[4][QBUFSZ];
1146 boolean rslt, badopt = FALSE;
1147 int fldnum, num = 0, ccount = 0;
1151 hsbuf[0][0] = hsbuf[1][0] = hsbuf[2][0] = hsbuf[3][0] = '\0';
1152 while (*op && fldnum < 4 && ccount < (QBUFSZ - 2)) {
1156 rslt = assign_hilite(&hsbuf[0][0], &hsbuf[1][0], &hsbuf[2][0],
1157 &hsbuf[3][0], from_configfile);
1163 hsbuf[0][0] = hsbuf[1][0] = '\0';
1164 hsbuf[2][0] = hsbuf[3][0] = '\0';
1167 } else if (c == '/') {
1171 hsbuf[fldnum][ccount++] = c;
1172 hsbuf[fldnum][ccount] = '\0';
1176 if (fldnum >= 2 && !badopt) {
1177 rslt = assign_hilite(&hsbuf[0][0], &hsbuf[1][0], &hsbuf[2][0],
1178 &hsbuf[3][0], from_configfile);
1188 clear_status_hilites(from_configfile)
1189 boolean from_configfile;
1194 for (i = 0; i < MAXBLSTATS; ++i) {
1195 (void) memset((genericptr_t) &status_hilites[i], 0,
1196 sizeof(struct hilite_s));
1197 /* notify window port */
1198 if (!from_configfile)
1199 status_threshold(i, blstats[0][i].anytype, it, 0, 0, 0);
1204 assign_hilite(sa, sb, sc, sd, from_configfile)
1205 char *sa, *sb, *sc, *sd;
1206 boolean from_configfile;
1209 int i = -1, dt = -1, idx = -1;
1210 int coloridx[2] = { -1, -1 };
1211 boolean inverse[2] = { FALSE, FALSE };
1212 boolean bold[2] = { FALSE, FALSE };
1213 boolean normal[2] = { 0, 0 };
1214 boolean percent = FALSE, down_up = FALSE, changed = FALSE;
1216 enum statusfields fld = BL_FLUSH;
1217 threshold.a_void = 0;
1220 * hilite_status: hitpoints/10%/red/normal
1223 /* field name to statusfield */
1224 for (i = 0; sa && i < SIZE(fieldids); ++i) {
1225 if (strcmpi(sa, fieldids[i].fieldname) == 0) {
1227 fld = fieldids[i].fldid;
1233 status_hilites[idx].set = FALSE; /* mark it "unset" */
1238 if ((strcmpi(sb, "updown") == 0) || (strcmpi(sb, "downup") == 0)
1239 || (strcmpi(sb, "up") == 0) || (strcmpi(sb, "down") == 0)) {
1241 } else if ((strcmpi(sb, "changed") == 0)
1242 && (fld == BL_TITLE || fld == BL_ALIGN || fld == BL_LEVELDESC
1243 || fld == BL_CONDITION)) {
1244 changed = TRUE; /* changed is only thing allowed */
1252 } else if (!index("0123456789", *tmp))
1256 if (strlen(sb) > 0) {
1257 dt = blstats[0][idx].anytype;
1260 (void) s_to_anything(&threshold, sb, dt);
1263 if (percent && (threshold.a_int < 1 || threshold.a_int > 100))
1265 if (!threshold.a_void && (strcmp(sb, "0") != 0))
1270 for (i = 0; i < 2; ++i) {
1279 break; /* sc is mandatory; sd is not */
1282 if (strcmpi(how, "bold") == 0) {
1284 } else if (strcmpi(how, "inverse") == 0) {
1286 } else if (strcmpi(how, "normal") == 0) {
1290 char colorname[BUFSZ];
1291 for (k = 0; k < CLR_MAX; ++k) {
1292 /* we have to make a copy to change space to dash */
1293 (void) strcpy(colorname, c_obj_colors[k]);
1294 for (tmp = index(colorname, ' '); tmp;
1295 tmp = index(colorname, ' '))
1297 if (strcmpi(how, colorname) == 0) {
1307 /* Assign the values */
1309 for (i = 0; i < 2; ++i) {
1311 status_hilites[idx].coloridx[i] = BL_HILITE_INVERSE;
1313 status_hilites[idx].coloridx[i] = BL_HILITE_BOLD;
1314 else if (coloridx[i])
1315 status_hilites[idx].coloridx[i] = coloridx[i];
1317 status_hilites[idx].coloridx[i] = BL_HILITE_NONE;
1321 status_hilites[idx].behavior = BL_TH_VAL_PERCENTAGE;
1323 status_hilites[idx].behavior = BL_TH_UPDOWN;
1324 else if (threshold.a_void)
1325 status_hilites[idx].behavior = BL_TH_VAL_ABSOLUTE;
1327 status_hilites[idx].behavior = BL_TH_NONE;
1329 if (status_hilites[idx].behavior != BL_TH_NONE) {
1330 status_hilites[idx].threshold = threshold;
1331 status_hilites[idx].set = TRUE;
1333 status_hilites[idx].anytype = dt;
1335 /* Now finally, we notify the window port */
1336 if (!from_configfile)
1337 status_threshold(idx, status_hilites[idx].anytype,
1338 status_hilites[idx].threshold,
1339 status_hilites[idx].behavior,
1340 status_hilites[idx].coloridx[0],
1341 status_hilites[idx].coloridx[1]);
1347 status_notify_windowport(all)
1354 for (idx = 0; idx < MAXBLSTATS; ++idx) {
1355 if (status_hilites[idx].set)
1356 status_threshold(idx, status_hilites[idx].anytype,
1357 status_hilites[idx].threshold,
1358 status_hilites[idx].behavior,
1359 status_hilites[idx].coloridx[0],
1360 status_hilites[idx].coloridx[1]);
1362 status_threshold(idx, blstats[0][idx].anytype, it, 0, 0, 0);
1368 * get_status_hilites
1370 * Returns a string containing all the status hilites in the
1371 * same format that is used to specify a status hilite preference
1372 * in the config file.
1375 get_status_hilites(buf, bufsiz)
1379 int i, j, k, coloridx;
1380 const char *text = (char *) 0;
1381 char tmp[BUFSZ], colorname[BUFSZ];
1382 boolean val_percentage, val_absolute, up_down;
1383 boolean added_one = FALSE;
1389 bufsiz--; /* required trailing null */
1390 for (i = 0; i < MAXBLSTATS; ++i) {
1391 val_percentage = val_absolute = up_down = FALSE;
1392 if (status_hilites[i].set) {
1399 k = strlen(fieldids[i].fieldname);
1401 Strcat(buf, fieldids[i].fieldname);
1408 if (status_hilites[i].behavior == BL_TH_VAL_PERCENTAGE) {
1409 val_percentage = TRUE;
1410 } else if (status_hilites[i].behavior == BL_TH_VAL_ABSOLUTE) {
1411 val_absolute = TRUE;
1412 } else if (status_hilites[i].behavior == BL_TH_UPDOWN) {
1417 if (status_hilites[i].behavior != BL_TH_UPDOWN) {
1418 anything_to_s(tmp, &status_hilites[i].threshold,
1419 blstats[0][i].anytype);
1423 if (k < (bufsiz - 1)) {
1426 Strcat(buf, "%"), k++;
1429 for (j = 0; j < 2; ++j) {
1434 coloridx = status_hilites[i].coloridx[j];
1436 if (coloridx == BL_HILITE_BOLD)
1438 else if (coloridx == BL_HILITE_INVERSE)
1444 (void) strcpy(colorname, c_obj_colors[coloridx]);
1445 for (blank = index(colorname, ' '); blank;
1446 blank = index(colorname, ' '))
1461 STATIC_OVL const char *
1462 clridx_to_s(buf, idx)
1466 static const char *a[] = { "bold", "inverse", "normal" };
1471 if (idx < 0 && idx >= BL_HILITE_BOLD)
1472 Strcpy(buf, a[idx + 3]);
1473 else if (idx >= 0 && idx < CLR_MAX)
1474 Strcpy(buf, c_obj_colors[idx]);
1475 /* replace spaces with - */
1476 for(p = buf; *p; p++)
1477 if(*p == ' ') *p = '-';
1483 status_hilite_menu()
1485 int i, j, k, pick_cnt, pick_idx, opt_idx;
1486 menu_item *statfield_picks = (menu_item *) 0;
1487 const char *fieldname;
1488 int field_picks[MAXBLSTATS], res;
1489 struct hilite_s hltemp[MAXBLSTATS];
1490 char buf[BUFSZ], thresholdbuf[BUFSZ], below[BUFSZ], above[BUFSZ];
1494 tmpwin = create_nhwindow(NHW_MENU);
1496 for (i = 0; i < MAXBLSTATS; i++) {
1497 (void) memset(&hltemp[i], 0, sizeof(struct hilite_s));
1498 fieldname = fieldids[i].fieldname;
1500 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, fieldname,
1504 end_menu(tmpwin, "Change hilite on which status field(s):");
1505 if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &statfield_picks)) > 0) {
1506 for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) {
1507 opt_idx = statfield_picks[pick_idx].item.a_int - 1;
1508 field_picks[opt_idx] = 1;
1510 free((genericptr_t) statfield_picks);
1511 statfield_picks = (menu_item *) 0;
1513 destroy_nhwindow(tmpwin);
1517 for (i = 0; i < MAXBLSTATS; i++) {
1518 if (field_picks[i]) {
1519 menu_item *pick = (menu_item *) 0;
1520 Sprintf(buf, "Threshold behavior options for %s:",
1521 fieldids[i].fieldname);
1522 tmpwin = create_nhwindow(NHW_MENU);
1524 if (i == BL_CONDITION) {
1526 any.a_int = BL_TH_CONDITION + 1;
1527 add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, ATR_NONE,
1528 "Condition bitmask threshold.", MENU_UNSELECTED);
1531 any.a_int = BL_TH_NONE + 1;
1532 add_menu(tmpwin, NO_GLYPH, &any, 'n', 0, ATR_NONE, "None",
1534 if (i != BL_CONDITION) {
1535 if (blstats[0][i].idxmax > 0) {
1537 any.a_int = BL_TH_VAL_PERCENTAGE + 1;
1538 add_menu(tmpwin, NO_GLYPH, &any, 'p', 0, ATR_NONE,
1539 "Percentage threshold.", MENU_UNSELECTED);
1542 any.a_int = BL_TH_UPDOWN + 1;
1543 add_menu(tmpwin, NO_GLYPH, &any, 'u', 0, ATR_NONE,
1544 "UpDown threshold.", MENU_UNSELECTED);
1546 any.a_int = BL_TH_VAL_ABSOLUTE + 1;
1547 add_menu(tmpwin, NO_GLYPH, &any, 'v', 0, ATR_NONE,
1548 "Value threshold.", MENU_UNSELECTED);
1550 end_menu(tmpwin, buf);
1551 if ((res = select_menu(tmpwin, PICK_ONE, &pick)) > 0) {
1552 hltemp[i].behavior = pick->item.a_int - 1;
1553 free((genericptr_t) pick);
1555 destroy_nhwindow(tmpwin);
1559 if (hltemp[i].behavior == BL_TH_UPDOWN) {
1560 Sprintf(below, "%s decreases", fieldids[i].fieldname);
1561 Sprintf(above, "%s increases", fieldids[i].fieldname);
1562 } else if (hltemp[i].behavior) {
1563 /* Have them enter the threshold*/
1565 buf, "Set %s threshold to what%s?", fieldids[i].fieldname,
1566 (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE)
1568 : (hltemp[i].behavior == BL_TH_CONDITION) ? " mask"
1570 getlin(buf, thresholdbuf);
1571 if (thresholdbuf[0] == '\033')
1573 (void) s_to_anything(&hltemp[i].threshold, thresholdbuf,
1574 blstats[0][i].anytype);
1575 if (!hltemp[i].threshold.a_void)
1578 Sprintf(below, "%s falls below %s%s", fieldids[i].fieldname,
1580 (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%"
1582 Sprintf(above, "%s rises above %s%s", fieldids[i].fieldname,
1584 (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%"
1587 for (j = 0; j < 2 && (hltemp[i].behavior != BL_TH_NONE); ++j) {
1588 char prompt[QBUFSZ];
1589 /* j == 0 below, j == 1 above */
1590 menu_item *pick2 = (menu_item *) 0;
1592 Sprintf(prompt, "Display how when %s?", j ? above : below);
1593 tmpwin = create_nhwindow(NHW_MENU);
1595 for (k = -3; k < CLR_MAX; ++k) {
1596 /* if (k == -1) continue; */
1598 any.a_int = (k >= 0) ? k + 1 : k;
1600 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
1601 c_obj_colors[k], MENU_UNSELECTED);
1603 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
1604 "normal", MENU_UNSELECTED);
1606 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
1607 "inverse", MENU_UNSELECTED);
1609 add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
1610 "bold", MENU_UNSELECTED);
1612 end_menu(tmpwin, prompt);
1613 if ((res = select_menu(tmpwin, PICK_ONE, &pick2)) > 0) {
1614 hltemp[i].coloridx[j] = (pick2->item.a_char > 0)
1615 ? pick2->item.a_int - 1
1616 : pick2->item.a_int;
1617 free((genericptr_t) pick2);
1619 destroy_nhwindow(tmpwin);
1626 for (i = 0; i < MAXBLSTATS; i++) {
1627 if (field_picks[i]) {
1628 Sprintf(eos(buf), "%s/%s%s/", fieldids[i].fieldname,
1629 (hltemp[i].behavior == BL_TH_UPDOWN)
1631 : anything_to_s(thresholdbuf, &hltemp[i].threshold,
1632 blstats[0][i].anytype),
1633 (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%" : "");
1634 /* borrow thresholdbuf for use with these last two */
1635 Sprintf(eos(buf), "%s/",
1636 clridx_to_s(thresholdbuf, hltemp[i].coloridx[0]));
1637 Sprintf(eos(buf), "%s ",
1638 clridx_to_s(thresholdbuf, hltemp[i].coloridx[1]));
1641 return set_status_hilites(buf, FALSE);
1643 #endif /*STATUS_HILITES*/
1644 #endif /*STATUS_VIA_WINDOWPORT*/