diff --git a/common.mk b/common.mk index 0d3455c..f131617 100644 --- a/common.mk +++ b/common.mk @@ -48,7 +48,7 @@ _OBJS += particles.o player.o plasmaBlob.o plasmaDroid.o pistolBlob.o pistolDroi _OBJS += quadtree.o _OBJS += radar.o _OBJS += shotgunBlob.o shotgunDroid.o sound.o spreadGunBlob.o spreadGunDroid.o sprites.o structures.o -_OBJS += tankCommander.o tankTrack.o teeka.o teleporter.o text.o textures.o title.o transition.o triggers.o +_OBJS += tankCommander.o tankTrack.o teeka.o teleporter.o text.o textures.o title.o transition.o triggers.o trophies.o _OBJS += unit.o util.o _OBJS += weapons.o weaponPickup.o widgets.o world.o worldLoader.o worldSaver.o diff --git a/src/defs.h b/src/defs.h index 1a8b4d3..3085cf9 100644 --- a/src/defs.h +++ b/src/defs.h @@ -321,3 +321,25 @@ enum WT_SPINNER, WT_PLAIN_BUTTON }; + +enum +{ + STAT_KEYS_FOUND, + STAT_CELLS_FOUND, + STAT_HEARTS_FOUND, + STAT_DEATHS, + STAT_SHOTS_FIRED, + STAT_SHOTS_HIT, + STAT_EYE_DROID_EXPLOSION_KILLS, + STAT_FLY_TIME, + STAT_SWIM_TIME, + STAT_CHERRIES_PICKED_UP, + STAT_BATTERIES_PICKED_UP, + STAT_WEAPONS_PICKED_UP, + STAT_ENEMIES_KILLED, + STAT_TARGETS_DEFEATED, + STAT_MIAS_RESCUED, + STAT_MISSIONS_PLAYED, + STAT_TIME_PLAYED, + STAT_MAX +}; diff --git a/src/entities/blobs/bob.c b/src/entities/blobs/bob.c index 8a7c5fd..b028b46 100644 --- a/src/entities/blobs/bob.c +++ b/src/entities/blobs/bob.c @@ -116,7 +116,6 @@ static void tick(void) world.bob->health = world.bob->healthMax; } - /* if (world.isTrainingMission) { world.bob->power = MIN(world.bob->power + 0.01, world.bob->powerMax); @@ -125,7 +124,6 @@ static void tick(void) { world.bob->power = MIN(world.bob->power + 0.00065, world.bob->powerMax); } - */ if (dev.cheatPower) { @@ -370,7 +368,7 @@ static void doDying(void) playSound(SND_SPLAT, CH_BOB); - game.deaths++; + game.stats[STAT_DEATHS]++; } } @@ -497,6 +495,8 @@ static void bobSwim(void) activate(1); clearControl(CONTROL_JETPACK); } + + game.stats[STAT_SWIM_TIME]++; } static void bobFly(void) @@ -536,6 +536,8 @@ static void bobFly(void) world.bob->dx = MIN(FLY_SPEED, MAX(world.bob->dx, -FLY_SPEED)); world.bob->dy = MIN(FLY_SPEED, MAX(world.bob->dy, -FLY_SPEED)); + + game.stats[STAT_FLY_TIME]++; } static void fireWeapon(void) @@ -550,7 +552,6 @@ static void fireWeapon(void) break; case WPN_SPREAD: fireSpread((Entity*)world.bob, 3); - game.statShotsFired[WPN_SPREAD] += 2; break; case WPN_LASER: fireLaser((Entity*)world.bob); @@ -562,7 +563,7 @@ static void fireWeapon(void) break; } - game.statShotsFired[world.bob->weaponType]++; + game.stats[STAT_SHOTS_FIRED]++; } diff --git a/src/entities/blobs/mia.c b/src/entities/blobs/mia.c index afe63cd..d160655 100644 --- a/src/entities/blobs/mia.c +++ b/src/entities/blobs/mia.c @@ -125,8 +125,7 @@ static void preTeleport(void) m = (MIA*)self; - m->teleportTimer--; - if (m->teleportTimer <= FPS) + if (--m->teleportTimer <= FPS) { m->action = teleport; m->flags |= (EF_NO_CLIP | EF_WEIGHTLESS); @@ -140,11 +139,10 @@ static void teleport(void) m = (MIA*)self; - m->teleportTimer--; - if (m->teleportTimer <= 0) + if (--m->teleportTimer <= 0) { addTeleportStars(self); - addRescuedMIA(m->name); + game.stats[STAT_MIAS_RESCUED]++; updateObjective("MIA"); m->alive = ALIVE_DEAD; } diff --git a/src/entities/blobs/mia.h b/src/entities/blobs/mia.h index 42f6383..cfd31be 100644 --- a/src/entities/blobs/mia.h +++ b/src/entities/blobs/mia.h @@ -27,8 +27,8 @@ extern void addTeleportStars(Entity *e); extern void setGameplayMessage(int type, char *format, ...); extern void playSound(int snd, int ch); extern void updateObjective(char *targetName); -extern void addRescuedMIA(char *name); extern void initEntity(Entity *e); extern Entity *self; +extern Game game; extern World world; diff --git a/src/entities/boss/blobBoss.c b/src/entities/boss/blobBoss.c index 1dc6785..bc902be 100644 --- a/src/entities/boss/blobBoss.c +++ b/src/entities/boss/blobBoss.c @@ -384,8 +384,8 @@ static void die2(void) updateObjective(b->name); - addDefeatedTarget(b->name); + game.stats[STAT_TARGETS_DEFEATED]++; - game.enemiesKilled++; + game.stats[STAT_ENEMIES_KILLED]++; } } diff --git a/src/entities/boss/blobBoss.h b/src/entities/boss/blobBoss.h index 047af0c..1f0baa2 100644 --- a/src/entities/boss/blobBoss.h +++ b/src/entities/boss/blobBoss.h @@ -34,7 +34,6 @@ extern int getDistance(int x1, int y1, int x2, int y2); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern int enemyCanSeePlayer(Entity *e); extern void updateObjective(char *targetName); -extern void addDefeatedTarget(char *name); extern Entity *self; extern Game game; diff --git a/src/entities/boss/eyeDroidCommander.c b/src/entities/boss/eyeDroidCommander.c index 88305d6..7dbba42 100644 --- a/src/entities/boss/eyeDroidCommander.c +++ b/src/entities/boss/eyeDroidCommander.c @@ -376,9 +376,11 @@ static void die2() updateObjective(b->name); - addDefeatedTarget(b->name); + game.stats[STAT_TARGETS_DEFEATED]++; - game.enemiesKilled++; + awardTrophy(""); + + game.stats[STAT_ENEMIES_KILLED]++; } } diff --git a/src/entities/boss/eyeDroidCommander.h b/src/entities/boss/eyeDroidCommander.h index c81f961..0dedc86 100644 --- a/src/entities/boss/eyeDroidCommander.h +++ b/src/entities/boss/eyeDroidCommander.h @@ -29,13 +29,13 @@ extern void addSmokeParticles(float x, float y); extern int rrnd(int low, int high); extern int getDistance(int x1, int y1, int x2, int y2); extern int enemyCanSeePlayer(Entity *e); -extern void addDefeatedTarget(char *name); extern void updateObjective(char *targetName); extern double randF(void); extern void playSound(int snd, int ch); extern Bullet *createBaseBullet(Unit *owner); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void addExplosion(float x, float y, int radius, Entity *owner); +extern void awardTrophy(char *id); extern Entity *self; extern Game game; diff --git a/src/entities/boss/tankCommander.c b/src/entities/boss/tankCommander.c index 4a96042..6778a9b 100644 --- a/src/entities/boss/tankCommander.c +++ b/src/entities/boss/tankCommander.c @@ -330,9 +330,11 @@ static void die2(void) updateObjective(b->name); - addDefeatedTarget(b->name); + game.stats[STAT_TARGETS_DEFEATED]++; - game.enemiesKilled++; + awardTrophy(""); + + game.stats[STAT_ENEMIES_KILLED]++; } } diff --git a/src/entities/boss/tankCommander.h b/src/entities/boss/tankCommander.h index 73e471f..7d2fd42 100644 --- a/src/entities/boss/tankCommander.h +++ b/src/entities/boss/tankCommander.h @@ -28,7 +28,6 @@ extern float limit(float i, float a, float b); extern int rrnd(int low, int high); extern int getDistance(int x1, int y1, int x2, int y2); extern int enemyCanSeePlayer(Entity *e); -extern void addDefeatedTarget(char *name); extern void updateObjective(char *targetName); extern void playSound(int snd, int ch); extern Bullet *createBaseBullet(Unit *owner); @@ -36,6 +35,7 @@ extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addScorchDecal(int x, int y); extern void initTankTrack(Entity *e); +extern void awardTrophy(char *id); extern Entity *self; extern Game game; diff --git a/src/entities/bullets/bullet.c b/src/entities/bullets/bullet.c index 1adf93b..4b9c845 100644 --- a/src/entities/bullets/bullet.c +++ b/src/entities/bullets/bullet.c @@ -118,7 +118,7 @@ static void touch(Entity *other) if (b->owner->type == world.bob->type) { - game.statShotsHit[b->weaponType]++; + game.stats[STAT_SHOTS_HIT]++; } } } diff --git a/src/entities/bullets/grenade.c b/src/entities/bullets/grenade.c index 8244a7b..6991ec6 100644 --- a/src/entities/bullets/grenade.c +++ b/src/entities/bullets/grenade.c @@ -82,7 +82,7 @@ static void touch(Entity *other) if (b->owner->type == world.bob->type) { - game.statShotsHit[WPN_GRENADES]++; + game.stats[STAT_SHOTS_HIT]++; } if (!(other->flags & EF_BOMB_SHIELD)) diff --git a/src/entities/bullets/laser.c b/src/entities/bullets/laser.c index 1822f27..d7569fb 100644 --- a/src/entities/bullets/laser.c +++ b/src/entities/bullets/laser.c @@ -74,7 +74,7 @@ static void touch(Entity *other) if (b->owner->type == world.bob->type) { - game.statShotsHit[WPN_LASER]++; + game.stats[STAT_SHOTS_HIT]++; } if (other->type == ET_BOB && world.bob->stunTimer == 0) diff --git a/src/entities/evilBlobs/evilBlob.c b/src/entities/evilBlobs/evilBlob.c index 3b72353..8a44aaf 100644 --- a/src/entities/evilBlobs/evilBlob.c +++ b/src/entities/evilBlobs/evilBlob.c @@ -85,10 +85,10 @@ static void die2(void) if (u->isMissionTarget) { - addDefeatedTarget(u->name); + game.stats[STAT_TARGETS_DEFEATED]++; } - game.enemiesKilled++; + game.stats[STAT_ENEMIES_KILLED]++; mx = (int) ((u->x + (u->w / 2)) / MAP_TILE_SIZE); my = (int) (u->y / MAP_TILE_SIZE) + 1; diff --git a/src/entities/evilBlobs/evilBlob.h b/src/entities/evilBlobs/evilBlob.h index ea6e159..c81460c 100644 --- a/src/entities/evilBlobs/evilBlob.h +++ b/src/entities/evilBlobs/evilBlob.h @@ -30,7 +30,6 @@ extern void playSound(int snd, int ch); extern void addBloodDecal(int x, int y); extern void updateObjective(char *targetName); extern int enemyCanSeePlayer(Entity *e); -extern void addDefeatedTarget(char *name); extern void fireTriggers(char *name); extern void addRandomItems(float x, float y); extern int rrnd(int low, int high); diff --git a/src/entities/eyeDroids/eyeDroid.c b/src/entities/eyeDroids/eyeDroid.c index a3086ad..db80115 100644 --- a/src/entities/eyeDroids/eyeDroid.c +++ b/src/entities/eyeDroids/eyeDroid.c @@ -93,10 +93,10 @@ static void touch(Entity *other) if (u->isMissionTarget) { - addDefeatedTarget(u->name); + game.stats[STAT_TARGETS_DEFEATED]++; } - game.enemiesKilled++; + game.stats[STAT_ENEMIES_KILLED]++; mx = (int) ((u->x + (u->w / 2)) / MAP_TILE_SIZE); my = (int) ((u->y + u->h) / MAP_TILE_SIZE) + 1; diff --git a/src/entities/eyeDroids/eyeDroid.h b/src/entities/eyeDroids/eyeDroid.h index b378011..d8f0c0b 100644 --- a/src/entities/eyeDroids/eyeDroid.h +++ b/src/entities/eyeDroids/eyeDroid.h @@ -28,7 +28,6 @@ extern float limit(float i, float a, float b); extern void playSound(int snd, int ch); extern void updateObjective(char *targetName); extern int enemyCanSeePlayer(Entity *e); -extern void addDefeatedTarget(char *name); extern void fireTriggers(char *name); extern void addRandomItems(float x, float y); extern int rrnd(int low, int high); diff --git a/src/entities/items/battery.c b/src/entities/items/battery.c index c389488..607b6bc 100644 --- a/src/entities/items/battery.c +++ b/src/entities/items/battery.c @@ -51,5 +51,7 @@ static void touch(Entity *other) pickupItem(); playSound(SND_ITEM, CH_ITEM); + + game.stats[STAT_BATTERIES_PICKED_UP]++; } } diff --git a/src/entities/items/battery.h b/src/entities/items/battery.h index 6ca76ad..362171e 100644 --- a/src/entities/items/battery.h +++ b/src/entities/items/battery.h @@ -27,4 +27,5 @@ extern void setGameplayMessage(int type, char *format, ...); extern int touchedPlayer(Entity *e); extern Entity *self; +extern Game game; extern World world; diff --git a/src/entities/items/cell.c b/src/entities/items/cell.c index 8e367cf..1ac99f3 100644 --- a/src/entities/items/cell.c +++ b/src/entities/items/cell.c @@ -50,6 +50,8 @@ static void touch(Entity *other) { game.cells++; + game.stats[STAT_CELLS_FOUND]++; + world.bob->power = world.bob->powerMax = game.cells; setGameplayMessage(MSG_OBJECTIVE, _("Found a battery cell - Max power increased!")); diff --git a/src/entities/items/cherry.c b/src/entities/items/cherry.c index 26873c5..0d6ec40 100644 --- a/src/entities/items/cherry.c +++ b/src/entities/items/cherry.c @@ -48,5 +48,7 @@ static void touch(Entity *other) pickupItem(); playSound(SND_CHERRY, CH_BOB); + + game.stats[STAT_CHERRIES_PICKED_UP]++; } } diff --git a/src/entities/items/cherry.h b/src/entities/items/cherry.h index c98a6c0..309002f 100644 --- a/src/entities/items/cherry.h +++ b/src/entities/items/cherry.h @@ -28,4 +28,5 @@ extern void pickupItem(void); extern float limit(float i, float a, float b); extern Entity *self; +extern Game game; extern World world; diff --git a/src/entities/items/heart.c b/src/entities/items/heart.c index bbae850..3e8ba3b 100644 --- a/src/entities/items/heart.c +++ b/src/entities/items/heart.c @@ -62,6 +62,8 @@ static void touch(Entity *other) { game.hearts++; + game.stats[STAT_HEARTS_FOUND]++; + world.bob->health = world.bob->healthMax = game.hearts; setGameplayMessage(MSG_OBJECTIVE, _("Found a heart - Max health increased!")); diff --git a/src/entities/items/item.c b/src/entities/items/item.c index 7f426d0..78c8097 100644 --- a/src/entities/items/item.c +++ b/src/entities/items/item.c @@ -135,7 +135,7 @@ static void bobPickupItem(void) if (i->thinkTime == 0) { addItem(i); - game.keysFound++; + game.stats[STAT_KEYS_FOUND]++; updateObjective("KEY"); setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), i->name); diff --git a/src/entities/items/keycard.c b/src/entities/items/keycard.c index 7e6017a..ba4776b 100644 --- a/src/entities/items/keycard.c +++ b/src/entities/items/keycard.c @@ -106,5 +106,7 @@ static void touchWhiteKeycard(Entity *other) updateObjective("White Keycard"); teekaExitMission(); + + awardTrophy(""); } } diff --git a/src/entities/items/keycard.h b/src/entities/items/keycard.h index 1a7ae9e..f74a649 100644 --- a/src/entities/items/keycard.h +++ b/src/entities/items/keycard.h @@ -23,5 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern Entity *createItem(void); extern void updateObjective(char *targetName); extern void teekaExitMission(void); +extern void awardTrophy(char *id); extern World world; diff --git a/src/entities/items/weaponPickup.c b/src/entities/items/weaponPickup.c index 88e56fa..eba2733 100644 --- a/src/entities/items/weaponPickup.c +++ b/src/entities/items/weaponPickup.c @@ -96,5 +96,7 @@ static void touch(Entity *other) pickupItem(); playSound(SND_WEAPON, CH_ITEM); + + game.stats[STAT_WEAPONS_PICKED_UP]++; } } diff --git a/src/entities/items/weaponPickup.h b/src/entities/items/weaponPickup.h index af0b559..5848231 100644 --- a/src/entities/items/weaponPickup.h +++ b/src/entities/items/weaponPickup.h @@ -29,4 +29,5 @@ extern const char *getWeaponName(int i); extern Entity *initConsumable(void); extern Entity *self; +extern Game game; extern World world; diff --git a/src/game/game.c b/src/game/game.c index b79e61d..21aeb22 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -32,39 +32,11 @@ void initGame(void) game.cells = 5; game.hearts = 10; - game.timePlayed = 0; + game.stats[STAT_TIME_PLAYED] = 0; loadMetaInfo(); } -void addRescuedMIA(char *name) -{ - int i; - - for (i = 0 ; i < game.totalMIAs ; i++) - { - if (strcmp(game.mias[i], "") == 0) - { - STRNCPY(game.mias[i], name, MAX_NAME_LENGTH); - return; - } - } -} - -void addDefeatedTarget(char *name) -{ - int i; - - for (i = 0 ; i < game.totalTargets ; i++) - { - if (strcmp(game.targets[i], "") == 0) - { - STRNCPY(game.targets[i], name, MAX_NAME_LENGTH); - return; - } - } -} - int getNumItemsCarried(void) { int rtn, i; @@ -265,7 +237,6 @@ static void loadMetaInfo(void) { cJSON *root; char *text; - int i; text = readFile("data/meta/meta.json"); @@ -279,18 +250,6 @@ static void loadMetaInfo(void) SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Meta [keys=%d, targets=%d, mias=%d, hearts=%d, cells=%d]", game.totalKeys, game.totalTargets, game.totalMIAs, game.totalHearts, game.totalCells); - game.mias = malloc(sizeof(char*) * game.totalMIAs); - for (i = 0 ; i < game.totalMIAs ; i++) - { - game.mias[i] = malloc(MAX_NAME_LENGTH); - } - - game.targets = malloc(sizeof(char*) * game.totalTargets); - for (i = 0 ; i < game.totalTargets ; i++) - { - game.targets[i] = malloc(MAX_NAME_LENGTH); - } - cJSON_Delete(root); free(text); diff --git a/src/game/trophies.c b/src/game/trophies.c new file mode 100644 index 0000000..76a2163 --- /dev/null +++ b/src/game/trophies.c @@ -0,0 +1,25 @@ +/* +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 "trophies.h" + +void awardTrophy(char *id) +{ +} diff --git a/src/game/trophies.h b/src/game/trophies.h new file mode 100644 index 0000000..8ad0dc9 --- /dev/null +++ b/src/game/trophies.h @@ -0,0 +1,21 @@ +/* +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" diff --git a/src/main.c b/src/main.c index ebf238d..5205071 100644 --- a/src/main.c +++ b/src/main.c @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) frames = 0; - game.timePlayed++; + game.stats[STAT_TIME_PLAYED]++; nextSecond = SDL_GetTicks() + 1000; } diff --git a/src/structs.h b/src/structs.h index 1d4a542..cf7429b 100644 --- a/src/structs.h +++ b/src/structs.h @@ -345,25 +345,16 @@ typedef struct { typedef struct { int cells; int hearts; - int keysFound; int totalMIAs; int totalTargets; int totalCells; int totalHearts; int totalKeys; - int deaths; - int statShotsFired[WPN_ANY]; - int statShotsHit[WPN_ANY]; - int enemiesKilled; - int missionsPlayed; - long timePlayed; + unsigned int stats[STAT_MAX]; char worldId[MAX_NAME_LENGTH]; int isResumingMission; int isComplete; - char **mias; - char **targets; Tuple keys[MAX_KEY_TYPES]; - Tuple originalKeys[MAX_KEY_TYPES]; Tuple missionStatusHead, *missionStatusTail; } Game; diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index 2e8e744..d46e78c 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -23,9 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void initAtlasTest(void) { dev.cheatStatic = 0; - dev.cheatBlind = 0; + dev.cheatBlind = 1; dev.cheatNoEnemies = 0; - dev.cheatKeys = 1; + dev.cheatKeys = 0; dev.cheatPower = 1; dev.cheatHealth = 1; @@ -33,7 +33,7 @@ void initAtlasTest(void) initHub(); - loadWorld("greenlands1"); + loadWorld("greenlands2"); initWorld(); diff --git a/src/world/world.c b/src/world/world.c index 8d0deda..b962d07 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -80,7 +80,7 @@ void initWorld(void) if (!game.isResumingMission) { - game.missionsPlayed++; + game.stats[STAT_MISSIONS_PLAYED]++; } world.bob->flags |= EF_GONE;