Challenge #8, defend extraction point. Added flag to allow AI to sometimes ignore extraction point.

This commit is contained in:
Steve 2016-03-06 09:47:44 +00:00
parent e28390a496
commit 922b39c0ea
7 changed files with 78 additions and 6 deletions

54
data/challenges/08.json Normal file
View File

@ -0,0 +1,54 @@
{
"name" : "Defend Extraction Point",
"description" : "Defend Extraction Point",
"background" : "AUTO",
"planet" : "AUTO",
"music" : "AUTO",
"player" : {
"type" : "Leopard",
"side" : "SIDE_ALLIES",
"pilot" : "-",
"squadron" : "-",
"x" : 25,
"y" : 25
},
"challenge" : {
"timeLimit" : 90,
"killLimit" : 12,
"escapeLimit" : 12,
"challenges" : [
{
"type" : "CHALLENGE_PLAYER_KILLS",
"value" : 6
},
{
"type" : "CHALLENGE_PLAYER_KILLS",
"value" : 9
},
{
"type" : "CHALLENGE_PLAYER_KILLS",
"value" : 12
}
]
},
"fighters" : [
{
"groupName" : "Dart",
"types" : "Dart",
"x" : 25,
"y" : 28,
"side" : "SIDE_REBEL",
"scatter" : 5000,
"number" : 12,
"flags" : "+EF_RETREATING",
"aiFlags" : "+AIF_GOAL_EXTRACTION+AIF_UNLIMITED_RANGE+AIF_DEFENSIVE+AIF_COVERS_RETREAT"
}
],
"entities" : [
{
"type" : "ET_EXTRACTION_POINT",
"x" : 25.1,
"y" : 25.1
}
]
}

View File

@ -58,14 +58,18 @@ void doAI(void)
return;
}
if ((self->aiFlags & AIF_DEFENSIVE) && rand() % 25 && nearEnemies())
if ((self->aiFlags & AIF_DEFENSIVE) && rand() % 10 && nearEnemies())
{
return;
}
if ((self->aiFlags & AIF_GOAL_EXTRACTION) && nearExtractionPoint())
{
return;
/* near extraction point, but you might decide to continue to fight, anyway */
if ((self->aiFlags & AIF_COVERS_RETREAT) && rand() % 3)
{
return;
}
}
if ((self->aiFlags & AIF_COLLECTS_ITEMS) && nearItems())
@ -544,7 +548,7 @@ static int nearEnemies(void)
int i, numEnemies;
Entity *e, **candidates;
candidates = getAllEntsWithin(self->x - (self->w / 2) - 500, self->y - (self->h / 2) - 500, 1000, 1000, self);
candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self);
self->target = NULL;
self->targetLocation.x = self->targetLocation.y = 0;
@ -555,9 +559,12 @@ static int nearEnemies(void)
{
if ((e->flags & EF_TAKES_DAMAGE) && e->side != self->side && !(e->flags & EF_DISABLED))
{
self->targetLocation.x += e->x;
self->targetLocation.y += e->y;
numEnemies++;
if (getDistance(e->x, e->y, self->x, self->y) < 1000)
{
self->targetLocation.x += e->x;
self->targetLocation.y += e->y;
numEnemies++;
}
}
}
@ -572,6 +579,7 @@ static int nearEnemies(void)
self->action = fleeEnemies;
self->aiActionTime = FPS * 2;
return 1;
}

View File

@ -107,6 +107,11 @@ static int challengeFinished(void)
return 1;
}
if (game.currentMission->challengeData.escapeLimit > 0 && (battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_ENEMIES_ESCAPED]) >= game.currentMission->challengeData.escapeLimit)
{
return 1;
}
if (game.currentMission->challengeData.waypointLimit > 0 && battle.stats[STAT_WAYPOINTS_VISITED] >= game.currentMission->challengeData.waypointLimit)
{
return 1;

View File

@ -111,6 +111,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define AIF_MOVES_TO_LEADER (2 << 12)
#define AIF_EVADE (2 << 13)
#define AIF_WANDERS (2 << 14)
#define AIF_COVERS_RETREAT (2 << 15)
/* player abilities */
#define BOOST_RECHARGE_TIME (FPS * 7)

View File

@ -79,6 +79,7 @@ Mission *loadMissionMeta(char *filename)
mission->challengeData.timeLimit = getJSONValue(node, "timeLimit", 0) * FPS;
mission->challengeData.killLimit = getJSONValue(node, "killLimit", 0);
mission->challengeData.escapeLimit = getJSONValue(node, "escapeLimit", 0);
mission->challengeData.waypointLimit = getJSONValue(node, "waypointLimit", 0);
mission->challengeData.noMissiles = getJSONValue(node, "noMissiles", 0);
mission->challengeData.noECM = getJSONValue(node, "noECM", 0);

View File

@ -43,6 +43,7 @@ typedef struct Trophy Trophy;
typedef struct {
int debug;
int takeScreenshots;
char *screenshotFolder;
int noAIWeapons;
int showFPS;
int playerImmortal;
@ -247,6 +248,7 @@ typedef struct {
int killLimit;
int lossLimit;
int itemLimit;
int escapeLimit;
int waypointLimit;
int noMissiles;
int noBoost;

View File

@ -76,6 +76,7 @@ void initLookups(void)
addLookup("AIF_LONG_RANGE_FIRE", AIF_LONG_RANGE_FIRE);
addLookup("AIF_MOVES_TO_LEADER", AIF_MOVES_TO_LEADER);
addLookup("AIF_WANDERS", AIF_WANDERS);
addLookup("AIF_COVERS_RETREAT", AIF_COVERS_RETREAT);
addLookup("DT_ANY", DT_ANY);
addLookup("DT_NO_SPIN", DT_NO_SPIN);