eliminate the uses of the manually maintained BL_MASK_BITS

Use CONDITION_SIZE which does not require manual updating.

Also attempts to adjust win32 graphics window port for
the new fields.

That port has its own field names and should be adjusted
to using the following which are declared extern in
include/botl.h.

   struct conditions[CONDITION_COUNT];
   int cond_idx[CONDITION_COUNT];

The former contains the fields that were port-specifically
added to the win32 graphical port and more, plus it is
centrally maintained and currently utilized by tty and curses.

The cond_idx[] array contains the ranked ordering of the
condition fields from highest ranking to lowest. Instead
of indexing like this:
	int i;
	for (i = 0; i < CONDITION_COUNT; ++i) {
	    ...conditons[i].enabled;
 	    ...condtions[i].text[0];
	}

you can use the ranked ordering like this:
	int i, ci;
	for (i = 0; i < CONDITION_COUNT; ++i) {
	    ci = cond_idx[i];
	    ...conditons[ci].enabled;
 	    ...condtions[ci].text[0];
	}
This commit is contained in:
nhmall
2020-02-08 20:40:38 -05:00
parent 4096ce8454
commit 2da95e4dc0
4 changed files with 52 additions and 31 deletions

View File

@@ -114,7 +114,7 @@ enum blconditions {
#define BL_MASK_TRAPPED 0x04000000L
#define BL_MASK_UNCONSC 0x08000000L
#define BL_MASK_WOUNDEDL 0x10000000L
#define BL_MASK_BITS 28 /* number of mask bits that can be set */
#define BL_MASK_BITS 29 /* number of mask bits that can be set */
/* clang-format on */
struct conditions_t {

View File

@@ -721,7 +721,7 @@ boolean border;
time_and_score |= 2;
cond_count = 0;
if (curses_condition_bits) {
for (i = 0; i < BL_MASK_BITS; ++i)
for (i = 0; i < CONDITION_COUNT; ++i)
if (curses_condition_bits & (1 << i))
++cond_count;
}
@@ -996,7 +996,7 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */
condbuf[0] = '\0';
if (nohilite)
*nohilite = TRUE; /* assume ok */
for (i = 0; i < BL_MASK_BITS; ++i) {
for (i = 0; i < CONDITION_COUNT; ++i) {
ci = cond_idx[i];
bitmsk = conditions[ci].mask;
if (curses_condition_bits & bitmsk) {
@@ -1025,7 +1025,7 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */
cond_bits = curses_condition_bits;
/* show active conditions directly; for vertical, three per line */
for (i = 0; i < BL_MASK_BITS; ++i) {
for (i = 0; i < CONDITION_COUNT; ++i) {
ci = cond_idx[i];
bitmsk = conditions[ci].mask;
if (cond_bits & bitmsk) {

View File

@@ -21,7 +21,7 @@ static const int *fieldorders[] = { fieldorder1, fieldorder2, NULL };
static const int fieldcounts[NHSW_LINES] = { SIZE(fieldorder1) - 1, SIZE(fieldorder2) - 1};
#define MSWIN_MAX_LINE1_STRINGS (SIZE(fieldorder1) - 1)
#define MSWIN_MAX_LINE2_STRINGS (SIZE(fieldorder2) - 1 + BL_MASK_BITS)
#define MSWIN_MAX_LINE2_STRINGS (SIZE(fieldorder2) - 1 + CONDITION_COUNT)
#define MSWIN_MAX_LINE_STRINGS (MSWIN_MAX_LINE1_STRINGS > MSWIN_MAX_LINE2_STRINGS ? \
MSWIN_MAX_LINE1_STRINGS : MSWIN_MAX_LINE2_STRINGS)

View File

@@ -2798,26 +2798,41 @@ NHMessageBox(HWND hWnd, LPCTSTR text, UINT type)
static mswin_status_lines _status_lines;
static mswin_status_string _status_strings[MAXBLSTATS];
static mswin_status_string _condition_strings[BL_MASK_BITS];
static mswin_status_string _condition_strings[CONDITION_COUNT];
static mswin_status_field _status_fields[MAXBLSTATS];
static mswin_condition_field _condition_fields[BL_MASK_BITS] = {
{ BL_MASK_STONE, "Stone" },
{ BL_MASK_SLIME, "Slime" },
{ BL_MASK_STRNGL, "Strngl" },
{ BL_MASK_FOODPOIS, "FoodPois" },
{ BL_MASK_TERMILL, "TermIll" },
{ BL_MASK_BLIND, "Blind" },
{ BL_MASK_DEAF, "Deaf" },
{ BL_MASK_STUN, "Stun" },
{ BL_MASK_CONF, "Conf" },
{ BL_MASK_HALLU, "Hallu" },
{ BL_MASK_LEV, "Lev" },
{ BL_MASK_FLY, "Fly" },
{ BL_MASK_RIDE, "Ride" }
static mswin_condition_field _condition_fields[CONDITION_COUNT] = {
{ BL_MASK_BAREH, "Bare" },
{ BL_MASK_BLIND, "Blind" },
{ BL_MASK_BUSY, "Busy" },
{ BL_MASK_CONF, "Conf" },
{ BL_MASK_DEAF, "Deaf" },
{ BL_MASK_ELF_IRON, "Iron" },
{ BL_MASK_FLY, "Fly" },
{ BL_MASK_FOODPOIS, "FoodPois" },
{ BL_MASK_GLOWHANDS, "Glow" },
{ BL_MASK_GRAB, "Grab" },
{ BL_MASK_HALLU, "Hallu" },
{ BL_MASK_HELD, "Held" },
{ BL_MASK_ICY, "Icy" },
{ BL_MASK_INLAVA, "Lava" },
{ BL_MASK_LEV, "Lev" },
{ BL_MASK_PARLYZ, "Parlyz" },
{ BL_MASK_RIDE, "Ride" },
{ BL_MASK_SLEEPING, "Zzz" },
{ BL_MASK_SLIME, "Slime" },
{ BL_MASK_SLIPPERY, "Slip" },
{ BL_MASK_STONE, "Stone" },
{ BL_MASK_STRNGL, "Strngl" },
{ BL_MASK_STUN, "Stun" },
{ BL_MASK_SUBMERGED, "Sub" },
{ BL_MASK_TERMILL, "TermIll" },
{ BL_MASK_TETHERED, "Teth" },
{ BL_MASK_TRAPPED, "Trap" },
{ BL_MASK_UNCONSC, "Out" },
{ BL_MASK_WOUNDEDL, "Legs" },
};
extern winid WIN_STATUS;
#ifdef STATUS_HILITES
@@ -2839,6 +2854,7 @@ void
mswin_status_init(void)
{
logDebug("mswin_status_init()\n");
int ci;
for (int i = 0; i < SIZE(_status_fields); i++) {
mswin_status_field * status_field = &_status_fields[i];
@@ -2847,9 +2863,10 @@ mswin_status_init(void)
}
for (int i = 0; i < SIZE(_condition_fields); i++) {
mswin_condition_field * condition_field = &_condition_fields[i];
nhassert(condition_field->mask == (1 << i));
condition_field->bit_position = i;
ci = cond_idx[i];
mswin_condition_field * condition_field = &_condition_fields[ci];
nhassert(condition_field->mask == (1 << ci));
condition_field->bit_position = ci;
}
for (int i = 0; i < SIZE(_status_strings); i++) {
@@ -2858,7 +2875,8 @@ mswin_status_init(void)
}
for (int i = 0; i < SIZE(_condition_strings); i++) {
mswin_status_string * status_string = &_condition_strings[i];
ci = cond_idx[i];
mswin_status_string * status_string = &_condition_strings[ci];
status_string->str = NULL;
}
@@ -2883,10 +2901,11 @@ mswin_status_init(void)
&_status_strings[field_index];
if (field_index == BL_CONDITION) {
for (int j = 0; j < BL_MASK_BITS; j++) {
for (int j = 0; j < CONDITION_COUNT; j++) {
ci = cond_idx[j];
nhassert(status_strings->count <= SIZE(status_strings->status_strings));
status_strings->status_strings[status_strings->count++] =
&_condition_strings[j];
&_condition_strings[ci];
}
}
}
@@ -3043,7 +3062,7 @@ mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color,
long cond, *condptr = (long *) ptr;
char *text = (char *) ptr;
MSNHMsgUpdateStatus update_cmd_data;
int ocolor, ochar;
int ocolor, ochar, ci;
unsigned ospecial;
logDebug("mswin_status_update(%d, %p, %d, %d, %x, %p)\n", idx, ptr, chg, percent, color, condmasks);
@@ -3067,14 +3086,16 @@ mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color,
switch (idx) {
case BL_CONDITION: {
mswin_condition_field * condition_field = _condition_fields;
mswin_condition_field * condition_field;
nhassert(status_string->str == NULL);
cond = *condptr;
for (int i = 0; i < BL_MASK_BITS; i++, condition_field++) {
status_string = &_condition_strings[i];
for (int i = 0; i < CONDITION_COUNT; i++) {
ci = cond_idx[i];
condition_field = &_condition_fields[ci];
status_string = &_condition_strings[ci];
if (condition_field->mask & cond) {
status_string->str = condition_field->name;