diff --git a/common.mk b/common.mk index 1c386c9..0eaeff2 100644 --- a/common.mk +++ b/common.mk @@ -28,12 +28,12 @@ OBJS += galacticMap.o game.o grid.o OBJS += hud.o OBJS += init.o input.o io.o items.o OBJS += load.o lookup.o -OBJS += main.o mission.o missionInfo.o +OBJS += main.o messageBox.o mission.o missionInfo.o OBJS += objectives.o options.o OBJS += player.o OBJS += radar.o rope.o -OBJS += save.o sound.o starfield.o starSystems.o stats.o -OBJS += testMission.o textures.o text.o title.o transition.o triggers.o +OBJS += save.o script.o sound.o starfield.o starSystems.o stats.o +OBJS += testMission.o textures.o text.o title.o transition.o OBJS += util.o OBJS += waypoints.o widgets.o diff --git a/src/battle/battle.c b/src/battle/battle.c index 6a33ecf..1c9aade 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -45,7 +45,6 @@ void initBattle(void) battle.entityTail = &battle.entityHead; battle.effectTail = &battle.effectHead; battle.objectiveTail = &battle.objectiveHead; - battle.triggerTail = &battle.triggerHead; app.delegate.logic = &logic; app.delegate.draw = &draw; @@ -61,6 +60,8 @@ void initBattle(void) initRadar(); + initMessageBox(); + initMissionInfo(); resetWaypoints(); @@ -133,16 +134,23 @@ static void doBattle(void) doPlayer(); - if (battle.status != MS_IN_PROGRESS) + doMessageBox(); + + if (battle.status == MS_IN_PROGRESS) + { + doScript(); + } + else { battle.missionFinishedTimer--; } - battle.stats[STAT_TIME]++; if (battle.stats[STAT_TIME] % FPS == 0) { - checkTrigger("TIME", TRIGGER_TIME); + runScriptFunction("TIME %d", battle.stats[STAT_TIME] / 60); } + + battle.stats[STAT_TIME]++; } static void draw(void) @@ -169,6 +177,8 @@ static void draw(void) drawHud(); + drawMessageBox(); + drawMissionInfo(); switch (show) @@ -265,8 +275,6 @@ static void continueGame(void) destroyBattle(); - resetHud(); - initGalacticMap(); } @@ -290,8 +298,6 @@ static void retry(void) destroyBattle(); - resetHud(); - initBattle(); loadMission(game.currentMission->filename); @@ -303,8 +309,6 @@ static void quitBattle(void) destroyBattle(); - resetHud(); - initGalacticMap(); } @@ -333,7 +337,6 @@ void destroyBattle(void) Bullet *b; Effect *e; Objective *o; - Trigger *t; while (battle.entityHead.next) { @@ -367,13 +370,13 @@ void destroyBattle(void) } battle.objectiveTail = &battle.objectiveHead; - while (battle.triggerHead.next) - { - t = battle.triggerHead.next; - battle.triggerHead.next = t->next; - free(t); - } - battle.triggerTail = &battle.triggerHead; + cJSON_Delete(battle.missionJSON); + + resetHud(); + + resetMessageBox(); + + destroyScript(); destroyGrid(); } diff --git a/src/battle/battle.h b/src/battle/battle.h index 25ac097..68415ac 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../defs.h" #include "../structs.h" +#include "../json/cJSON.h" #define SHOW_BATTLE 0 #define SHOW_MENU 1 @@ -61,12 +62,18 @@ extern void scrollBackground(float x, float y); extern void initOptions(void (*returnFromOptions)(void)); extern void drawOptions(void); extern void playSound(int id); -extern void checkTrigger(char *name, int type); extern void resetWaypoints(void); extern void doPlayerSelect(void); extern void destroyGrid(void); extern void completeMission(void); extern void initEffects(void); +extern void doScript(void); +extern void destroyScript(void); +extern void runScriptFunction(char *format, ...); +extern void initMessageBox(void); +extern void doMessageBox(void); +extern void drawMessageBox(void); +extern void resetMessageBox(void); extern App app; extern Battle battle; diff --git a/src/battle/fighters.c b/src/battle/fighters.c index b889bc9..4571586 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -259,8 +259,6 @@ void doFighter(void) updateObjective(self->name, TT_ESCAPED); updateCondition(self->name, TT_ESCAPED); - - checkTrigger("ESCAPE", TRIGGER_ESCAPES); } if (self->alive == ALIVE_DEAD) @@ -295,7 +293,7 @@ void doFighter(void) addHudMessage(colors.red, "Ally has been killed"); } - checkTrigger("ALLIES_KILLED", TRIGGER_LOSSES); + runScriptFunction("ALLIES_KILLED %d", battle.stats[STAT_ALLIES_KILLED]); } } } @@ -304,8 +302,6 @@ void doFighter(void) adjustObjectiveTargetValue(self->name, TT_ESCAPED, -1); updateCondition(self->name, TT_DESTROY); - - checkTrigger(self->name, TRIGGER_KILLS); } } } diff --git a/src/battle/fighters.h b/src/battle/fighters.h index 58cc1a7..d39f494 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -38,7 +38,6 @@ extern void updateObjective(char *name, int type); extern void updateCondition(char *name, int type); extern Entity *getFighterDef(char *name); extern void addHudMessage(SDL_Color c, char *format, ...); -extern void checkTrigger(char *name, int type); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern Entity *spawnEntity(void); extern void adjustObjectiveTargetValue(char *name, int type, int amount); @@ -49,6 +48,7 @@ extern long flagsToLong(char *flags); extern void addShieldSplinterEffect(Entity *ent); extern void completeMission(void); extern void drawShieldHitEffect(Entity *e); +extern void runScriptFunction(char *format, ...); extern App app; extern Battle battle; diff --git a/src/battle/items.c b/src/battle/items.c index 157554d..a5a3933 100644 --- a/src/battle/items.c +++ b/src/battle/items.c @@ -110,8 +110,6 @@ static void action(void) playBattleSound(SND_GET_ITEM, self->x, self->y); updateObjective(self->name, TT_ITEM); - - checkTrigger(self->name, TRIGGER_ITEM); if (e == player) { diff --git a/src/battle/items.h b/src/battle/items.h index f30437e..91df009 100644 --- a/src/battle/items.h +++ b/src/battle/items.h @@ -32,7 +32,6 @@ extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int extern void playBattleSound(int id, int x, int y); extern void addHudMessage(SDL_Color c, char *format, ...); extern void updateObjective(char *name, int type); -extern void checkTrigger(char *name, int type); extern Battle battle; extern Entity *self; diff --git a/src/battle/messageBox.c b/src/battle/messageBox.c new file mode 100644 index 0000000..90a08ce --- /dev/null +++ b/src/battle/messageBox.c @@ -0,0 +1,105 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "messageBox.h" + +static MessageBox head; +static MessageBox *tail; + +void initMessageBox(void) +{ + memset(&head, 0, sizeof(MessageBox)); + tail = &head; +} + +void addMessageBox(int time, char *title, char *body) +{ + MessageBox *msg = malloc(sizeof(MessageBox)); + memset(msg, 0, sizeof(MessageBox)); + tail->next = msg; + tail = msg; + + STRNCPY(msg->title, title, MAX_NAME_LENGTH); + STRNCPY(msg->body, body, MAX_DESCRIPTION_LENGTH); + msg->time = time * FPS; +} + +void doMessageBox(void) +{ + MessageBox *msg, *prev; + + msg = head.next; + prev = &head; + + if (msg) + { + if (--msg->time <= -FPS) + { + prev->next = msg->next; + free(msg); + msg = prev; + } + + prev = msg; + } +} + +void drawMessageBox(void) +{ + MessageBox *msg = head.next; + SDL_Rect r; + + if (msg && msg->time > 0) + { + r.y = 50; + r.w = 650; + r.h = 110; + r.x = (SCREEN_WIDTH - r.w) / 2; + + SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); + SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); + SDL_RenderFillRect(app.renderer, &r); + SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 128); + SDL_RenderDrawRect(app.renderer, &r); + SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); + + drawText(r.x + 10, r.y + 5, 18, TA_LEFT, colors.cyan, msg->title); + + limitTextWidth(600); + + drawText(r.x + 10, r.y + 30, 18, TA_LEFT, colors.white, msg->body); + + limitTextWidth(0); + } +} + +void resetMessageBox(void) +{ + MessageBox *messageBox; + + while (head.next) + { + messageBox = head.next; + head.next = messageBox->next; + free(messageBox); + } + + tail = &head; +} diff --git a/src/battle/messageBox.h b/src/battle/messageBox.h new file mode 100644 index 0000000..c8066e2 --- /dev/null +++ b/src/battle/messageBox.h @@ -0,0 +1,30 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "SDL2/SDL.h" + +#include "../defs.h" +#include "../structs.h" + +extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); +extern void limitTextWidth(int width); + +extern App app; +extern Colors colors; diff --git a/src/battle/script.c b/src/battle/script.c new file mode 100644 index 0000000..73ac040 --- /dev/null +++ b/src/battle/script.c @@ -0,0 +1,178 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "script.h" + +static void executeNextLine(ScriptRunner *runner); + +static cJSON *scriptJSON; +static ScriptRunner head; +static ScriptRunner *tail; +static char funcNameBuffer[MAX_NAME_LENGTH]; + +void initScript(cJSON *scriptNode) +{ + memset(&head, 0, sizeof(ScriptRunner)); + tail = &head; + + scriptJSON = scriptNode; +} + +void doScript(void) +{ + ScriptRunner *runner, *prev; + + prev = &head; + + for (runner = head.next ; runner != NULL ; runner = runner->next) + { + runner->delay = MAX(0, runner->delay - 1); + + if (!runner->delay) + { + executeNextLine(runner); + + if (!runner->line) + { + if (runner == tail) + { + tail = prev; + } + + prev->next = runner->next; + free(runner); + runner = prev; + } + } + + prev = runner; + } +} + +void runScriptFunction(const char *format, ...) +{ + ScriptRunner *scriptRunner; + cJSON *function; + char *functionName; + va_list args; + + memset(&funcNameBuffer, '\0', sizeof(funcNameBuffer)); + + va_start(args, format); + vsprintf(funcNameBuffer, format, args); + va_end(args); + + function = scriptJSON->child; + + while (function) + { + functionName = cJSON_GetObjectItem(function, "function")->valuestring; + + if (strcmp(functionName, funcNameBuffer) == 0) + { + scriptRunner = malloc(sizeof(ScriptRunner)); + memset(scriptRunner, 0, sizeof(ScriptRunner)); + + scriptRunner->line = cJSON_GetObjectItem(function, "lines")->child; + + tail->next = scriptRunner; + tail = scriptRunner; + + printf("Running script '%s'\n", funcNameBuffer); + } + + function = function->next; + } +} + +static void executeNextLine(ScriptRunner *runner) +{ + char *line; + char command[24]; + char strParam[2][256]; + int intParam[2]; + + line = runner->line->valuestring; + + sscanf(line, "%s", command); + + if (strcmp(command, "ACTIVATE_ENTITY") == 0) + { + sscanf(line, "%*s %[^\n]", strParam[0]); + activateEntities(strParam[0]); + } + else if (strcmp(command, "ACTIVATE_OBJECTIVE") == 0) + { + sscanf(line, "%*s %d", &intParam[0]); + activateObjective(intParam[0]); + } + else if (strcmp(command, "MSG_BOX") == 0) + { + sscanf(line, "%*s %d %[^;]%*c%[^\n]", &intParam[0], strParam[0], strParam[1]); + addMessageBox(intParam[0], strParam[0], strParam[1]); + } + else if (strcmp(command, "WAIT") == 0) + { + sscanf(line, "%*s %d", &intParam[0]); + runner->delay = intParam[0] * FPS; + } + else if (strcmp(command, "COMPLETE_MISSION") == 0) + { + addHudMessage(colors.green, "Mission Complete!"); + completeMission(); + } + else if (strcmp(command, "FAIL_MISSION") == 0) + { + addHudMessage(colors.red, "Mission Failed!"); + failMission(); + } + else if (strcmp(command, "RETREAT_ALLIES") == 0) + { + battle.epic = 0; + retreatAllies(); + } + else if (strcmp(command, "RETREAT_ENEMIES") == 0) + { + battle.epic = 0; + retreatEnemies(); + } + else + { + printf("ERROR: Unrecognised script command '%s'\n", command); + printf("ERROR: Offending line: '%s'\n", line); + exit(1); + } + + runner->line = runner->line->next; +} + +void destroyScript(void) +{ + ScriptRunner *scriptRunner; + + while (head.next) + { + scriptRunner = head.next; + head.next = scriptRunner->next; + free(scriptRunner); + } + + tail = &head; +} diff --git a/src/battle/triggers.h b/src/battle/script.h similarity index 89% rename from src/battle/triggers.h rename to src/battle/script.h index f16d908..945b5b5 100644 --- a/src/battle/triggers.h +++ b/src/battle/script.h @@ -22,14 +22,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../defs.h" #include "../structs.h" +#include "../json/cJSON.h" extern void completeMission(void); extern void failMission(void); +extern void retreatEnemies(void); +extern void retreatAllies(void); extern void addHudMessage(SDL_Color c, char *format, ...); +extern void addMessageBox(int time, char *title, char *format, ...); extern void activateEntities(char *name); extern void activateObjective(int num); -extern void activateEntityGroup(char *groupName); -extern void retreatAllies(void); extern Battle battle; extern Colors colors; diff --git a/src/battle/triggers.c b/src/battle/triggers.c deleted file mode 100644 index 1e54d0a..0000000 --- a/src/battle/triggers.c +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright (C) 2015 Parallel Realities - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#include "triggers.h" - -static int conditionMet(Trigger *trigger); -static void fireTrigger(Trigger *trigger); - -void checkTrigger(char *name, int type) -{ - Trigger *trigger; - - for (trigger = battle.triggerHead.next ; trigger != NULL ; trigger = trigger->next) - { - if (trigger->type == type && strcmp(trigger->targetName, name) == 0 && conditionMet(trigger)) - { - fireTrigger(trigger); - } - } -} - -static int conditionMet(Trigger *trigger) -{ - switch (trigger->type) - { - case TRIGGER_TIME: - return trigger->targetValue == battle.stats[STAT_TIME] / FPS; - - case TRIGGER_KILLS: - return trigger->targetValue == battle.stats[STAT_ENEMIES_KILLED]; - - case TRIGGER_LOSSES: - return trigger->targetValue == battle.stats[STAT_ALLIES_KILLED]; - - case TRIGGER_WAYPOINT: - return 1; - - case TRIGGER_ESCAPES: - return trigger->targetValue == battle.stats[STAT_ENEMIES_ESCAPED]; - } - - return 0; -} - -static void fireTrigger(Trigger *trigger) -{ - switch (trigger->action) - { - case TA_COMPLETE_MISSION: - addHudMessage(colors.green, "Mission Complete!"); - completeMission(); - break; - - case TA_FAIL_MISSION: - addHudMessage(colors.red, "Mission Failed!"); - failMission(); - break; - - case TA_ACTIVE_ENTITY: - activateEntities(trigger->actionValue); - break; - - case TA_ACTIVE_ENTITY_GROUP: - activateEntityGroup(trigger->actionValue); - break; - - case TA_ACTIVE_OBJECTIVE: - activateObjective(atoi(trigger->actionValue)); - break; - - case TA_RETREAT_ALLIES: - battle.epic = 0; - addHudMessage(colors.red, "Mission Aborted! Retreat!"); - retreatAllies(); - break; - } -} diff --git a/src/battle/waypoints.c b/src/battle/waypoints.c index 56423eb..ad2a34d 100644 --- a/src/battle/waypoints.c +++ b/src/battle/waypoints.c @@ -63,7 +63,7 @@ static void think(void) updateObjective("Waypoint", TT_WAYPOINT); - checkTrigger(self->name, TRIGGER_WAYPOINT); + runScriptFunction(self->name); activateNextWaypoint(self->id); } diff --git a/src/battle/waypoints.h b/src/battle/waypoints.h index 6a14ea9..4dc3b4b 100644 --- a/src/battle/waypoints.h +++ b/src/battle/waypoints.h @@ -28,7 +28,7 @@ extern int getDistance(int x1, int y1, int x2, int y2); extern void addHudMessage(SDL_Color c, char *format, ...); extern Entity *spawnEntity(void); extern void updateObjective(char *name, int type); -extern void checkTrigger(char *name, int type); +extern void runScriptFunction(char *format, ...); extern Battle battle; extern Colors colors; diff --git a/src/defs.h b/src/defs.h index 1ceaff2..012f0c2 100644 --- a/src/defs.h +++ b/src/defs.h @@ -190,26 +190,6 @@ enum TT_ITEM }; -enum -{ - TRIGGER_TIME, - TRIGGER_KILLS, - TRIGGER_LOSSES, - TRIGGER_WAYPOINT, - TRIGGER_ESCAPES, - TRIGGER_ITEM -}; - -enum -{ - TA_COMPLETE_MISSION, - TA_FAIL_MISSION, - TA_ACTIVE_ENTITY, - TA_ACTIVE_ENTITY_GROUP, - TA_ACTIVE_OBJECTIVE, - TA_RETREAT_ALLIES -}; - enum { MS_START, diff --git a/src/draw/text.c b/src/draw/text.c index 7ca8e72..9823204 100644 --- a/src/draw/text.c +++ b/src/draw/text.c @@ -26,7 +26,7 @@ static void cacheText(unsigned long hash, SDL_Texture *t); static unsigned long hashcode(const char *str, int size); static void drawTextNormal(int x, int y, int size, int align, SDL_Color c, char *text); static void drawTextSplit(int x, int y, int size, int align, SDL_Color c, char *text); -void textSize(char *text, int size, int *w, int *h); +static void textSize(char *text, int size, int *w, int *h); static char drawTextBuffer[MAX_DESCRIPTION_LENGTH]; static TTF_Font *font[MAX_FONTS]; @@ -142,7 +142,7 @@ static void drawTextSplit(int x, int y, int size, int align, SDL_Color c, char * drawTextNormal(x, y, size, align, c, drawTextBuffer); } -void textSize(char *text, int size, int *w, int *h) +static void textSize(char *text, int size, int *w, int *h) { if (!font[size]) { diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 82cee44..0b46068 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "mission.h" static void loadObjectives(cJSON *node); -static void loadTriggers(cJSON *node); static void loadPlayer(cJSON *node); static void loadFighters(cJSON *node); static void loadEntities(cJSON *node); @@ -51,8 +50,6 @@ void loadMission(char *filename) battle.planet.y = ((200 + rand() % 100) / 10) * GRID_CELL_HEIGHT; loadObjectives(cJSON_GetObjectItem(root, "objectives")); - - loadTriggers(cJSON_GetObjectItem(root, "triggers")); loadPlayer(cJSON_GetObjectItem(root, "player")); @@ -69,7 +66,8 @@ void loadMission(char *filename) loadEpicData(cJSON_GetObjectItem(root, "epic")); } - cJSON_Delete(root); + initScript(cJSON_GetObjectItem(root, "script")); + free(text); srand(time(NULL)); @@ -164,36 +162,6 @@ static void loadObjectives(cJSON *node) } } -static void loadTriggers(cJSON *node) -{ - Trigger *t; - - if (node) - { - node = node->child; - - while (node) - { - t = malloc(sizeof(Trigger)); - memset(t, 0, sizeof(Trigger)); - battle.triggerTail->next = t; - battle.triggerTail = t; - - t->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring); - STRNCPY(t->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH); - t->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint; - t->action = lookup(cJSON_GetObjectItem(node, "action")->valuestring); - - if (cJSON_GetObjectItem(node, "actionValue")) - { - STRNCPY(t->actionValue, cJSON_GetObjectItem(node, "actionValue")->valuestring, MAX_NAME_LENGTH); - } - - node = node->next; - } - } -} - static void loadPlayer(cJSON *node) { char *type; diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index dd627a1..43c1976 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -42,6 +42,7 @@ extern Entity *spawnExtractionPoint(void); extern Entity *spawnItem(char *type); extern void failIncompleteObjectives(void); extern void retreatEnemies(void); +extern void initScript(cJSON *missionJSON); extern Battle battle; extern Entity *player; diff --git a/src/galaxy/stats.h b/src/galaxy/stats.h index c48209c..e277f5c 100644 --- a/src/galaxy/stats.h +++ b/src/galaxy/stats.h @@ -27,9 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void drawWidgets(char *groupName); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); -extern void blit(SDL_Texture *texture, int x, int y, int centered); -extern SDL_Texture *getTexture(char *filename); -extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); extern Widget *getWidget(const char *name, const char *group); extern App app; diff --git a/src/structs.h b/src/structs.h index f199d14..eb0b694 100644 --- a/src/structs.h +++ b/src/structs.h @@ -18,7 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -struct SDL_Texture; typedef struct Texture Texture; typedef struct Lookup Lookup; typedef struct Weapon Weapon; @@ -32,8 +31,9 @@ typedef struct Mission Mission; typedef struct Pulse Pulse; typedef struct Widget Widget; typedef struct HudMessage HudMessage; -typedef struct Trigger Trigger; +typedef struct MessageBox MessageBox; typedef struct GridCell GridCell; +typedef struct ScriptRunner ScriptRunner; typedef struct { float x; @@ -43,7 +43,7 @@ typedef struct { struct Texture { char name[MAX_DESCRIPTION_LENGTH]; long hash; - struct SDL_Texture *texture; + SDL_Texture *texture; Texture *next; }; @@ -115,7 +115,7 @@ struct Entity { Entity *owner; void (*action)(void); void (*die)(void); - struct SDL_Texture *texture; + SDL_Texture *texture; Entity *next; }; @@ -189,15 +189,6 @@ struct Challenge { Challenge *next; }; -struct Trigger { - int type; - char targetName[MAX_NAME_LENGTH]; - int targetValue; - int action; - char actionValue[MAX_NAME_LENGTH]; - Trigger *next; -}; - struct Mission { char name[MAX_NAME_LENGTH]; char description[MAX_DESCRIPTION_LENGTH]; @@ -256,11 +247,17 @@ typedef struct { Bullet bulletHead, *bulletTail; Effect effectHead, *effectTail; Objective objectiveHead, *objectiveTail; - Trigger triggerHead, *triggerTail; + struct cJSON *missionJSON; unsigned int stats[STAT_MAX]; GridCell grid[GRID_SIZE][GRID_SIZE]; } Battle; +struct ScriptRunner { + struct cJSON *line; + long delay; + ScriptRunner *next; +}; + typedef struct { StarSystem starSystemHead, *starSystemTail; Mission *currentMission; @@ -294,6 +291,13 @@ struct HudMessage { HudMessage *next; }; +struct MessageBox { + char title[MAX_NAME_LENGTH]; + char body[MAX_DESCRIPTION_LENGTH]; + int time; + MessageBox *next; +}; + typedef struct { int x; int y; diff --git a/src/system/lookup.c b/src/system/lookup.c index d58841d..546b103 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -125,18 +125,6 @@ void initLookups(void) addLookup("STAT_ITEMS_COLLECTED", STAT_ITEMS_COLLECTED); addLookup("STAT_EPIC_KILL_STREAK", STAT_EPIC_KILL_STREAK); addLookup("STAT_TIME", STAT_TIME); - - addLookup("TRIGGER_TIME", TRIGGER_TIME); - addLookup("TRIGGER_KILLS", TRIGGER_KILLS); - addLookup("TRIGGER_LOSSES", TRIGGER_LOSSES); - addLookup("TRIGGER_WAYPOINT", TRIGGER_WAYPOINT); - - addLookup("TA_COMPLETE_MISSION", TA_COMPLETE_MISSION); - addLookup("TA_FAIL_MISSION", TA_FAIL_MISSION); - addLookup("TA_ACTIVE_ENTITY", TA_ACTIVE_ENTITY); - addLookup("TA_ACTIVE_OBJECTIVE", TA_ACTIVE_OBJECTIVE); - addLookup("TA_ACTIVE_ENTITY_GROUP", TA_ACTIVE_ENTITY_GROUP); - addLookup("TA_RETREAT_ALLIES", TA_RETREAT_ALLIES); } static void addLookup(char *name, long value)