forked from github/server
Deutliche Beschleunigung von get_unitrow() durch Liste der Feinde pro Heer.
This commit is contained in:
parent
5296949c1b
commit
81a8fde774
|
@ -347,24 +347,23 @@ fbattlerecord(battle * b, faction * f, const char *s)
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean
|
#define enemy(as, ds) (as->enemy[ds->index]&E_ENEMY)
|
||||||
enemy(const side * as, const side * ds)
|
|
||||||
{
|
|
||||||
switch(as->enemy[ds->index]) {
|
|
||||||
case E_ENEMY:
|
|
||||||
case E_ENEMY|E_ATTACKING:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_enemy(side * as, side * ds, boolean attacking)
|
set_enemy(side * as, side * ds, boolean attacking)
|
||||||
{
|
{
|
||||||
ds->enemy[as->index] |= E_ENEMY;
|
int i;
|
||||||
as->enemy[ds->index] |= E_ENEMY;
|
for (i=0;i!=128;++i) {
|
||||||
if (attacking) as->enemy[ds->index] |= E_ATTACKING;
|
if (ds->enemies[i]==NULL) ds->enemies[i]=as;
|
||||||
|
if (ds->enemies[i]==as) break;
|
||||||
|
}
|
||||||
|
for (i=0;i!=128;++i) {
|
||||||
|
if (as->enemies[i]==NULL) as->enemies[i]=ds;
|
||||||
|
if (as->enemies[i]==ds) break;
|
||||||
|
}
|
||||||
|
ds->enemy[as->index] |= E_ENEMY;
|
||||||
|
as->enemy[ds->index] |= E_ENEMY;
|
||||||
|
if (attacking) as->enemy[ds->index] |= E_ATTACKING;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ALLIANCES
|
#ifdef ALLIANCES
|
||||||
|
@ -506,7 +505,6 @@ get_unitrow(const fighter * af)
|
||||||
static size_t csize = 0;
|
static size_t csize = 0;
|
||||||
|
|
||||||
battle * b = af->side->battle;
|
battle * b = af->side->battle;
|
||||||
void **si;
|
|
||||||
int enemyfront = 0;
|
int enemyfront = 0;
|
||||||
int line, result;
|
int line, result;
|
||||||
int retreat = 0;
|
int retreat = 0;
|
||||||
|
@ -530,17 +528,16 @@ get_unitrow(const fighter * af)
|
||||||
else memset(counted, 0, bsize*sizeof(boolean));
|
else memset(counted, 0, bsize*sizeof(boolean));
|
||||||
memset(size, 0, sizeof(size));
|
memset(size, 0, sizeof(size));
|
||||||
for (line=FIRST_ROW;line!=NUMROWS;++line) {
|
for (line=FIRST_ROW;line!=NUMROWS;++line) {
|
||||||
|
int si;
|
||||||
/* how many enemies are there in the first row? */
|
/* how many enemies are there in the first row? */
|
||||||
for (si = b->sides.begin; si != b->sides.end; ++si) {
|
for (si=0;af->side->enemies[si];++si) {
|
||||||
side *s = *si;
|
side *s = af->side->enemies[si];
|
||||||
if (s->size[line] && enemy(s, af->side))
|
if (s->size[line]>0) {
|
||||||
{
|
int ai;
|
||||||
void ** sf;
|
|
||||||
enemyfront += s->size[line]; /* - s->nonblockers[line] (nicht, weil angreifer) */
|
enemyfront += s->size[line]; /* - s->nonblockers[line] (nicht, weil angreifer) */
|
||||||
for (sf = b->sides.begin; sf != b->sides.end; ++sf) {
|
for (ai=0;s->enemies[ai];++ai) {
|
||||||
side * ally = *sf;
|
side * ally = s->enemies[ai];
|
||||||
if (!counted[ally->index] && enemy(s, ally) && !enemy(ally, af->side))
|
if (!counted[ally->index] && !enemy(ally, af->side)) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
counted[ally->index] = true;
|
counted[ally->index] = true;
|
||||||
for (i=0;i!=NUMROWS;++i) size[i] += ally->size[i] - ally->nonblockers[i];
|
for (i=0;i!=NUMROWS;++i) size[i] += ally->size[i] - ally->nonblockers[i];
|
||||||
|
|
|
@ -84,6 +84,7 @@ extern "C" {
|
||||||
# define E_ENEMY 1
|
# define E_ENEMY 1
|
||||||
# define E_ATTACKING 2
|
# define E_ATTACKING 2
|
||||||
int enemy[128];
|
int enemy[128];
|
||||||
|
struct side * enemies[128];
|
||||||
cvector fighters; /* vector der Einheiten dieser Fraktion */
|
cvector fighters; /* vector der Einheiten dieser Fraktion */
|
||||||
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
|
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
|
||||||
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
|
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
|
||||||
|
|
|
@ -907,7 +907,7 @@ get_addresses(faction * f)
|
||||||
}
|
}
|
||||||
|
|
||||||
seen_region * reuse;
|
seen_region * reuse;
|
||||||
#define MAXSEEHASH 4999
|
#define MAXSEEHASH 10007
|
||||||
seen_region * seehash[MAXSEEHASH];
|
seen_region * seehash[MAXSEEHASH];
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue