Don't update target location, unless there are enemies nearby.
This commit is contained in:
parent
f7e8c6303e
commit
505fbb2547
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue