Added ability for enemy fighters to surrender, if AIF_SURRENDERS is set.

This commit is contained in:
Steve 2016-05-22 12:08:19 +01:00
parent d4a99ae80f
commit 41aff3ee3c
5 changed files with 65 additions and 0 deletions

View File

@ -53,6 +53,8 @@ static void wander(void);
static void doWander(void); static void doWander(void);
static int selectWeaponForTarget(Entity *e); static int selectWeaponForTarget(Entity *e);
static void deployMine(void); static void deployMine(void);
static int isSurrendering(void);
static void doSurrender(void);
void doAI(void) void doAI(void)
{ {
@ -103,6 +105,11 @@ void doAI(void)
return; return;
} }
if ((self->aiFlags & AIF_SURRENDERS) && (battle.stats[STAT_TIME] % 6 == 0) && isSurrendering())
{
return;
}
if (!(self->aiFlags & AIF_AVOIDS_COMBAT)) if (!(self->aiFlags & AIF_AVOIDS_COMBAT))
{ {
if (self->speed) if (self->speed)
@ -583,6 +590,54 @@ static int isRetreating(void)
return self->flags & EF_RETREATING; return self->flags & EF_RETREATING;
} }
static int isSurrendering(void)
{
float chance;
if (!(self->flags & EF_SURRENDERED))
{
if (self->health < self->maxHealth)
{
chance = self->health;
chance /= self->maxHealth;
chance *= 100;
if (rand() % 100 > chance)
{
self->aiActionTime = FPS * 3;
self->aiFlags |= AIF_AVOIDS_COMBAT;
self->aiFlags &= ~AIF_SURRENDERS;
self->flags |= EF_MUST_DISABLE;
self->flags |= EF_MISSION_TARGET;
self->action = doSurrender;
battle.stats[STAT_ENEMIES_SURRENDERED]++;
runScriptFunction("ENEMY_SURRENDERED %d", battle.stats[STAT_ENEMIES_SURRENDERED]);
addHudMessage(colors.white, _("%s has surrendered"), self->name);
return 1;
}
}
}
return 0;
}
static void doSurrender(void)
{
if (--self->aiActionTime <= 0)
{
self->flags |= EF_SURRENDERED;
nextAction();
}
}
static int nearEnemies(void) static int nearEnemies(void)
{ {
int i, numEnemies, x, y; int i, numEnemies, x, y;

View File

@ -345,6 +345,11 @@ void doFighter(void)
updateCondition(self->name, TT_DESTROY); updateCondition(self->name, TT_DESTROY);
updateCondition(self->groupName, TT_DESTROY); updateCondition(self->groupName, TT_DESTROY);
if (self->flags & EF_SURRENDERED)
{
updateCondition("SURRENDERED", TT_DESTROY);
}
} }
} }
} }

View File

@ -109,6 +109,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define EF_NO_THREAT (2 << 23) #define EF_NO_THREAT (2 << 23)
#define EF_DROPS_ITEMS (2 << 24) #define EF_DROPS_ITEMS (2 << 24)
#define EF_COMMON_FIGHTER (2 << 25) #define EF_COMMON_FIGHTER (2 << 25)
#define EF_SURRENDERED (2 << 26)
#define AIF_NONE 0 #define AIF_NONE 0
#define AIF_FOLLOWS_PLAYER (2 << 0) #define AIF_FOLLOWS_PLAYER (2 << 0)
@ -132,6 +133,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define AIF_ASSASSIN (2 << 18) #define AIF_ASSASSIN (2 << 18)
#define AIF_SUSPICIOUS (2 << 19) #define AIF_SUSPICIOUS (2 << 19)
#define AIF_ZAK_SUSPICIOUS (2 << 20) #define AIF_ZAK_SUSPICIOUS (2 << 20)
#define AIF_SURRENDERS (2 << 21)
/* player abilities */ /* player abilities */
#define BOOST_RECHARGE_TIME (FPS * 7) #define BOOST_RECHARGE_TIME (FPS * 7)
@ -376,6 +378,7 @@ enum
STAT_CAPITAL_SHIPS_DESTROYED, STAT_CAPITAL_SHIPS_DESTROYED,
STAT_CAPITAL_SHIPS_LOST, STAT_CAPITAL_SHIPS_LOST,
STAT_MINES_DESTROYED, STAT_MINES_DESTROYED,
STAT_ENEMIES_SURRENDERED,
/* add stats before here, so as not to mess up the stats screen */ /* add stats before here, so as not to mess up the stats screen */
STAT_TIME, STAT_TIME,
STAT_MAX STAT_MAX

View File

@ -70,6 +70,7 @@ void initStats(void)
statDescription[STAT_CAPITAL_SHIPS_DESTROYED] = _("Capital Ships Destroyed"); statDescription[STAT_CAPITAL_SHIPS_DESTROYED] = _("Capital Ships Destroyed");
statDescription[STAT_CAPITAL_SHIPS_LOST] = _("Capital Ships Lost"); statDescription[STAT_CAPITAL_SHIPS_LOST] = _("Capital Ships Lost");
statDescription[STAT_MINES_DESTROYED] = _("Mines Destroyed"); statDescription[STAT_MINES_DESTROYED] = _("Mines Destroyed");
statDescription[STAT_ENEMIES_SURRENDERED] = _("Enemies Surrendered");
statDescription[STAT_TIME] = _("Time Played"); statDescription[STAT_TIME] = _("Time Played");
} }

View File

@ -93,6 +93,7 @@ void initLookups(void)
addLookup("AIF_ASSASSIN", AIF_ASSASSIN); addLookup("AIF_ASSASSIN", AIF_ASSASSIN);
addLookup("AIF_SUSPICIOUS", AIF_SUSPICIOUS); addLookup("AIF_SUSPICIOUS", AIF_SUSPICIOUS);
addLookup("AIF_ZAK_SUSPICIOUS", AIF_ZAK_SUSPICIOUS); addLookup("AIF_ZAK_SUSPICIOUS", AIF_ZAK_SUSPICIOUS);
addLookup("AIF_SURRENDERS", AIF_SURRENDERS);
addLookup("DT_ANY", DT_ANY); addLookup("DT_ANY", DT_ANY);
addLookup("DT_NO_SPIN", DT_NO_SPIN); addLookup("DT_NO_SPIN", DT_NO_SPIN);