]> git.jsancho.org Git - lugaru.git/blob - Source/Game.h
Remove Constants.h
[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 class Game
65 {
66         public:
67                 typedef std::map<std::string, GLuint> TextureList;
68                 typedef std::map<GLuint, std::string> GLTextureList;
69                 typedef TextureList::iterator TexIter;
70                 static TextureList textures;
71
72                 GLuint terraintexture;
73                 GLuint terraintexture2;
74                 GLuint terraintexture3;
75                 GLuint screentexture;
76                 GLuint screentexture2;
77                 GLuint logotexture;
78                 GLuint loadscreentexture;
79                 GLuint Maparrowtexture;
80                 GLuint Mapboxtexture;
81                 GLuint Mapcircletexture;
82                 GLuint cursortexture;
83                 GLuint Mainmenuitems[10];
84
85                 int nummenuitems;
86                 int startx[100];
87                 int starty[100];
88                 int endx[100];
89                 int endy[100];
90                 float selectedlong[100];
91                 float offsetx[100];
92                 float offsety[100];
93                 float movex[100];
94                 float movey[100];
95                 float transition;
96                 int anim;
97                 int selected;
98                 int keyselect;
99                 int loaddistrib;
100                 int indemo;
101
102                 bool won;
103
104                 bool entername;
105
106                 char menustring[100][256];
107                 char registrationname[256];
108                 float registrationnumber;
109
110                 int newdetail;
111                 int newscreenwidth;
112                 int newscreenheight;
113
114                 bool gameon;
115                 float deltah,deltav;
116                 int mousecoordh,mousecoordv;
117                 int oldmousecoordh,oldmousecoordv;
118                 float rotation,rotation2;
119                 SkyBox skybox;
120                 bool cameramode;
121                 bool cameratogglekeydown;
122                 bool chattogglekeydown;
123                 int olddrawmode;
124                 int drawmode;
125                 bool drawmodetogglekeydown;
126                 bool explodetogglekeydown;
127                 bool detailtogglekeydown;
128                 bool firstload;
129                 bool oldbutton;
130
131                 float leveltime;
132                 float loadtime;
133
134                 Model hawk;
135                 XYZ hawkcoords;
136                 XYZ realhawkcoords;
137                 GLuint hawktexture;
138                 float hawkrotation;
139                 float hawkcalldelay;
140
141                 Model eye;
142                 Model iris;
143                 Model cornea;
144
145                 bool stealthloading;
146
147                 int campaignnumlevels;
148                 char campaignmapname[50][256];
149                 char campaigndescription[50][256];
150                 int campaignchoosenext[50];
151                 int campaignnumnext[50];
152                 int campaignnextlevel[50][10];
153                 int campaignchoicesmade;
154                 int campaignchoices[5000];
155                 int campaignlocationx[50];
156                 int campaignlocationy[50];
157                 int campaignchoicenum;
158                 int campaignchoicewhich[10];
159                 int whichchoice;
160
161                 int numlevelspassed;
162                 int levelorder[5000];
163                 int levelvisible[50];
164                 int levelhighlight[50];
165
166                 bool minimap;
167
168                 int musictype,oldmusictype,oldoldmusictype;
169                 bool realthreat;
170
171                 Model rabbit;
172                 XYZ rabbitcoords;
173
174                 XYZ mapcenter;
175                 float mapradius;
176
177                 Text text;
178                 float fps;
179
180                 XYZ cameraloc;
181                 float cameradist;
182
183                 bool envtogglekeydown;
184                 bool slomotogglekeydown;
185                 bool texturesizetogglekeydown;
186                 bool freezetogglekeydown;
187                 int drawtoggle;
188
189                 bool editorenabled;
190                 int editortype;
191                 float editorsize;
192                 float editorrotation;
193                 float editorrotation2;
194
195                 float brightness;
196
197                 int quit;
198                 int tryquit;
199
200                 XYZ pathpoint[30];
201                 int numpathpoints;
202                 int numpathpointconnect[30];
203                 int pathpointconnect[30][30];
204                 int pathpointselected;
205
206                 int endgame;
207                 bool scoreadded;
208                 int numchallengelevels;
209
210                 bool console;
211                 int archiveselected;
212                 char consoletext[15][256];
213                 int consolechars[15];
214                 bool chatting;
215                 char displaytext[15][256];
216                 int displaychars[15];
217                 float displaytime[15];
218                 float displayblinkdelay;
219                 bool displayblink;
220                 int displayselected;
221                 bool consolekeydown;
222                 bool consoletogglekeydown;
223                 float consoleblinkdelay;
224                 bool consoleblink;
225                 int consoleselected;
226                 //int togglekey[140];
227                 //float togglekeydelay[140];
228                 bool registernow;
229                 bool autocam;
230
231                 unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey;
232                 bool oldattackkey;
233
234                 static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
235                 static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
236                 void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
237                 bool AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
238                 void InitGame();
239                 void LoadStuff();
240                 void LoadingScreen();
241                 void FadeLoadingScreen(float howmuch);
242                 void Dispose();
243                 int DrawGLScene(StereoSide side);
244                 void DrawGL();
245                 void Tick();
246                 void TickOnce();
247                 void TickOnceAfter();
248                 void SetUpLighting();
249                 void Loadlevel(int which);
250                 void Loadlevel(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                 bool mainmenutogglekeydown;
301                 //int mainmenu;
302                 Account* accountactive;
303 };
304
305 #ifndef __forceinline
306 #  ifdef __GNUC__
307 #    define __forceinline inline __attribute__((always_inline))
308 #  endif
309 #endif
310
311 static __forceinline void swap_gl_buffers(void)
312 {
313     SDL_GL_SwapBuffers();
314 }
315
316 extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
317 //#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
318 #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
319 //#define STUBBED(x)
320
321 extern int numplayers;
322
323 extern int numdialogues;
324 const int max_dialogues = 20;
325 const int max_dialoguelength = 20;
326 extern int numdialogueboxes[max_dialogues];
327 extern int dialoguetype[max_dialogues];
328 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
329 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
330 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
331 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
332 extern char dialoguename[max_dialogues][max_dialoguelength][64];
333 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
334 extern XYZ participantlocation[max_dialogues][10];
335 extern int participantfocus[max_dialogues][max_dialoguelength];
336 extern int participantaction[max_dialogues][max_dialoguelength];
337 extern float participantrotation[max_dialogues][10];
338 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
339 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
340 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
341 extern int indialogue;
342 extern int whichdialogue;
343 extern int directing;
344 extern float dialoguetime;
345 extern int dialoguegonethrough[20];
346
347 enum maptypes {
348   mapkilleveryone, mapgosomewhere,
349   mapkillsomeone, mapkillmost // These two are unused
350 };
351
352 enum pathtypes {wpkeepwalking, wppause};
353
354 static const char *pathtypenames[] = {"keepwalking", "pause"};
355
356 enum editortypes {typeactive, typesitting, typesittingwall, typesleeping,
357                   typedead1, typedead2, typedead3, typedead4};
358
359 static const char *editortypenames[] = {
360   "active", "sitting", "sitting wall", "sleeping",
361   "dead1", "dead2", "dead3", "dead4"
362 };
363
364 #endif