From 915eec5cf05986a4091801e6970f7cb7a63d9bc7 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 14 Apr 2016 16:10:21 +0100 Subject: [PATCH] Allow shadow mines to hunt player, or wander around if not near them. --- src/battle/mine.c | 53 +++++++++++++++++++++++++++++++---------------- src/battle/mine.h | 1 + 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/battle/mine.c b/src/battle/mine.c index 0f0f4ff..eae4f98 100644 --- a/src/battle/mine.c +++ b/src/battle/mine.c @@ -128,30 +128,45 @@ static void lookForPlayer(void) { distance = getDistance(self->x, self->y, player->x, player->y); - if (distance < SCREEN_WIDTH) + if (distance < SCREEN_WIDTH * 2) { dx = player->x - self->x; dy = player->y - self->y; - - norm = sqrt(dx * dx + dy * dy); - - dx /= norm; - dy /= norm; - - self->dx = dx * self->speed; - self->dy = dy * self->speed; - - if (distance <= TRIGGER_RANGE) + } + else + { + if (--self->aiActionTime > 0) { - self->systemPower--; - - if (self->systemPower <= 0) - { - self->health = 0; - } - return; } + + dx = rand() % 1000; + dx -= rand() % 1000; + + dy = rand() % 1000; + dy -= rand() % 1000; + + self->aiActionTime = FPS * (5 + (rand() % 15)); + } + + norm = sqrt(dx * dx + dy * dy); + + dx /= norm; + dy /= norm; + + self->dx = dx * self->speed; + self->dy = dy * self->speed; + + if (distance <= TRIGGER_RANGE) + { + self->systemPower--; + + if (self->systemPower <= 0) + { + self->health = 0; + } + + return; } } @@ -174,6 +189,8 @@ static void die(void) self->alive = ALIVE_DEAD; updateObjective(self->name, TT_DESTROY); + + runScriptFunction("MINES_DESTROYED %d", battle.stats[STAT_MINES_DESTROYED]); } static void doSplashDamage(void) diff --git a/src/battle/mine.h b/src/battle/mine.h index ea4c02b..b83ba95 100644 --- a/src/battle/mine.h +++ b/src/battle/mine.h @@ -32,6 +32,7 @@ extern void addMineExplosion(void); extern void damageFighter(Entity *e, int amount, long flags); extern void playBattleSound(int id, int x, int y); extern void updateObjective(char *name, int type); +extern void runScriptFunction(const char *format, ...); extern Battle battle; extern Entity *player;