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