fix overpopulation-checks and movement based on splitsize.

This commit is contained in:
Enno Rehling 2016-10-03 20:15:38 +02:00
parent 26a416c5ba
commit fbdf845cb9

View file

@ -269,21 +269,27 @@ static direction_t richest_neighbour(region * r, faction * f, int absolut)
static bool room_for_race_in_region(region * r, const race * rc) static bool room_for_race_in_region(region * r, const race * rc)
{ {
if (rc->splitsize > 0) {
unit *u; unit *u;
int c = 0; int c = 0;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
if (u_race(u) == rc) if (u_race(u) == rc) {
c += u->number; c += u->number;
if (c > rc->splitsize * 2) {
return false;
} }
}
return (c <= (rc->splitsize * 2)); }
}
return true;
} }
static direction_t random_neighbour(region * r, unit * u) static direction_t random_neighbour(region * r, unit * u)
{ {
int i; int i;
region * next[MAXDIRECTIONS]; region *next[MAXDIRECTIONS], *backup[MAXDIRECTIONS];
region **pick;
int rr, c = 0, c2 = 0; int rr, c = 0, c2 = 0;
const race *rc = u_race(u); const race *rc = u_race(u);
@ -298,19 +304,22 @@ static direction_t random_neighbour(region * r, unit * u)
} else { } else {
next[i] = NULL; next[i] = NULL;
} }
backup[i] = rn;
c2++; c2++;
} else { } else {
next[i] = NULL; next[i] = NULL;
backup[i] = NULL;
} }
} }
pick = next;
if (c == 0) { if (c == 0) {
if (c2 == 0) { if (c2 == 0) {
return NODIRECTION; return NODIRECTION;
} }
else { else {
pick = backup;
c = c2; c = c2;
c2 = 0; /* c2 == 0 -> room_for_race nicht beachten */
} }
} }
@ -320,14 +329,14 @@ static direction_t random_neighbour(region * r, unit * u)
/* Durchzählen */ /* Durchzählen */
c = -1; c = 0;
for (i = 0; i != MAXDIRECTIONS; i++) { for (i = 0; i != MAXDIRECTIONS; i++) {
region *rn = next[i]; region *rn = pick[i];
if (rn) { if (rn) {
c++;
if (c == rr) { if (c == rr) {
return (direction_t)i; return (direction_t)i;
} }
c++;
} }
} }
@ -543,19 +552,21 @@ static order *monster_learn(unit * u)
return NULL; return NULL;
} }
static bool check_overpopulated(unit * u) static bool check_overpopulated(const unit * u)
{ {
const race *rc = u_race(u);
if (rc->splitsize > 0) {
unit *u2; unit *u2;
int c = 0; int c = 0;
for (u2 = u->region->units; u2; u2 = u2->next) { for (u2 = u->region->units; u2; u2 = u2->next) {
if (u_race(u2) == u_race(u) && u != u2) if (u != u2 && u_race(u2) == rc) {
c += u2->number; c += u2->number;
} if (c > rc->splitsize * 2)
if (c > u_race(u)->splitsize * 2)
return true; return true;
}
}
}
return false; return false;
} }