Added ability to flag fighters and prevent team mates from killing mission targets.

This commit is contained in:
Steve 2015-10-23 22:44:39 +01:00
parent f206f2052b
commit 67d92cedb9
7 changed files with 69 additions and 5 deletions

View File

@ -31,6 +31,14 @@
"type" : "StaticDart", "type" : "StaticDart",
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
"x" : 800, "x" : 800,
"y" : 200,
"flags" : "FF_NO_KILL+FF_DISABLE"
},
{
"name" : "TAF",
"type" : "Ray",
"side" : "SIDE_ALLIES",
"x" : 100,
"y" : 200 "y" : 200
} }
] ]

View File

@ -43,12 +43,14 @@ static void boost(void);
static void slow(void); static void slow(void);
static int targetOutOfRange(void); static int targetOutOfRange(void);
static void moveToPlayer(void); static void moveToPlayer(void);
static int canAttack(Fighter *f);
static int selectWeapon(int type);
void doAI(void) void doAI(void)
{ {
int r; int r;
if (!self->target || targetOutOfRange()) if (!self->target || targetOutOfRange() || self->target->systemPower <= 0)
{ {
findTarget(); findTarget();
@ -144,9 +146,11 @@ static void findTarget(void)
int closest = 2000; int closest = 2000;
int dist = 2000; int dist = 2000;
self->target = NULL;
for (f = battle.fighterHead.next ; f != NULL ; f = f->next) for (f = battle.fighterHead.next ; f != NULL ; f = f->next)
{ {
if (f->side != self->side && f->health > 0) if (f->side != self->side && f->health > 0 && canAttack(f))
{ {
dist = getDistance(self->x, self->y, f->x, f->y); dist = getDistance(self->x, self->y, f->x, f->y);
if (dist < closest) if (dist < closest)
@ -158,6 +162,44 @@ static void findTarget(void)
} }
} }
static int canAttack(Fighter *f)
{
self->selectedGunType = self->guns[0].type;
if (f->flags & FF_DISABLE)
{
if (f->systemPower > 0)
{
return selectWeapon(BT_MAG);
}
return 0;
}
if (f->flags & FF_NO_KILL)
{
return selectWeapon(BT_LASER) || selectWeapon(BT_MAG);
}
return 1;
}
static int selectWeapon(int type)
{
int i;
for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++)
{
if (self->guns[i].type == type)
{
self->selectedGunType = type;
return 1;
}
}
return 0;
}
static void faceTarget(Fighter *f) static void faceTarget(Fighter *f)
{ {
int dir; int dir;

View File

@ -73,8 +73,6 @@ Fighter *spawnFighter(char *name, int x, int y, int side)
randomizeDart(f); randomizeDart(f);
} }
f->selectedGunType = f->guns[0].type;
f->defaultAction = doAI; f->defaultAction = doAI;
f->die = die; f->die = die;

View File

@ -50,6 +50,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define BF_ENGINE (2 << 0) #define BF_ENGINE (2 << 0)
#define BF_SYSTEM_DAMAGE (2 << 1) #define BF_SYSTEM_DAMAGE (2 << 1)
#define FF_NONE 0
#define FF_NO_KILL (2 << 0)
#define FF_DISABLE (2 << 1)
#define FF_IMMORTAL (2 << 2)
enum enum
{ {
TA_LEFT, TA_LEFT,
@ -145,7 +150,8 @@ enum
MS_FAILED MS_FAILED
}; };
enum { enum
{
WT_BUTTON, WT_BUTTON,
WT_SELECT WT_SELECT
}; };

View File

@ -143,6 +143,11 @@ static void loadFighters(cJSON *node)
STRNCPY(f->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH); STRNCPY(f->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
if (cJSON_GetObjectItem(node, "flags"))
{
f->flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring);
}
node = node->next; node = node->next;
} }
} }

View File

@ -34,6 +34,7 @@ extern void endSectionTransition(void);
extern void playMusic(char *filename); extern void playMusic(char *filename);
extern void stopMusic(void); extern void stopMusic(void);
extern void initPlayer(void); extern void initPlayer(void);
extern long flagsToLong(char *flags);
extern Battle battle; extern Battle battle;
extern Fighter *player; extern Fighter *player;

View File

@ -30,6 +30,10 @@ void initLookups(void)
memset(&head, 0, sizeof(Lookup)); memset(&head, 0, sizeof(Lookup));
tail = &head; tail = &head;
addLookup("FF_NO_KILL", FF_NO_KILL);
addLookup("FF_DISABLE", FF_DISABLE);
addLookup("FF_IMMORTAL", FF_IMMORTAL);
addLookup("TT_DESTROY", TT_DESTROY); addLookup("TT_DESTROY", TT_DESTROY);
addLookup("TT_DISABLE", TT_DISABLE); addLookup("TT_DISABLE", TT_DISABLE);