diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 3382de9..04aad7f 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -258,29 +258,35 @@ static void separate(void) int distance; float dx, dy, force; int count; - Entity *f; + Entity *e, **candidates; + int i; dx = dy = 0; count = 0; force = 0; - for (f = battle.entityHead.next ; f != NULL ; f = f->next) + candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self); + i = 0; + e = candidates[i]; + + while (e) { - if (f != self && f->active) + distance = getDistance(e->x, e->y, self->x, self->y); + + if (distance > 0 && distance < self->separationRadius) { - distance = getDistance(f->x, f->y, self->x, self->y); + angle = getAngle(self->x, self->y, e->x, e->y); - if (distance > 0 && distance < self->separationRadius) - { - angle = getAngle(self->x, self->y, f->x, f->y); - - dx += sin(TO_RAIDANS(angle)); - dy += -cos(TO_RAIDANS(angle)); - force += (self->separationRadius - distance) * 0.005; - - count++; - } + dx += sin(TO_RAIDANS(angle)); + dy += -cos(TO_RAIDANS(angle)); + force += (self->separationRadius - distance) * 0.005; + + count++; } + + i++; + + e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL; } if (count > 0) diff --git a/src/battle/fighters.h b/src/battle/fighters.h index c304d91..1d59898 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -38,6 +38,7 @@ extern void updateCondition(char *name, int type); extern Entity *getFighterDef(char *name); extern void addHudMessage(SDL_Color c, char *format, ...); extern void checkTrigger(char *name, int type); +extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern Entity *spawnEntity(void); extern App app;