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