1 /* Tower Toppler - Nebulus
2 * Copyright (C) 2000-2012 Andreas R�ver
3 *
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.
8
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. See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "game.h"
20 #include "archi.h"
21 #include "menu.h"
22 #include "decl.h"
23 #include "sound.h"
24 #include "level.h"
25 #include "configuration.h"
26 #include "highscore.h"
27
28 #include <stdlib.h>
29 #include <time.h>
30 #include <string.h>
31 #include <unistd.h>
32
33 #include <stdexcept>
34
35 #if ENABLE_NLS == 1
36 #include <libintl.h>
37 #include <sys/types.h>
38 #include <dirent.h>
39 #endif
40
printhelp(void)41 static void printhelp(void) {
42 printf(_("\n\tOptions:\n\n -f\tEnable fullscreen mode\n -s\tSilence, disable all sound\n -dX\tSet debug level to X (default: %i)\n"), config.debug_level());
43 }
44
parse_arguments(int argc,char * argv[])45 static bool parse_arguments(int argc, char *argv[]) {
46 for (int t = 1; t < argc; t++) {
47 if (!strncmp(argv[t], "-f", 2)) config.fullscreen(true);
48 else if (!strncmp(argv[t], "-s", 2)) config.nosound(true);
49 else if (strstr(argv[t], "-d") == argv[t]) {
50 char parm = argv[t][2];
51 if (parm >= '0' && parm <= '9') {
52 printf(_("Debug level is now %c.\n"), parm);
53 config.debug_level(parm - '0');
54 } else printf(_("Illegal debug level value, using default.\n"));
55 } else {
56 printhelp();
57 return false;
58 }
59 }
60 return true;
61 }
62
startgame(void)63 static void startgame(void) {
64
65 lev_findmissions();
66 gam_init();
67 men_init();
68 snd_init();
69 if (!config.nomusic())
70 snd_playTitle();
71 men_main();
72 if (!config.nomusic())
73 snd_stopTitle();
74 lev_done();
75 snd_done();
76 gam_done();
77 }
78
QuitFunction(void)79 static void QuitFunction(void) {
80 SDL_Quit();
81 }
82
main(int argc,char * argv[])83 int main(int argc, char *argv[]) {
84
85 // The following line was moved from a global variable to a pointer.
86 // This was to allow the Mac OS X version of SDL to reposition the current
87 // working directory so that the hardcoded paths in the binary to point
88 // to the right spot without a lot of jiggery pokery.
89 // - jasonk@toast442.org
90
91 dataarchive = new archive(open_data_file("toppler.dat"));
92
93 #if ENABLE_NLS == 1
94 setlocale(LC_MESSAGES, "");
95 setlocale(LC_CTYPE, "");
96
97 DIR *dir = opendir("locale");
98 bindtextdomain("toppler", dir == NULL ? LOCALEDIR : "locale");
99 if (dir)
100 closedir(dir);
101 textdomain("toppler");
102 #endif
103
104 printf(_("Nebulous version %s"), VERSION);
105 printf("\n");
106
107 hsc_init();
108
109 if (parse_arguments(argc, argv)) {
110 SDL_InitSubSystem(SDL_INIT_VIDEO);
111 SDL_WM_SetCaption(_("Nebulous"), NULL);
112
113 int mouse = SDL_ShowCursor(config.fullscreen() ? 0 : 1);
114 tt_has_focus = true;
115 atexit(QuitFunction);
116 srand(time(0));
117 startgame();
118 printf(_("Thanks for playing!\n"));
119 SDL_ShowCursor(mouse);
120 SDL_Quit();
121 }
122
123 return 0;
124 }
125