From d71bee6b11eef10bec32f13562b80f428d0fb6e3 Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 14 Feb 2018 07:26:51 +0000 Subject: [PATCH] Use single variable to track mission type. --- src/defs.h | 8 ++++++++ src/entities/blobs/bob.c | 6 +++--- src/entities/unit.c | 2 +- src/structs.h | 4 +--- src/test/atlasTest.c | 4 +++- src/test/atlasTest.h | 1 + src/world/items.c | 4 ++-- src/world/map.c | 2 +- src/world/world.c | 4 ++-- src/world/worldLoader.c | 7 ++++--- 10 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/defs.h b/src/defs.h index 3085cf9..6b2e611 100644 --- a/src/defs.h +++ b/src/defs.h @@ -215,6 +215,14 @@ enum MS_COMPLETE }; +enum +{ + MT_NORMAL, + MT_TRAINING, + MT_OUTPOST, + MT_BOSS +}; + enum { WS_START, diff --git a/src/entities/blobs/bob.c b/src/entities/blobs/bob.c index b028b46..e5d9347 100644 --- a/src/entities/blobs/bob.c +++ b/src/entities/blobs/bob.c @@ -110,13 +110,13 @@ static void init(void) static void tick(void) { - if (world.isTrainingMission || dev.cheatHealth) + if (world.missionType == MT_TRAINING || dev.cheatHealth) { world.bob->alive = ALIVE_ALIVE; world.bob->health = world.bob->healthMax; } - if (world.isTrainingMission) + if (world.missionType == MT_TRAINING) { world.bob->power = MIN(world.bob->power + 0.01, world.bob->powerMax); } @@ -387,7 +387,7 @@ void stunBob(void) static void applyDamage(int damage) { - if (!(world.bob->flags & EF_IMMUNE) && !world.isTrainingMission && !dev.cheatHealth && world.bob->alive != ALIVE_DEAD) + if (!(world.bob->flags & EF_IMMUNE) && world.missionType != MT_TRAINING && !dev.cheatHealth && world.bob->alive != ALIVE_DEAD) { if (world.bob->health < 0) { diff --git a/src/entities/unit.c b/src/entities/unit.c index ee7b563..a2ab34d 100644 --- a/src/entities/unit.c +++ b/src/entities/unit.c @@ -45,7 +45,7 @@ Unit *createUnit(void) u->canCarryItem = rand() % 100 < 85; - if (world.isOutpostMission) + if (world.missionType == MT_OUTPOST) { u->canCarryItem = 1; u->health = u->healthMax = rrnd(1, 4); diff --git a/src/structs.h b/src/structs.h index cf7429b..808d507 100644 --- a/src/structs.h +++ b/src/structs.h @@ -439,10 +439,8 @@ typedef struct { int allObjectivesComplete; int frameCounter; int currentStatus; - int isTrainingMission; - int isBossMission; + int missionType; int isBossActive; - int isOutpostMission; int isReturnVisit; int missionCompleteTimer; int observationTimer; diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index d46e78c..cad3697 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -33,11 +33,13 @@ void initAtlasTest(void) initHub(); - loadWorld("greenlands2"); + loadWorld("greenlands4"); initWorld(); initMap(); initEntities(); + + saveConfig(); } diff --git a/src/test/atlasTest.h b/src/test/atlasTest.h index 9045be1..97fb12b 100644 --- a/src/test/atlasTest.h +++ b/src/test/atlasTest.h @@ -26,5 +26,6 @@ extern void initHub(void); extern void initGame(void); extern void initEntities(void); extern void loadWorld(char *id); +extern void saveConfig(void); extern Dev dev; diff --git a/src/world/items.c b/src/world/items.c index f4e891f..4d9e5c5 100644 --- a/src/world/items.c +++ b/src/world/items.c @@ -61,7 +61,7 @@ static int getRandomPlayerWeaponAt(int x, int y) { int type; - type = getRandomPlayerWeapon(world.isBossMission); + type = getRandomPlayerWeapon(world.missionType == MT_BOSS); if (world.map.data[(x / MAP_TILE_SIZE)][(y / MAP_TILE_SIZE)] == MAP_TILE_WATER) { @@ -69,7 +69,7 @@ static int getRandomPlayerWeaponAt(int x, int y) } else if (type == WPN_PISTOL && rand() % 100 < 25) { - type = getRandomPlayerWeapon(world.isBossMission); + type = getRandomPlayerWeapon(world.missionType == MT_BOSS); } return type; diff --git a/src/world/map.c b/src/world/map.c index f63bc61..3c06846 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -259,7 +259,7 @@ static void loadMapData(void) { sscanf(p, "%d", &i); - if (!world.isOutpostMission) + if (world.missionType != MT_OUTPOST) { if (i >= 4 && i <= 7) { diff --git a/src/world/world.c b/src/world/world.c index b962d07..c2ce178 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -67,7 +67,7 @@ void initWorld(void) observationIndex = 0; - if (world.isBossMission) + if (world.missionType == MT_BOSS) { startMission(); hideAllWidgets(); @@ -390,7 +390,7 @@ static void doCommon(void) spawnEnemies(); } - if (world.isBossMission && --world.helperItemTimer <= 0) + if (world.missionType == MT_BOSS && --world.helperItemTimer <= 0) { addHelperItems(); } diff --git a/src/world/worldLoader.c b/src/world/worldLoader.c index e752f5d..bd614d8 100644 --- a/src/world/worldLoader.c +++ b/src/world/worldLoader.c @@ -61,9 +61,10 @@ void loadWorld(char *id) STRNCPY(world.tileset, cJSON_GetObjectItem(root, "tileset")->valuestring, MAX_NAME_LENGTH); STRNCPY(world.background, cJSON_GetObjectItem(root, "background")->valuestring, MAX_FILENAME_LENGTH); world.entityCounter = cJSON_GetObjectItem(root, "entityCounter")->valueint; - world.isTrainingMission = strcmp(world.id, "beachApproach") == 0; - world.isBossMission = strncmp(world.id, "boss", 4) == 0; - world.isOutpostMission = strncmp(world.id, "outpost", 7) == 0; + + world.missionType = strcmp(world.id, "beachApproach") == 0 ? MT_TRAINING : MT_NORMAL; + world.missionType = strncmp(world.id, "outpost", 7) == 0 ? MT_OUTPOST : world.missionType; + world.missionType = strncmp(world.id, "boss", 4) == 0 ? MT_BOSS : world.missionType; loadEnemyTypes(cJSON_GetObjectItem(root, "enemyTypes")->valuestring);