Debug system v2 -- now, it supports debug levels, there's a global level, but overrid...
[dbw.git] / src / main.cpp
blobde6d6da37b85dac8cfe8ed24edefd92a71212f29
1 /*
2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "CAudio.h"
23 #include "CEngine.h"
24 #include "CGame.h"
25 #include "CGameData.h"
26 #include "CGraphics.h"
27 #include "CMap.h"
28 #include "config.h"
29 #include "defs.h"
30 #include "main.h"
32 // for sucking SDL implementation on windows
33 // -- no, we don't need SDL_main!!!
34 #undef main
36 // Global variables
37 Audio audio;
38 Engine engine;
39 Game game;
40 GameData gameData;
41 Graphics graphics;
42 Map map;
44 Entity defEnemy[MAX_ENEMIES];
45 Entity defItem[MAX_ITEMS];
46 Entity player;
47 Weapon weapon[MAX_WEAPONS];
50 void showHelp()
52 printf("\n");
53 printf("DirtY BLoB WaRs (Version %s)\n", VERSION);
54 printf("Copyright (C) 2004 Parallel Realities\n");
55 printf("Copyright (C) 2007-2008 Kovago Zoltan and contributors\n");
56 printf("Licensed under the GNU General Public License (GPL)\n\n");
58 // printf("The DirtY BLoB WaRs gameplay manual can be found in,\n");
59 // printf("\t%s\n\n", GAMEPLAYMANUAL);
61 printf("Additional Commands\n");
62 printf("\t--fullscreen Start the game in Full Screen mode\n");
63 printf("\t--mono Use mono sound output instead of stereo\n");
64 printf("\t--noaudio Disables audio\n");
65 printf("\t--version Display version number\n");
66 printf("\t--help This help\n\n");
68 exit(0);
71 void showVersion()
73 printf("DirtY BLoB WaRs version: %s, branch: %s\n", VERSION, BRANCH);
75 // showVersion is the command name, and not showVersionAndCopyright !!!
76 /* printf("Copyright (C) 2004 Parallel Realities\nCopyright (C) 2007 Kovago Zoltan\n");
77 printf("Licensed under the GNU General Public License (GPL)\n\n");*/
78 exit(0);
81 int main(int argc, char *argv[])
83 int requiredSection = SECTION_INTRO;
84 bool showSprites = false;
85 bool hub = false;
87 for (int i = 1 ; i < argc ; i++)
89 if (strcmp(argv[i], "--fullscreen") == 0) engine.fullScreen = true;
90 else if (strcmp(argv[i], "--noaudio") == 0) engine.useAudio = 0;
91 else if (strcmp(argv[i], "--mono") == 0) engine.useAudio = 1;
92 else if (strcmp(argv[i], "--version") == 0) showVersion();
93 else if (strcmp(argv[i], "--help") == 0) showHelp();
95 // DEBUG
96 #ifdef DEBUG
97 else if (strcmp(argv[i], "--show-func") == 0) DebugStream::show_func = true;
98 else if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--debug") == 0)) DebugLevelManager::ParseOpts(argv[++i]);
99 #endif
100 else if (strcmp(argv[i], "--map") == 0) {game.setMapName(argv[++i]); requiredSection = SECTION_GAME;}
101 else if (strcmp(argv[i], "--skill") == 0) game.skill = atoi(argv[++i]);
102 else if (strcmp(argv[i], "--showsprites") == 0) showSprites = true;
103 else if (strcmp(argv[i], "--hub") == 0) hub = true;
104 else if (strcmp(argv[i], "--randomscreens") == 0) graphics.takeRandomScreenShots = true;
105 /// @todo Move devNoMonsters to cheats..
106 else if (strcmp(argv[i], "--nomonsters") == 0) engine.devNoMonsters = true;
107 /// @todo Add a credits options to menu
108 else if (strcmp(argv[i], "--credits") == 0) requiredSection = SECTION_CREDITS;
109 else warning << "Unknown parameter '" << argv[i] << "', ignored.." << std::endl;
112 #if DEMO
113 game.setMapName("data/floodedTunnel1");
114 requiredSection = SECTION_GAME;
115 game.skill = 1;
116 #endif
118 atexit(cleanup);
120 initSystem(argv[0]);
122 player.setName("Player");
124 engine.flushInput();
126 engine.allowQuit = true;
128 if (hub)
130 requiredSection = SECTION_HUB;
131 loadGame(0);
132 loadResources();
135 if (game.skill == 3)
137 game.hasAquaLung = game.hasJetPack = true;
140 if (showSprites)
142 showAllSprites();
145 while (true)
147 switch (requiredSection)
149 case SECTION_INTRO:
150 requiredSection = doIntro();
151 break;
153 case SECTION_TITLE:
154 requiredSection = title();
155 break;
157 case SECTION_HUB:
158 requiredSection = doHub();
159 break;
161 case SECTION_GAME:
162 if (!game.continueFromCheckPoint)
164 #if DEMO
165 showDemoStart();
166 #endif
167 checkStartCutscene();
168 loadResources();
170 requiredSection = doGame();
171 break;
173 case SECTION_GAMEOVER:
174 requiredSection = gameover();
175 break;
177 case SECTION_EASYOVER:
178 map.clear();
179 game.clear();
180 easyGameFinished();
181 requiredSection = SECTION_TITLE;
182 break;
184 case SECTION_CREDITS:
185 doCredits();
186 requiredSection = SECTION_TITLE;
187 break;
191 return 0;