2 Copyright (C) 2004 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 void checkForLicense()
25 if (!engine.loadData(_("data/license")))
27 graphics.showLicenseErrorAndExit();
32 Show the GNU Public License the first time the game is played. Waits 4 seconds
33 and then proceeds. THIS MUST NOT BE REMOVED!!!!!
37 SDL_FillRect(graphics.screen, NULL, graphics.black);
40 SDL_FillRect(graphics.screen, NULL, graphics.black);
41 SDL_Surface *pic = graphics.loadImage("gfx/main/licensePic.png");
42 graphics.blit(pic, 0, 0, graphics.screen, false);
50 char *token = strtok((char*)engine.dataBuffer, "\n");
54 sscanf(token, "%d %[^\n\r]", &y, line);
61 graphics.drawString(line, 320, y, true, graphics.screen);
63 token = strtok(NULL, "\n");
73 graphics.drawString(_("Press Space to Continue..."), 320, 440, true, graphics.screen);
80 graphics.updateScreen();
83 if (engine.keyState[SDLK_SPACE])
88 SDL_FillRect(graphics.screen, NULL, graphics.black);
93 void setupUserHomeDirectory()
95 char *userHome = getenv("HOME");
97 if ((!userHome) || (userHome == NULL))
99 printf("Couldn't determine user home directory! Exitting.\n");
103 debug(("User Home = %s\n", userHome));
108 sprintf(dir, "%s/.parallelrealities", userHome);
109 if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
111 printf("Couldn't create required directory '%s'", dir);
115 sprintf(dir, "%s/.parallelrealities/blobwars", userHome);
116 if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
118 printf("Couldn't create required directory '%s'", dir);
122 char gameSavePath[PATH_MAX];
123 sprintf(gameSavePath, "%s/.parallelrealities/blobwars/", userHome);
124 engine.setUserHome(gameSavePath);
134 char configPath[PATH_MAX];
136 sprintf(configPath, "%sconfig", engine.userHomeDirectory);
138 debug(("Loading Config from %s\n", configPath));
140 FILE *fp = fopen(configPath, "rb");
147 fscanf(fp, "%f %d", &version, &release);
149 debug(("Version = %.2f - Expected %.2f\n", version, VERSION));
150 debug(("Release = %d - Expected %d\n", release, RELEASE));
152 if ((version != VERSION) && (release != RELEASE))
157 fscanf(fp, "%d %d %d %d %d %d %d", &engine.fullScreen, &game.musicVol, &game.soundVol, &game.output, &game.brightness, &engine.extremeAvailable, &game.gore);
161 debug(("Extreme Mode = %d\n", engine.extremeAvailable));
162 debug(("Output Type = %d\n", game.output));
164 // Override audio if there is no sound available
165 if ((engine.useAudio) && (game.output))
167 engine.useAudio = game.output;
170 config.loadKeyConfig();
171 config.loadJoystickConfig();
178 char configPath[PATH_MAX];
180 sprintf(configPath, "%sconfig", engine.userHomeDirectory);
182 FILE *fp = fopen(configPath, "wb");
186 printf("Error Saving Config to %s\n", configPath);
190 fprintf(fp, "%f %d\n", VERSION, RELEASE);
191 fprintf(fp, "%d %d %d %d %d %d %d\n", engine.fullScreen, game.musicVol, game.soundVol, game.output, game.brightness, engine.extremeAvailable, game.gore);
195 debug(("Output Type = %d\n", game.output));
199 Chugg chugg chugg.... brrr... chugg chugg chugg...brrrrrr... chugg ch..
200 BRRRRRRRRRRRRRRRRRMMMMMMMMMMMMMMMMMMM!! Well, hopefully anyway! ;)
205 setupUserHomeDirectory();
208 bool displayLicense = loadConfig();
210 long flags = SDL_INIT_VIDEO|SDL_INIT_JOYSTICK;
214 flags |= SDL_INIT_AUDIO;
217 /* Initialize the SDL library */
218 if (SDL_Init(flags) < 0)
220 printf("Couldn't initialize SDL: %s\n", SDL_GetError());
224 if (!engine.fullScreen)
226 graphics.screen = SDL_SetVideoMode(640, 480, 0, SDL_HWPALETTE);
230 graphics.screen = SDL_SetVideoMode(640, 480, 0, SDL_HWPALETTE | SDL_FULLSCREEN);
233 if (graphics.screen == NULL)
235 printf("Couldn't set 640x480 video mode: %s\n", SDL_GetError());
239 // This (attempts to) set the gamma correction. We attempt to catch an error here
240 // in case someone has done something really stupid in the config file(!!)
241 if (game.brightness != -1) {
242 Math::limitInt(&game.brightness, 1, 20);
243 float brightness = game.brightness;
245 SDL_SetGamma(brightness, brightness, brightness);
250 printf("Couldn't initialize SDL TTF: %s\n", SDL_GetError());
256 if (Mix_OpenAudio(22050, AUDIO_S16, engine.useAudio, 1024) < 0)
258 printf("Warning: Couldn't set 22050 Hz 16-bit audio - Reason: %s\n", Mix_GetError());
259 printf("Sound and Music will be disabled\n");
264 debug(("Found %d Joysticks...\n", SDL_NumJoysticks()));
266 if (SDL_NumJoysticks() > 0)
268 debug(("Opening Joystick - %s...\n", SDL_JoystickName(0)));
269 SDL_JoystickEventState(SDL_ENABLE);
270 config.sdlJoystick = SDL_JoystickOpen(0);
273 SDL_ShowCursor(SDL_DISABLE);
274 SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE);
276 graphics.registerEngine(&engine);
277 graphics.mapColors();
279 audio.registerEngine(&engine);
280 audio.setSoundVolume(game.soundVol);
281 audio.setMusicVolume(game.musicVol);
282 audio.output = game.output;
284 debug(("Sound Volume = %d\n", game.soundVol));
285 debug(("Music Volume = %d\n", game.musicVol));
286 debug(("Output Type = %d\n", game.output));
287 debug(("Brightness = %d\n", game.brightness));
288 debug(("tmp dir = %s\n", engine.userHomeDirectory));
289 debug(("Pack Dir = %s\n", PAKLOCATION));
290 debug(("Loading Fonts...\n"));
294 char tempPath[PATH_MAX];
295 sprintf(tempPath, "%sfont.ttf", engine.userHomeDirectory);
298 SDL_Delay(1000); // wait one second, just to be sure!
300 if (!engine.unpack("data/vera.ttf", PAK_FONT))
302 engine.reportFontFailure();
306 debug(("Trying to load correct font pixel sizes using a really half arsed routine!\n"));
307 debug(("If it crashes then you'll know why!\n"));
309 graphics.loadFont(0, "data/vera.ttf", 7);
310 graphics.loadFont(1, "data/vera.ttf", 9);
311 graphics.loadFont(2, "data/vera.ttf", 11);
312 graphics.loadFont(3, "data/vera.ttf", 13);
313 graphics.loadFont(4, "data/vera.ttf", 15);
315 debug(("Font sizes all loaded!!\n"));
317 audio.loadSound(SND_CHEAT, "sound/Lock And Load!!!");
318 audio.loadSound(SND_HIGHLIGHT, "sound/menu.wav");
319 audio.loadSound(SND_SELECT, "sound/select.wav");
321 SDL_Surface *device = graphics.loadImage("gfx/main/alienDevice.png");
323 #ifndef SDL_FRAMEWORK
324 SDL_WM_SetIcon(device, NULL);
326 SDL_WM_SetCaption("Blob Wars : Metal Blob Solid", "Blob Wars");
327 SDL_EnableKeyRepeat(350, 80);
329 SDL_FreeSurface(device);
331 if (strstr(engine.userHomeDirectory, "/root"))
333 graphics.showRootWarning();
345 engine.saveConfig = true;
347 debug(("Init Complete...\n"));
351 Removes [hopefully] all the resources that has been
352 loaded and created during the game. This is called by
357 char tempPath[PATH_MAX];
359 debug(("Cleaning Up...\n"));
361 debug(("Updating Replay Data\n"));
362 replayData.header.score = game.score;
364 debug(("Freeing Audio...\n"));
367 debug(("Removing Music...\n"));
368 sprintf(tempPath, "%smusic.mod", engine.userHomeDirectory);
371 debug(("Freeing Game Info...\n"));
374 debug(("Freeing Map Data...\n"));
377 debug(("Freeing Engine Data...\n"));
380 debug(("Freeing Graphics...\n"));
383 debug(("Saving Config...\n"));
384 if (engine.saveConfig)
389 debug(("Removing Font File...\n"));
390 sprintf(tempPath, "%sfont.ttf", engine.userHomeDirectory);
393 if (SDL_NumJoysticks() > 0)
395 SDL_JoystickEventState(SDL_DISABLE);
396 for (int i = 0 ; i < SDL_NumJoysticks() ; i++)
398 debug(("Closing Joystick #%d - %s...\n", i, SDL_JoystickName(i)));
399 SDL_JoystickClose(config.sdlJoystick);
403 debug(("Closing Audio...\n"));
409 debug(("Closing TTF...\n"));
412 debug(("Closing SDL Sub System...\n"));
415 debug(("All Done.\n"));
417 if (replayData.replayMode == REPLAY_MODE::PLAYBACK)
419 printf("\n==== ACTUAL PLAYBACK DATA ====\n");
420 replayData.printReplayInformation();