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