From 2cd629cf862d48dcb4fdf4ddec607d892a4e3cc7 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 18 Feb 2018 09:29:26 +0000 Subject: [PATCH] Added post mission code. --- common.mk | 2 +- src/defs.h | 1 + src/hub/postMission.c | 90 +++++++++++++++++++++++++++++++++++++++++++ src/hub/postMission.h | 33 ++++++++++++++++ src/world/world.c | 22 +++++++---- src/world/world.h | 4 ++ 6 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 src/hub/postMission.c create mode 100644 src/hub/postMission.h diff --git a/common.mk b/common.mk index 4d1c751..4722617 100644 --- a/common.mk +++ b/common.mk @@ -44,7 +44,7 @@ _OBJS += key.o keycard.o _OBJS += laser.o laserBlob.o laserDroid.o laserTrap.o lift.o lookup.o _OBJS += machineGunBlob.o machineGunDroid.o main.o map.o maths.o mia.o missile.o _OBJS += objectives.o -_OBJS += particles.o player.o plasmaBlob.o plasmaDroid.o pistolBlob.o pistolDroid.o powerPoint.o powerPool.o pressurePlate.o pushBlock.o +_OBJS += particles.o player.o plasmaBlob.o plasmaDroid.o pistolBlob.o pistolDroid.o postMission.o powerPoint.o powerPool.o pressurePlate.o pushBlock.o _OBJS += quadtree.o _OBJS += radar.o _OBJS += shotgunBlob.o shotgunDroid.o sound.o spreadGunBlob.o spreadGunDroid.o sprites.o structures.o diff --git a/src/defs.h b/src/defs.h index 50b955c..5c92917 100644 --- a/src/defs.h +++ b/src/defs.h @@ -232,6 +232,7 @@ enum WS_PAUSED, WS_GAME_COMPLETE, WS_OBSERVING, + WS_QUIT, WS_COMPLETE, WS_MISSION_COMPLETE, WS_GAME_OVER diff --git a/src/hub/postMission.c b/src/hub/postMission.c new file mode 100644 index 0000000..718f879 --- /dev/null +++ b/src/hub/postMission.c @@ -0,0 +1,90 @@ +/* +Copyright (C) 2018 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 "postMission.h" + +static void logic(void); +static void draw(void); +static void doPostMission(void); +static void updateMissionStatus(void); + +void initPostMission(void) +{ + startSectionTransition(); + + if (world.state != WS_QUIT) + { + updateMissionStatus(); + } + + app.delegate.logic = logic; + app.delegate.draw = draw; + + endSectionTransition(); +} + +static void updateMissionStatus(void) +{ + Tuple *t; + + for (t = game.missionStatusHead.next ; t != NULL ; t = t->next) + { + if (strcmp(t->key, world.id) == 0) + { + t->value.i = getMissionStatus(); + return; + } + } + + t = malloc(sizeof(Tuple)); + memset(t, 0, sizeof(Tuple)); + game.missionStatusTail->next = t; + game.missionStatusTail = t; + + STRNCPY(t->key, world.id, MAX_NAME_LENGTH); + t->value.i = getMissionStatus(); +} + +static void logic(void) +{ + if (world.state != WS_QUIT) + { + doPostMission(); + } + else + { + doPostMission(); + } +} + +static void draw(void) +{ +} + +static void doPostMission(void) +{ + saveGame(); + + saveWorld(); + + destroyWorld(); + + initHub(); +} diff --git a/src/hub/postMission.h b/src/hub/postMission.h new file mode 100644 index 0000000..101aec6 --- /dev/null +++ b/src/hub/postMission.h @@ -0,0 +1,33 @@ +/* +Copyright (C) 2018 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 "../common.h" + +extern void startSectionTransition(void); +extern void endSectionTransition(void); +extern void initHub(void); +extern void saveGame(void); +extern void saveWorld(void); +extern void destroyWorld(void); +extern int getMissionStatus(void); + +extern App app; +extern Game game; +extern World world; diff --git a/src/world/world.c b/src/world/world.c index 3cdb55d..3b7c83f 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -42,7 +42,6 @@ static void options(void); static void stats(void); static void trophies(void); static void quit(void); -static void destroyWorld(void); static Texture *background; static int observationIndex; @@ -50,6 +49,8 @@ static int showingWidgets; void initWorld(void) { + startSectionTransition(); + loadWorld(game.worldId); background = getTexture(world.background); @@ -73,6 +74,8 @@ void initWorld(void) initMap(); initEntities(); + + addKeysFromStash(); world.enemySpawnTimer = (FPS * rrnd(world.minEnemySpawnTime, world.maxEnemySpawnTime)); @@ -106,6 +109,8 @@ void initWorld(void) app.delegate.logic = logic; app.delegate.draw = draw; + + endSectionTransition(); } static void logic(void) @@ -390,9 +395,9 @@ static void doWorldComplete(void) { world.missionCompleteTimer--; - if (world.missionCompleteTimer <= 0) + if (world.missionCompleteTimer == 0) { - + initPostMission(); } else if (world.missionCompleteTimer == FPS * 1.5) { @@ -401,10 +406,6 @@ static void doWorldComplete(void) addTeleportStars((Entity*)world.bob); playSound(SND_TELEPORT, CH_BOB); } - else if (world.missionCompleteTimer == 0) - { - destroyWorld(); - } else { doBob(); @@ -593,6 +594,11 @@ int getMissionStatus(void) Objective *o; Entity *e; int status; + + if (world.missionType == MT_TRAINING) + { + return MS_COMPLETE; + } status = MS_COMPLETE; @@ -677,7 +683,7 @@ static void quit(void) { } -static void destroyWorld(void) +void destroyWorld(void) { int i; diff --git a/src/world/world.h b/src/world/world.h index 15ed57f..3f58e14 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -86,6 +86,10 @@ extern void destroyQuadtree(void); extern void loadWorld(char *id); extern void initMap(void); extern void initEntities(void); +extern void saveGame(void); +extern void saveWorld(void); +extern void initPostMission(void); +extern void addKeysFromStash(void); extern App app; extern Colors colors;