DEBUG_FAST macro and extra code to verify the FASTCOUNT code.

This commit is contained in:
Enno Rehling 2007-03-04 21:30:39 +00:00
parent 6c8c7ae592
commit e7e0ef994b
1 changed files with 37 additions and 18 deletions

View File

@ -84,6 +84,8 @@ static FILE *bdebug;
# define DAMAGE_QUOTIENT 1 /* damage += skilldiff/DAMAGE_QUOTIENT */ # define DAMAGE_QUOTIENT 1 /* damage += skilldiff/DAMAGE_QUOTIENT */
#endif #endif
#define DEBUG_FAST /* should be disabled when I'm sure it works */
typedef enum combatmagic { typedef enum combatmagic {
DO_PRECOMBATSPELL, DO_PRECOMBATSPELL,
DO_POSTCOMBATSPELL DO_POSTCOMBATSPELL
@ -487,7 +489,7 @@ get_unitrow(const fighter * af, const side * vs)
b->rowcache.result = get_row(af->side, row, vs); b->rowcache.result = get_row(af->side, row, vs);
return b->rowcache.result; return b->rowcache.result;
} }
#if 1 /* validation code */ #ifdef DEBUG_FAST /* validation code */
{ {
int i = get_row(af->side, row, vs); int i = get_row(af->side, row, vs);
assert(i==b->rowcache.result); assert(i==b->rowcache.result);
@ -1262,20 +1264,45 @@ count_allies(const side * as, int minrow, int maxrow, int select)
return count; return count;
} }
static int
count_enemies_i(battle * b, const fighter * af, int minrow, int maxrow, int select)
{
side *es, *as = af->side;
int i = 0;
for (es = b->sides; es; es = es->next) {
if (as==NULL || enemy(es, as)) {
int offset = 0;
if (select&SELECT_DISTANCE) {
offset = get_unitrow(af, es) - FIGHT_ROW;
}
i += count_side(es, as, minrow-offset, maxrow-offset, select);
if (i>0 && (select&SELECT_FIND)) break;
}
}
return i;
}
int int
count_enemies(battle * b, const fighter * af, int minrow, int maxrow, int select) count_enemies(battle * b, const fighter * af, int minrow, int maxrow, int select)
{ {
int i = 0;
side *es, *as = af->side;
#ifdef FASTCOUNT #ifdef FASTCOUNT
int sr = statusrow(af->status); int sr = statusrow(af->status);
side *as = af->side;
if (b->alive==b->fast.alive && as==b->fast.side && sr==b->fast.status && minrow==b->fast.minrow && maxrow==b->fast.maxrow) { if (b->alive==b->fast.alive && as==b->fast.side && sr==b->fast.status && minrow==b->fast.minrow && maxrow==b->fast.maxrow) {
if (b->fast.enemies[select]>=0) { if (b->fast.enemies[select]>=0) {
#ifdef DEBUG_FAST
int i = count_enemies_i(b, af, minrow, maxrow, select);
assert(i==b->fast.enemies[select]);
#endif
return b->fast.enemies[select]; return b->fast.enemies[select];
} else if (select&SELECT_FIND) { } else if (select&SELECT_FIND) {
if (b->fast.enemies[select-SELECT_FIND]>=0) { if (b->fast.enemies[select-SELECT_FIND]>=0) {
#ifdef DEBUG_FAST
int i = count_enemies_i(b, af, minrow, maxrow, select);
assert((i>0)==(b->fast.enemies[select-SELECT_FIND]>0));
#endif
return b->fast.enemies[select-SELECT_FIND]; return b->fast.enemies[select-SELECT_FIND];
} }
} }
@ -1287,23 +1314,15 @@ count_enemies(battle * b, const fighter * af, int minrow, int maxrow, int select
b->fast.maxrow = maxrow; b->fast.maxrow = maxrow;
memset(b->fast.enemies, -1, sizeof(b->fast.enemies)); memset(b->fast.enemies, -1, sizeof(b->fast.enemies));
} }
#endif #endif
if (maxrow<FIRST_ROW) return 0; if (maxrow>=FIRST_ROW) {
for (es = b->sides; es; es = es->next) { int i = count_enemies_i(b, af, minrow, maxrow, select);
if (as==NULL || enemy(es, as)) {
int offset = 0;
if (select&SELECT_DISTANCE) {
offset = get_unitrow(af, es) - FIGHT_ROW;
}
i += count_side(es, as, minrow-offset, maxrow-offset, select);
if (i>0 && (select&SELECT_FIND)) break;
}
}
#ifdef FASTCOUNT #ifdef FASTCOUNT
b->fast.enemies[select] = i; b->fast.enemies[select] = i;
#endif #endif
return i; return i;
}
return 0;
} }
troop troop