Wander takes priority over moving to leaders. Don't suddenly stop when close to leader during flocking.

This commit is contained in:
Steve 2016-04-10 08:36:27 +01:00
parent 379b01fe32
commit 61b3ede526
1 changed files with 22 additions and 11 deletions

View File

@ -154,7 +154,7 @@ static void doFighterAI(void)
if (!self->target) if (!self->target)
{ {
/* takes priority over move to player */ /* move to leader and wander take priority over move to player */
if (self->aiFlags & AIF_MOVES_TO_LEADER) if (self->aiFlags & AIF_MOVES_TO_LEADER)
{ {
if (!lookForLeader()) if (!lookForLeader())
@ -169,14 +169,14 @@ static void doFighterAI(void)
} }
} }
} }
else if (self->aiFlags & AIF_MOVES_TO_PLAYER && player != NULL)
{
moveToPlayer();
}
else if (self->aiFlags & AIF_WANDERS) else if (self->aiFlags & AIF_WANDERS)
{ {
doWander(); doWander();
} }
else if (self->aiFlags & AIF_MOVES_TO_PLAYER && player != NULL)
{
moveToPlayer();
}
else else
{ {
applyFighterBrakes(); applyFighterBrakes();
@ -704,18 +704,25 @@ static void moveToPlayer(void)
int dist = getDistance(self->x, self->y, player->x, player->y); int dist = getDistance(self->x, self->y, player->x, player->y);
float oldSpeed; float oldSpeed;
if (dist <= 350) if (dist <= 250)
{ {
wantedAngle = getAngle(player->x, player->y, player->x + (player->dx * 1000), player->y + (player->dy * 1000)); wantedAngle = getAngle(player->x, player->y, player->x + (player->dx * 1000), player->y + (player->dy * 1000));
turnToFace(wantedAngle); turnToFace(wantedAngle);
if (player->thrust)
{
oldSpeed = self->speed; oldSpeed = self->speed;
self->speed = sqrt(player->thrust); self->speed = sqrt(player->thrust);
applyFighterThrust(); applyFighterThrust();
self->speed = oldSpeed; self->speed = oldSpeed;
} }
else else
{
applyFighterBrakes();
}
}
else
{ {
faceTarget(player); faceTarget(player);
@ -898,7 +905,7 @@ static void moveToLeader(void)
if (dist <= ((self->leader->type != ET_CAPITAL_SHIP) ? 350 : 550)) if (dist <= ((self->leader->type != ET_CAPITAL_SHIP) ? 350 : 550))
{ {
if (self->leader->thrust > 0) if (self->leader->thrust)
{ {
wantedAngle = getAngle(self->leader->x, self->leader->y, self->leader->x + (self->leader->dx * 1000), self->leader->y + (self->leader->dy * 1000)); wantedAngle = getAngle(self->leader->x, self->leader->y, self->leader->x + (self->leader->dx * 1000), self->leader->y + (self->leader->dy * 1000));
@ -912,6 +919,10 @@ static void moveToLeader(void)
/* don't all react at once */ /* don't all react at once */
self->aiActionTime = FPS + (rand() % FPS); self->aiActionTime = FPS + (rand() % FPS);
} }
else
{
applyFighterBrakes();
}
} }
else else
{ {