Removed triggers, and replaced with script system. Added message box.
This commit is contained in:
parent
8b669448e8
commit
9de6d6c737
|
@ -28,12 +28,12 @@ OBJS += galacticMap.o game.o grid.o
|
||||||
OBJS += hud.o
|
OBJS += hud.o
|
||||||
OBJS += init.o input.o io.o items.o
|
OBJS += init.o input.o io.o items.o
|
||||||
OBJS += load.o lookup.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 += objectives.o options.o
|
||||||
OBJS += player.o
|
OBJS += player.o
|
||||||
OBJS += radar.o rope.o
|
OBJS += radar.o rope.o
|
||||||
OBJS += save.o sound.o starfield.o starSystems.o stats.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 triggers.o
|
OBJS += testMission.o textures.o text.o title.o transition.o
|
||||||
OBJS += util.o
|
OBJS += util.o
|
||||||
OBJS += waypoints.o widgets.o
|
OBJS += waypoints.o widgets.o
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ void initBattle(void)
|
||||||
battle.entityTail = &battle.entityHead;
|
battle.entityTail = &battle.entityHead;
|
||||||
battle.effectTail = &battle.effectHead;
|
battle.effectTail = &battle.effectHead;
|
||||||
battle.objectiveTail = &battle.objectiveHead;
|
battle.objectiveTail = &battle.objectiveHead;
|
||||||
battle.triggerTail = &battle.triggerHead;
|
|
||||||
|
|
||||||
app.delegate.logic = &logic;
|
app.delegate.logic = &logic;
|
||||||
app.delegate.draw = &draw;
|
app.delegate.draw = &draw;
|
||||||
|
@ -61,6 +60,8 @@ void initBattle(void)
|
||||||
|
|
||||||
initRadar();
|
initRadar();
|
||||||
|
|
||||||
|
initMessageBox();
|
||||||
|
|
||||||
initMissionInfo();
|
initMissionInfo();
|
||||||
|
|
||||||
resetWaypoints();
|
resetWaypoints();
|
||||||
|
@ -133,16 +134,23 @@ static void doBattle(void)
|
||||||
|
|
||||||
doPlayer();
|
doPlayer();
|
||||||
|
|
||||||
if (battle.status != MS_IN_PROGRESS)
|
doMessageBox();
|
||||||
|
|
||||||
|
if (battle.status == MS_IN_PROGRESS)
|
||||||
|
{
|
||||||
|
doScript();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
battle.missionFinishedTimer--;
|
battle.missionFinishedTimer--;
|
||||||
}
|
}
|
||||||
|
|
||||||
battle.stats[STAT_TIME]++;
|
|
||||||
if (battle.stats[STAT_TIME] % FPS == 0)
|
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)
|
static void draw(void)
|
||||||
|
@ -169,6 +177,8 @@ static void draw(void)
|
||||||
|
|
||||||
drawHud();
|
drawHud();
|
||||||
|
|
||||||
|
drawMessageBox();
|
||||||
|
|
||||||
drawMissionInfo();
|
drawMissionInfo();
|
||||||
|
|
||||||
switch (show)
|
switch (show)
|
||||||
|
@ -265,8 +275,6 @@ static void continueGame(void)
|
||||||
|
|
||||||
destroyBattle();
|
destroyBattle();
|
||||||
|
|
||||||
resetHud();
|
|
||||||
|
|
||||||
initGalacticMap();
|
initGalacticMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,8 +298,6 @@ static void retry(void)
|
||||||
|
|
||||||
destroyBattle();
|
destroyBattle();
|
||||||
|
|
||||||
resetHud();
|
|
||||||
|
|
||||||
initBattle();
|
initBattle();
|
||||||
|
|
||||||
loadMission(game.currentMission->filename);
|
loadMission(game.currentMission->filename);
|
||||||
|
@ -303,8 +309,6 @@ static void quitBattle(void)
|
||||||
|
|
||||||
destroyBattle();
|
destroyBattle();
|
||||||
|
|
||||||
resetHud();
|
|
||||||
|
|
||||||
initGalacticMap();
|
initGalacticMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +337,6 @@ void destroyBattle(void)
|
||||||
Bullet *b;
|
Bullet *b;
|
||||||
Effect *e;
|
Effect *e;
|
||||||
Objective *o;
|
Objective *o;
|
||||||
Trigger *t;
|
|
||||||
|
|
||||||
while (battle.entityHead.next)
|
while (battle.entityHead.next)
|
||||||
{
|
{
|
||||||
|
@ -367,13 +370,13 @@ void destroyBattle(void)
|
||||||
}
|
}
|
||||||
battle.objectiveTail = &battle.objectiveHead;
|
battle.objectiveTail = &battle.objectiveHead;
|
||||||
|
|
||||||
while (battle.triggerHead.next)
|
cJSON_Delete(battle.missionJSON);
|
||||||
{
|
|
||||||
t = battle.triggerHead.next;
|
resetHud();
|
||||||
battle.triggerHead.next = t->next;
|
|
||||||
free(t);
|
resetMessageBox();
|
||||||
}
|
|
||||||
battle.triggerTail = &battle.triggerHead;
|
destroyScript();
|
||||||
|
|
||||||
destroyGrid();
|
destroyGrid();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
#include "../structs.h"
|
#include "../structs.h"
|
||||||
|
#include "../json/cJSON.h"
|
||||||
|
|
||||||
#define SHOW_BATTLE 0
|
#define SHOW_BATTLE 0
|
||||||
#define SHOW_MENU 1
|
#define SHOW_MENU 1
|
||||||
|
@ -61,12 +62,18 @@ extern void scrollBackground(float x, float y);
|
||||||
extern void initOptions(void (*returnFromOptions)(void));
|
extern void initOptions(void (*returnFromOptions)(void));
|
||||||
extern void drawOptions(void);
|
extern void drawOptions(void);
|
||||||
extern void playSound(int id);
|
extern void playSound(int id);
|
||||||
extern void checkTrigger(char *name, int type);
|
|
||||||
extern void resetWaypoints(void);
|
extern void resetWaypoints(void);
|
||||||
extern void doPlayerSelect(void);
|
extern void doPlayerSelect(void);
|
||||||
extern void destroyGrid(void);
|
extern void destroyGrid(void);
|
||||||
extern void completeMission(void);
|
extern void completeMission(void);
|
||||||
extern void initEffects(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 App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
|
|
|
@ -259,8 +259,6 @@ void doFighter(void)
|
||||||
updateObjective(self->name, TT_ESCAPED);
|
updateObjective(self->name, TT_ESCAPED);
|
||||||
|
|
||||||
updateCondition(self->name, TT_ESCAPED);
|
updateCondition(self->name, TT_ESCAPED);
|
||||||
|
|
||||||
checkTrigger("ESCAPE", TRIGGER_ESCAPES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->alive == ALIVE_DEAD)
|
if (self->alive == ALIVE_DEAD)
|
||||||
|
@ -295,7 +293,7 @@ void doFighter(void)
|
||||||
addHudMessage(colors.red, "Ally has been killed");
|
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);
|
adjustObjectiveTargetValue(self->name, TT_ESCAPED, -1);
|
||||||
|
|
||||||
updateCondition(self->name, TT_DESTROY);
|
updateCondition(self->name, TT_DESTROY);
|
||||||
|
|
||||||
checkTrigger(self->name, TRIGGER_KILLS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ extern void updateObjective(char *name, int type);
|
||||||
extern void updateCondition(char *name, int type);
|
extern void updateCondition(char *name, int type);
|
||||||
extern Entity *getFighterDef(char *name);
|
extern Entity *getFighterDef(char *name);
|
||||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
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 **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
|
||||||
extern Entity *spawnEntity(void);
|
extern Entity *spawnEntity(void);
|
||||||
extern void adjustObjectiveTargetValue(char *name, int type, int amount);
|
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 addShieldSplinterEffect(Entity *ent);
|
||||||
extern void completeMission(void);
|
extern void completeMission(void);
|
||||||
extern void drawShieldHitEffect(Entity *e);
|
extern void drawShieldHitEffect(Entity *e);
|
||||||
|
extern void runScriptFunction(char *format, ...);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
|
|
|
@ -111,8 +111,6 @@ static void action(void)
|
||||||
|
|
||||||
updateObjective(self->name, TT_ITEM);
|
updateObjective(self->name, TT_ITEM);
|
||||||
|
|
||||||
checkTrigger(self->name, TRIGGER_ITEM);
|
|
||||||
|
|
||||||
if (e == player)
|
if (e == player)
|
||||||
{
|
{
|
||||||
addHudMessage(colors.white, "Picked up %s", self->name);
|
addHudMessage(colors.white, "Picked up %s", self->name);
|
||||||
|
|
|
@ -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 playBattleSound(int id, int x, int y);
|
||||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||||
extern void updateObjective(char *name, int type);
|
extern void updateObjective(char *name, int type);
|
||||||
extern void checkTrigger(char *name, int type);
|
|
||||||
|
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Entity *self;
|
extern Entity *self;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
|
@ -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;
|
||||||
|
}
|
|
@ -22,14 +22,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
#include "../structs.h"
|
#include "../structs.h"
|
||||||
|
#include "../json/cJSON.h"
|
||||||
|
|
||||||
extern void completeMission(void);
|
extern void completeMission(void);
|
||||||
extern void failMission(void);
|
extern void failMission(void);
|
||||||
|
extern void retreatEnemies(void);
|
||||||
|
extern void retreatAllies(void);
|
||||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||||
|
extern void addMessageBox(int time, char *title, char *format, ...);
|
||||||
extern void activateEntities(char *name);
|
extern void activateEntities(char *name);
|
||||||
extern void activateObjective(int num);
|
extern void activateObjective(int num);
|
||||||
extern void activateEntityGroup(char *groupName);
|
|
||||||
extern void retreatAllies(void);
|
|
||||||
|
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -63,7 +63,7 @@ static void think(void)
|
||||||
|
|
||||||
updateObjective("Waypoint", TT_WAYPOINT);
|
updateObjective("Waypoint", TT_WAYPOINT);
|
||||||
|
|
||||||
checkTrigger(self->name, TRIGGER_WAYPOINT);
|
runScriptFunction(self->name);
|
||||||
|
|
||||||
activateNextWaypoint(self->id);
|
activateNextWaypoint(self->id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ extern int getDistance(int x1, int y1, int x2, int y2);
|
||||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||||
extern Entity *spawnEntity(void);
|
extern Entity *spawnEntity(void);
|
||||||
extern void updateObjective(char *name, int type);
|
extern void updateObjective(char *name, int type);
|
||||||
extern void checkTrigger(char *name, int type);
|
extern void runScriptFunction(char *format, ...);
|
||||||
|
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
|
|
20
src/defs.h
20
src/defs.h
|
@ -190,26 +190,6 @@ enum
|
||||||
TT_ITEM
|
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
|
enum
|
||||||
{
|
{
|
||||||
MS_START,
|
MS_START,
|
||||||
|
|
|
@ -26,7 +26,7 @@ static void cacheText(unsigned long hash, SDL_Texture *t);
|
||||||
static unsigned long hashcode(const char *str, int size);
|
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 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);
|
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 char drawTextBuffer[MAX_DESCRIPTION_LENGTH];
|
||||||
static TTF_Font *font[MAX_FONTS];
|
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);
|
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])
|
if (!font[size])
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "mission.h"
|
#include "mission.h"
|
||||||
|
|
||||||
static void loadObjectives(cJSON *node);
|
static void loadObjectives(cJSON *node);
|
||||||
static void loadTriggers(cJSON *node);
|
|
||||||
static void loadPlayer(cJSON *node);
|
static void loadPlayer(cJSON *node);
|
||||||
static void loadFighters(cJSON *node);
|
static void loadFighters(cJSON *node);
|
||||||
static void loadEntities(cJSON *node);
|
static void loadEntities(cJSON *node);
|
||||||
|
@ -52,8 +51,6 @@ void loadMission(char *filename)
|
||||||
|
|
||||||
loadObjectives(cJSON_GetObjectItem(root, "objectives"));
|
loadObjectives(cJSON_GetObjectItem(root, "objectives"));
|
||||||
|
|
||||||
loadTriggers(cJSON_GetObjectItem(root, "triggers"));
|
|
||||||
|
|
||||||
loadPlayer(cJSON_GetObjectItem(root, "player"));
|
loadPlayer(cJSON_GetObjectItem(root, "player"));
|
||||||
|
|
||||||
loadFighters(cJSON_GetObjectItem(root, "fighters"));
|
loadFighters(cJSON_GetObjectItem(root, "fighters"));
|
||||||
|
@ -69,7 +66,8 @@ void loadMission(char *filename)
|
||||||
loadEpicData(cJSON_GetObjectItem(root, "epic"));
|
loadEpicData(cJSON_GetObjectItem(root, "epic"));
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(root);
|
initScript(cJSON_GetObjectItem(root, "script"));
|
||||||
|
|
||||||
free(text);
|
free(text);
|
||||||
|
|
||||||
srand(time(NULL));
|
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)
|
static void loadPlayer(cJSON *node)
|
||||||
{
|
{
|
||||||
char *type;
|
char *type;
|
||||||
|
|
|
@ -42,6 +42,7 @@ extern Entity *spawnExtractionPoint(void);
|
||||||
extern Entity *spawnItem(char *type);
|
extern Entity *spawnItem(char *type);
|
||||||
extern void failIncompleteObjectives(void);
|
extern void failIncompleteObjectives(void);
|
||||||
extern void retreatEnemies(void);
|
extern void retreatEnemies(void);
|
||||||
|
extern void initScript(cJSON *missionJSON);
|
||||||
|
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Entity *player;
|
extern Entity *player;
|
||||||
|
|
|
@ -27,9 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
extern void drawWidgets(char *groupName);
|
extern void drawWidgets(char *groupName);
|
||||||
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
|
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 Widget *getWidget(const char *name, const char *group);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
|
|
|
@ -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 Texture Texture;
|
||||||
typedef struct Lookup Lookup;
|
typedef struct Lookup Lookup;
|
||||||
typedef struct Weapon Weapon;
|
typedef struct Weapon Weapon;
|
||||||
|
@ -32,8 +31,9 @@ typedef struct Mission Mission;
|
||||||
typedef struct Pulse Pulse;
|
typedef struct Pulse Pulse;
|
||||||
typedef struct Widget Widget;
|
typedef struct Widget Widget;
|
||||||
typedef struct HudMessage HudMessage;
|
typedef struct HudMessage HudMessage;
|
||||||
typedef struct Trigger Trigger;
|
typedef struct MessageBox MessageBox;
|
||||||
typedef struct GridCell GridCell;
|
typedef struct GridCell GridCell;
|
||||||
|
typedef struct ScriptRunner ScriptRunner;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float x;
|
float x;
|
||||||
|
@ -43,7 +43,7 @@ typedef struct {
|
||||||
struct Texture {
|
struct Texture {
|
||||||
char name[MAX_DESCRIPTION_LENGTH];
|
char name[MAX_DESCRIPTION_LENGTH];
|
||||||
long hash;
|
long hash;
|
||||||
struct SDL_Texture *texture;
|
SDL_Texture *texture;
|
||||||
Texture *next;
|
Texture *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ struct Entity {
|
||||||
Entity *owner;
|
Entity *owner;
|
||||||
void (*action)(void);
|
void (*action)(void);
|
||||||
void (*die)(void);
|
void (*die)(void);
|
||||||
struct SDL_Texture *texture;
|
SDL_Texture *texture;
|
||||||
Entity *next;
|
Entity *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -189,15 +189,6 @@ struct Challenge {
|
||||||
Challenge *next;
|
Challenge *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Trigger {
|
|
||||||
int type;
|
|
||||||
char targetName[MAX_NAME_LENGTH];
|
|
||||||
int targetValue;
|
|
||||||
int action;
|
|
||||||
char actionValue[MAX_NAME_LENGTH];
|
|
||||||
Trigger *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mission {
|
struct Mission {
|
||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
char description[MAX_DESCRIPTION_LENGTH];
|
char description[MAX_DESCRIPTION_LENGTH];
|
||||||
|
@ -256,11 +247,17 @@ typedef struct {
|
||||||
Bullet bulletHead, *bulletTail;
|
Bullet bulletHead, *bulletTail;
|
||||||
Effect effectHead, *effectTail;
|
Effect effectHead, *effectTail;
|
||||||
Objective objectiveHead, *objectiveTail;
|
Objective objectiveHead, *objectiveTail;
|
||||||
Trigger triggerHead, *triggerTail;
|
struct cJSON *missionJSON;
|
||||||
unsigned int stats[STAT_MAX];
|
unsigned int stats[STAT_MAX];
|
||||||
GridCell grid[GRID_SIZE][GRID_SIZE];
|
GridCell grid[GRID_SIZE][GRID_SIZE];
|
||||||
} Battle;
|
} Battle;
|
||||||
|
|
||||||
|
struct ScriptRunner {
|
||||||
|
struct cJSON *line;
|
||||||
|
long delay;
|
||||||
|
ScriptRunner *next;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
StarSystem starSystemHead, *starSystemTail;
|
StarSystem starSystemHead, *starSystemTail;
|
||||||
Mission *currentMission;
|
Mission *currentMission;
|
||||||
|
@ -294,6 +291,13 @@ struct HudMessage {
|
||||||
HudMessage *next;
|
HudMessage *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MessageBox {
|
||||||
|
char title[MAX_NAME_LENGTH];
|
||||||
|
char body[MAX_DESCRIPTION_LENGTH];
|
||||||
|
int time;
|
||||||
|
MessageBox *next;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
|
|
@ -125,18 +125,6 @@ void initLookups(void)
|
||||||
addLookup("STAT_ITEMS_COLLECTED", STAT_ITEMS_COLLECTED);
|
addLookup("STAT_ITEMS_COLLECTED", STAT_ITEMS_COLLECTED);
|
||||||
addLookup("STAT_EPIC_KILL_STREAK", STAT_EPIC_KILL_STREAK);
|
addLookup("STAT_EPIC_KILL_STREAK", STAT_EPIC_KILL_STREAK);
|
||||||
addLookup("STAT_TIME", STAT_TIME);
|
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)
|
static void addLookup(char *name, long value)
|
||||||
|
|
Loading…
Reference in New Issue