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