diff --git a/data/missions/sol/02 - weapons.json b/data/missions/sol/02 - weapons.json index 26eca49..acc604c 100644 --- a/data/missions/sol/02 - weapons.json +++ b/data/missions/sol/02 - weapons.json @@ -8,7 +8,8 @@ { "description" : "Destroy Dart", "targetName" : "Dart", - "targetValue" : 1 + "targetValue" : 1, + "targetType" : "TT_DESTROY" } ], "player" : { diff --git a/data/missions/sol/03 - moving target.json b/data/missions/sol/03 - moving target.json index 07106a2..6f67f76 100644 --- a/data/missions/sol/03 - moving target.json +++ b/data/missions/sol/03 - moving target.json @@ -8,7 +8,8 @@ { "description" : "Eliminate Dart", "targetName" : "Dart", - "targetValue" : 1 + "targetValue" : 1, + "targetType" : "TT_DESTROY" } ], "player" : { diff --git a/data/missions/sol/04 - real target.json b/data/missions/sol/04 - real target.json index 69d875d..54856c8 100644 --- a/data/missions/sol/04 - real target.json +++ b/data/missions/sol/04 - real target.json @@ -8,7 +8,8 @@ { "description" : "Eliminate Dart", "targetName" : "Dart", - "targetValue" : 1 + "targetValue" : 1, + "targetType" : "TT_DESTROY" } ], "player" : { diff --git a/data/missions/sol/05 - wingmates.json b/data/missions/sol/05 - wingmates.json index ad3514e..08a6bec 100644 --- a/data/missions/sol/05 - wingmates.json +++ b/data/missions/sol/05 - wingmates.json @@ -8,7 +8,8 @@ { "description" : "Eliminate Darts", "targetName" : "Dart", - "targetValue" : 3 + "targetValue" : 3, + "targetType" : "TT_DESTROY" } ], "player" : { diff --git a/data/missions/sol/06 - final.json b/data/missions/sol/06 - final.json index a396c18..a86d272 100644 --- a/data/missions/sol/06 - final.json +++ b/data/missions/sol/06 - final.json @@ -8,7 +8,8 @@ { "description" : "Eliminate Darts", "targetName" : "Dart", - "targetValue" : 3 + "targetValue" : 3, + "targetType" : "TT_DESTROY" } ], "challenges" : [ diff --git a/data/missions/temper/01 - pirate uprising #1.json b/data/missions/temper/01 - pirate uprising #1.json index 7732fa7..6ee56e6 100644 --- a/data/missions/temper/01 - pirate uprising #1.json +++ b/data/missions/temper/01 - pirate uprising #1.json @@ -8,7 +8,8 @@ { "description" : "Eliminate Darts", "targetName" : "Dart", - "targetValue" : 30 + "targetValue" : 30, + "targetType" : "TT_DESTROY" } ], "challenges" : [ diff --git a/data/missions/temper/02 - pirate uprising #2.json b/data/missions/temper/02 - pirate uprising #2.json index 555182b..88a8014 100644 --- a/data/missions/temper/02 - pirate uprising #2.json +++ b/data/missions/temper/02 - pirate uprising #2.json @@ -8,7 +8,8 @@ { "description" : "Eliminate Darts", "targetName" : "Dart", - "targetValue" : 36 + "targetValue" : 36, + "targetType" : "TT_DESTROY" } ], "challenges" : [ diff --git a/data/missions/temper/03 - pirate uprising #3.json b/data/missions/temper/03 - pirate uprising #3.json index 49b580f..ef12163 100644 --- a/data/missions/temper/03 - pirate uprising #3.json +++ b/data/missions/temper/03 - pirate uprising #3.json @@ -8,13 +8,15 @@ { "description" : "Capture Pirate Leader", "targetName" : "Pirate Leader", - "targetValue" : 1 + "targetValue" : 1, + "targetType" : "TT_DISABLE" }, { "description" : "Do not kill pirate leader", "targetName" : "Pirate Leader", "targetValue" : 1, - "condition" : 1 + "targetType" : "TT_DESTROY", + "isCondition" : 1 } ], "player" : { @@ -26,7 +28,7 @@ "fighters" : [ { "name" : "Pirate Leader", - "type" : "UnarmedDart", + "type" : "StaticDart", "side" : "SIDE_PIRATE", "x" : 800, "y" : 200 diff --git a/makefile b/makefile index 6dcd124..415be9d 100644 --- a/makefile +++ b/makefile @@ -9,7 +9,7 @@ CXXFLAGS += -g -lefence 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 %.h $(SEARCHPATH) @@ -30,7 +30,7 @@ OBJS += objectives.o options.o OBJS += player.o OBJS += radar.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 += widgets.o diff --git a/src/battle/fighters.c b/src/battle/fighters.c index e4fdcc1..87b1682 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -238,17 +238,17 @@ void doFighters(void) f->die(); } - if (f->systemPower <= 0 && f->alive == ALIVE_ALIVE) + if (f->systemPower <= 0) { - f->dx *= 0.995; - f->dy *= 0.995; + f->dx *= 0.99; + f->dy *= 0.99; f->thrust = 0; f->shield = f->maxShield = 0; 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; } } @@ -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) diff --git a/src/battle/fighters.h b/src/battle/fighters.h index d2226df..151157c 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -33,8 +33,8 @@ extern void addEngineEffect(void); extern void addFighterExplosion(void); extern void addSmallFighterExplosion(void); extern void playBattleSound(int id, int x, int y); -extern void updateObjective(char *name); -extern void updateCondition(char *name); +extern void updateObjective(char *name, int type); +extern void updateCondition(char *name, int type); extern Fighter *getFighterDef(char *name); extern void addHudMessage(SDL_Color c, char *format, ...); diff --git a/src/battle/missionInfo.c b/src/battle/missionInfo.c index 664b3da..b0930ae 100644 --- a/src/battle/missionInfo.c +++ b/src/battle/missionInfo.c @@ -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, y, 22, TA_CENTER, colors.white, "%d / %d", o->currentValue, o->targetValue); + if (o->targetValue > 1) + { + 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]); } diff --git a/src/battle/objectives.c b/src/battle/objectives.c index ed7a8b1..c143228 100644 --- a/src/battle/objectives.c +++ b/src/battle/objectives.c @@ -20,19 +20,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "objectives.h" +void completeConditions(void); void failIncompleteObjectives(void); void doObjectives(void) { - int conditionFailed; + int objectiveFailed; Objective *o; battle.numObjectivesComplete = battle.numObjectivesTotal = 0; - conditionFailed = 0; + objectiveFailed = 0; for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) { - battle.numObjectivesTotal++; + if (!o->isCondition) + { + battle.numObjectivesTotal++; + } if (o->currentValue == o->targetValue) { @@ -43,9 +47,9 @@ void doObjectives(void) break; case OS_FAILED: - if (!o->optional) + if (!o->isOptional) { - conditionFailed = 1; + objectiveFailed = 1; } break; } @@ -61,24 +65,28 @@ void doObjectives(void) game.stats.missionsCompleted++; + completeConditions(); + updateChallenges(); } - if (conditionFailed) + if (objectiveFailed) { battle.status = MS_FAILED; battle.missionFinishedTimer = FPS; + + failIncompleteObjectives(); } } } -void updateObjective(char *name) +void updateObjective(char *name, int type) { Objective *o; 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++; @@ -100,25 +108,39 @@ void updateObjective(char *name) } } -void updateCondition(char *name) +void updateCondition(char *name, int type) { Objective *o; 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++; if (o->currentValue == o->targetValue) { 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) { Objective *o; diff --git a/src/defs.h b/src/defs.h index d614454..cd86c39 100644 --- a/src/defs.h +++ b/src/defs.h @@ -130,6 +130,12 @@ enum OS_CONDITION }; +enum +{ + TT_DESTROY, + TT_DISABLE +}; + enum { MS_START, diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 102ff33..bef7182 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -87,6 +87,17 @@ static void loadObjectives(cJSON *node) STRNCPY(o->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH); STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH); 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 = o; diff --git a/src/main.c b/src/main.c index 3c53a13..2210aa7 100644 --- a/src/main.c +++ b/src/main.c @@ -41,8 +41,7 @@ int main(int argc, char *argv[]) if (argc > 1) { - initBattle(); - loadMission(argv[1]); + loadTestMission(argv[1]); } else { diff --git a/src/main.h b/src/main.h index 559a93e..a1f8145 100644 --- a/src/main.h +++ b/src/main.h @@ -30,7 +30,7 @@ extern void initSDL(void); extern void initBattle(void); extern void initGameSystem(void); extern void initTitle(void); -extern void loadMission(char *filename); +extern void loadTestMission(char *filename); extern void saveScreenshot(void); App app; diff --git a/src/structs.h b/src/structs.h index 81805c4..837ff54 100644 --- a/src/structs.h +++ b/src/structs.h @@ -157,10 +157,12 @@ struct Effect { struct Objective { char description[MAX_DESCRIPTION_LENGTH]; char targetName[MAX_NAME_LENGTH]; + int targetType; int currentValue; int targetValue; int status; - int optional; + int isCondition; + int isOptional; Objective *next; }; diff --git a/src/system/lookup.c b/src/system/lookup.c index 6d613a8..c79469a 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -30,6 +30,9 @@ void initLookups(void) memset(&head, 0, sizeof(Lookup)); tail = &head; + addLookup("TT_DESTROY", TT_DESTROY); + addLookup("TT_DISABLE", TT_DISABLE); + addLookup("WT_BUTTON", WT_BUTTON); addLookup("WT_SELECT", WT_SELECT); diff --git a/src/test/testMission.c b/src/test/testMission.c new file mode 100644 index 0000000..b39ca65 --- /dev/null +++ b/src/test/testMission.c @@ -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); +} diff --git a/src/test/testMission.h b/src/test/testMission.h new file mode 100644 index 0000000..a2692ad --- /dev/null +++ b/src/test/testMission.h @@ -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;