From 75327aa3f8e087c3d0b5b71d4ec2ff215fae2c50 Mon Sep 17 00:00:00 2001 From: Julie Marchant Date: Sat, 22 Jun 2019 08:34:57 -0400 Subject: [PATCH] Allow aliens to attack "less desirable" targets if they can't find a good one. The way it previously was, in particular, Sid 100% refused to attack fighting vessels and Phoebe and Ursula 100% refused to attack non-fighting vessels. This was most notable with the Urusor mission, where Sid would just become completely idle after disabling the last non-combat vessel and would often just drift off into the distance as a result (especially annoying in Classic difficulty as this could make it very difficult to find the remaining enemies). So now, instead these targets are treated as "undesirables", which normally will be avoided but will be accepted after 30 frames. This stops allies from idling around forever. This rule has also been applied to a rule that didn't allow targeting enemies beyond a particular distance. I'm keeping it in Classic difficulty for now, but might add an exception later. --- src/alien.c | 22 ++++++++++++++++++---- src/defs.h | 2 ++ src/structs.h | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/alien.c b/src/alien.c index 96ce245..098c8d6 100644 --- a/src/alien.c +++ b/src/alien.c @@ -869,6 +869,7 @@ void aliens_init() aliens[i].active = 0; aliens[i].shield = -1; aliens[i].flags = 0; + aliens[i].badTargetCount = 0; } switch (game.area) @@ -1651,12 +1652,14 @@ void alien_searchForTarget(Object *alien) { int i; Object *targetEnemy; + int badTarget = 0; if (alien->flags & FL_WEAPCO) { if (CHANCE(1 / 10.)) { alien->target = &player; + alien->badTargetCount = 0; return; } } @@ -1668,8 +1671,11 @@ void alien_searchForTarget(Object *alien) // return fire. This will save him from messing about (unless we're on the last mission) if ((alien->classDef == CD_SID) && (game.area != MISN_EARTH)) { - if ((targetEnemy->flags & FL_DISABLED) || (!(targetEnemy->flags & FL_NOFIRE))) + if (targetEnemy->flags & FL_DISABLED) return; + + if (!(targetEnemy->flags & FL_NOFIRE)) + badTarget = 1; } // Tell Phoebe and Ursula not to attack ships that cannot fire or are disabled (unless we're on the last mission) @@ -1683,7 +1689,7 @@ void alien_searchForTarget(Object *alien) if ((targetEnemy->flags & FL_DISABLED) || (targetEnemy->flags & FL_NOFIRE)) - return; + badTarget = 1; } } @@ -1697,12 +1703,20 @@ void alien_searchForTarget(Object *alien) return; if (abs((int)alien->x - (int)alien->target->x) > 550) - return; + badTarget = 1; if (abs((int)alien->y - (int)alien->target->y) > 400) - return; + badTarget = 1; + + if (badTarget) + { + alien->badTargetCount++; + if (alien->badTargetCount < BAD_TARGET_ALLOW_TIME) + return; + } alien->target = targetEnemy; + alien->badTargetCount = 0; } /* diff --git a/src/defs.h b/src/defs.h index aea8c7c..8424b66 100644 --- a/src/defs.h +++ b/src/defs.h @@ -89,6 +89,8 @@ along with this program. If not, see . #define ALIEN_WARP_SPEED MIN(-15, -3 * screen->w / 160) #define ALIEN_WARP_ACCEL (game.difficulty == DIFFICULTY_ORIGINAL ? -15: -0.5) +#define BAD_TARGET_ALLOW_TIME 30 + #define SLAVE_RESCUE_TARGET 250 #define PIXFONT_LINE_HEIGHT 16 diff --git a/src/structs.h b/src/structs.h index 60d0fe5..954d4ea 100644 --- a/src/structs.h +++ b/src/structs.h @@ -45,6 +45,8 @@ typedef struct Object_ { int face; // Either 0 or 1 + int badTargetCount; + struct Object_ *owner; // Who owns this Object int chance[2]; // Chance of using the weapons (out of 1000)