]> git.jsancho.org Git - lugaru.git/blob - Source/Game.h
little cleanup about campaign level handling
[lugaru.git] / Source / Game.h
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru 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 #ifndef _GAME_H_
23 #define _GAME_H_
24
25 #include "SDL.h"
26
27 #if (defined(__APPLE__) && defined(__MACH__))
28 #  ifdef PLATFORM_MACOSX
29 #    error Do not define PLATFORM_MACOSX for new builds. It is for the old Carbonized build.
30 #  endif
31 #endif
32
33 #ifdef PLATFORM_MACOSX
34 #include <Carbon.h>
35 #include "Quicktime.h"
36 #endif
37
38 //Jordan included glut.h
39 //#include <glut.h>
40
41 #include "TGALoader.h"
42
43 #include "Terrain.h"
44 #include "Skybox.h"
45 #include "Skeleton.h"
46 #include "Models.h"
47 #include "Lights.h"
48 #include "Person.h"
49 #include "Sprite.h"
50 //#include <agl.h>
51 #include "Text.h"
52 #include "Objects.h"
53 //#include <DrawSprocket.h>
54 #include "Weapons.h"
55 #include "binio.h"
56 #include <fstream>
57 #include "gamegl.h"
58 #include "Stereo.h"
59 #include "Account.h"
60 #include "Sounds.h"
61
62 #define NB_CAMPAIGN_MENU_ITEM 7
63
64 extern GLuint rabbittexture;
65
66 struct TextureInfo;
67
68 class Game
69 {
70         public:
71                 static std::vector<TextureInfo> textures;
72
73                 GLuint terraintexture;
74                 GLuint terraintexture2;
75                 GLuint terraintexture3;
76                 GLuint screentexture;
77                 GLuint screentexture2;
78                 GLuint logotexture;
79                 GLuint loadscreentexture;
80                 GLuint Maparrowtexture;
81                 GLuint Mapboxtexture;
82                 GLuint Mapcircletexture;
83                 GLuint cursortexture;
84                 GLuint Mainmenuitems[10];
85
86                 int nummenuitems;
87                 int startx[100];
88                 int starty[100];
89                 int endx[100];
90                 int endy[100];
91                 float selectedlong[100];
92                 float offsetx[100];
93                 float offsety[100];
94                 int selected;
95                 int keyselect;
96                 int indemo;
97
98                 bool won;
99
100                 bool entername;
101
102                 char menustring[100][256];
103                 char registrationname[256];
104                 float registrationnumber;
105
106                 int newdetail;
107                 int newscreenwidth;
108                 int newscreenheight;
109
110                 bool gameon;
111                 float deltah,deltav;
112                 int mousecoordh,mousecoordv;
113                 int oldmousecoordh,oldmousecoordv;
114                 float rotation,rotation2;
115                 SkyBox skybox;
116                 bool cameramode;
117                 int olddrawmode;
118                 int drawmode;
119                 bool firstload;
120                 bool oldbutton;
121
122                 float leveltime;
123                 float loadtime;
124
125                 Model hawk;
126                 XYZ hawkcoords;
127                 XYZ realhawkcoords;
128                 GLuint hawktexture;
129                 float hawkrotation;
130                 float hawkcalldelay;
131
132                 Model eye;
133                 Model iris;
134                 Model cornea;
135
136                 bool stealthloading;
137
138                 int campaignnumlevels;
139                 char campaignmapname[50][256];
140                 char campaigndescription[50][256];
141                 int campaignchoosenext[50];
142                 int campaignnumnext[50]; // 0 on final level. As David said: he meant to add story branching, but he eventually hadn't. 
143                 int campaignnextlevel[50][10];
144                 int campaignlocationx[50];
145                 int campaignlocationy[50];
146                 int whichchoice;
147                 int actuallevel;
148
149                 bool minimap;
150
151                 int musictype,oldmusictype,oldoldmusictype;
152                 bool realthreat;
153
154                 Model rabbit;
155                 XYZ rabbitcoords;
156
157                 XYZ mapcenter;
158                 float mapradius;
159
160                 Text text;
161                 float fps;
162
163                 XYZ cameraloc;
164                 float cameradist;
165
166                 int drawtoggle;
167
168                 bool editorenabled;
169                 int editortype;
170                 float editorsize;
171                 float editorrotation;
172                 float editorrotation2;
173
174                 float brightness;
175
176                 int quit;
177                 int tryquit;
178
179                 XYZ pathpoint[30];
180                 int numpathpoints;
181                 int numpathpointconnect[30];
182                 int pathpointconnect[30][30];
183                 int pathpointselected;
184
185                 int endgame;
186                 bool scoreadded;
187                 int numchallengelevels;
188
189                 bool console;
190                 int archiveselected;
191                 char consoletext[15][256];
192                 int consolechars[15];
193                 bool chatting;
194                 char displaytext[15][256];
195                 int displaychars[15];
196                 float displaytime[15];
197                 float displayblinkdelay;
198                 bool displayblink;
199                 int displayselected;
200                 bool consolekeydown;
201                 float consoleblinkdelay;
202                 bool consoleblink;
203                 int consoleselected;
204                 bool autocam;
205
206                 unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey;
207                 bool oldattackkey;
208
209                 static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
210                 static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
211                 static void LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
212                 static void LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload);
213                 void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
214         bool AddClothes(const char *fileName, GLubyte *array);
215                 void InitGame();
216                 void LoadScreenTexture();
217                 void LoadStuff();
218                 void LoadingScreen();
219                 void LoadCampaign();
220                 static std::vector<std::string> ListCampaigns();
221                 void FadeLoadingScreen(float howmuch);
222                 void Dispose();
223                 int DrawGLScene(StereoSide side);
224                 void DrawMenu();
225                 void DrawGL();
226         //factored from Tick() -sf17k
227                 void MenuTick();
228         void doTutorial();
229         void doDebugKeys();
230                 void doJumpReversals();
231                 void doAerialAcrobatics();
232                 void doAttacks();
233                 void doPlayerCollisions();
234                 void doAI(int i);
235         //end factored
236                 void Tick();
237                 void TickOnce();
238                 void TickOnceAfter();
239                 void SetUpLighting();
240                 void Loadlevel(int which);
241                 void Loadlevel(const char *name);
242                 void Setenvironment(int which);
243                 GLvoid ReSizeGLScene(float fov, float near);
244                 int findPathDist(int start,int end);
245                 int checkcollide(XYZ startpoint, XYZ endpoint);
246                 int checkcollide(XYZ startpoint, XYZ endpoint, int what);
247                 int loading;
248                 float talkdelay;
249                 
250                 void fireSound(int sound=fireendsound);
251                 void setKeySelected();
252
253                 int numboundaries;
254                 XYZ boundary[360];
255
256                 int whichlevel;
257                 int oldenvironment;
258                 int targetlevel;
259                 float changedelay;
260
261                 float musicvolume[4];
262                 float oldmusicvolume[4];
263                 int musicselected;
264                 int change;
265                 Game();
266                 ~Game() {
267                         for(int i=0;i<10;i++){
268                                 if(Mainmenuitems[i])glDeleteTextures( 1, &Mainmenuitems[i] );
269                         }
270                         glDeleteTextures( 1, &cursortexture );
271                         glDeleteTextures( 1, &Maparrowtexture );
272                         glDeleteTextures( 1, &Mapboxtexture );
273                         glDeleteTextures( 1, &Mapcircletexture );
274                         glDeleteTextures( 1, &terraintexture );
275                         glDeleteTextures( 1, &terraintexture2 );
276                         if(screentexture>0)glDeleteTextures( 1, &screentexture );
277                         if(screentexture2>0)glDeleteTextures( 1, &screentexture2 );
278                         glDeleteTextures( 1, &hawktexture );
279                         glDeleteTextures( 1, &logotexture );
280                         glDeleteTextures( 1, &loadscreentexture );
281
282                         Dispose();
283                 }
284                 bool isWaiting() { return waiting; };
285         private:
286                 void setKeySelected_thread();
287                 static int thread(void *data);
288                 void inputText(char* str, int* charselected, int* nb_chars);
289                 void flash();
290                 bool waiting;
291                 //int mainmenu;
292                 Account* accountactive;
293 };
294
295 //keeps track of which textures are loaded
296 //TODO: delete them properly
297 struct TextureInfo {
298     bool isLoaded;
299     bool isSkin;
300     const char* fileName;
301     GLuint* ptextureid;
302     int mipmap;
303     bool hasalpha;
304     GLubyte* array;
305     int* skinsize;
306
307     void load() {
308         if(isSkin)
309             Game::LoadTextureSaveData(fileName,ptextureid,mipmap,array,skinsize,isLoaded);
310         else
311             Game::LoadTextureData(fileName,ptextureid,mipmap,hasalpha);
312         isLoaded=true;
313     }
314     TextureInfo(const char *_fileName, GLuint *_ptextureid,int _mipmap, bool _hasalpha):
315         isLoaded(false), isSkin(false), array(NULL), skinsize(NULL),
316         fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), hasalpha(_hasalpha) { }
317     TextureInfo(const char *_fileName, GLuint *_ptextureid, int _mipmap, GLubyte *_array, int *_skinsize):
318         isLoaded(false), isSkin(true), hasalpha(false),
319         fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), array(_array), skinsize(_skinsize) { }
320 };
321
322 #ifndef __forceinline
323 #  ifdef __GNUC__
324 #    define __forceinline inline __attribute__((always_inline))
325 #  endif
326 #endif
327
328 static __forceinline void swap_gl_buffers(void)
329 {
330     SDL_GL_SwapBuffers();
331 }
332
333 extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
334 //#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
335 #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
336 //#define STUBBED(x)
337
338 extern int numplayers;
339
340 extern int numdialogues;
341 const int max_dialogues = 20;
342 const int max_dialoguelength = 20;
343 extern int numdialogueboxes[max_dialogues];
344 extern int dialoguetype[max_dialogues];
345 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
346 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
347 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
348 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
349 extern char dialoguename[max_dialogues][max_dialoguelength][64];
350 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
351 extern XYZ participantlocation[max_dialogues][10];
352 extern int participantfocus[max_dialogues][max_dialoguelength];
353 extern int participantaction[max_dialogues][max_dialoguelength];
354 extern float participantrotation[max_dialogues][10];
355 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
356 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
357 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
358 extern int indialogue;
359 extern int whichdialogue;
360 extern int directing;
361 extern float dialoguetime;
362 extern int dialoguegonethrough[20];
363
364 enum maptypes {
365   mapkilleveryone, mapgosomewhere,
366   mapkillsomeone, mapkillmost // These two are unused
367 };
368
369 enum pathtypes {wpkeepwalking, wppause};
370
371 static const char *pathtypenames[] = {"keepwalking", "pause"};
372
373 enum editortypes {typeactive, typesitting, typesittingwall, typesleeping,
374                   typedead1, typedead2, typedead3, typedead4};
375
376 static const char *editortypenames[] = {
377   "active", "sitting", "sitting wall", "sleeping",
378   "dead1", "dead2", "dead3", "dead4"
379 };
380
381 #endif