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
1 changed files with 33 additions and 22 deletions

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)
{
unit *u;
int c = 0;
if (rc->splitsize > 0) {
unit *u;
int c = 0;
for (u = r->units; u; u = u->next) {
if (u_race(u) == rc)
c += u->number;
for (u = r->units; u; u = u->next) {
if (u_race(u) == rc) {
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)
{
int i;
region * next[MAXDIRECTIONS];
region *next[MAXDIRECTIONS], *backup[MAXDIRECTIONS];
region **pick;
int rr, c = 0, c2 = 0;
const race *rc = u_race(u);
@ -298,19 +304,22 @@ static direction_t random_neighbour(region * r, unit * u)
} else {
next[i] = NULL;
}
backup[i] = rn;
c2++;
} else {
next[i] = NULL;
backup[i] = NULL;
}
}
pick = next;
if (c == 0) {
if (c2 == 0) {
return NODIRECTION;
}
else {
pick = backup;
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 */
c = -1;
c = 0;
for (i = 0; i != MAXDIRECTIONS; i++) {
region *rn = next[i];
region *rn = pick[i];
if (rn) {
c++;
if (c == rr) {
return (direction_t)i;
}
c++;
}
}
@ -543,19 +552,21 @@ static order *monster_learn(unit * u)
return NULL;
}
static bool check_overpopulated(unit * u)
static bool check_overpopulated(const unit * u)
{
unit *u2;
int c = 0;
const race *rc = u_race(u);
if (rc->splitsize > 0) {
unit *u2;
int c = 0;
for (u2 = u->region->units; u2; u2 = u2->next) {
if (u_race(u2) == u_race(u) && u != u2)
c += u2->number;
for (u2 = u->region->units; u2; u2 = u2->next) {
if (u != u2 && u_race(u2) == rc) {
c += u2->number;
if (c > rc->splitsize * 2)
return true;
}
}
}
if (c > u_race(u)->splitsize * 2)
return true;
return false;
}