diff --git a/src/battle/ai.c b/src/battle/ai.c index 8ba7ae1..5f4f661 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -25,7 +25,7 @@ static int isInFOV(Entity *e, int fov); static void preAttack(void); static void huntTarget(void); static void huntAndAttackTarget(void); -static void evade(void); +static void moveToTargetLocation(void); static void nextAction(void); static void findTarget(void); static int hasClearShot(void); @@ -48,6 +48,8 @@ static int getActionChance(int type); static void doFighterAI(void); static void doGunAI(void); static void moveToLeader(void); +static void wander(void); +static void doWander(void); void doAI(void) { @@ -104,6 +106,11 @@ void doAI(void) return; } + if (self->aiFlags & AIF_WANDERS) + { + doWander(); + } + /* no idea - just stay where you are */ applyFighterBrakes(); } @@ -167,7 +174,7 @@ static void doFighterAI(void) { self->targetLocation.x = self->target->x + (rand() % 250 - rand() % 250); self->targetLocation.y = self->target->y + (rand() % 250 - rand() % 250); - self->action = evade; + self->action = moveToTargetLocation; self->aiActionTime = FPS; } else if (r <= getActionChance(AI_FALLBACK)) @@ -470,7 +477,7 @@ static void turnAndFly(int wantedAngle) nextAction(); } -static void evade(void) +static void moveToTargetLocation(void) { int wantedAngle = getAngle(self->x, self->y, self->targetLocation.x, self->targetLocation.y); @@ -770,3 +777,28 @@ static void moveToLeader(void) applyFighterThrust(); } } + +static void doWander(void) +{ + self->targetLocation.x = 5 + (rand() % (GRID_SIZE - 10)); + self->targetLocation.x *= GRID_CELL_WIDTH; + + self->targetLocation.y = 5 + (rand() % (GRID_SIZE - 10)); + self->targetLocation.y *= GRID_CELL_HEIGHT; + + self->aiActionTime = FPS * 15; + + wander(); +} + +static void wander(void) +{ + moveToTargetLocation(); + + if (nearEnemies()) + { + self->aiActionTime = 0; + } + + nextAction(); +} diff --git a/src/defs.h b/src/defs.h index d162986..f960903 100644 --- a/src/defs.h +++ b/src/defs.h @@ -104,6 +104,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define AIF_LONG_RANGE_FIRE (2 << 11) #define AIF_MOVES_TO_LEADER (2 << 12) #define AIF_EVADE (2 << 13) +#define AIF_WANDERS (2 << 14) /* player abilities */ #define BOOST_RECHARGE_TIME (FPS * 7) diff --git a/src/system/lookup.c b/src/system/lookup.c index 43c97a9..ad49b55 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -63,6 +63,7 @@ void initLookups(void) addLookup("AIF_AGGRESSIVE", AIF_AGGRESSIVE); addLookup("AIF_LONG_RANGE_FIRE", AIF_LONG_RANGE_FIRE); addLookup("AIF_MOVES_TO_LEADER", AIF_MOVES_TO_LEADER); + addLookup("AIF_WANDERS", AIF_WANDERS); addLookup("DT_ANY", DT_ANY); addLookup("DT_NO_SPIN", DT_NO_SPIN);