From 7e7b8c54546182783196ab9fde1adbf2d4a7e06e Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 20 May 2016 10:51:35 +0100 Subject: [PATCH] Moved max suspicion reaction to scripts in missions. --- .../missions/krasst/01 - infiltration #5.json | 11 +++ .../01 - infiltration #2.json | 12 +++ .../missions/tigris/01 - infiltration #3.json | 12 +++ .../trilliack/99 - infiltration #4.json | 12 +++ src/battle/ai.c | 19 ----- src/battle/ai.h | 4 - src/battle/battle.c | 17 ++++ src/battle/battle.h | 1 + src/battle/hud.h | 1 - src/battle/script.c | 84 +++++++++++++------ src/battle/script.h | 1 + 11 files changed, 123 insertions(+), 51 deletions(-) diff --git a/data/missions/krasst/01 - infiltration #5.json b/data/missions/krasst/01 - infiltration #5.json index 048771b..5ec1fce 100644 --- a/data/missions/krasst/01 - infiltration #5.json +++ b/data/missions/krasst/01 - infiltration #5.json @@ -217,6 +217,17 @@ "ACTIVATE_JUMPGATE 0", "MSG_BOX Hicks;They've shutdown the jumpgate ..." ] + }, + { + "function" : "MAX_SUSPICION_LEVEL", + "lines" : [ + "UPDATE_ENTITY_SIDE SIDE_ALLIES Hicks", + "PANDORAN_MSG_BOX Pandoran;Intruder alert! We have an intruder! All units, target and destroy that fighter!", + "IMPORTANT_MSG_BOX Hicks;Hell! My cover's been blown, they're on to me!", + "ACTIVATE_JUMPGATE 0", + "WAIT_MSG_BOX", + "STOP_SCRIPT" + ] } ] } diff --git a/data/missions/sampi-persei vii/01 - infiltration #2.json b/data/missions/sampi-persei vii/01 - infiltration #2.json index 1a15e87..3433722 100644 --- a/data/missions/sampi-persei vii/01 - infiltration #2.json +++ b/data/missions/sampi-persei vii/01 - infiltration #2.json @@ -171,6 +171,18 @@ "ACTIVATE_JUMPGATE", "RETREAT_ALLIES" ] + }, + { + "function" : "MAX_SUSPICION_LEVEL", + "lines" : [ + "UPDATE_ENTITY_SIDE SIDE_ALLIES Hicks", + "PANDORAN_MSG_BOX Wing Commander;Intruder alert! We have an intruder! All units, target and destroy that fighter!", + "IMPORTANT_MSG_BOX Hicks;Hell! My cover's been blown, they're on to me!", + "ACTIVATE_JUMPGATE 0", + "ACTIVATE_TRESPASSER_SPAWNER", + "WAIT_MSG_BOX", + "STOP_SCRIPT" + ] } ] } diff --git a/data/missions/tigris/01 - infiltration #3.json b/data/missions/tigris/01 - infiltration #3.json index f027e21..5bfc394 100644 --- a/data/missions/tigris/01 - infiltration #3.json +++ b/data/missions/tigris/01 - infiltration #3.json @@ -164,6 +164,18 @@ "ACTIVATE_JUMPGATE", "RETREAT_ALLIES" ] + }, + { + "function" : "MAX_SUSPICION_LEVEL", + "lines" : [ + "UPDATE_ENTITY_SIDE SIDE_ALLIES Hicks", + "PANDORAN_MSG_BOX Wing Commander;Intruder alert! We have an intruder! All units, target and destroy that fighter!", + "IMPORTANT_MSG_BOX Hicks;Hell! My cover's been blown, they're on to me!", + "ACTIVATE_JUMPGATE 0", + "ACTIVATE_TRESPASSER_SPAWNER", + "WAIT_MSG_BOX", + "STOP_SCRIPT" + ] } ] } diff --git a/data/missions/trilliack/99 - infiltration #4.json b/data/missions/trilliack/99 - infiltration #4.json index 4c6a39b..6d4e1b2 100644 --- a/data/missions/trilliack/99 - infiltration #4.json +++ b/data/missions/trilliack/99 - infiltration #4.json @@ -171,6 +171,18 @@ "WAIT 1", "PANDORAN_MSG_BOX Wing Commander;Mission complete. Prepare for extraction." ] + }, + { + "function" : "MAX_SUSPICION_LEVEL", + "lines" : [ + "UPDATE_ENTITY_SIDE SIDE_ALLIES Hicks", + "PANDORAN_MSG_BOX Wing Commander;Intruder alert! We have an intruder! All units, target and destroy that fighter!", + "IMPORTANT_MSG_BOX Hicks;Hell! My cover's been blown, they're on to me!", + "ACTIVATE_JUMPGATE 0", + "ACTIVATE_TRESPASSER_SPAWNER", + "WAIT_MSG_BOX", + "STOP_SCRIPT" + ] } ] } diff --git a/src/battle/ai.c b/src/battle/ai.c index c311f8f..7307366 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -968,12 +968,8 @@ static void wander(void) */ void checkSuspicionLevel(void) { - battle.hasSuspicionLevel = 0; - if (battle.status == MS_IN_PROGRESS && player->side != SIDE_ALLIES) { - battle.hasSuspicionLevel = 1; - battle.suspicionCoolOff = MAX(battle.suspicionCoolOff - 1, 0); /* raise if player is too far away and there are no enemies */ @@ -988,21 +984,6 @@ void checkSuspicionLevel(void) battle.suspicionLevel++; battle.suspicionCoolOff = FPS * 30; } - - if (battle.suspicionLevel >= MAX_SUSPICION_LEVEL) - { - player->side = SIDE_ALLIES; - - addMessageBox(self->name, "Intruder alert! We have an intruder! All units, target and destroy that fighter!", MB_PANDORAN); - - addMessageBox(player->name, _("Hell! My cover's been blown, they're on to me!"), MB_IMPORTANT); - - destroyScript(); - - activateJumpgate(0); - - activateTrespasserSpawner(); - } } } diff --git a/src/battle/ai.h b/src/battle/ai.h index 476a23a..465eb74 100644 --- a/src/battle/ai.h +++ b/src/battle/ai.h @@ -39,10 +39,6 @@ extern void addHudMessage(SDL_Color c, char *format, ...); extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); extern char *getTranslatedString(char *string); extern Entity *spawnMine(int type); -extern void addMessageBox(char *title, char *body, int type); -extern void destroyScript(void); -extern void activateTrespasserSpawner(void); -extern void activateJumpgate(int activate); extern void runScriptFunction(char *format, ...); extern Battle battle; diff --git a/src/battle/battle.c b/src/battle/battle.c index ffb8ecb..81fbf58 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -34,6 +34,7 @@ static void retry(void); static void start(void); static void options(void); static void returnFromOptions(void); +static void checkSuspicionLevel(void); static int show; static float ssx, ssy; @@ -156,6 +157,8 @@ static void doBattle(void) doDebris(); doPlayer(); + + checkSuspicionLevel(); if (player->alive == ALIVE_ALIVE) { @@ -398,6 +401,20 @@ static void postBattle(void) app.saveGame = 1; } +static void checkSuspicionLevel(void) +{ + if (battle.hasSuspicionLevel && battle.suspicionLevel >= MAX_SUSPICION_LEVEL) + { + cancelScript(); + + resetMessageBox(); + + runScriptFunction("MAX_SUSPICION_LEVEL"); + + battle.hasSuspicionLevel = 0; + } +} + void destroyBattle(void) { Entity *ent; diff --git a/src/battle/battle.h b/src/battle/battle.h index 855d871..3515d66 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -87,6 +87,7 @@ extern void runScriptFunction(const char *format, ...); extern void doSpawners(void); extern void doTrophyAlerts(void); extern void drawTrophyAlert(void); +extern void cancelScript(void); extern App app; extern Battle battle; diff --git a/src/battle/hud.h b/src/battle/hud.h index 0b0b032..b67c9b8 100644 --- a/src/battle/hud.h +++ b/src/battle/hud.h @@ -39,6 +39,5 @@ extern int jumpgateEnabled(void); extern App app; extern Battle battle; extern Colors colors; -extern Dev dev; extern Entity *player; extern Game game; diff --git a/src/battle/script.c b/src/battle/script.c index 6383a1d..b6a049b 100644 --- a/src/battle/script.c +++ b/src/battle/script.c @@ -21,10 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "script.h" static void executeNextLine(ScriptRunner *runner); +void destroyScript(void); static cJSON *scriptJSON, *rootJSON; static ScriptRunner head; static ScriptRunner *tail; +static int runScript; void initScript(cJSON *root) { @@ -34,6 +36,8 @@ void initScript(cJSON *root) tail = &head; rootJSON = root; + + runScript = 0; scriptJSON = cJSON_GetObjectItem(root, "script"); @@ -47,6 +51,8 @@ void initScript(cJSON *root) function = function->next; } + + runScript = 1; } } @@ -54,35 +60,38 @@ void doScript(void) { ScriptRunner *runner, *prev; - prev = &head; - - for (runner = head.next ; runner != NULL ; runner = runner->next) + if (runScript) { - runner->delay = MAX(0, runner->delay - 1); + prev = &head; - if (runner->waitForMessageBox) + for (runner = head.next ; runner != NULL ; runner = runner->next) { - runner->waitForMessageBox = showingMessageBoxes(); - } + runner->delay = MAX(0, runner->delay - 1); - if (!runner->delay && !runner->waitForMessageBox) - { - executeNextLine(runner); - - if (!runner->line) + if (runner->waitForMessageBox) { - if (runner == tail) - { - tail = prev; - } - - prev->next = runner->next; - free(runner); - runner = prev; + runner->waitForMessageBox = showingMessageBoxes(); } - } - prev = runner; + if (!runner->delay && !runner->waitForMessageBox) + { + executeNextLine(runner); + + if (!runner->line) + { + if (runner == tail) + { + tail = prev; + } + + prev->next = runner->next; + free(runner); + runner = prev; + } + } + + prev = runner; + } } } @@ -94,7 +103,7 @@ void runScriptFunction(const char *format, ...) char funcNameBuffer[MAX_NAME_LENGTH]; va_list args; - if (scriptJSON) + if (scriptJSON && runScript) { memset(&funcNameBuffer, '\0', sizeof(funcNameBuffer)); @@ -134,7 +143,7 @@ void runScriptTimeFunctions(void) char funcNameBuffer[MAX_NAME_LENGTH]; int intParam; - if (scriptJSON) + if (scriptJSON && runScript) { function = scriptJSON->child; @@ -293,16 +302,37 @@ static void executeNextLine(ScriptRunner *runner) sscanf(line, "%*s %s %[^\n]", strParam[0], strParam[1]); updateEntitySide(strParam[0], strParam[1]); } + else if (strcmp(command, "ACTIVATE_TRESPASSER_SPAWNER") == 0) + { + activateTrespasserSpawner(); + } + else if (strcmp(command, "STOP_SCRIPT") == 0) + { + runScript = 0; + } else { - printf("ERROR: Unrecognised script command '%s'\n", command); - printf("ERROR: Offending line: '%s'\n", line); - exit(1); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "ERROR: Unrecognised script command '%s'\n", command); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "ERROR: Offending line: '%s'\n", line); } runner->line = runner->line->next; } +void cancelScript(void) +{ + ScriptRunner *runner; + + while (head.next) + { + runner = head.next; + head.next = runner->next; + free(runner); + } + + tail = &head; +} + void destroyScript(void) { ScriptRunner *scriptRunner; diff --git a/src/battle/script.h b/src/battle/script.h index 297d8ce..450ad5a 100644 --- a/src/battle/script.h +++ b/src/battle/script.h @@ -41,6 +41,7 @@ extern void completeAllObjectives(void); extern void createChristabelLocation(void); extern void killEntity(char *name); extern void updateEntitySide(char *side, char *entity); +extern void activateTrespasserSpawner(void); extern Battle battle; extern Colors colors;