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