Don't update target location, unless there are enemies nearby.

This commit is contained in:
Steve 2016-04-06 16:49:47 +01:00
parent f7e8c6303e
commit 505fbb2547
1 changed files with 7 additions and 4 deletions

View File

@ -578,13 +578,13 @@ static int isRetreating(void)
static int nearEnemies(void) static int nearEnemies(void)
{ {
int i, numEnemies; int i, numEnemies, x, y;
Entity *e, **candidates; Entity *e, **candidates;
candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self); candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self);
self->target = NULL; self->target = NULL;
self->targetLocation.x = self->targetLocation.y = 0; x = y = 0;
numEnemies = 0; numEnemies = 0;
@ -599,8 +599,8 @@ static int nearEnemies(void)
if (getDistance(e->x, e->y, self->x, self->y) < 1000) if (getDistance(e->x, e->y, self->x, self->y) < 1000)
{ {
self->targetLocation.x += e->x; x += e->x;
self->targetLocation.y += e->y; y += e->y;
numEnemies++; numEnemies++;
} }
} }
@ -608,6 +608,9 @@ static int nearEnemies(void)
if (numEnemies) if (numEnemies)
{ {
self->targetLocation.x = x;
self->targetLocation.y = y;
self->targetLocation.x /= numEnemies; self->targetLocation.x /= numEnemies;
self->targetLocation.y /= numEnemies; self->targetLocation.y /= numEnemies;