Merge branch 'status_hilite' of https://rodney.nethack.org:20040/git/NHsource into status_hilite

This commit is contained in:
Alex Kompel
2015-05-31 21:32:13 -07:00
7 changed files with 782 additions and 538 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 botl.h $NHDT-Date: 1433082340 2015/05/31 14:25:40 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.12 $ */
/* NetHack 3.6 botl.h $NHDT-Date: 1433105378 2015/05/31 20:49:38 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.14 $ */
/* Copyright (c) Michael Allison, 2003 */
/* NetHack may be freely redistributed. See license for details. */
@@ -22,7 +22,7 @@
#ifdef STATUS_VIA_WINDOWPORT
#if 0
/* clang-format off */
#define BL_BOGUS -1
#define BL_FLUSH -1
#define BL_TITLE 0
#define BL_STR 1
#define BL_DX 2
@@ -47,12 +47,12 @@
#define BL_EXP 21
#define BL_CONDITION 22
/* clang-format on */
#else
enum statusfields { BL_BOGUS = -1, BL_TITLE = 0, BL_STR, BL_DX, BL_CO, BL_IN,
enum statusfields { BL_FLUSH = -1, BL_TITLE = 0, BL_STR, BL_DX, BL_CO, BL_IN,
BL_WI, BL_CH, BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX,
BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX, BL_LEVELDESC,
BL_EXP, BL_CONDITION };
#define BL_FLUSH BL_BOGUS
#define MAXBLSTATS BL_CONDITION+1
#define BEFORE 0

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 extern.h $NHDT-Date: 1433087625 2015/05/31 15:53:45 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.499 $ */
/* NetHack 3.6 extern.h $NHDT-Date: 1433105379 2015/05/31 20:49:39 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.500 $ */
/* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */
@@ -155,7 +155,7 @@ E void NDECL(status_finish);
E void FDECL(status_notify_windowport, (BOOLEAN_P));
#ifdef STATUS_HILITES
E boolean FDECL(set_status_hilites, (char *op, BOOLEAN_P));
E void NDECL(clear_status_hilites);
E void FDECL(clear_status_hilites, (BOOLEAN_P));
E char *FDECL(get_status_hilites, (char *, int));
E boolean NDECL(status_hilite_menu);
#endif

View File

@@ -215,6 +215,13 @@ E short FDECL(set_tty_font_name, (winid, char *));
#endif
E char *NDECL(tty_get_color_string);
#endif
#ifdef STATUS_VIA_WINDOWPORT
E void NDECL(tty_status_init);
E void FDECL(tty_status_update, (int, genericptr_t, int, int));
#ifdef STATUS_HILITES
E void FDECL(tty_status_threshold, (int, int, anything, int, int, int));
#endif
#endif
/* other defs that really should go away (they're tty specific) */
E void NDECL(tty_start_screen);

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 botl.c $NHDT-Date: 1433088374 2015/05/31 16:06:14 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.56 $ */
/* NetHack 3.6 botl.c $NHDT-Date: 1433115548 2015/05/31 23:39:08 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.60 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -10,95 +10,133 @@ extern const char *hu_stat[]; /* defined in eat.c */
const char *const enc_stat[] = { "", "Burdened", "Stressed",
"Strained", "Overtaxed", "Overloaded" };
#ifdef STATUS_VIA_WINDOWPORT
struct istat_s {
long time;
unsigned anytype;
anything a;
char *val;
int valwidth;
int idxmax;
enum statusfields fld;
};
STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */
STATIC_DCL const char *NDECL(rank);
/* If entries are added to this, botl.h will require updating too */
struct istat_s initblstats[MAXBLSTATS] = {
{ 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 80, 0, BL_TITLE},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_STR},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_DX},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_CO},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_IN},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_WI},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_CH},
{ 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 40, 0, BL_ALIGN},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0, BL_SCORE},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0, BL_CAP},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 30, 0, BL_GOLD},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_ENE},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_ENEMAX},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 10, 0, BL_XP},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_AC},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_HD},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 20, 0, BL_TIME},
{ 0L, ANY_UINT, {(genericptr_t)0L}, (char *)0, 40, 0, BL_HUNGER},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_HP},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_HPMAX},
{ 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 80, 0, BL_LEVELDESC},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0, BL_EXP},
{ 0L, ANY_MASK32,{(genericptr_t)0L},(char *)0, 0, 0, BL_CONDITION}
};
#ifndef STATUS_VIA_WINDOWPORT
static struct fieldid_t {
const char *fieldname;
enum statusfields fldid;
} fieldids[] = {
{"title", BL_TITLE},
{"strength", BL_STR},
{"dexterity", BL_DX},
{"constitution", BL_CO},
{"intelligence", BL_IN},
{"wisdom", BL_WI},
{"charisma", BL_CH},
{"alignment", BL_ALIGN},
{"score", BL_SCORE},
{"carrying-capacity", BL_CAP},
{"gold", BL_GOLD},
{"power", BL_ENE},
{"power-max", BL_ENEMAX},
{"experience-level", BL_XP},
{"armor-class", BL_AC},
{"HD", BL_HD},
{"time", BL_TIME},
{"hunger", BL_HUNGER},
{"hitpoints", BL_HP},
{"hitpoints-max", BL_HPMAX},
{"dungeon-level", BL_LEVELDESC},
{"experience", BL_EXP},
{"condition", BL_CONDITION},
};
struct istat_s blstats[2][MAXBLSTATS];
static boolean blinit = FALSE, update_all = FALSE;
STATIC_DCL void NDECL(init_blstats);
STATIC_DCL char *FDECL(anything_to_s, (char *, anything *, int));
STATIC_DCL void FDECL(s_to_anything, (anything *, char *, int));
STATIC_OVL int FDECL(percentage, (struct istat_s *, struct istat_s *));
STATIC_OVL int FDECL(compare_blstats, (struct istat_s *, struct istat_s *));
#ifdef STATUS_HILITES
STATIC_DCL boolean FDECL(assign_hilite, (char *, char *, char *, char *, BOOLEAN_P));
STATIC_DCL const char *FDECL(clridx_to_s, (char *, int));
#endif
#else
STATIC_DCL void NDECL(bot1);
STATIC_DCL void NDECL(bot2);
#endif
STATIC_OVL NEARDATA int mrank_sz =
0; /* loaded by max_rank_sz (from u_init) */
STATIC_DCL const char *NDECL(rank);
STATIC_OVL void
bot1()
{
char newbot1[MAXCO];
register char *nb;
register int i, j;
Strcpy(newbot1, plname);
if ('a' <= newbot1[0] && newbot1[0] <= 'z')
newbot1[0] += 'A' - 'a';
newbot1[10] = 0;
Sprintf(nb = eos(newbot1), " the ");
if (Upolyd) {
char mbot[BUFSZ];
int k = 0;
Strcpy(mbot, mons[u.umonnum].mname);
while (mbot[k] != 0) {
if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
&& mbot[k] <= 'z')
mbot[k] += 'A' - 'a';
k++;
}
Strcpy(nb = eos(nb), mbot);
} else
Strcpy(nb = eos(nb), rank());
Sprintf(nb = eos(nb), " ");
i = mrank_sz + 15;
j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */
if ((i - j) > 0)
Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */
if (ACURR(A_STR) > 18) {
if (ACURR(A_STR) > STR18(100))
Sprintf(nb = eos(nb), "St:%2d ", ACURR(A_STR) - 100);
else if (ACURR(A_STR) < STR18(100))
Sprintf(nb = eos(nb), "St:18/%02d ", ACURR(A_STR) - 18);
else
Sprintf(nb = eos(nb), "St:18/** ");
} else
Sprintf(nb = eos(nb), "St:%-1d ", ACURR(A_STR));
Sprintf(nb = eos(nb), "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS),
ACURR(A_CHA));
Sprintf(nb = eos(nb),
(u.ualign.type == A_CHAOTIC)
? " Chaotic"
: (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful");
#ifdef SCORE_ON_BOTL
if (flags.showscore)
Sprintf(nb = eos(nb), " S:%ld", botl_score());
#endif
curs(WIN_STATUS, 1, 0);
putstr(WIN_STATUS, 0, newbot1);
}
STATIC_OVL void
bot2()
{
char newbot2[MAXCO];
register char *nb;
int hp, hpmax;
int cap = near_capacity();
hp = Upolyd ? u.mh : u.uhp;
hpmax = Upolyd ? u.mhmax : u.uhpmax;
if (hp < 0)
hp = 0;
(void) describe_level(newbot2);
Sprintf(nb = eos(newbot2), "%s:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d",
encglyph(objnum_to_glyph(GOLD_PIECE)), money_cnt(invent), hp,
hpmax, u.uen, u.uenmax, u.uac);
if (Upolyd)
Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
else if (flags.showexp)
Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel, u.uexp);
else
Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
if (flags.time)
Sprintf(nb = eos(nb), " T:%ld", moves);
if (strcmp(hu_stat[u.uhs], " ")) {
Sprintf(nb = eos(nb), " ");
Strcat(newbot2, hu_stat[u.uhs]);
}
if (Confusion)
Sprintf(nb = eos(nb), " Conf");
if (Sick) {
if (u.usick_type & SICK_VOMITABLE)
Sprintf(nb = eos(nb), " FoodPois");
if (u.usick_type & SICK_NONVOMITABLE)
Sprintf(nb = eos(nb), " Ill");
}
if (Blind)
Sprintf(nb = eos(nb), " Blind");
if (Stunned)
Sprintf(nb = eos(nb), " Stun");
if (Hallucination)
Sprintf(nb = eos(nb), " Hallu");
if (Slimed)
Sprintf(nb = eos(nb), " Slime");
if (cap > UNENCUMBERED)
Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
curs(WIN_STATUS, 1, 1);
putmixed(WIN_STATUS, 0, newbot2);
}
void
bot()
{
if (youmonst.data) {
bot1();
bot2();
}
context.botl = context.botlx = 0;
}
#endif /* !STATUS_VIA_WINDOWPORT */
/* convert experience level (1..30) to rank index (0..8) */
int
@@ -222,64 +260,6 @@ botl_score()
}
#endif
#ifndef STATUS_VIA_WINDOWPORT
STATIC_OVL void
bot1()
{
char newbot1[MAXCO];
register char *nb;
register int i, j;
Strcpy(newbot1, plname);
if ('a' <= newbot1[0] && newbot1[0] <= 'z')
newbot1[0] += 'A' - 'a';
newbot1[10] = 0;
Sprintf(nb = eos(newbot1), " the ");
if (Upolyd) {
char mbot[BUFSZ];
int k = 0;
Strcpy(mbot, mons[u.umonnum].mname);
while (mbot[k] != 0) {
if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
&& mbot[k] <= 'z')
mbot[k] += 'A' - 'a';
k++;
}
Strcpy(nb = eos(nb), mbot);
} else
Strcpy(nb = eos(nb), rank());
Sprintf(nb = eos(nb), " ");
i = mrank_sz + 15;
j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */
if ((i - j) > 0)
Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */
if (ACURR(A_STR) > 18) {
if (ACURR(A_STR) > STR18(100))
Sprintf(nb = eos(nb), "St:%2d ", ACURR(A_STR) - 100);
else if (ACURR(A_STR) < STR18(100))
Sprintf(nb = eos(nb), "St:18/%02d ", ACURR(A_STR) - 18);
else
Sprintf(nb = eos(nb), "St:18/** ");
} else
Sprintf(nb = eos(nb), "St:%-1d ", ACURR(A_STR));
Sprintf(nb = eos(nb), "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS),
ACURR(A_CHA));
Sprintf(nb = eos(nb),
(u.ualign.type == A_CHAOTIC)
? " Chaotic"
: (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful");
#ifdef SCORE_ON_BOTL
if (flags.showscore)
Sprintf(nb = eos(nb), " S:%ld", botl_score());
#endif
curs(WIN_STATUS, 1, 0);
putstr(WIN_STATUS, 0, newbot1);
}
#endif
/* provide the name of the current level for display by various ports */
int
describe_level(buf)
@@ -302,71 +282,342 @@ char *buf;
return ret;
}
#ifndef STATUS_VIA_WINDOWPORT
STATIC_OVL void
bot2()
{
char newbot2[MAXCO];
register char *nb;
int hp, hpmax;
int cap = near_capacity();
#ifdef STATUS_VIA_WINDOWPORT
/* =======================================================================*/
hp = Upolyd ? u.mh : u.uhp;
hpmax = Upolyd ? u.mhmax : u.uhpmax;
STATIC_DCL void NDECL(init_blstats);
STATIC_DCL char *FDECL(anything_to_s, (char *, anything *, int));
STATIC_DCL void FDECL(s_to_anything, (anything *, char *, int));
STATIC_OVL int FDECL(percentage, (struct istat_s *, struct istat_s *));
STATIC_OVL int FDECL(compare_blstats, (struct istat_s *, struct istat_s *));
if (hp < 0)
hp = 0;
(void) describe_level(newbot2);
Sprintf(nb = eos(newbot2), "%s:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d",
encglyph(objnum_to_glyph(GOLD_PIECE)), money_cnt(invent), hp,
hpmax, u.uen, u.uenmax, u.uac);
#ifdef STATUS_HILITES
STATIC_DCL boolean FDECL(assign_hilite, (char *, char *, char *, char *, BOOLEAN_P));
STATIC_DCL const char *FDECL(clridx_to_s, (char *, int));
#endif
if (Upolyd)
Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
else if (flags.showexp)
Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel, u.uexp);
else
Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
/* structure that tracks the status details in the core */
struct istat_s {
long time;
unsigned anytype;
anything a;
char *val;
int valwidth;
enum statusfields idxmax;
enum statusfields fld;
};
if (flags.time)
Sprintf(nb = eos(nb), " T:%ld", moves);
if (strcmp(hu_stat[u.uhs], " ")) {
Sprintf(nb = eos(nb), " ");
Strcat(newbot2, hu_stat[u.uhs]);
}
if (Confusion)
Sprintf(nb = eos(nb), " Conf");
if (Sick) {
if (u.usick_type & SICK_VOMITABLE)
Sprintf(nb = eos(nb), " FoodPois");
if (u.usick_type & SICK_NONVOMITABLE)
Sprintf(nb = eos(nb), " Ill");
}
if (Blind)
Sprintf(nb = eos(nb), " Blind");
if (Stunned)
Sprintf(nb = eos(nb), " Stun");
if (Hallucination)
Sprintf(nb = eos(nb), " Hallu");
if (Slimed)
Sprintf(nb = eos(nb), " Slime");
if (cap > UNENCUMBERED)
Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
curs(WIN_STATUS, 1, 1);
putmixed(WIN_STATUS, 0, newbot2);
}
/* If entries are added to this, botl.h will require updating too */
STATIC_DCL struct istat_s initblstats[MAXBLSTATS] = {
{ 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 80, 0, BL_TITLE},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_STR},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_DX},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_CO},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_IN},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_WI},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_CH},
{ 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 40, 0, BL_ALIGN},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0, BL_SCORE},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0, BL_CAP},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 30, 0, BL_GOLD},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, BL_ENEMAX, BL_ENE},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_ENEMAX},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 10, 0, BL_XP},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_AC},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_HD},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 20, 0, BL_TIME},
{ 0L, ANY_UINT, {(genericptr_t)0L}, (char *)0, 40, 0, BL_HUNGER},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, BL_HPMAX, BL_HP},
{ 0L, ANY_INT, {(genericptr_t)0L}, (char *)0, 10, 0, BL_HPMAX},
{ 0L, ANY_STR, {(genericptr_t)0L}, (char *)0, 80, 0, BL_LEVELDESC},
{ 0L, ANY_LONG, {(genericptr_t)0L}, (char *)0, 20, 0, BL_EXP},
{ 0L, ANY_MASK32,{(genericptr_t)0L},(char *)0, 0, 0, BL_CONDITION}
};
static struct fieldid_t {
const char *fieldname;
enum statusfields fldid;
} fieldids[] = {
{"title", BL_TITLE},
{"strength", BL_STR},
{"dexterity", BL_DX},
{"constitution", BL_CO},
{"intelligence", BL_IN},
{"wisdom", BL_WI},
{"charisma", BL_CH},
{"alignment", BL_ALIGN},
{"score", BL_SCORE},
{"carrying-capacity", BL_CAP},
{"gold", BL_GOLD},
{"power", BL_ENE},
{"power-max", BL_ENEMAX},
{"experience-level", BL_XP},
{"armor-class", BL_AC},
{"HD", BL_HD},
{"time", BL_TIME},
{"hunger", BL_HUNGER},
{"hitpoints", BL_HP},
{"hitpoints-max", BL_HPMAX},
{"dungeon-level", BL_LEVELDESC},
{"experience", BL_EXP},
{"condition", BL_CONDITION},
};
struct istat_s blstats[2][MAXBLSTATS];
static boolean blinit = FALSE, update_all = FALSE;
void
bot()
{
if (youmonst.data) {
bot1();
bot2();
}
context.botl = context.botlx = 0;
}
char buf[BUFSZ];
register char *nb;
static int idx = 0, idx_p, idxmax;
boolean updated = FALSE;
unsigned anytype;
int i, pc, chg, cap;
struct istat_s *curr, *prev;
boolean valset[MAXBLSTATS], chgval = FALSE;
#else /* STATUS_VIA_WINDOWPORT */
if (!blinit)
panic("bot before init.");
if (!youmonst.data) {
context.botl = context.botlx = 0;
update_all = FALSE;
return;
}
cap = near_capacity();
idx_p = idx;
idx = 1 - idx; /* 0 -> 1, 1 -> 0 */
/* clear the "value set" indicators */
(void) memset((genericptr_t) valset, 0, MAXBLSTATS * sizeof(boolean));
/*
* Player name and title.
*/
buf[0] = '\0';
Strcpy(buf, plname);
if ('a' <= buf[0] && buf[0] <= 'z')
buf[0] += 'A' - 'a';
buf[10] = 0;
Sprintf(nb = eos(buf), " the ");
if (Upolyd) {
char mbot[BUFSZ];
int k = 0;
Strcpy(mbot, mons[u.umonnum].mname);
while (mbot[k] != 0) {
if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
&& mbot[k] <= 'z')
mbot[k] += 'A' - 'a';
k++;
}
Sprintf1(nb = eos(nb), mbot);
} else
Sprintf1(nb = eos(nb), rank());
Sprintf(blstats[idx][BL_TITLE].val, "%-29s", buf);
valset[BL_TITLE] = TRUE; /* indicate val already set */
/* Strength */
buf[0] = '\0';
blstats[idx][BL_STR].a.a_int = ACURR(A_STR);
if (ACURR(A_STR) > 18) {
if (ACURR(A_STR) > STR18(100))
Sprintf(buf, "%2d", ACURR(A_STR) - 100);
else if (ACURR(A_STR) < STR18(100))
Sprintf(buf, "18/%02d", ACURR(A_STR) - 18);
else
Sprintf(buf, "18/**");
} else
Sprintf(buf, "%-1d", ACURR(A_STR));
Strcpy(blstats[idx][BL_STR].val, buf);
valset[BL_STR] = TRUE; /* indicate val already set */
/* Dexterity, constitution, intelligence, wisdom, charisma. */
blstats[idx][BL_DX].a.a_int = ACURR(A_DEX);
blstats[idx][BL_CO].a.a_int = ACURR(A_CON);
blstats[idx][BL_IN].a.a_int = ACURR(A_INT);
blstats[idx][BL_WI].a.a_int = ACURR(A_WIS);
blstats[idx][BL_CH].a.a_int = ACURR(A_CHA);
/* Alignment */
Strcpy(blstats[idx][BL_ALIGN].val,
(u.ualign.type == A_CHAOTIC)
? "Chaotic"
: (u.ualign.type == A_NEUTRAL) ? "Neutral" : "Lawful");
/* Score */
blstats[idx][BL_SCORE].a.a_long =
#ifdef SCORE_ON_BOTL
botl_score();
#else
0;
#endif
/* Hit points */
blstats[idx][BL_HP].a.a_int = Upolyd ? u.mh : u.uhp;
blstats[idx][BL_HPMAX].a.a_int = Upolyd ? u.mhmax : u.uhpmax;
if (blstats[idx][BL_HP].a.a_int < 0)
blstats[idx][BL_HP].a.a_int = 0;
/* Dungeon level. */
(void) describe_level(blstats[idx][BL_LEVELDESC].val);
valset[BL_LEVELDESC] = TRUE; /* indicate val already set */
/* Gold */
blstats[idx][BL_GOLD].a.a_long = money_cnt(invent);
/*
* The tty port needs to display the current symbol for gold
* as a field header, so to accomodate that we pass gold with
* that already included. If a window port needs to use the text
* gold amount without the leading "$:" the port will have to
* add 2 to the value pointer it was passed in status_update()
* for the BL_GOLD case.
*
* Another quirk of BL_GOLD is that the field display may have
* changed if a new symbol set was loaded, or we entered or left
* the rogue level.
*/
Sprintf(blstats[idx][BL_GOLD].val, "%s:%ld",
encglyph(objnum_to_glyph(GOLD_PIECE)),
blstats[idx][BL_GOLD].a.a_long);
valset[BL_GOLD] = TRUE; /* indicate val already set */
/* Power (magical energy) */
blstats[idx][BL_ENE].a.a_int = u.uen;
blstats[idx][BL_ENEMAX].a.a_int = u.uenmax;
/* Armor class */
blstats[idx][BL_AC].a.a_int = u.uac;
/* Monster level (if Upolyd) */
if (Upolyd)
blstats[idx][BL_HD].a.a_int = mons[u.umonnum].mlevel;
else
blstats[idx][BL_HD].a.a_int = 0;
/* Experience */
blstats[idx][BL_XP].a.a_int = u.ulevel;
blstats[idx][BL_EXP].a.a_int = u.uexp;
/* Time (moves) */
blstats[idx][BL_TIME].a.a_long = moves;
/* Hunger */
blstats[idx][BL_HUNGER].a.a_uint = u.uhs;
*(blstats[idx][BL_HUNGER].val) = '\0';
if (strcmp(hu_stat[u.uhs], " ") != 0)
Strcpy(blstats[idx][BL_HUNGER].val, hu_stat[u.uhs]);
valset[BL_HUNGER] = TRUE;
/* Carrying capacity */
*(blstats[idx][BL_CAP].val) = '\0';
blstats[idx][BL_CAP].a.a_int = cap;
if (cap > UNENCUMBERED)
Strcpy(blstats[idx][BL_CAP].val, enc_stat[cap]);
valset[BL_CAP] = TRUE;
/* Conditions */
if (Blind)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_BLIND;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_BLIND;
if (Confusion)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_CONF;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_CONF;
if (Sick && u.usick_type & SICK_VOMITABLE)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FOODPOIS;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_FOODPOIS;
if (Sick && u.usick_type & SICK_NONVOMITABLE)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_ILL;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_ILL;
if (Hallucination)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_HALLU;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_HALLU;
if (Stunned)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STUNNED;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_STUNNED;
if (Slimed)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_SLIMED;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_SLIMED;
/*
* Now pass the changed values to window port.
*/
for (i = 0; i < MAXBLSTATS; i++) {
if (((i == BL_SCORE) && !flags.showscore)
|| ((i == BL_EXP) && !flags.showexp)
|| ((i == BL_TIME) && !flags.time) || ((i == BL_HD) && !Upolyd)
|| ((i == BL_XP || i == BL_EXP) && Upolyd))
continue;
anytype = blstats[idx][i].anytype;
curr = &blstats[idx][i];
prev = &blstats[idx_p][i];
chg = 0;
if (update_all || ((chg = compare_blstats(prev, curr)) != 0)
|| ((chgval = (valset[i] && strcmp(blstats[idx][i].val,
blstats[idx_p][i].val)))
!= 0)) {
idxmax = blstats[idx][i].idxmax;
pc = (idxmax) ? percentage(curr, &blstats[idx][idxmax]) : 0;
if (!valset[i])
(void) anything_to_s(curr->val, &curr->a, anytype);
if (anytype != ANY_MASK32) {
status_update(i, (genericptr_t) curr->val,
valset[i] ? chgval : chg, pc);
} else {
status_update(i,
/* send pointer to mask */
(genericptr_t) &curr->a.a_ulong, chg, 0);
}
updated = TRUE;
}
}
/*
* It is possible to get here, with nothing having been pushed
* to the window port, when none of the info has changed. In that
* case, we need to force a call to status_update() when
* context.botlx is set. The tty port in particular has a problem
* if that isn't done, since it sets context.botlx when a menu or
* text display obliterates the status line.
*
* To work around it, we call status_update() with ficticious
* index of BL_FLUSH (-1).
*/
if (context.botlx && !updated)
status_update(BL_FLUSH, (genericptr_t) 0, 0, 0);
context.botl = context.botlx = 0;
update_all = FALSE;
}
void
status_initialize(reassessment)
@@ -509,7 +760,7 @@ boolean
fieldname = "condition";
status_enablefield(fld, fieldname, fieldfmt, TRUE);
break;
case BL_BOGUS:
case BL_FLUSH:
default:
break;
}
@@ -777,258 +1028,6 @@ struct istat_s *bl, *maxbl;
return result;
}
void
bot()
{
char buf[BUFSZ];
register char *nb;
static int idx = 0, idx_p, idxmax;
boolean updated = FALSE;
unsigned anytype;
int i, pc, chg, cap;
struct istat_s *curr, *prev;
boolean valset[MAXBLSTATS], chgval = FALSE;
if (!blinit)
panic("bot before init.");
if (!youmonst.data) {
context.botl = context.botlx = 0;
update_all = FALSE;
return;
}
cap = near_capacity();
idx_p = idx;
idx = 1 - idx; /* 0 -> 1, 1 -> 0 */
/* clear the "value set" indicators */
(void) memset((genericptr_t) valset, 0, MAXBLSTATS * sizeof(boolean));
/*
* Player name and title.
*/
buf[0] = '\0';
Strcpy(buf, plname);
if ('a' <= buf[0] && buf[0] <= 'z')
buf[0] += 'A' - 'a';
buf[10] = 0;
Sprintf(nb = eos(buf), " the ");
if (Upolyd) {
char mbot[BUFSZ];
int k = 0;
Strcpy(mbot, mons[u.umonnum].mname);
while (mbot[k] != 0) {
if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
&& mbot[k] <= 'z')
mbot[k] += 'A' - 'a';
k++;
}
Sprintf1(nb = eos(nb), mbot);
} else
Sprintf1(nb = eos(nb), rank());
Sprintf(blstats[idx][BL_TITLE].val, "%-29s", buf);
valset[BL_TITLE] = TRUE; /* indicate val already set */
/* Strength */
buf[0] = '\0';
blstats[idx][BL_STR].a.a_int = ACURR(A_STR);
if (ACURR(A_STR) > 18) {
if (ACURR(A_STR) > STR18(100))
Sprintf(buf, "%2d", ACURR(A_STR) - 100);
else if (ACURR(A_STR) < STR18(100))
Sprintf(buf, "18/%02d", ACURR(A_STR) - 18);
else
Sprintf(buf, "18/**");
} else
Sprintf(buf, "%-1d", ACURR(A_STR));
Strcpy(blstats[idx][BL_STR].val, buf);
valset[BL_STR] = TRUE; /* indicate val already set */
/* Dexterity, constitution, intelligence, wisdom, charisma. */
blstats[idx][BL_DX].a.a_int = ACURR(A_DEX);
blstats[idx][BL_CO].a.a_int = ACURR(A_CON);
blstats[idx][BL_IN].a.a_int = ACURR(A_INT);
blstats[idx][BL_WI].a.a_int = ACURR(A_WIS);
blstats[idx][BL_CH].a.a_int = ACURR(A_CHA);
/* Alignment */
Strcpy(blstats[idx][BL_ALIGN].val,
(u.ualign.type == A_CHAOTIC)
? "Chaotic"
: (u.ualign.type == A_NEUTRAL) ? "Neutral" : "Lawful");
/* Score */
blstats[idx][BL_SCORE].a.a_long =
#ifdef SCORE_ON_BOTL
botl_score();
#else
0;
#endif
/* Hit points */
blstats[idx][BL_HP].a.a_int = Upolyd ? u.mh : u.uhp;
blstats[idx][BL_HPMAX].a.a_int = Upolyd ? u.mhmax : u.uhpmax;
if (blstats[idx][BL_HP].a.a_int < 0)
blstats[idx][BL_HP].a.a_int = 0;
/* Dungeon level. */
(void) describe_level(blstats[idx][BL_LEVELDESC].val);
valset[BL_LEVELDESC] = TRUE; /* indicate val already set */
/* Gold */
blstats[idx][BL_GOLD].a.a_long = money_cnt(invent);
/*
* The tty port needs to display the current symbol for gold
* as a field header, so to accomodate that we pass gold with
* that already included. If a window port needs to use the text
* gold amount without the leading "$:" the port will have to
* add 2 to the value pointer it was passed in status_update()
* for the BL_GOLD case.
*
* Another quirk of BL_GOLD is that the field display may have
* changed if a new symbol set was loaded, or we entered or left
* the rogue level.
*/
Sprintf(blstats[idx][BL_GOLD].val, "%s:%ld",
encglyph(objnum_to_glyph(GOLD_PIECE)),
blstats[idx][BL_GOLD].a.a_long);
valset[BL_GOLD] = TRUE; /* indicate val already set */
/* Power (magical energy) */
blstats[idx][BL_ENE].a.a_int = u.uen;
blstats[idx][BL_ENEMAX].a.a_int = u.uenmax;
/* Armor class */
blstats[idx][BL_AC].a.a_int = u.uac;
/* Monster level (if Upolyd) */
if (Upolyd)
blstats[idx][BL_HD].a.a_int = mons[u.umonnum].mlevel;
else
blstats[idx][BL_HD].a.a_int = 0;
/* Experience */
blstats[idx][BL_XP].a.a_int = u.ulevel;
blstats[idx][BL_EXP].a.a_int = u.uexp;
/* Time (moves) */
blstats[idx][BL_TIME].a.a_long = moves;
/* Hunger */
blstats[idx][BL_HUNGER].a.a_uint = u.uhs;
*(blstats[idx][BL_HUNGER].val) = '\0';
if (strcmp(hu_stat[u.uhs], " ") != 0)
Strcpy(blstats[idx][BL_HUNGER].val, hu_stat[u.uhs]);
valset[BL_HUNGER] = TRUE;
/* Carrying capacity */
*(blstats[idx][BL_CAP].val) = '\0';
blstats[idx][BL_CAP].a.a_int = cap;
if (cap > UNENCUMBERED)
Strcpy(blstats[idx][BL_CAP].val, enc_stat[cap]);
valset[BL_CAP] = TRUE;
/* Conditions */
if (Blind)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_BLIND;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_BLIND;
if (Confusion)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_CONF;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_CONF;
if (Sick && u.usick_type & SICK_VOMITABLE)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FOODPOIS;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_FOODPOIS;
if (Sick && u.usick_type & SICK_NONVOMITABLE)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_ILL;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_ILL;
if (Hallucination)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_HALLU;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_HALLU;
if (Stunned)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STUNNED;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_STUNNED;
if (Slimed)
blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_SLIMED;
else
blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_SLIMED;
/*
* Now pass the changed values to window port.
*/
for (i = 0; i < MAXBLSTATS; i++) {
if (((i == BL_SCORE) && !flags.showscore)
|| ((i == BL_EXP) && !flags.showexp)
|| ((i == BL_TIME) && !flags.time) || ((i == BL_HD) && !Upolyd)
|| ((i == BL_XP || i == BL_EXP) && Upolyd))
continue;
anytype = blstats[idx][i].anytype;
curr = &blstats[idx][i];
prev = &blstats[idx_p][i];
chg = 0;
if (update_all || ((chg = compare_blstats(prev, curr)) != 0)
|| ((chgval = (valset[i] && strcmp(blstats[idx][i].val,
blstats[idx_p][i].val)))
!= 0)) {
idxmax = blstats[idx][i].idxmax;
pc = (idxmax) ? percentage(curr, &blstats[idx][idxmax]) : 0;
if (!valset[i])
(void) anything_to_s(curr->val, &curr->a, anytype);
if (anytype != ANY_MASK32) {
status_update(i, (genericptr_t) curr->val,
valset[i] ? chgval : chg, pc);
} else {
status_update(i,
/* send pointer to mask */
(genericptr_t) &curr->a.a_ulong, chg, 0);
}
updated = TRUE;
}
}
/*
* It is possible to get here, with nothing having been pushed
* to the window port, when none of the info has changed. In that
* case, we need to force a call to status_update() when
* context.botlx is set. The tty port in particular has a problem
* if that isn't done, since it sets context.botlx when a menu or
* text display obliterates the status line.
*
* To work around it, we call status_update() with ficticious
* index of BL_BOGUS (-1).
*/
if (context.botlx && !updated)
status_update(BL_BOGUS, (genericptr_t) 0, 0, 0);
context.botl = context.botlx = 0;
update_all = FALSE;
}
#ifdef STATUS_HILITES
@@ -1102,7 +1101,8 @@ boolean from_configfile;
}
void
clear_status_hilites()
clear_status_hilites(from_configfile)
boolean from_configfile;
{
int i;
anything it;
@@ -1111,7 +1111,8 @@ clear_status_hilites()
(void) memset((genericptr_t) &status_hilites[i], 0,
sizeof(struct hilite_s));
/* notify window port */
status_threshold(i, blstats[0][i].anytype, it, 0, 0, 0);
if (!from_configfile)
status_threshold(i, blstats[0][i].anytype, it, 0, 0, 0);
}
}
@@ -1128,7 +1129,7 @@ boolean from_configfile;
boolean normal[2] = { 0, 0 };
boolean percent = FALSE, down_up = FALSE, changed = FALSE;
anything threshold;
enum statusfields fld = BL_BOGUS;
enum statusfields fld = BL_FLUSH;
threshold.a_void = 0;
/* Example:
@@ -1263,7 +1264,9 @@ status_notify_windowport(all)
boolean all;
{
int idx;
anything it;
it.a_void = 0;
for (idx = 0; idx < MAXBLSTATS; ++idx) {
if (status_hilites[idx].set)
status_threshold(idx, status_hilites[idx].anytype,
@@ -1271,6 +1274,9 @@ boolean all;
status_hilites[idx].behavior,
status_hilites[idx].coloridx[0],
status_hilites[idx].coloridx[1]);
else
status_threshold(idx, blstats[0][idx].anytype, it, 0, 0, 0);
}
}

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 options.c $NHDT-Date: 1433087806 2015/05/31 15:56:46 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.209 $ */
/* NetHack 3.6 options.c $NHDT-Date: 1433105391 2015/05/31 20:49:51 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.210 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -3146,7 +3146,7 @@ boolean tinitial, tfrom_file;
complain_about_duplicate(opts, 1);
op = string_for_opt(opts, TRUE);
if (op && negated) {
clear_status_hilites();
clear_status_hilites(tfrom_file);
return;
} else if (!op) {
/* a value is mandatory */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 windows.c $NHDT-Date: 1433087641 2015/05/31 15:54:01 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.30 $ */
/* NetHack 3.6 windows.c $NHDT-Date: 1433105394 2015/05/31 20:49:54 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.32 $ */
/* Copyright (c) D. Cohrs, 1993. */
/* NetHack may be freely redistributed. See license for details. */
@@ -804,10 +804,10 @@ const char *string UNUSED;
/* genl backward compat stuff */
/*****************************************************************************/
const char *fieldnm[MAXBLSTATS];
const char *fieldfmt[MAXBLSTATS];
char *vals[MAXBLSTATS];
boolean activefields[MAXBLSTATS];
const char *status_fieldnm[MAXBLSTATS];
const char *status_fieldfmt[MAXBLSTATS];
char *status_vals[MAXBLSTATS];
boolean status_activefields[MAXBLSTATS];
NEARDATA winid WIN_STATUS;
void
@@ -815,10 +815,10 @@ genl_status_init()
{
int i;
for (i = 0; i < MAXBLSTATS; ++i) {
vals[i] = (char *) alloc(MAXCO);
*vals[i] = '\0';
activefields[i] = FALSE;
fieldfmt[i] = (const char *) 0;
status_vals[i] = (char *) alloc(MAXCO);
*status_vals[i] = '\0';
status_activefields[i] = FALSE;
status_fieldfmt[i] = (const char *) 0;
}
/* Use a window for the genl version; backward port compatibility */
WIN_STATUS = create_nhwindow(NHW_STATUS);
@@ -833,9 +833,9 @@ genl_status_finish()
/* free alloc'd memory here */
for (i = 0; i < MAXBLSTATS; ++i) {
if (vals[i])
free((genericptr_t) vals[i]);
vals[i] = (char *) 0;
if (status_vals[i])
free((genericptr_t) status_vals[i]);
status_vals[i] = (char *) 0;
}
}
@@ -846,9 +846,9 @@ const char *nm;
const char *fmt;
boolean enable;
{
fieldfmt[fieldidx] = fmt;
fieldnm[fieldidx] = nm;
activefields[fieldidx] = enable;
status_fieldfmt[fieldidx] = fmt;
status_fieldnm[fieldidx] = nm;
status_activefields[fieldidx] = enable;
}
void
@@ -863,52 +863,52 @@ genericptr_t ptr;
enum statusfields fieldorder[2][15] = {
{ BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, BL_ALIGN,
BL_SCORE, BL_BOGUS, BL_BOGUS, BL_BOGUS, BL_BOGUS, BL_BOGUS, BL_BOGUS},
BL_SCORE, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH},
{ BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX, BL_ENE, BL_ENEMAX,
BL_AC, BL_XP, BL_EXP, BL_HD, BL_TIME, BL_HUNGER,
BL_CAP, BL_CONDITION, BL_BOGUS}
BL_CAP, BL_CONDITION, BL_FLUSH}
};
if (idx != BL_BOGUS) {
if (!activefields[idx])
if (idx != BL_FLUSH) {
if (!status_activefields[idx])
return;
switch (idx) {
case BL_CONDITION:
cond = *condptr;
*vals[idx] = '\0';
*status_vals[idx] = '\0';
if (cond & BL_MASK_BLIND)
Strcat(vals[idx], " Blind");
Strcat(status_vals[idx], " Blind");
if (cond & BL_MASK_CONF)
Strcat(vals[idx], " Conf");
Strcat(status_vals[idx], " Conf");
if (cond & BL_MASK_FOODPOIS)
Strcat(vals[idx], " FoodPois");
Strcat(status_vals[idx], " FoodPois");
if (cond & BL_MASK_ILL)
Strcat(vals[idx], " Ill");
Strcat(status_vals[idx], " Ill");
if (cond & BL_MASK_STUNNED)
Strcat(vals[idx], " Stun");
Strcat(status_vals[idx], " Stun");
if (cond & BL_MASK_HALLU)
Strcat(vals[idx], " Hallu");
Strcat(status_vals[idx], " Hallu");
if (cond & BL_MASK_SLIMED)
Strcat(vals[idx], " Slime");
Strcat(status_vals[idx], " Slime");
break;
default:
Sprintf(vals[idx], fieldfmt[idx] ? fieldfmt[idx] : "%s", text);
Sprintf(status_vals[idx], status_fieldfmt[idx] ? status_fieldfmt[idx] : "%s", text);
break;
}
}
/* This genl version updates everything on the display, everytime */
newbot1[0] = '\0';
for (i = 0; fieldorder[0][i] != BL_BOGUS; ++i) {
for (i = 0; fieldorder[0][i] != BL_FLUSH; ++i) {
int idx1 = fieldorder[0][i];
if (activefields[idx1])
Strcat(newbot1, vals[idx1]);
if (status_activefields[idx1])
Strcat(newbot1, status_vals[idx1]);
}
newbot2[0] = '\0';
for (i = 0; fieldorder[1][i] != BL_BOGUS; ++i) {
for (i = 0; fieldorder[1][i] != BL_FLUSH; ++i) {
int idx2 = fieldorder[1][i];
if (activefields[idx2])
Strcat(newbot2, vals[idx2]);
if (status_activefields[idx2])
Strcat(newbot2, status_vals[idx2]);
}
curs(WIN_STATUS, 1, 0);
putstr(WIN_STATUS, 0, newbot1);

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 wintty.c $NHDT-Date: 1433082408 2015/05/31 14:26:48 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.95 $ */
/* NetHack 3.6 wintty.c $NHDT-Date: 1433115559 2015/05/31 23:39:19 $ $NHDT-Branch: status_hilite $:$NHDT-Revision: 1.98 $ */
/* Copyright (c) David Cohrs, 1991 */
/* NetHack may be freely redistributed. See license for details. */
@@ -89,10 +89,11 @@ struct window_procs tty_procs = {
#endif
tty_getmsghistory, tty_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
genl_status_init, genl_status_finish, genl_status_enablefield,
genl_status_update,
tty_status_init,
genl_status_finish, genl_status_enablefield,
tty_status_update,
#ifdef STATUS_HILITES
genl_status_threshold,
tty_status_threshold,
#endif
#endif
genl_can_suspend_yes,
@@ -3031,89 +3032,319 @@ const char *s;
#ifdef STATUS_VIA_WINDOWPORT
/*
* These come from the genl_ routines
* in src/windows.c
* The following data structures come from the genl_ routines in
* src/windows.c and as such are considered to be on the window-port
* "side" of things, rather than the NetHack-core "side" of things.
*/
extern const char *fieldnm[MAXBLSTATS];
extern const char *fieldfmt[MAXBLSTATS];
extern char *vals[MAXBLSTATS];
extern boolean activefields[MAXBLSTATS];
extern const char *status_fieldnm[MAXBLSTATS];
extern const char *status_fieldfmt[MAXBLSTATS];
extern char *status_vals[MAXBLSTATS];
extern boolean status_activefields[MAXBLSTATS];
extern winid WIN_STATUS;
#ifdef STATUS_HILITES
typedef struct hilite_data_struct {
int thresholdtype;
anything threshold;
int behavior;
int under;
int over;
} hilite_data_t;
static hilite_data_t tty_status_hilites[MAXBLSTATS];
static int tty_status_colors[MAXBLSTATS];
struct color_option {
int color;
int attr_bits;
};
static void FDECL(start_color_option, (struct color_option));
static void FDECL(end_color_option, (struct color_option));
static void FDECL(apply_color_option, (struct color_option, const char *));
static void FDECL(add_colored_text, (const char *, char *));
#endif
void
tty_status_update(idx, ptr, chg, percent)
int idx, chg, percent;
tty_status_init()
{
int i;
/* let genl_status_init do most of the initialization */
genl_status_init();
for (i = 0; i < MAXBLSTATS; ++i) {
#ifdef STATUS_HILITES
tty_status_colors[i] = CLR_MAX; /* no color */
tty_status_hilites[i].thresholdtype = 0;
tty_status_hilites[i].behavior = BL_TH_NONE;
tty_status_hilites[i].under = BL_HILITE_NONE;
tty_status_hilites[i].over = BL_HILITE_NONE;
#endif /* STATUS_HILITES */
}
}
/*
* *_status_update()
* -- update the value of a status field.
* -- the fldindex identifies which field is changing and
* is an integer index value from botl.h
* -- fldindex could be any one of the following from botl.h:
* BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
* BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX,
* BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX,
* BL_LEVELDESC, BL_EXP, BL_CONDITION
* -- fldindex could also be BL_FLUSH (-1), which is not really
* a field index, but is a special trigger to tell the
* windowport that it should redisplay all its status fields,
* even if no changes have been presented to it.
* -- ptr is usually a "char *", unless fldindex is BL_CONDITION.
* If fldindex is BL_CONDITION, then ptr is a long value with
* any or none of the following bits set (from botl.h):
* BL_MASK_BLIND 0x00000001L
* BL_MASK_CONF 0x00000002L
* BL_MASK_FOODPOIS 0x00000004L
* BL_MASK_ILL 0x00000008L
* BL_MASK_HALLU 0x00000010L
* BL_MASK_STUNNED 0x00000020L
* BL_MASK_SLIMED 0x00000040L
* -- The value passed for BL_GOLD includes a leading
* symbol for GOLD "$:nnn". If the window port needs to use
* the textual gold amount without the leading "$:" the port
* will have to add 2 to the passed "ptr" for the BL_GOLD case.
*/
void
tty_status_update(fldidx, ptr, chg, percent)
int fldidx, chg, percent;
genericptr_t ptr;
{
char newbot1[MAXCO], newbot2[MAXCO];
long cond, *condptr = (long *) ptr;
register int i;
char *text = (char *) ptr;
/* Mapping BL attributes to tty attributes
* BL_HILITE_NONE -1 + 3 = 2 (statusattr[2])
* BL_HILITE_INVERSE -2 + 3 = 1 (statusattr[1])
* BL_HILITE_BOLD -3 + 3 = 0 (statusattr[0])
*/
int statusattr[] = {ATR_BOLD, ATR_INVERSE, ATR_NONE};
int attridx = 0;
long value = -1L;
enum statusfields fieldorder[2][15] = {
{ BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, BL_ALIGN,
BL_SCORE, BL_BOGUS, BL_BOGUS, BL_BOGUS, BL_BOGUS, BL_BOGUS, BL_BOGUS},
BL_SCORE, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH},
{ BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX, BL_ENE, BL_ENEMAX,
BL_AC, BL_XP, BL_EXP, BL_HD, BL_TIME, BL_HUNGER,
BL_CAP, BL_CONDITION, BL_BOGUS}
BL_CAP, BL_CONDITION, BL_FLUSH}
};
if (idx != BL_BOGUS) {
if (!activefields[idx])
if (fldidx != BL_FLUSH) {
if (!status_activefields[fldidx])
return;
switch (idx) {
switch (fldidx) {
case BL_CONDITION:
cond = *condptr;
*vals[idx] = '\0';
*status_vals[fldidx] = '\0';
if (cond & BL_MASK_BLIND)
Strcat(vals[idx], " Blind");
Strcat(status_vals[fldidx], " Blind");
if (cond & BL_MASK_CONF)
Strcat(vals[idx], " Conf");
Strcat(status_vals[fldidx], " Conf");
if (cond & BL_MASK_FOODPOIS)
Strcat(vals[idx], " FoodPois");
Strcat(status_vals[fldidx], " FoodPois");
if (cond & BL_MASK_ILL)
Strcat(vals[idx], " Ill");
Strcat(status_vals[fldidx], " Ill");
if (cond & BL_MASK_STUNNED)
Strcat(vals[idx], " Stun");
Strcat(status_vals[fldidx], " Stun");
if (cond & BL_MASK_HALLU)
Strcat(vals[idx], " Hallu");
Strcat(status_vals[fldidx], " Hallu");
if (cond & BL_MASK_SLIMED)
Strcat(vals[idx], " Slime");
Strcat(status_vals[fldidx], " Slime");
value = cond;
break;
default:
Sprintf(vals[idx], fieldfmt[idx] ? fieldfmt[idx] : "%s", text);
value = atol(text);
Sprintf(status_vals[fldidx],
status_fieldfmt[fldidx] ? status_fieldfmt[fldidx] :
"%s", text);
break;
}
}
/* This genl version updates everything on the display, everytime */
newbot1[0] = '\0';
for (i = 0; fieldorder[0][i] != BL_BOGUS; ++i) {
int idx1 = fieldorder[0][i];
if (activefields[idx1])
Strcat(newbot1, vals[idx1]);
}
newbot2[0] = '\0';
for (i = 0; fieldorder[1][i] != BL_BOGUS; ++i) {
int idx2 = fieldorder[1][i];
if (activefields[idx2])
Strcat(newbot2, vals[idx2]);
#ifdef STATUS_HILITES
switch (tty_status_hilites[fldidx].behavior) {
case BL_TH_NONE:
tty_status_colors[fldidx] = CLR_MAX;
break;
case BL_TH_UPDOWN:
if (chg > 0)
tty_status_colors[fldidx] = tty_status_hilites[fldidx].over;
else if (chg < 0)
tty_status_colors[fldidx] = tty_status_hilites[fldidx].under;
else
tty_status_colors[fldidx] = CLR_MAX;
break;
case BL_TH_VAL_PERCENTAGE:
{
int pct_th = 0;
if (tty_status_hilites[fldidx].thresholdtype != ANY_INT) {
impossible("tty_status_update: unsupported percentage "
"threshold type %d",
tty_status_hilites[fldidx].thresholdtype);
break;
}
pct_th = tty_status_hilites[fldidx].threshold.a_int;
tty_status_colors[fldidx] = (percent >= pct_th)
? tty_status_hilites[fldidx].over
: tty_status_hilites[fldidx].under;
}
break;
case BL_TH_VAL_ABSOLUTE:
{
int c = CLR_MAX;
int o = tty_status_hilites[fldidx].over;
int u = tty_status_hilites[fldidx].under;
anything *t = &tty_status_hilites[fldidx].threshold;
switch (tty_status_hilites[fldidx].thresholdtype) {
case ANY_LONG:
c = (value >= t->a_long) ? o : u;
break;
case ANY_INT:
c = (value >= t->a_int) ? o : u;
break;
case ANY_UINT:
c = ((unsigned long) value >= t->a_uint) ? o : u;
break;
case ANY_ULONG:
c = ((unsigned long) value >= t->a_ulong) ? o : u;
break;
case ANY_MASK32:
c = (value & t->a_ulong) ? o : u;
break;
default:
impossible("tty_status_update: unsupported absolute threshold "
"type %d\n",
tty_status_hilites[fldidx].thresholdtype);
break;
}
tty_status_colors[fldidx] = c;
}
break;
}
#endif /* STATUS_HILITES */
/* This version copied from the genl_ version currently
* updates everything on the display, everytime
*/
curs(WIN_STATUS, 1, 0);
putstr(WIN_STATUS, 0, newbot1);
for (i = 0; fieldorder[0][i] != BL_FLUSH; ++i) {
int fldidx1 = fieldorder[0][i];
if (status_activefields[fldidx1]) {
if (tty_status_colors[fldidx1] < 0 &&
tty_status_colors[fldidx1] >= -3) {
/* attribute, not a color */
attridx = tty_status_colors[fldidx1] + 3;
term_start_attr(statusattr[attridx]);
putstr(WIN_STATUS, 0, status_vals[fldidx1]);
term_end_attr(statusattr[attridx]);
#ifdef TEXTCOLOR
} else if (tty_status_colors[fldidx1] != NO_COLOR) {
term_start_color(tty_status_colors[fldidx1]);
putstr(WIN_STATUS, 0, status_vals[fldidx1]);
term_end_color();
#endif
} else
putstr(WIN_STATUS, 0, status_vals[fldidx1]);
}
}
curs(WIN_STATUS, 1, 1);
putmixed(WIN_STATUS, 0, newbot2); /* putmixed() due to GOLD glyph */
for (i = 0; fieldorder[1][i] != BL_FLUSH; ++i) {
int fldidx2 = fieldorder[1][i];
if (status_activefields[fldidx2]) {
if (tty_status_colors[fldidx2] < 0 &&
tty_status_colors[fldidx2] >= -3) {
/* attribute, not a color */
attridx = tty_status_colors[fldidx2] + 3;
term_start_attr(statusattr[attridx]);
putstr(WIN_STATUS, 0, status_vals[fldidx2]);
term_end_attr(statusattr[attridx]);
#ifdef TEXTCOLOR
} else if (tty_status_colors[fldidx2] != NO_COLOR) {
term_start_color(tty_status_colors[fldidx2]);
if (fldidx2 == BL_GOLD) {
/* putmixed() due to GOLD glyph */
putmixed(WIN_STATUS, 0, status_vals[fldidx2]);
} else {
putstr(WIN_STATUS, 0, status_vals[fldidx2]);
}
term_end_color();
#endif
} else
putstr(WIN_STATUS, 0, status_vals[fldidx2]);
}
}
return;
}
#ifdef STATUS_HILITES
/*
* status_threshold(int fldidx, int threshholdtype, anything threshold,
* int behavior, int under, int over)
*
* -- called when a hiliting preference is added, changed, or
* removed.
* -- the fldindex identifies which field is having its hiliting
* preference set. It is an integer index value from botl.h
* -- fldindex could be any one of the following from botl.h:
* BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
* BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX,
* BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX,
* BL_LEVELDESC, BL_EXP, BL_CONDITION
* -- datatype is P_INT, P_UINT, P_LONG, or P_MASK.
* -- threshold is an "anything" union which can contain the
* datatype value.
* -- behavior is used to define how threshold is used and can
* be BL_TH_NONE, BL_TH_VAL_PERCENTAGE, BL_TH_VAL_ABSOLUTE,
* or BL_TH_UPDOWN. BL_TH_NONE means don't do anything above
* or below the threshold. BL_TH_VAL_PERCENTAGE treats the
* threshold value as a precentage of the maximum possible
* value. BL_TH_VAL_ABSOLUTE means that the threshold is an
* actual value. BL_TH_UPDOWN means that threshold is not
* used, and the two below/above hilite values indicate how
* to display something going down (under) or rising (over).
* -- under is the hilite attribute used if value is below the
* threshold. The attribute can be BL_HILITE_NONE,
* BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one
* of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN,
* CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY,
* CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE,
* CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15).
* -- over is the hilite attribute used if value is at or above
* the threshold. The attribute can be BL_HILITE_NONE,
* BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one
* of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN,
* CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY,
* CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE,
* CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15).
*/
void
tty_status_threshold(fldidx, thresholdtype, threshold, behavior, under, over)
int fldidx, thresholdtype;
int behavior, under, over;
anything threshold;
{
tty_status_hilites[fldidx].thresholdtype = thresholdtype;
tty_status_hilites[fldidx].threshold = threshold;
tty_status_hilites[fldidx].behavior = behavior;
tty_status_hilites[fldidx].under = under;
tty_status_hilites[fldidx].over = over;
return;
}
#endif /* STATUS_HILITES */
#endif /*STATUS_VIA_WINDOWPORT*/