]> git.jsancho.org Git - lugaru.git/blob - Source/Game.h
Some cleans, some duplicated code corrected.
[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 campaignlocationx[50];
148                 int campaignlocationy[50];
149                 int campaignchoicenum;
150                 int campaignchoicewhich[10];
151                 int whichchoice;
152
153                 int numlevelspassed;
154                 int levelorder[5000];
155                 int levelvisible[50];
156                 int levelhighlight[50];
157
158                 bool minimap;
159
160                 int musictype,oldmusictype,oldoldmusictype;
161                 bool realthreat;
162
163                 Model rabbit;
164                 XYZ rabbitcoords;
165
166                 XYZ mapcenter;
167                 float mapradius;
168
169                 Text text;
170                 float fps;
171
172                 XYZ cameraloc;
173                 float cameradist;
174
175                 int drawtoggle;
176
177                 bool editorenabled;
178                 int editortype;
179                 float editorsize;
180                 float editorrotation;
181                 float editorrotation2;
182
183                 float brightness;
184
185                 int quit;
186                 int tryquit;
187
188                 XYZ pathpoint[30];
189                 int numpathpoints;
190                 int numpathpointconnect[30];
191                 int pathpointconnect[30][30];
192                 int pathpointselected;
193
194                 int endgame;
195                 bool scoreadded;
196                 int numchallengelevels;
197
198                 bool console;
199                 int archiveselected;
200                 char consoletext[15][256];
201                 int consolechars[15];
202                 bool chatting;
203                 char displaytext[15][256];
204                 int displaychars[15];
205                 float displaytime[15];
206                 float displayblinkdelay;
207                 bool displayblink;
208                 int displayselected;
209                 bool consolekeydown;
210                 float consoleblinkdelay;
211                 bool consoleblink;
212                 int consoleselected;
213                 bool autocam;
214
215                 unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey;
216                 bool oldattackkey;
217
218                 static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
219                 static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
220                 static void LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
221                 static void LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload);
222                 void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
223         bool AddClothes(const char *fileName, GLubyte *array);
224                 void InitGame();
225                 void LoadScreenTexture();
226                 void LoadStuff();
227                 void LoadingScreen();
228                 void LoadCampaign();
229                 void FadeLoadingScreen(float howmuch);
230                 void Dispose();
231                 int DrawGLScene(StereoSide side);
232                 void DrawMenu();
233                 void DrawGL();
234         //factored from Tick() -sf17k
235                 void MenuTick();
236         void doTutorial();
237         void doDebugKeys();
238                 void doJumpReversals();
239                 void doAerialAcrobatics();
240                 void doAttacks();
241                 void doPlayerCollisions();
242                 void doAI(int i);
243         //end factored
244                 void Tick();
245                 void TickOnce();
246                 void TickOnceAfter();
247                 void SetUpLighting();
248                 void Loadlevel(int which);
249                 void Loadlevel(const char *name);
250                 void Setenvironment(int which);
251                 GLvoid ReSizeGLScene(float fov, float near);
252                 int findPathDist(int start,int end);
253                 int checkcollide(XYZ startpoint, XYZ endpoint);
254                 int checkcollide(XYZ startpoint, XYZ endpoint, int what);
255                 int loading;
256                 float talkdelay;
257                 
258                 void fireSound(int sound=fireendsound);
259                 void setKeySelected();
260
261                 int numboundaries;
262                 XYZ boundary[360];
263
264                 int whichlevel;
265                 int oldenvironment;
266                 int targetlevel;
267                 float changedelay;
268
269                 float musicvolume[4];
270                 float oldmusicvolume[4];
271                 int musicselected;
272                 int change;
273                 Game();
274                 ~Game() {
275                         for(int i=0;i<10;i++){
276                                 if(Mainmenuitems[i])glDeleteTextures( 1, &Mainmenuitems[i] );
277                         }
278                         glDeleteTextures( 1, &cursortexture );
279                         glDeleteTextures( 1, &Maparrowtexture );
280                         glDeleteTextures( 1, &Mapboxtexture );
281                         glDeleteTextures( 1, &Mapcircletexture );
282                         glDeleteTextures( 1, &terraintexture );
283                         glDeleteTextures( 1, &terraintexture2 );
284                         if(screentexture>0)glDeleteTextures( 1, &screentexture );
285                         if(screentexture2>0)glDeleteTextures( 1, &screentexture2 );
286                         glDeleteTextures( 1, &hawktexture );
287                         glDeleteTextures( 1, &logotexture );
288                         glDeleteTextures( 1, &loadscreentexture );
289
290                         Dispose();
291                 }
292                 bool isWaiting() { return waiting; };
293         private:
294                 void setKeySelected_thread();
295                 static int thread(void *data);
296                 void inputText(char* str, int* charselected, int* nb_chars);
297                 void flash();
298                 bool waiting;
299                 //int mainmenu;
300                 Account* accountactive;
301 };
302
303 //keeps track of which textures are loaded
304 //TODO: delete them properly
305 struct TextureInfo{
306     bool isLoaded;
307     bool isSkin;
308     const char* fileName;
309     GLuint* ptextureid;
310     int mipmap;
311     bool hasalpha;
312     GLubyte* array;
313     int* skinsize;
314
315     void load(){
316         if(isSkin)
317             Game::LoadTextureSaveData(fileName,ptextureid,mipmap,array,skinsize,isLoaded);
318         else
319             Game::LoadTextureData(fileName,ptextureid,mipmap,hasalpha);
320         isLoaded=true;
321     }
322     TextureInfo(const char *_fileName, GLuint *_ptextureid,int _mipmap, bool _hasalpha):
323         isLoaded(false), isSkin(false), array(NULL), skinsize(NULL),
324         fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), hasalpha(_hasalpha) { }
325     TextureInfo(const char *_fileName, GLuint *_ptextureid, int _mipmap, GLubyte *_array, int *_skinsize):
326         isLoaded(false), isSkin(true), hasalpha(false),
327         fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), array(_array), skinsize(_skinsize) { }
328 };
329
330 #ifndef __forceinline
331 #  ifdef __GNUC__
332 #    define __forceinline inline __attribute__((always_inline))
333 #  endif
334 #endif
335
336 static __forceinline void swap_gl_buffers(void)
337 {
338     SDL_GL_SwapBuffers();
339 }
340
341 extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
342 //#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
343 #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
344 //#define STUBBED(x)
345
346 extern int numplayers;
347
348 extern int numdialogues;
349 const int max_dialogues = 20;
350 const int max_dialoguelength = 20;
351 extern int numdialogueboxes[max_dialogues];
352 extern int dialoguetype[max_dialogues];
353 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
354 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
355 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
356 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
357 extern char dialoguename[max_dialogues][max_dialoguelength][64];
358 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
359 extern XYZ participantlocation[max_dialogues][10];
360 extern int participantfocus[max_dialogues][max_dialoguelength];
361 extern int participantaction[max_dialogues][max_dialoguelength];
362 extern float participantrotation[max_dialogues][10];
363 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
364 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
365 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
366 extern int indialogue;
367 extern int whichdialogue;
368 extern int directing;
369 extern float dialoguetime;
370 extern int dialoguegonethrough[20];
371
372 enum maptypes {
373   mapkilleveryone, mapgosomewhere,
374   mapkillsomeone, mapkillmost // These two are unused
375 };
376
377 enum pathtypes {wpkeepwalking, wppause};
378
379 static const char *pathtypenames[] = {"keepwalking", "pause"};
380
381 enum editortypes {typeactive, typesitting, typesittingwall, typesleeping,
382                   typedead1, typedead2, typedead3, typedead4};
383
384 static const char *editortypenames[] = {
385   "active", "sitting", "sitting wall", "sleeping",
386   "dead1", "dead2", "dead3", "dead4"
387 };
388
389 #endif