summary refs log tree commit diff
path: root/src/GameInitDispose.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GameInitDispose.cpp')
-rw-r--r--src/GameInitDispose.cpp243
1 files changed, 18 insertions, 225 deletions
diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp
index bd8a05f..9700e25 100644
--- a/src/GameInitDispose.cpp
+++ b/src/GameInitDispose.cpp
@@ -27,7 +27,6 @@
 #include <AL/alc.h>
 #include <GL/glu.h>
 
-#include "config.h"
 #include "misc.h"
 #include "Game.h"
 #include "Support.h"
@@ -90,7 +89,8 @@ Game* makeGame(Config config)
 	psychicaimkey = GLFW_KEY_Q;
 	psychickey = GLFW_KEY_Z;
 
-	game->customlevels = config.custom_levels;
+	game->levels = config.levels.ptr;
+	game->nummissions = config.levels.len;
 	game->debug = config.debug;
 
 	// TODO: Read high score
@@ -240,228 +240,22 @@ void initGame(Game* game)
 
 	// Level setup
 	game->killedinnocent = 0; // haven't shot any civilians yet...
-
-	if (game->customlevels) {
-		game->nummissions = 1; // default level in case of load failure
-		game->type = randomshoot_type;
-		game->possiblegun[0] = handgun1;
-		game->possiblegun[1] = handgun2;
-		game->possiblegun[2] = shotgun;
-		game->numpossibleguns = 3;
-		game->evilprobability = 6;
-		bodyguard.whichgun = knife;
-		bodyguard.reloads[bodyguard.whichgun] = 6;
-		if (!game->gameinprogress)
-			game->score = 0;
-		game->timeremaining = 50;
-		game->difficulty= 0.8f;
-
-		std::ifstream ipstream {"data/customlevels.txt"};
-		if (ipstream) {
-			ipstream.ignore(256,'\n');//ignore descriptive text
-			ipstream >> game->nummissions;
-			for (int j = 0; j <= game->mission; ++j) {
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-				ipstream >> game->type;
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-				ipstream >> environment;
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-				ipstream >> game->numpossibleguns;
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-
-				for (int i = 0; i < game->numpossibleguns; ++i)
-					ipstream >> game->possiblegun[i];
-
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-				ipstream >> game->evilprobability;
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-				ipstream >> bodyguard.whichgun;
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-				ipstream >> bodyguard.reloads[bodyguard.whichgun];
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-				ipstream >> game->timeremaining;
-				ipstream.ignore(256,'\n');
-				ipstream.ignore(256,'\n');
-				ipstream >> game->difficulty;
-				ipstream.ignore(256,'\n');
-			}
-			ipstream.close();
-		} else {
-			game->customlevels = 0;
-		}
-	}
-
-	if (!game->customlevels) {
-		game->nummissions = 13;
-		if (!game->gameinprogress)
-			game->score = 0;
-
-		switch (game->mission) {
-		case 0:
-			environment = sunny_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = handgun1;
-			game->possiblegun[1] = handgun2;
-			game->possiblegun[2] = shotgun;
-			game->numpossibleguns = 3;
-			game->evilprobability = 6;
-			bodyguard.whichgun = assaultrifle;
-			bodyguard.reloads[bodyguard.whichgun] = 6;
-			game->timeremaining = 50;
-			game->difficulty = 0.6f;
-			break;
-		case 1:
-			environment = snowy_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = knife;
-			game->possiblegun[1] = assaultrifle;
-			game->numpossibleguns = 2;
-			game->evilprobability = 5;
-			bodyguard.whichgun = handgun2;
-			bodyguard.reloads[bodyguard.whichgun] = 3;
-			game->timeremaining = 40;
-			game->difficulty = 0.6f;
-			break;
-		case 2:
-			environment = foggy_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = sniperrifle;
-			game->numpossibleguns = 1;
-			game->evilprobability = 5;
-			bodyguard.whichgun = sniperrifle;
-			bodyguard.reloads[bodyguard.whichgun] = 4;
-			game->timeremaining = 50;
-			game->difficulty = 0.9f;
-			break;
-		case 3:
-			environment = firey_environment;
-			game->type = zombie_type;
-			game->numpossibleguns = 0;
-			game->evilprobability = 5;
-			bodyguard.whichgun = shotgun;
-			bodyguard.reloads[bodyguard.whichgun] = 5;
-			game->timeremaining = 35;
-			game->difficulty = 0.7f;
-			break;
-		case 4:
-			environment = snowy_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = sniperrifle;
-			game->possiblegun[1] = assaultrifle;
-			game->numpossibleguns = 2;
-			game->evilprobability = 5;
-			bodyguard.whichgun = grenade;
-			bodyguard.reloads[bodyguard.whichgun] = 20;
-			game->timeremaining = 30;
-			game->difficulty = 0.5f;
-			break;
-		case 5:
-			environment = rainy_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = handgun1;
-			game->possiblegun[1] = shotgun;
-			game->possiblegun[2] = assaultrifle;
-			game->numpossibleguns = 3;
-			game->evilprobability = 6;
-			bodyguard.whichgun = knife;
-			bodyguard.reloads[bodyguard.whichgun] = 3;
-			game->timeremaining = 40;
-			game->difficulty = 0.8f;
-			break;
-		case 6:
-			environment = night_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[1] = handgun1;
-			game->possiblegun[2] = handgun2;
-			game->possiblegun[3] = shotgun;
-			game->numpossibleguns = 3;
-			game->evilprobability = 5;
-			bodyguard.whichgun = handgun1;
-			bodyguard.reloads[bodyguard.whichgun] = 4;
-			game->timeremaining = 30;
-			game->difficulty = 1.0f;
-			break;
-		case 7:
-			environment = firey_environment;
-			game->type = zombie_type;
-			bodyguard.whichgun = assaultrifle;
-			bodyguard.reloads[bodyguard.whichgun] = 5;
-			game->timeremaining = 30;
-			game->difficulty = 1.0f;
-			break;
-		case 8:
-			environment = rainy_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = handgun1;
-			game->possiblegun[1] = handgun2;
-			game->possiblegun[2] = shotgun;
-			game->possiblegun[3] = sniperrifle;
-			game->possiblegun[4] = assaultrifle;
-			game->numpossibleguns = 5;
-			game->evilprobability = 5;
-			bodyguard.whichgun = nogun;
-			bodyguard.reloads[bodyguard.whichgun] = 3;
-			game->timeremaining = 40;
-			game->difficulty = 0.8f;
-			break;
-		case 9:
-			environment = snowy_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = knife;
-			game->possiblegun[1] = handgun1;
-			game->possiblegun[2] = handgun2;
-			game->possiblegun[3] = shotgun;
-			game->possiblegun[4] = sniperrifle;
-			game->possiblegun[5] = assaultrifle;
-			game->numpossibleguns = 6;
-			game->evilprobability = 4;
-			bodyguard.whichgun = handgun1;
-			bodyguard.reloads[bodyguard.whichgun] = 3;
-			game->timeremaining = 90;
-			game->difficulty = 1.0f;
-			break;
-		case 10:
-			environment = night_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = sniperrifle;
-			game->numpossibleguns = 1;
-			game->evilprobability = 5;
-			bodyguard.whichgun = sniperrifle;
-			bodyguard.reloads[bodyguard.whichgun] = 4;
-			game->timeremaining = 30;
-			game->difficulty = 1.3f;
-			break;
-		case 11:
-			environment = sunny_environment;
-			game->type = randomshoot_type;
-			game->possiblegun[0] = knife;
-			game->possiblegun[1] = sniperrifle;
-			game->numpossibleguns = 2;
-			game->evilprobability = 4;
-			bodyguard.whichgun = knife;
-			game->timeremaining = 30;
-			game->difficulty = 1.5f;
-			break;
-		case 12:
-			environment = firey_environment;
-			game->type = zombie_type;
-			game->possiblegun[0] = knife;
-			game->possiblegun[1] = sniperrifle;
-			bodyguard.whichgun = handgun2;
-			bodyguard.reloads[bodyguard.whichgun] = 10;
-			game->timeremaining = 60;
-			game->difficulty = 1.5f;
-			break;
-		}
-	}
+	if (!game->gameinprogress)
+		game->score = 0;
+	auto& level = game->levels[game->mission];
+	environment = level.environment;
+	game->type = (level.evil_weapons & 1 << nogun)
+		? zombie_type : randomshoot_type;
+	game->numpossibleguns = 0;
+	for (auto weapon : { sniperrifle, assaultrifle, handgun1,
+	                     handgun2, shotgun, grenade, knife })
+		if (level.evil_weapons & 1 << weapon)
+			game->possiblegun[game->numpossibleguns++] = weapon;
+	game->evilprobability = level.evil_rarity;
+	bodyguard.whichgun = level.guard_weapon;
+	bodyguard.reloads[bodyguard.whichgun] = level.guard_reloads;
+	game->timeremaining = level.time;
+	game->difficulty = level.difficulty;
 
 	//Setup fast radian to degree conversion
 	rad2deg= 56.54866776;
@@ -509,7 +303,6 @@ void initGame(Game* game)
 		alSourcePlay(sound_source);
 		alSourcef(sound_source, AL_MIN_GAIN, 1);
 		alSourcef(sound_source, AL_MAX_GAIN, 1);
-
 	}
 
 	// Setup random seed