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 += 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
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 "../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;
|
|
@ -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);
|
||||
|
||||
checkTrigger(self->name, TRIGGER_WAYPOINT);
|
||||
runScriptFunction(self->name);
|
||||
|
||||
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 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;
|
||||
|
|
20
src/defs.h
20
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,
|
||||
|
|
|
@ -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])
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue