File: main.cpp

package info (click to toggle)
blobandconquer 1.11-dfsg%2B20-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 89,720 kB
  • sloc: cpp: 39,033; ansic: 362; makefile: 143
file content (249 lines) | stat: -rw-r--r-- 6,677 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
Copyright (C) 2006 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 "attributes.h"
#include "main.h"

void GCC_NORETURN showHelp()
{
	SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_VIDEO);
	
	printf("\n");
	printf("Blob Wars, Episode II - Blob And Conquer (Version %.2f, Release %d)\n", VERSION, RELEASE);
	printf("Copyright (C) 2006 Parallel Realities\n");
	printf("Licensed under the GNU General Public License (GPL)\n\n");

	printf("The Blob And Conquer gameplay manual can be found in,\n");
	printf("\t%s\n\n", GAMEPLAYMANUAL);
	
	printf("\t-fullscreen         Start the game in fullscreen mode (default)\n");
	printf("\t-window             Start the game in windowed mode\n");
	
	for (unsigned i = 0 ; i < MAX_RESOLUTIONS ; i++)
	{
		if (graphics->screenMode[i].w == 0)
		{
			continue;
		}
		
		if (i == 0)
		{
			printf("\t-screensize         %d - %d x %d\n", i, graphics->screenMode[i].w, graphics->screenMode[i].h);
		}
		else
		{
			printf("\t                    %d - %d x %d\n", i, graphics->screenMode[i].w, graphics->screenMode[i].h);
		}
	}
	
	for (int i = 0 ; i < SDL_NumJoysticks() ; i++)
	{
		if (i == 0)
		{
			printf("\t-joystick 0         Enable joystick '%s' (default)\n", SDL_JoystickName(i));
		}
		else
		{
			printf("\t-joystick %d         Enable joystick '%s'\n", i, SDL_JoystickName(i));
		}
	}
	
	printf("\t-mono               Use mono sound\n");
	printf("\t-stereo             Use stereo sound (default)\n");
	printf("\t-noaudio            Disables audio\n");
	printf("\t-version            Display version number\n");
	printf("\t--help              This help\n\n");

	exit(0);
}

void GCC_NORETURN showVersion()
{
	printf("\n");
	printf("Blob Wars, Episode II - Blob And Conquer (Version %.2f, Release %d)\n", VERSION, RELEASE);
	printf("Copyright (C) 2006 Parallel Realities\n");
	printf("Licensed under the GNU General Public License (GPL)\n\n");
	exit(0);
}

int main(int argc, char *argv[])
{
	#if RELEASE
	if (chdir(PAKLOCATION))
	{
		perror("Could not chdir to " PAKLOCATION ":");
		return 1;
	}
	#endif

	setlocale(LC_ALL, "");
	setlocale(LC_NUMERIC, "C");
	textdomain("blobAndConquer");
	bindtextdomain("blobAndConquer", LOCALEDIR);

	/*
	 * Prevent the use of XWayland in Wayland environments, as it can lead to a crash when trying to render the game window.
	 * This setting forces the use of native Wayland if available, and fall back to X11 when not in a Wayland session.
	 * The crash can still be reproduced by exporting SDL_VIDEODRIVER=x11 prior to running the game on Wayland.
	 * See https://bugs.debian.org/1037045 for more details.
	 */
	setenv("SDL_VIDEODRIVER", "wayland,x11", 0);

	atexit(cleanup);
	
	game->saveSlot = -1;
	String missionName;
	int requiredSection = SECTION_TITLE;
	int puzzleType = -1;
	
	for (int i = 1 ; i < argc ; i++)
	{
		if (strcmp(argv[i], "-fullscreen") == 0) graphics->fullscreen = true;
		else if (strcmp(argv[i], "-noaudio") == 0) audio->useAudio = 0;
		else if (strcmp(argv[i], "-mono") == 0) audio->useAudio = 1;
		else if (strcmp(argv[i], "-version") == 0) showVersion();
		else if (strcmp(argv[i], "--help") == 0) showHelp();
		else if (strcmp(argv[i], "-joystick") == 0) engine->joystickIndex = atoi(argv[++i]);
		else if (strcmp(argv[i], "-mission") == 0) missionName = argv[++i];
		else if (strcmp(argv[i], "-load") == 0) game->saveSlot = atoi(argv[++i]);
		else if (strcmp(argv[i], "-nomonsters") == 0) game->nomonsters = true;
		else if (strcmp(argv[i], "-noitems") == 0) game->noitems = true;
		else if (strcmp(argv[i], "-allstatic") == 0) game->allStatic = true;
		else if (strcmp(argv[i], "-mastermind") == 0) puzzleType = PUZZLE_TYPE_MASTERMIND;
		else if (strcmp(argv[i], "-lasergrid") == 0) puzzleType = PUZZLE_TYPE_LASERGRID;
		else if (strcmp(argv[i], "-credits") == 0) requiredSection = SECTION_CREDITS;
	}
	
	initSystem();
	
	initOpenGL();
	
	initCommonResources();
	
	switch (puzzleType)
	{
		case PUZZLE_TYPE_MASTERMIND:
			loadWidgets("data/widgets/masterMind");
			while (true)
			{
				mission->enemyLevel = Math::rrand(1, 5);
				doMasterMindPuzzle(rand() % 9999999);
			}
			break;
			
		case PUZZLE_TYPE_LASERGRID:
			while (true)
			{
				mission->enemyLevel = Math::rrand(1, 5);
				doLaserGridPuzzle(rand() % 9999999);
			}
			break;
			
		default:
			break;
	}
	
	loadAllDefinitions();
	
	initCutsceneInstructions();
	
	removeUnneededResources();
	
	if (game->saveSlot != -1)
	{
		requiredSection = SECTION_LOAD;
	}
	else if (missionName != "")
	{
		game->targetLocation = "default";
		game->mission = missionName.getText();
		loadMission(game->mission.getText());
		requiredSection = SECTION_BATTLE;
	}
	#if !DEV
	else
	{
		doIntro();
	}
	#endif
	
	while (true)
	{
		if ((requiredSection != SECTION_BATTLE) && (requiredSection != SECTION_GAMEOVER))
		{
			removeUnneededResources();
		}
	
		switch (requiredSection)
		{
			case SECTION_TITLE:
				requiredSection = doTitle();
				break;
				
			case SECTION_NEWGAME:
				game->mission = "mission01";
				game->targetLocation = "default";
				loadMission(game->mission.getText());
				requiredSection = SECTION_BATTLE;
				break;
				
			case SECTION_TRAINING:
				game->training = true;
				loadMission("training");
				requiredSection = SECTION_BATTLE;
				break;
				
			case SECTION_BATTLE:
				requiredSection = mainBattleLoop();
				break;
				
			case SECTION_CHANGE_LEVEL:
				game->mission = game->targetMission.getText();
				loadMission(game->mission.getText());
				requiredSection = SECTION_BATTLE;
				break;
				
			case SECTION_GAMEOVER:
				requiredSection = doGameOver();
				break;
				
			case SECTION_LOAD:
				game->targetLocation = "@none@";
				loadGameData(game->saveSlot, false);
				requiredSection = SECTION_BATTLE;
				break;
				
			case SECTION_RESTART:
				game->targetLocation = "@none@";
				loadGameData(game->saveSlot, true);
				requiredSection = SECTION_BATTLE;
				break;
				
			case SECTION_CREDITS:
				doCredits();
				requiredSection = SECTION_TITLE;
				break;
		}
	}
	
	debug(("main() Exiting\n"));
	
	return 0;
}