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