Added objective target types, and conditional objectives.

This commit is contained in:
Steve 2015-10-22 07:08:03 +01:00
parent a8a5d507fb
commit 204055ea72
21 changed files with 155 additions and 37 deletions

View File

@ -8,7 +8,8 @@
{ {
"description" : "Destroy Dart", "description" : "Destroy Dart",
"targetName" : "Dart", "targetName" : "Dart",
"targetValue" : 1 "targetValue" : 1,
"targetType" : "TT_DESTROY"
} }
], ],
"player" : { "player" : {

View File

@ -8,7 +8,8 @@
{ {
"description" : "Eliminate Dart", "description" : "Eliminate Dart",
"targetName" : "Dart", "targetName" : "Dart",
"targetValue" : 1 "targetValue" : 1,
"targetType" : "TT_DESTROY"
} }
], ],
"player" : { "player" : {

View File

@ -8,7 +8,8 @@
{ {
"description" : "Eliminate Dart", "description" : "Eliminate Dart",
"targetName" : "Dart", "targetName" : "Dart",
"targetValue" : 1 "targetValue" : 1,
"targetType" : "TT_DESTROY"
} }
], ],
"player" : { "player" : {

View File

@ -8,7 +8,8 @@
{ {
"description" : "Eliminate Darts", "description" : "Eliminate Darts",
"targetName" : "Dart", "targetName" : "Dart",
"targetValue" : 3 "targetValue" : 3,
"targetType" : "TT_DESTROY"
} }
], ],
"player" : { "player" : {

View File

@ -8,7 +8,8 @@
{ {
"description" : "Eliminate Darts", "description" : "Eliminate Darts",
"targetName" : "Dart", "targetName" : "Dart",
"targetValue" : 3 "targetValue" : 3,
"targetType" : "TT_DESTROY"
} }
], ],
"challenges" : [ "challenges" : [

View File

@ -8,7 +8,8 @@
{ {
"description" : "Eliminate Darts", "description" : "Eliminate Darts",
"targetName" : "Dart", "targetName" : "Dart",
"targetValue" : 30 "targetValue" : 30,
"targetType" : "TT_DESTROY"
} }
], ],
"challenges" : [ "challenges" : [

View File

@ -8,7 +8,8 @@
{ {
"description" : "Eliminate Darts", "description" : "Eliminate Darts",
"targetName" : "Dart", "targetName" : "Dart",
"targetValue" : 36 "targetValue" : 36,
"targetType" : "TT_DESTROY"
} }
], ],
"challenges" : [ "challenges" : [

View File

@ -8,13 +8,15 @@
{ {
"description" : "Capture Pirate Leader", "description" : "Capture Pirate Leader",
"targetName" : "Pirate Leader", "targetName" : "Pirate Leader",
"targetValue" : 1 "targetValue" : 1,
"targetType" : "TT_DISABLE"
}, },
{ {
"description" : "Do not kill pirate leader", "description" : "Do not kill pirate leader",
"targetName" : "Pirate Leader", "targetName" : "Pirate Leader",
"targetValue" : 1, "targetValue" : 1,
"condition" : 1 "targetType" : "TT_DESTROY",
"isCondition" : 1
} }
], ],
"player" : { "player" : {
@ -26,7 +28,7 @@
"fighters" : [ "fighters" : [
{ {
"name" : "Pirate Leader", "name" : "Pirate Leader",
"type" : "UnarmedDart", "type" : "StaticDart",
"side" : "SIDE_PIRATE", "side" : "SIDE_PIRATE",
"x" : 800, "x" : 800,
"y" : 200 "y" : 200

View File

@ -9,7 +9,7 @@ CXXFLAGS += -g -lefence
LIBS = `sdl2-config --libs` -lSDL2_mixer -lSDL2_image -lSDL2_ttf -lm LIBS = `sdl2-config --libs` -lSDL2_mixer -lSDL2_image -lSDL2_ttf -lm
SEARCHPATH += src/ src/battle src/draw src/game src/galaxy src/json src/system SEARCHPATH += src/ src/battle src/draw src/game src/galaxy src/json src/system src/test
vpath %.c $(SEARCHPATH) vpath %.c $(SEARCHPATH)
vpath %.h $(SEARCHPATH) vpath %.h $(SEARCHPATH)
@ -30,7 +30,7 @@ OBJS += objectives.o options.o
OBJS += player.o OBJS += player.o
OBJS += radar.o OBJS += radar.o
OBJS += save.o sound.o starfield.o starSystems.o stats.o OBJS += save.o sound.o starfield.o starSystems.o stats.o
OBJS += textures.o text.o title.o transition.o OBJS += testMission.o textures.o text.o title.o transition.o
OBJS += util.o OBJS += util.o
OBJS += widgets.o OBJS += widgets.o

View File

@ -238,17 +238,17 @@ void doFighters(void)
f->die(); f->die();
} }
if (f->systemPower <= 0 && f->alive == ALIVE_ALIVE) if (f->systemPower <= 0)
{ {
f->dx *= 0.995; f->dx *= 0.99;
f->dy *= 0.995; f->dy *= 0.99;
f->thrust = 0; f->thrust = 0;
f->shield = f->maxShield = 0; f->shield = f->maxShield = 0;
f->action = NULL; f->action = NULL;
if (f->dx <= 0.01 && f->dy <= 0.01) if (f->alive == ALIVE_ALIVE)
{ {
updateObjective(f->name); updateObjective(f->name, TT_DISABLE);
f->alive = ALIVE_DISABLED; f->alive = ALIVE_DISABLED;
} }
} }
@ -275,9 +275,9 @@ void doFighters(void)
} }
} }
updateObjective(f->name); updateObjective(f->name, TT_DESTROY);
updateCondition(f->name); updateCondition(f->name, TT_DESTROY);
} }
if (f == battle.fighterTail) if (f == battle.fighterTail)

View File

@ -33,8 +33,8 @@ extern void addEngineEffect(void);
extern void addFighterExplosion(void); extern void addFighterExplosion(void);
extern void addSmallFighterExplosion(void); extern void addSmallFighterExplosion(void);
extern void playBattleSound(int id, int x, int y); extern void playBattleSound(int id, int x, int y);
extern void updateObjective(char *name); extern void updateObjective(char *name, int type);
extern void updateCondition(char *name); extern void updateCondition(char *name, int type);
extern Fighter *getFighterDef(char *name); extern Fighter *getFighterDef(char *name);
extern void addHudMessage(SDL_Color c, char *format, ...); extern void addHudMessage(SDL_Color c, char *format, ...);

View File

@ -106,7 +106,10 @@ static void drawMissionSummary(SDL_Texture *header)
} }
drawText(SCREEN_WIDTH / 2 - 100, y, 22, TA_RIGHT, colors.white, o->description); drawText(SCREEN_WIDTH / 2 - 100, y, 22, TA_RIGHT, colors.white, o->description);
if (o->targetValue > 1)
{
drawText(SCREEN_WIDTH / 2, y, 22, TA_CENTER, colors.white, "%d / %d", o->currentValue, o->targetValue); drawText(SCREEN_WIDTH / 2, y, 22, TA_CENTER, colors.white, "%d / %d", o->currentValue, o->targetValue);
}
drawText(SCREEN_WIDTH / 2 + 100, y, 22, TA_LEFT, color, objectiveStatus[o->status]); drawText(SCREEN_WIDTH / 2 + 100, y, 22, TA_LEFT, color, objectiveStatus[o->status]);
} }

View File

@ -20,19 +20,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "objectives.h" #include "objectives.h"
void completeConditions(void);
void failIncompleteObjectives(void); void failIncompleteObjectives(void);
void doObjectives(void) void doObjectives(void)
{ {
int conditionFailed; int objectiveFailed;
Objective *o; Objective *o;
battle.numObjectivesComplete = battle.numObjectivesTotal = 0; battle.numObjectivesComplete = battle.numObjectivesTotal = 0;
conditionFailed = 0; objectiveFailed = 0;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{
if (!o->isCondition)
{ {
battle.numObjectivesTotal++; battle.numObjectivesTotal++;
}
if (o->currentValue == o->targetValue) if (o->currentValue == o->targetValue)
{ {
@ -43,9 +47,9 @@ void doObjectives(void)
break; break;
case OS_FAILED: case OS_FAILED:
if (!o->optional) if (!o->isOptional)
{ {
conditionFailed = 1; objectiveFailed = 1;
} }
break; break;
} }
@ -61,24 +65,28 @@ void doObjectives(void)
game.stats.missionsCompleted++; game.stats.missionsCompleted++;
completeConditions();
updateChallenges(); updateChallenges();
} }
if (conditionFailed) if (objectiveFailed)
{ {
battle.status = MS_FAILED; battle.status = MS_FAILED;
battle.missionFinishedTimer = FPS; battle.missionFinishedTimer = FPS;
failIncompleteObjectives();
} }
} }
} }
void updateObjective(char *name) void updateObjective(char *name, int type)
{ {
Objective *o; Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
if (o->status != OS_CONDITION && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0) if (!o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
{ {
o->currentValue++; o->currentValue++;
@ -100,25 +108,39 @@ void updateObjective(char *name)
} }
} }
void updateCondition(char *name) void updateCondition(char *name, int type)
{ {
Objective *o; Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
if (o->status == OS_CONDITION && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0) if (o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
{ {
o->currentValue++; o->currentValue++;
if (o->currentValue == o->targetValue) if (o->currentValue == o->targetValue)
{ {
o->status = OS_FAILED; o->status = OS_FAILED;
addHudMessage(colors.green, "%s - Objective Failed!", o->description); addHudMessage(colors.red, "%s - Objective Failed!", o->description);
} }
} }
} }
} }
void completeConditions(void)
{
Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{
if (o->isCondition)
{
o->status = OS_COMPLETE;
}
}
}
void failIncompleteObjectives(void) void failIncompleteObjectives(void)
{ {
Objective *o; Objective *o;

View File

@ -130,6 +130,12 @@ enum
OS_CONDITION OS_CONDITION
}; };
enum
{
TT_DESTROY,
TT_DISABLE
};
enum enum
{ {
MS_START, MS_START,

View File

@ -87,6 +87,17 @@ static void loadObjectives(cJSON *node)
STRNCPY(o->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH); STRNCPY(o->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH); STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH);
o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint; o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
o->targetType = lookup(cJSON_GetObjectItem(node, "targetType")->valuestring);
if (cJSON_GetObjectItem(node, "isCondition"))
{
o->isCondition = cJSON_GetObjectItem(node, "isCondition")->valueint;
}
if (cJSON_GetObjectItem(node, "isOptional"))
{
o->isOptional = cJSON_GetObjectItem(node, "isOptional")->valueint;
}
battle.objectiveTail->next = o; battle.objectiveTail->next = o;
battle.objectiveTail = o; battle.objectiveTail = o;

View File

@ -41,8 +41,7 @@ int main(int argc, char *argv[])
if (argc > 1) if (argc > 1)
{ {
initBattle(); loadTestMission(argv[1]);
loadMission(argv[1]);
} }
else else
{ {

View File

@ -30,7 +30,7 @@ extern void initSDL(void);
extern void initBattle(void); extern void initBattle(void);
extern void initGameSystem(void); extern void initGameSystem(void);
extern void initTitle(void); extern void initTitle(void);
extern void loadMission(char *filename); extern void loadTestMission(char *filename);
extern void saveScreenshot(void); extern void saveScreenshot(void);
App app; App app;

View File

@ -157,10 +157,12 @@ struct Effect {
struct Objective { struct Objective {
char description[MAX_DESCRIPTION_LENGTH]; char description[MAX_DESCRIPTION_LENGTH];
char targetName[MAX_NAME_LENGTH]; char targetName[MAX_NAME_LENGTH];
int targetType;
int currentValue; int currentValue;
int targetValue; int targetValue;
int status; int status;
int optional; int isCondition;
int isOptional;
Objective *next; Objective *next;
}; };

View File

@ -30,6 +30,9 @@ void initLookups(void)
memset(&head, 0, sizeof(Lookup)); memset(&head, 0, sizeof(Lookup));
tail = &head; tail = &head;
addLookup("TT_DESTROY", TT_DESTROY);
addLookup("TT_DISABLE", TT_DISABLE);
addLookup("WT_BUTTON", WT_BUTTON); addLookup("WT_BUTTON", WT_BUTTON);
addLookup("WT_SELECT", WT_SELECT); addLookup("WT_SELECT", WT_SELECT);

34
src/test/testMission.c Normal file
View File

@ -0,0 +1,34 @@
/*
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 "testMission.h"
static Mission mission;
void loadTestMission(char *filename)
{
memset(&mission, 0, sizeof(Mission));
game.currentMission = &mission;
initBattle();
loadMission(filename);
}

29
src/test/testMission.h Normal file
View File

@ -0,0 +1,29 @@
/*
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 initBattle(void);
extern void loadMission(char *filename);
extern Game game;