diff --git a/src/battle/ai.c b/src/battle/ai.c index 20c2b1a..9d573b3 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -312,9 +312,9 @@ static void findTarget(void) Entity *e, **candidates; unsigned int dist, closest; - dist = closest = (battle.isEpic || (self->aiFlags & AIF_UNLIMITED_RANGE)) ? MAX_TARGET_RANGE : 1000; + dist = closest = (battle.isEpic || (self->aiFlags & AIF_UNLIMITED_RANGE)) ? MAX_TARGET_RANGE : SCREEN_WIDTH; - candidates = getAllEntsWithin(self->x - (self->w / 2) - dist, self->y - (self->h / 2) - dist, self->w + (dist * 2), self->h + (dist * 2), self); + candidates = getAllEntsInRadius(self->x, self->y, dist, self); self->target = NULL; @@ -588,7 +588,7 @@ static int nearEnemies(void) int i, numEnemies, x, y; Entity *e, **candidates; - candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self); + candidates = getAllEntsInRadius(self->x, self->y, SCREEN_WIDTH, self); self->target = NULL; x = y = 0; @@ -604,7 +604,7 @@ static int nearEnemies(void) continue; } - if (getDistance(e->x, e->y, self->x, self->y) < 1000) + if (getDistance(e->x, e->y, self->x, self->y) <= SCREEN_WIDTH) { x += e->x; y += e->y; @@ -658,7 +658,7 @@ static int nearMines(void) int i, numMines; Entity *e, **candidates; - candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self); + candidates = getAllEntsInRadius(self->x, self->y, SCREEN_HEIGHT, self); self->targetLocation.x = self->targetLocation.y = 0; @@ -666,7 +666,7 @@ static int nearMines(void) for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { - if (e->side != self->side && e->type == ET_MINE && getDistance(e->x, e->y, self->x, self->y) < 500) + if (e->side != self->side && e->type == ET_MINE && getDistance(e->x, e->y, self->x, self->y) <= SCREEN_HEIGHT) { self->targetLocation.x += e->x; self->targetLocation.y += e->y; @@ -774,7 +774,7 @@ static int nearItems(void) closest = MAX_TARGET_RANGE; - candidates = getAllEntsWithin(self->x - (self->w / 2) - (SCREEN_WIDTH / 4), self->y - (self->h / 2) - (SCREEN_HEIGHT / 4), SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, self); + candidates = getAllEntsInRadius(self->x, self->y, SCREEN_WIDTH / 2, self); self->target = NULL; @@ -822,7 +822,7 @@ static int nearTowableCraft(void) dist = closest = (battle.isEpic || (self->aiFlags & AIF_UNLIMITED_RANGE)) ? MAX_TARGET_RANGE : 2000; - candidates = getAllEntsWithin(self->x - (self->w / 2) - dist, self->y - (self->h / 2) - dist, self->w + (dist * 2), self->h + (dist * 2), self); + candidates = getAllEntsInRadius(self->x, self->y, dist, self); self->target = NULL; diff --git a/src/battle/ai.h b/src/battle/ai.h index 28823bb..202f8ed 100644 --- a/src/battle/ai.h +++ b/src/battle/ai.h @@ -36,7 +36,7 @@ extern float getAngle(int x1, int y1, int x2, int y2); extern void applyFighterThrust(void); extern void applyFighterBrakes(void); extern void addHudMessage(SDL_Color c, char *format, ...); -extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern char *getTranslatedString(char *string); extern Entity *spawnMine(int type); diff --git a/src/battle/bullets.c b/src/battle/bullets.c index 76ae769..d09dbdd 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -339,7 +339,7 @@ static void selectNewTarget(Bullet *b) { b->target = NULL; - candidates = getAllEntsWithin(b->x - (SCREEN_WIDTH / 2), b->y - (SCREEN_HEIGHT / 2), SCREEN_WIDTH, SCREEN_HEIGHT, NULL); + candidates = getAllEntsInRadius(b->x, b->y, SCREEN_HEIGHT, NULL); for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { diff --git a/src/battle/bullets.h b/src/battle/bullets.h index daa77e5..a7868d7 100644 --- a/src/battle/bullets.h +++ b/src/battle/bullets.h @@ -41,6 +41,7 @@ extern void addMissileEngineEffect(Bullet *b); extern float mod(float n, float x); extern void addMissileExplosion(Bullet *b); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern void playSound(int id); extern char *getTranslatedString(char *string); diff --git a/src/battle/capitalShips.c b/src/battle/capitalShips.c index ef5cdbb..2a89129 100644 --- a/src/battle/capitalShips.c +++ b/src/battle/capitalShips.c @@ -193,7 +193,7 @@ static int steer(void) count = 0; force = 0; - candidates = getAllEntsWithin(self->x - 1000, self->y - 1000, 2000, 2000, self); + candidates = getAllEntsInRadius(self->x, self->y, 2000, self); for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { diff --git a/src/battle/capitalShips.h b/src/battle/capitalShips.h index 7a45729..d3d1163 100644 --- a/src/battle/capitalShips.h +++ b/src/battle/capitalShips.h @@ -39,7 +39,7 @@ extern float mod(float n, float x); extern void applyFighterThrust(void); extern void addLargeEngineEffect(void); extern int getDistance(int x1, int y1, int x2, int y2); -extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern void addDebris(int x, int y, int amount); extern void runScriptFunction(char *format, ...); extern void updateObjective(char *name, int type); diff --git a/src/battle/fighters.c b/src/battle/fighters.c index c1ecde3..63aab77 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -345,7 +345,7 @@ static void separate(void) count = 0; force = 0; - candidates = getAllEntsWithin(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, self); + candidates = getAllEntsInRadius(self->x, self->y, self->separationRadius, self); for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { diff --git a/src/battle/fighters.h b/src/battle/fighters.h index c263834..67f6d1e 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -33,7 +33,7 @@ extern void playBattleSound(int id, int x, int y); extern void updateObjective(char *name, int type); extern void updateCondition(char *name, int type); extern void addHudMessage(SDL_Color c, char *format, ...); -extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern Entity *spawnEntity(void); extern void adjustObjectiveTargetValue(char *name, int type, int amount); extern void attachRope(void); diff --git a/src/battle/items.c b/src/battle/items.c index 07fb2d9..bd79b85 100644 --- a/src/battle/items.c +++ b/src/battle/items.c @@ -101,7 +101,7 @@ static void action(void) Entity *e, **candidates; int i; - candidates = getAllEntsWithin(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, self); + candidates = getAllEntsInRadius(self->x, self->y, MAX(self->w, self->h), self); for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { diff --git a/src/battle/items.h b/src/battle/items.h index 5d54998..3be5f74 100644 --- a/src/battle/items.h +++ b/src/battle/items.h @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern char *readFile(char *filename); extern SDL_Texture *getTexture(char *filename); extern Entity *spawnEntity(void); -extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); extern void playBattleSound(int id, int x, int y); extern void addHudMessage(SDL_Color c, char *format, ...); diff --git a/src/battle/jumpgate.c b/src/battle/jumpgate.c index 2754fd1..bab6fbf 100644 --- a/src/battle/jumpgate.c +++ b/src/battle/jumpgate.c @@ -172,11 +172,11 @@ static void handleFleeingEntities(void) Entity *e, **candidates; int i; - candidates = getAllEntsWithin(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, self); + candidates = getAllEntsInRadius(self->x, self->y, ESCAPE_DISTANCE * 2, self); for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { - if (e->health > 0 && e->flags & EF_RETREATING && getDistance(self->x, self->y, e->x, e->y) <= 255) + if (e->health > 0 && e->flags & EF_RETREATING && getDistance(self->x, self->y, e->x, e->y) <= ESCAPE_DISTANCE) { e->alive = ALIVE_ESCAPED; diff --git a/src/battle/jumpgate.h b/src/battle/jumpgate.h index 860c56d..f0a76b1 100644 --- a/src/battle/jumpgate.h +++ b/src/battle/jumpgate.h @@ -20,9 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" +#define ESCAPE_DISTANCE 256 + extern SDL_Texture *getTexture(char *filename); extern Entity *spawnEntity(void); -extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern int getDistance(int x1, int y1, int x2, int y2); extern void playBattleSound(int id, int x, int y); extern void blitRotated(SDL_Texture *texture, int x, int y, float angle); diff --git a/src/battle/mine.c b/src/battle/mine.c index a66d9e7..b53e7ad 100644 --- a/src/battle/mine.c +++ b/src/battle/mine.c @@ -99,7 +99,7 @@ static void lookForFighters(void) Entity *e, **candidates; int i; - candidates = getAllEntsWithin(self->x - (self->w / 2) - DAMAGE_RANGE, self->y - (self->h / 2) - DAMAGE_RANGE, self->w + DAMAGE_RANGE, self->h + DAMAGE_RANGE, self); + candidates = getAllEntsInRadius(self->x, self->y, DAMAGE_RANGE, self); for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { @@ -199,7 +199,7 @@ static void doSplashDamage(void) int i, dist, kills; float damage, percent; - candidates = getAllEntsWithin(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, self); + candidates = getAllEntsInRadius(self->x, self->y, DAMAGE_RANGE, self); kills = 0; diff --git a/src/battle/mine.h b/src/battle/mine.h index 91d3582..aeeadd8 100644 --- a/src/battle/mine.h +++ b/src/battle/mine.h @@ -21,12 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" #define TRIGGER_RANGE 150 -#define DAMAGE_RANGE 275 +#define DAMAGE_RANGE 250 #define SYSTEM_POWER 50 extern Entity *spawnEntity(void); extern SDL_Texture *getTexture(char *filename); -extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern int getDistance(int x1, int y1, int x2, int y2); extern void addMineExplosion(void); extern void damageFighter(Entity *e, int amount, long flags); diff --git a/src/battle/quadtree.c b/src/battle/quadtree.c index 76e644d..cecb6c4 100644 --- a/src/battle/quadtree.c +++ b/src/battle/quadtree.c @@ -233,6 +233,11 @@ Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore) return candidates; } +Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore) +{ + return getAllEntsWithin(x - radius / 2, y - radius / 2, radius, radius, ignore); +} + static void getAllEntsWithinNode(int x, int y, int w, int h, Entity *ignore, Quadtree *root) { int index, i; diff --git a/src/battle/rope.c b/src/battle/rope.c index 83ad9ce..2e577a2 100644 --- a/src/battle/rope.c +++ b/src/battle/rope.c @@ -27,7 +27,7 @@ void attachRope(void) if ((self->flags & EF_HAS_ROPE) && self->towing == NULL) { - candidates = getAllEntsWithin(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, self); + candidates = getAllEntsInRadius(self->x, self->y, self->separationRadius, self); for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) { diff --git a/src/battle/rope.h b/src/battle/rope.h index 39d76ff..c8dc18e 100644 --- a/src/battle/rope.h +++ b/src/battle/rope.h @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern float getAngle(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2); -extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); +extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern void addHudMessage(SDL_Color c, char *format, ...); extern void runScriptFunction(char *format, ...); extern char *getTranslatedString(char *string);