AI fighers will now attempt to avoid combat if they take too much damage in a short space of time.
This commit is contained in:
parent
817c5c22ee
commit
1849a20831
|
@ -51,7 +51,7 @@ static void moveToLeader(void);
|
||||||
|
|
||||||
void doAI(void)
|
void doAI(void)
|
||||||
{
|
{
|
||||||
if ((self->aiFlags & AIF_AVOIDS_COMBAT) && nearEnemies())
|
if ((self->aiFlags & (AIF_AVOIDS_COMBAT | AIF_EVADE)) && nearEnemies())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -129,10 +129,17 @@ static void doFighterAI(void)
|
||||||
if (self->aiFlags & AIF_MOVES_TO_LEADER)
|
if (self->aiFlags & AIF_MOVES_TO_LEADER)
|
||||||
{
|
{
|
||||||
if (!lookForLeader())
|
if (!lookForLeader())
|
||||||
|
{
|
||||||
|
if (self->aiFlags & AIF_MOVES_TO_PLAYER && player != NULL)
|
||||||
|
{
|
||||||
|
moveToPlayer();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
applyFighterBrakes();
|
applyFighterBrakes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (self->aiFlags & AIF_MOVES_TO_PLAYER && player != NULL)
|
else if (self->aiFlags & AIF_MOVES_TO_PLAYER && player != NULL)
|
||||||
{
|
{
|
||||||
moveToPlayer();
|
moveToPlayer();
|
||||||
|
@ -244,7 +251,7 @@ static void huntTarget(void)
|
||||||
static void huntAndAttackTarget(void)
|
static void huntAndAttackTarget(void)
|
||||||
{
|
{
|
||||||
int dist = getDistance(self->x, self->y, self->target->x, self->target->y);
|
int dist = getDistance(self->x, self->y, self->target->x, self->target->y);
|
||||||
int range = self->aiFlags & AIF_LONG_RANGE_FIRE ? 1250 : 625;
|
int range = self->aiFlags & AIF_LONG_RANGE_FIRE ? (SCREEN_WIDTH * 1.5) : SCREEN_HEIGHT;
|
||||||
|
|
||||||
faceTarget(self->target);
|
faceTarget(self->target);
|
||||||
|
|
||||||
|
@ -267,7 +274,7 @@ static void huntAndAttackTarget(void)
|
||||||
|
|
||||||
static int attackSecondaryTarget(Entity *e)
|
static int attackSecondaryTarget(Entity *e)
|
||||||
{
|
{
|
||||||
if (self->target->aiFlags & AIF_AVOIDS_COMBAT || self->target->flags & EF_SECONDARY_TARGET)
|
if (self->target->aiFlags & (AIF_AVOIDS_COMBAT | AIF_EVADE) || self->target->flags & EF_SECONDARY_TARGET)
|
||||||
{
|
{
|
||||||
return rand() % 4 == 0;
|
return rand() % 4 == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,13 @@ void doEntities(void)
|
||||||
e->shieldHit = MAX(e->shieldHit - 5, 0);
|
e->shieldHit = MAX(e->shieldHit - 5, 0);
|
||||||
e->systemHit = MAX(e->systemHit - 25, 0);
|
e->systemHit = MAX(e->systemHit - 25, 0);
|
||||||
|
|
||||||
|
e->aiDamageTimer = MAX(e->aiDamageTimer - 1, 0);
|
||||||
|
if (!e->aiDamageTimer)
|
||||||
|
{
|
||||||
|
e->aiDamagePerSec = 0;
|
||||||
|
e->aiFlags &= ~AIF_EVADE;
|
||||||
|
}
|
||||||
|
|
||||||
switch (e->type)
|
switch (e->type)
|
||||||
{
|
{
|
||||||
case ET_FIGHTER:
|
case ET_FIGHTER:
|
||||||
|
@ -213,8 +220,8 @@ void doEntities(void)
|
||||||
prev = e;
|
prev = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
battle.numAllies = numAllies;
|
battle.numAllies = numActiveAllies;
|
||||||
battle.numEnemies = numEnemies;
|
battle.numEnemies = numActiveEnemies;
|
||||||
|
|
||||||
if (!battle.numInitialEnemies)
|
if (!battle.numInitialEnemies)
|
||||||
{
|
{
|
||||||
|
|
|
@ -383,6 +383,9 @@ void damageFighter(Entity *e, int amount, long flags)
|
||||||
{
|
{
|
||||||
int prevShield = e->shield;
|
int prevShield = e->shield;
|
||||||
|
|
||||||
|
e->aiDamageTimer = FPS;
|
||||||
|
e->aiDamagePerSec += amount;
|
||||||
|
|
||||||
if (flags & BF_SYSTEM_DAMAGE)
|
if (flags & BF_SYSTEM_DAMAGE)
|
||||||
{
|
{
|
||||||
e->systemPower = MAX(0, e->systemPower - amount);
|
e->systemPower = MAX(0, e->systemPower - amount);
|
||||||
|
@ -438,6 +441,23 @@ void damageFighter(Entity *e, int amount, long flags)
|
||||||
|
|
||||||
playBattleSound(SND_SHIELD_HIT, e->x, e->y);
|
playBattleSound(SND_SHIELD_HIT, e->x, e->y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sometimes run away if you take too much damage in a short space of time
|
||||||
|
*/
|
||||||
|
if (e->type == ET_FIGHTER && e != player && e->aiDamagePerSec >= (e->maxHealth + e->maxShield) * 0.1 && (!(e->aiFlags & AIF_EVADE)))
|
||||||
|
{
|
||||||
|
if (rand() % 3)
|
||||||
|
{
|
||||||
|
e->action = doAI;
|
||||||
|
e->aiFlags |= AIF_EVADE;
|
||||||
|
e->aiActionTime = e->aiEvadeTimer = FPS * 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e->aiDamagePerSec = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void die(void)
|
static void die(void)
|
||||||
|
|
|
@ -102,6 +102,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#define AIF_INSTANT_DIE (2 << 11)
|
#define AIF_INSTANT_DIE (2 << 11)
|
||||||
#define AIF_LONG_RANGE_FIRE (2 << 12)
|
#define AIF_LONG_RANGE_FIRE (2 << 12)
|
||||||
#define AIF_MOVES_TO_LEADER (2 << 13)
|
#define AIF_MOVES_TO_LEADER (2 << 13)
|
||||||
|
#define AIF_EVADE (2 << 14)
|
||||||
|
|
||||||
/* player abilities */
|
/* player abilities */
|
||||||
#define BOOST_RECHARGE_TIME (FPS * 7)
|
#define BOOST_RECHARGE_TIME (FPS * 7)
|
||||||
|
|
|
@ -119,6 +119,9 @@ struct Entity {
|
||||||
int thinkTime;
|
int thinkTime;
|
||||||
int aiActionTime;
|
int aiActionTime;
|
||||||
int aiAggression;
|
int aiAggression;
|
||||||
|
int aiDamagePerSec;
|
||||||
|
int aiDamageTimer;
|
||||||
|
int aiEvadeTimer;
|
||||||
int separationRadius;
|
int separationRadius;
|
||||||
Weapon guns[MAX_FIGHTER_GUNS];
|
Weapon guns[MAX_FIGHTER_GUNS];
|
||||||
int missiles;
|
int missiles;
|
||||||
|
|
Loading…
Reference in New Issue