Misc. bug fixes.

This commit is contained in:
Steve 2015-11-20 22:52:48 +00:00
parent b44f208f6c
commit 0b9a6f8b1f
3 changed files with 40 additions and 42 deletions

View File

@ -90,7 +90,7 @@ static void doFighterAI(void)
int r; int r;
/* don't hold a grudge against current target */ /* don't hold a grudge against current target */
if ((self->target != NULL && self->target->health <= 0) || rand() % 2 == 0) if ((self->target != NULL && self->target->health <= 0) || rand() % 5 == 0)
{ {
self->action = doAI; self->action = doAI;
self->target = NULL; self->target = NULL;
@ -127,10 +127,10 @@ static void doFighterAI(void)
if (r <= getActionChance(AI_EVADE)) if (r <= getActionChance(AI_EVADE))
{ {
self->targetLocation.x = self->target->x + rand() % 500 - rand() % 500; self->targetLocation.x = self->target->x + (rand() % 150 - rand() % 150);
self->targetLocation.y = self->target->y + rand() % 500 - rand() % 500; self->targetLocation.y = self->target->y + (rand() % 150 - rand() % 150);
self->action = evade; self->action = evade;
self->aiActionTime = FPS * 2; self->aiActionTime = FPS;
} }
else if (r <= getActionChance(AI_BOOST)) else if (r <= getActionChance(AI_BOOST))
{ {
@ -355,6 +355,9 @@ static void preAttack(void)
{ {
if (!self->reload) if (!self->reload)
{ {
/* force weapon selection, otherwise we'll keep using lasers / mag */
canAttack(self->target);
if (self->guns[0].type && (self->missiles.ammo == 0 || rand() % 50 > 0)) if (self->guns[0].type && (self->missiles.ammo == 0 || rand() % 50 > 0))
{ {
fireGuns(self); fireGuns(self);
@ -395,7 +398,7 @@ static void turnAndFly(int wantedAngle)
static void evade(void) static void evade(void)
{ {
int wantedAngle = 180 + getAngle(self->x, self->y, self->targetLocation.x, self->targetLocation.y); int wantedAngle = getAngle(self->x, self->y, self->targetLocation.x, self->targetLocation.y);
turnAndFly(wantedAngle); turnAndFly(wantedAngle);
} }
@ -476,24 +479,19 @@ static void moveToPlayer(void)
static int nearExtractionPoint(void) static int nearExtractionPoint(void)
{ {
int i; int dist;
Entity *e, **candidates;
candidates = getAllEntsWithin(self->x - (self->w / 2), self->y - (self->h / 2), GRID_CELL_WIDTH, GRID_CELL_HEIGHT, self);
self->target = NULL; self->target = NULL;
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) if (battle.extractionPoint)
{ {
if (e->type == ET_EXTRACTION_POINT) dist = getDistance(self->x, self->y, battle.extractionPoint->x, battle.extractionPoint->y);
{
self->target = e;
}
}
if (self->target != NULL) if (dist <= 2000 || self->aiFlags & AIF_UNLIMITED_RANGE)
{ {
self->action = moveToExtractionPoint; self->target = battle.extractionPoint;
self->action = moveToExtractionPoint;
}
} }
return self->target != NULL; return self->target != NULL;

View File

@ -59,15 +59,6 @@ void doEntities(void)
removeFromGrid(e); removeFromGrid(e);
if (e->action != NULL)
{
if (--e->thinkTime <= 0)
{
e->thinkTime = 0;
e->action();
}
}
switch (e->type) switch (e->type)
{ {
case ET_FIGHTER: case ET_FIGHTER:
@ -92,14 +83,27 @@ void doEntities(void)
break; break;
} }
doRope(e); if (e->alive == ALIVE_ALIVE || e->alive == ALIVE_DYING)
{
if (e->action != NULL)
{
if (--e->thinkTime <= 0)
{
e->thinkTime = 0;
e->action();
}
}
restrictToGrid(e); doRope(e);
e->x += e->dx; restrictToGrid(e);
e->y += e->dy;
if (e->alive == ALIVE_DEAD || e->alive == ALIVE_ESCAPED) e->x += e->dx;
e->y += e->dy;
addToGrid(e);
}
else
{ {
if (e == battle.entityTail) if (e == battle.entityTail)
{ {
@ -124,13 +128,9 @@ void doEntities(void)
free(e); free(e);
e = prev; e = prev;
} }
else
{
addToGrid(e);
}
} }
if (e->type == ET_FIGHTER && (battle.epic || e->active)) if (e->type == ET_FIGHTER && (battle.epic || e->active) && !(e->flags & EF_NO_EPIC))
{ {
if (e->side == SIDE_ALLIES) if (e->side == SIDE_ALLIES)
{ {
@ -309,7 +309,7 @@ static void activateEpicFighters(int n, int side)
{ {
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (!e->active && e->type == ET_FIGHTER && ((side == SIDE_ALLIES && e->side == SIDE_ALLIES) || (side != SIDE_ALLIES && e->side != SIDE_ALLIES))) if (!e->active && e->type == ET_FIGHTER && !(e->flags & EF_NO_EPIC) && ((side == SIDE_ALLIES && e->side == SIDE_ALLIES) || (side != SIDE_ALLIES && e->side != SIDE_ALLIES)))
{ {
e->active = 1; e->active = 1;

View File

@ -113,7 +113,7 @@ void doPlayer(void)
if (app.keyboard[SDL_SCANCODE_RETURN] && player->missiles.ammo && player->target) if (app.keyboard[SDL_SCANCODE_RETURN] && player->missiles.ammo && player->target)
{ {
if (getDistance(player->x, player->y, player->target->x, player->target->y) <= 1000) if (getDistance(player->x, player->y, player->target->x, player->target->y) <= SCREEN_WIDTH)
{ {
fireMissile(player); fireMissile(player);
} }
@ -125,7 +125,7 @@ void doPlayer(void)
app.keyboard[SDL_SCANCODE_RETURN] = 0; app.keyboard[SDL_SCANCODE_RETURN] = 0;
} }
if (!player->target || player->target->health <= 0 || player->target->systemPower <= 0 || app.keyboard[SDL_SCANCODE_T]) if (!player->target || player->target->systemPower <= 0 || app.keyboard[SDL_SCANCODE_T])
{ {
selectTarget(); selectTarget();