From 05f58e0971cf48ca4c2f1495576a936d69cc36c2 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 10 Dec 2015 12:40:23 +0000 Subject: [PATCH] Added SECONDARY_TARGET flag. --- data/capitalShips/corvette.json | 16 ++++++++-------- src/battle/ai.c | 12 +++++++++++- src/defs.h | 1 + src/system/lookup.c | 1 + 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/data/capitalShips/corvette.json b/data/capitalShips/corvette.json index 0913f79..00f533d 100644 --- a/data/capitalShips/corvette.json +++ b/data/capitalShips/corvette.json @@ -100,7 +100,7 @@ "y" : -250, "reloadTime" : 40, "type" : "BT_ROCKET", - "flags" : "EF_TAKES_DAMAGE+EF_STATIC", + "flags" : "EF_TAKES_DAMAGE+EF_STATIC+EF_SECONDARY_TARGET", "aiFlags" : "AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" }, { @@ -110,7 +110,7 @@ "y" : -250, "reloadTime" : 40, "type" : "BT_ROCKET", - "flags" : "EF_TAKES_DAMAGE+EF_STATIC", + "flags" : "EF_TAKES_DAMAGE+EF_STATIC+EF_SECONDARY_TARGET", "aiFlags" : "AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" }, { @@ -120,7 +120,7 @@ "y" : 20, "reloadTime" : 10, "type" : "BT_PLASMA", - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_SECONDARY_TARGET", "aiFlags" : "AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" }, { @@ -130,7 +130,7 @@ "y" : 100, "reloadTime" : 10, "type" : "BT_PLASMA", - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_SECONDARY_TARGET", "aiFlags" : "AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" }, { @@ -140,7 +140,7 @@ "y" : 180, "reloadTime" : 10, "type" : "BT_PLASMA", - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_SECONDARY_TARGET", "aiFlags" : "AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" }, { @@ -150,7 +150,7 @@ "y" : 20, "reloadTime" : 10, "type" : "BT_PLASMA", - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_SECONDARY_TARGET", "aiFlags" : "AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" }, { @@ -160,7 +160,7 @@ "y" : 100, "reloadTime" : 10, "type" : "BT_PLASMA", - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_SECONDARY_TARGET", "aiFlags" : "AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" }, { @@ -170,7 +170,7 @@ "y" : 180, "reloadTime" : 10, "type" : "BT_PLASMA", - "flags" : "EF_TAKES_DAMAGE", + "flags" : "EF_TAKES_DAMAGE+EF_SECONDARY_TARGET", "aiFlags" : "AIF_AGGRESSIVE+AIF_LONG_RANGE_FIRE" } ] diff --git a/src/battle/ai.c b/src/battle/ai.c index 0ff263a..76feb9c 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -255,6 +255,16 @@ static void huntAndAttackTarget(void) nextAction(); } +static int attackSecondaryTarget(Entity *e) +{ + if (self->target->aiFlags & AIF_AVOIDS_COMBAT || self->target->flags & EF_SECONDARY_TARGET) + { + return rand() % 4 == 0; + } + + return 1; +} + static void findTarget(void) { int i; @@ -275,7 +285,7 @@ static void findTarget(void) if (dist < closest) { - if (!self->target || ((self->target->aiFlags & AIF_AVOIDS_COMBAT) == 0) || ((self->target->aiFlags & AIF_AVOIDS_COMBAT) && rand() % 10) == 0) + if (!self->target || attackSecondaryTarget(e)) { self->target = e; closest = dist; diff --git a/src/defs.h b/src/defs.h index c5aed92..9c846df 100644 --- a/src/defs.h +++ b/src/defs.h @@ -81,6 +81,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define EF_NO_EPIC (2 << 9) #define EF_STATIC (2 << 10) #define EF_TAKES_DAMAGE (2 << 11) +#define EF_SECONDARY_TARGET (2 << 12) #define AIF_NONE 0 #define AIF_FOLLOWS_PLAYER (2 << 0) diff --git a/src/system/lookup.c b/src/system/lookup.c index 45addf0..425e49a 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -45,6 +45,7 @@ void initLookups(void) addLookup("EF_NO_EPIC", EF_NO_EPIC); addLookup("EF_STATIC", EF_STATIC); addLookup("EF_TAKES_DAMAGE", EF_TAKES_DAMAGE); + addLookup("EF_SECONDARY_TARGET", EF_SECONDARY_TARGET); addLookup("AIF_NONE", AIF_NONE); addLookup("AIF_MOVES_TO_PLAYER", AIF_MOVES_TO_PLAYER);