diff --git a/data/missions/temper/03 - pirate uprising #3.json b/data/missions/temper/03 - pirate uprising #3.json index ef12163..fe48c0f 100644 --- a/data/missions/temper/03 - pirate uprising #3.json +++ b/data/missions/temper/03 - pirate uprising #3.json @@ -31,6 +31,14 @@ "type" : "StaticDart", "side" : "SIDE_PIRATE", "x" : 800, + "y" : 200, + "flags" : "FF_NO_KILL+FF_DISABLE" + }, + { + "name" : "TAF", + "type" : "Ray", + "side" : "SIDE_ALLIES", + "x" : 100, "y" : 200 } ] diff --git a/src/battle/ai.c b/src/battle/ai.c index bb5111b..0d434bf 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -43,12 +43,14 @@ static void boost(void); static void slow(void); static int targetOutOfRange(void); static void moveToPlayer(void); +static int canAttack(Fighter *f); +static int selectWeapon(int type); void doAI(void) { int r; - if (!self->target || targetOutOfRange()) + if (!self->target || targetOutOfRange() || self->target->systemPower <= 0) { findTarget(); @@ -144,9 +146,11 @@ static void findTarget(void) int closest = 2000; int dist = 2000; + self->target = NULL; + 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); 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) { int dir; diff --git a/src/battle/fighters.c b/src/battle/fighters.c index b166cf8..87b1682 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -73,8 +73,6 @@ Fighter *spawnFighter(char *name, int x, int y, int side) randomizeDart(f); } - f->selectedGunType = f->guns[0].type; - f->defaultAction = doAI; f->die = die; diff --git a/src/defs.h b/src/defs.h index cd86c39..c7f77f1 100644 --- a/src/defs.h +++ b/src/defs.h @@ -50,6 +50,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define BF_ENGINE (2 << 0) #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 { TA_LEFT, @@ -145,7 +150,8 @@ enum MS_FAILED }; -enum { +enum +{ WT_BUTTON, WT_SELECT }; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index cb92e6d..5bddf4d 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -142,6 +142,11 @@ static void loadFighters(cJSON *node) f = spawnFighter(type, x, y, side); 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; } diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 3c9f504..ed7391d 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -34,6 +34,7 @@ extern void endSectionTransition(void); extern void playMusic(char *filename); extern void stopMusic(void); extern void initPlayer(void); +extern long flagsToLong(char *flags); extern Battle battle; extern Fighter *player; diff --git a/src/system/lookup.c b/src/system/lookup.c index c79469a..7c48f73 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -30,6 +30,10 @@ void initLookups(void) memset(&head, 0, sizeof(Lookup)); 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_DISABLE", TT_DISABLE);