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 This bit is just for Linux and Unix users. It attempts to get the user's
94 home directory, then creates the .parallelrealities and .parallelrealities/blobwars
95 directories so that saves and temporary data files can be written there. Good, eh? :)
98 void setupUserHomeDirectory()
102 char *name
= getlogin();
108 pass
= getpwnam(name
);
112 pass
= getpwuid(geteuid());
117 printf("Couldn't determine the user home directory. Exitting.\n");
121 userHome
= pass
->pw_dir
;
123 debug(("User Home = %s\n", userHome
));
128 sprintf(dir
, "%s/.parallelrealities", userHome
);
129 if ((mkdir(dir
, S_IRWXU
|S_IRWXG
|S_IROTH
|S_IXOTH
) != 0) && (errno
!= EEXIST
))
131 printf("Couldn't create required directory '%s'", dir
);
135 sprintf(dir
, "%s/.parallelrealities/blobwars", userHome
);
136 if ((mkdir(dir
, S_IRWXU
|S_IRWXG
|S_IROTH
|S_IXOTH
) != 0) && (errno
!= EEXIST
))
138 printf("Couldn't create required directory '%s'", dir
);
142 char gameSavePath
[PATH_MAX
];
143 sprintf(gameSavePath
, "%s/.parallelrealities/blobwars/", userHome
);
144 engine
.setUserHome(gameSavePath
);
155 char configPath
[PATH_MAX
];
157 sprintf(configPath
, "%sconfig", engine
.userHomeDirectory
);
159 debug(("Loading Config from %s\n", configPath
));
161 FILE *fp
= fopen(configPath
, "rb");
168 fscanf(fp
, "%f %d", &version
, &release
);
170 debug(("Version = %.2f - Expected %.2f\n", version
, VERSION
));
171 debug(("Release = %d - Expected %d\n", release
, RELEASE
));
173 if ((version
!= VERSION
) && (release
!= RELEASE
))
178 fscanf(fp
, "%d %d %d %d %d %d %d", &engine
.fullScreen
, &game
.musicVol
, &game
.soundVol
, &game
.output
, &game
.brightness
, &engine
.extremeAvailable
, &game
.gore
);
182 debug(("Extreme Mode = %d\n", engine
.extremeAvailable
));
183 debug(("Output Type = %d\n", game
.output
));
185 // Override audio if there is no sound available
186 if ((engine
.useAudio
) && (game
.output
))
188 engine
.useAudio
= game
.output
;
191 config
.loadKeyConfig();
192 config
.loadJoystickConfig();
199 char configPath
[PATH_MAX
];
201 sprintf(configPath
, "%sconfig", engine
.userHomeDirectory
);
203 FILE *fp
= fopen(configPath
, "wb");
207 printf("Error Saving Config to %s\n", configPath
);
211 fprintf(fp
, "%f %d\n", VERSION
, RELEASE
);
212 fprintf(fp
, "%d %d %d %d %d %d %d\n", engine
.fullScreen
, game
.musicVol
, game
.soundVol
, game
.output
, game
.brightness
, engine
.extremeAvailable
, game
.gore
);
216 debug(("Output Type = %d\n", game
.output
));
220 Chugg chugg chugg.... brrr... chugg chugg chugg...brrrrrr... chugg ch..
221 BRRRRRRRRRRRRRRRRRMMMMMMMMMMMMMMMMMMM!! Well, hopefully anyway! ;)
226 setupUserHomeDirectory();
229 bool displayLicense
= loadConfig();
231 long flags
= SDL_INIT_VIDEO
|SDL_INIT_JOYSTICK
;
235 flags
|= SDL_INIT_AUDIO
;
238 /* Initialize the SDL library */
239 if (SDL_Init(flags
) < 0)
241 printf("Couldn't initialize SDL: %s\n", SDL_GetError());
245 if (!engine
.fullScreen
)
247 graphics
.screen
= SDL_SetVideoMode(640, 480, 0, SDL_HWPALETTE
);
251 graphics
.screen
= SDL_SetVideoMode(640, 480, 0, SDL_HWPALETTE
| SDL_FULLSCREEN
);
254 if (graphics
.screen
== NULL
)
256 printf("Couldn't set 640x480 video mode: %s\n", SDL_GetError());
260 // This (attempts to) set the gamma correction. We attempt to catch an error here
261 // in case someone has done something really stupid in the config file(!!)
262 if (game
.brightness
!= -1) {
263 Math::limitInt(&game
.brightness
, 1, 20);
264 float brightness
= game
.brightness
;
266 #if SDL_SETGAMMARAMP_CHECKS_FOR_A_NULL_PALETTE
267 SDL_SetGamma(brightness
, brightness
, brightness
);
273 printf("Couldn't initialize SDL TTF: %s\n", SDL_GetError());
279 if (Mix_OpenAudio(22050, AUDIO_S16
, engine
.useAudio
, 1024) < 0)
281 printf("Warning: Couldn't set 22050 Hz 16-bit audio - Reason: %s\n", Mix_GetError());
282 printf("Sound and Music will be disabled\n");
287 debug(("Found %d Joysticks...\n", SDL_NumJoysticks()));
289 if (SDL_NumJoysticks() > 0)
291 debug(("Opening Joystick - %s...\n", SDL_JoystickName(0)));
292 SDL_JoystickEventState(SDL_ENABLE
);
293 config
.sdlJoystick
= SDL_JoystickOpen(0);
296 SDL_ShowCursor(SDL_DISABLE
);
297 SDL_EventState(SDL_MOUSEMOTION
, SDL_DISABLE
);
299 graphics
.registerEngine(&engine
);
300 graphics
.mapColors();
302 audio
.registerEngine(&engine
);
303 audio
.setSoundVolume(game
.soundVol
);
304 audio
.setMusicVolume(game
.musicVol
);
305 audio
.output
= game
.output
;
307 debug(("Sound Volume = %d\n", game
.soundVol
));
308 debug(("Music Volume = %d\n", game
.musicVol
));
309 debug(("Output Type = %d\n", game
.output
));
310 debug(("Brightness = %d\n", game
.brightness
));
311 debug(("tmp dir = %s\n", engine
.userHomeDirectory
));
312 debug(("Pack Dir = %s\n", PAKLOCATION
));
313 debug(("Loading Fonts...\n"));
317 char tempPath
[PATH_MAX
];
318 sprintf(tempPath
, "%sfont.ttf", engine
.userHomeDirectory
);
321 SDL_Delay(1000); // wait one second, just to be sure!
323 if (!engine
.unpack("data/vera.ttf", PAK_FONT
))
325 engine
.reportFontFailure();
329 debug(("Trying to load correct font pixel sizes using a really half arsed routine!\n"));
330 debug(("If it crashes then you'll know why!\n"));
332 graphics
.loadFont(0, "data/vera.ttf", 7);
333 graphics
.loadFont(1, "data/vera.ttf", 9);
334 graphics
.loadFont(2, "data/vera.ttf", 11);
335 graphics
.loadFont(3, "data/vera.ttf", 13);
336 graphics
.loadFont(4, "data/vera.ttf", 15);
338 debug(("Font sizes all loaded!!\n"));
340 audio
.loadSound(SND_CHEAT
, "sound/Lock And Load!!!");
341 audio
.loadSound(SND_HIGHLIGHT
, "sound/menu.wav");
342 audio
.loadSound(SND_SELECT
, "sound/select.wav");
344 SDL_Surface
*device
= graphics
.loadImage("gfx/main/alienDevice.png");
346 #ifndef SDL_FRAMEWORK
347 SDL_WM_SetIcon(device
, NULL
);
349 SDL_WM_SetCaption("Blob Wars : Metal Blob Solid", "Blob Wars");
350 SDL_EnableKeyRepeat(350, 80);
352 SDL_FreeSurface(device
);
354 if (strstr(engine
.userHomeDirectory
, "/root"))
356 graphics
.showRootWarning();
368 engine
.saveConfig
= true;
370 debug(("Init Complete...\n"));
374 Removes [hopefully] all the resources that has been
375 loaded and created during the game. This is called by
380 char tempPath
[PATH_MAX
];
382 debug(("Cleaning Up...\n"));
384 debug(("Updating Replay Data"));
385 replayData
.header
.score
= game
.score
;
387 debug(("Freeing Audio...\n"));
390 debug(("Removing Music...\n"));
391 sprintf(tempPath
, "%smusic.mod", engine
.userHomeDirectory
);
394 debug(("Freeing Game Info...\n"));
397 debug(("Freeing Map Data...\n"));
400 debug(("Freeing Engine Data...\n"));
403 debug(("Freeing Graphics...\n"));
406 debug(("Saving Config...\n"));
407 if (engine
.saveConfig
)
412 debug(("Removing Font File...\n"));
413 sprintf(tempPath
, "%sfont.ttf", engine
.userHomeDirectory
);
416 if (SDL_NumJoysticks() > 0)
418 SDL_JoystickEventState(SDL_DISABLE
);
419 for (int i
= 0 ; i
< SDL_NumJoysticks() ; i
++)
421 debug(("Closing Joystick #%d - %s...\n", i
, SDL_JoystickName(i
)));
422 SDL_JoystickClose(config
.sdlJoystick
);
426 debug(("Closing Audio...\n"));
432 debug(("Closing TTF...\n"));
435 debug(("Closing SDL Sub System...\n"));
438 debug(("All Done.\n"));
440 if (replayData
.replayMode
== REPLAY_MODE::PLAYBACK
)
442 printf("\n==== ACTUAL PLAYBACK DATA ====\n");
443 replayData
.printReplayInformation();