]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/main.cpp
Add the -window option as a counterpart to -fullscreen.
[quix0rs-blobwars.git] / src / main.cpp
1 /*
2 Copyright (C) 2004-2011 Parallel Realities
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20
21 #include "main.h"
22
23 #include <locale.h>
24
25 void showHelp()
26 {
27         printf("\n");
28         printf("Blob Wars, Episode I - Metal Blob Solid (Version %.2f, Release %d)\n", VERSION, RELEASE);
29         printf("Copyright (C) 2004-2011 Parallel Realities\n");
30         printf("Licensed under the GNU General Public License (GPL)\n\n");
31
32         printf("The Metal Blob Solid gameplay manual can be found in,\n");
33         printf("\t%s\n\n", GAMEPLAYMANUAL);
34         
35         printf("Replay Commands\n");
36         printf("\t-map <filename>       Play the specified map (use -listmaps to see maps)\n");
37         printf("\t-record <filename>    Record a game and output to the specified file\n");
38         printf("\t-playback <filename>  Playback the specified recording\n");
39         printf("\t-listmaps             List the available maps for playing\n\n");
40         
41         printf("Replay Examples\n");
42         printf("\tblobwars -map data/grasslands1 -record replay.dat\n");
43         printf("\tblobwars -playback replay.dat\n\n");
44
45         printf("Additional Commands\n");
46         printf("\t-fullscreen         Start the game in Full Screen mode\n");
47         printf("\t-window             Start the game in Window mode\n");
48         printf("\t-mono               Use mono sound output instead of stereo\n");
49         printf("\t-noaudio            Disables audio\n");
50         printf("\t-version            Display version number\n");
51         printf("\t--help              This help\n\n");
52
53         exit(0);
54 }
55
56 void listMaps()
57 {
58         printf("\n");
59         printf("Blob Wars, Episode I - Metal Blob Solid (Version %.2f, Release %d)\n", VERSION, RELEASE);
60         printf("Copyright (C) 2004-2011 Parallel Realities\n");
61         printf("Licensed under the GNU General Public License (GPL)\n\n");
62         
63         printf("Available Maps\n");
64         printf("\tdata/arcticWastes\n");
65         printf("\tdata/assimilator\n");
66         printf("\tdata/caves1\n");
67         printf("\tdata/caves2\n");
68         printf("\tdata/caves3\n");
69         printf("\tdata/caves4\n");
70         printf("\tdata/comm\n");
71         printf("\tdata/finalBattle\n");
72         printf("\tdata/floodedTunnel1\n");
73         printf("\tdata/floodedTunnel2\n");
74         printf("\tdata/floodedTunnel3\n");
75         printf("\tdata/floodedTunnel4\n");
76         printf("\tdata/grasslands1\n");
77         printf("\tdata/grasslands2\n");
78         printf("\tdata/grasslands3\n");
79         printf("\tdata/hq\n");
80         printf("\tdata/icecave1\n");
81         printf("\tdata/icecave2\n");
82         printf("\tdata/spaceStation\n");
83         printf("\tdata/supply\n");
84         printf("\tdata/tomb1\n");
85         printf("\tdata/tomb2\n");
86         printf("\tdata/tomb3\n");
87         printf("\tdata/tomb4\n\n");
88         
89         exit(0);
90 }
91
92 void showVersion()
93 {
94         printf("\n");
95         printf("Blob Wars, Episode I - Metal Blob Solid (Version %.2f, Release %d)\n", VERSION, RELEASE);
96         printf("Copyright (C) 2004-2011 Parallel Realities\n");
97         printf("Licensed under the GNU General Public License (GPL)\n\n");
98 //      exit(0);
99 }
100
101 int main(int argc, char *argv[])
102 {
103         #if !USEPAK
104         debug(("Not Using PAK...\n"));
105         #endif
106
107         #if RELEASE
108         if (chdir(PAKLOCATION))
109         {
110                 perror("Could not chdir to " PAKLOCATION ":");
111                 return 1;
112         }
113         #endif
114         
115         config.engine = &engine;
116         
117         replayData.reset();
118
119         bindtextdomain("blobwars", LOCALEDIR);
120         setlocale(LC_ALL, "");
121         textdomain("blobwars");
122
123         atexit(cleanup);
124
125         bool showSprites = false;
126         bool hub = false;
127         
128         int recordMode = REPLAY_MODE::NONE;
129         int requiredSection = SECTION_INTRO;
130
131         initConfig();
132
133         for (int i = 1 ; i < argc ; i++)
134         {
135                 if (strcmp(argv[i], "-fullscreen") == 0) engine.fullScreen = true;
136                 else if (strcmp(argv[i], "-window") == 0) engine.fullScreen = false;
137                 else if (strcmp(argv[i], "-noaudio") == 0) engine.useAudio = 0;
138                 else if (strcmp(argv[i], "-mono") == 0) engine.useAudio = 1;
139                 else if (strcmp(argv[i], "-version") == 0) showVersion();
140                 else if (strcmp(argv[i], "--help") == 0) showHelp();
141                 else if (strcmp(argv[i], "-record") == 0) {recordMode = REPLAY_MODE::RECORD; strlcpy(replayData.filename, argv[++i], sizeof replayData.filename);}
142                 else if (strcmp(argv[i], "-playback") == 0) {recordMode = REPLAY_MODE::PLAYBACK; strlcpy(replayData.filename, argv[++i], sizeof replayData.filename);}
143                 else if (strcmp(argv[i], "-map") == 0) {game.setMapName(argv[++i]); requiredSection = SECTION_GAME;}
144                 else if (strcmp(argv[i], "-listmaps") == 0) listMaps();
145                 else if (strcmp(argv[i], "-credits") == 0) requiredSection = SECTION_CREDITS;
146                 
147                 #if DEBUG
148                 else if (strcmp(argv[i], "-showsprites") == 0) showSprites = true;
149                 else if (strcmp(argv[i], "-hub") == 0) hub = true;
150                 else if (strcmp(argv[i], "-randomscreens") == 0) graphics.takeRandomScreenShots = true;
151                 else if (strcmp(argv[i], "-nomonsters") == 0) engine.devNoMonsters = true;
152                 #endif
153
154                 else {fprintf(stderr, "Unknown argument '%s'\n", argv[i]); showHelp();}
155         }
156         
157         switch (recordMode)
158         {
159                 case REPLAY_MODE::NONE:
160                         // nothing to do...
161                         break;
162                         
163                 case REPLAY_MODE::RECORD:
164                         requiredSection = SECTION_GAME;
165                         strlcpy(replayData.header.map, game.mapName, sizeof replayData.header.map);
166                         replayData.header.skill = game.skill = 3;
167                         replayData.setMode(REPLAY_MODE::RECORD);
168                         break;
169                         
170                 case REPLAY_MODE::PLAYBACK:
171                         requiredSection = SECTION_GAME;
172                         replayData.setMode(REPLAY_MODE::PLAYBACK);
173                         replayData.header.time = 0;
174                         game.setMapName(replayData.header.map);
175                         game.skill = replayData.header.skill;
176                         break;
177         }
178
179         initSystem();
180         
181         // seed the random using the one generated
182         // via the replay data
183         Math::pSeed = replayData.header.randomSeed;
184         
185         player.setName("Player");
186
187         engine.flushInput();
188         
189         engine.allowQuit = true;
190
191         if (hub)
192         {
193                 requiredSection = SECTION_HUB;
194                 loadGame(0);
195                 loadResources();
196         }
197         
198         if (game.skill == 3)
199         {
200                 game.hasAquaLung = game.hasJetPack = true;
201         }
202
203         if (showSprites)
204         {
205                 showAllSprites();
206         }
207
208         while (true)
209         {
210                 switch (requiredSection)
211                 {
212                         case SECTION_INTRO:
213                                 requiredSection = doIntro();
214                                 break;
215
216                         case SECTION_TITLE:
217                                 requiredSection = title();
218                                 break;
219
220                         case SECTION_HUB:
221                                 requiredSection = doHub();
222                                 break;
223
224                         case SECTION_GAME:
225                                 if (!game.continueFromCheckPoint)
226                                 {
227                                         checkStartCutscene();
228                                         loadResources();
229                                 }
230                                 requiredSection = doGame();
231                                 break;
232
233                         case SECTION_GAMEOVER:
234                                 requiredSection = gameover();
235                                 break;
236                                 
237                         case SECTION_EASYOVER:
238                                 map.clear();
239                                 game.clear();
240                                 easyGameFinished();
241                                 requiredSection = SECTION_TITLE;
242                                 break;
243                                 
244                         case SECTION_CREDITS:
245                                 doCredits();
246                                 requiredSection = SECTION_TITLE;
247                                 break;
248                 }
249         }
250
251         return 0;
252 }