]> git.jsancho.org Git - lugaru.git/blob - Source/Game.h
MAJOR cleanup
[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                 int olddrawmode;
122                 int drawmode;
123                 bool firstload;
124                 bool oldbutton;
125
126                 float leveltime;
127                 float loadtime;
128
129                 Model hawk;
130                 XYZ hawkcoords;
131                 XYZ realhawkcoords;
132                 GLuint hawktexture;
133                 float hawkrotation;
134                 float hawkcalldelay;
135
136                 Model eye;
137                 Model iris;
138                 Model cornea;
139
140                 bool stealthloading;
141
142                 int campaignnumlevels;
143                 char campaignmapname[50][256];
144                 char campaigndescription[50][256];
145                 int campaignchoosenext[50];
146                 int campaignnumnext[50];
147                 int campaignnextlevel[50][10];
148                 int campaignchoicesmade;
149                 int campaignchoices[5000];
150                 int campaignlocationx[50];
151                 int campaignlocationy[50];
152                 int campaignchoicenum;
153                 int campaignchoicewhich[10];
154                 int whichchoice;
155
156                 int numlevelspassed;
157                 int levelorder[5000];
158                 int levelvisible[50];
159                 int levelhighlight[50];
160
161                 bool minimap;
162
163                 int musictype,oldmusictype,oldoldmusictype;
164                 bool realthreat;
165
166                 Model rabbit;
167                 XYZ rabbitcoords;
168
169                 XYZ mapcenter;
170                 float mapradius;
171
172                 Text text;
173                 float fps;
174
175                 XYZ cameraloc;
176                 float cameradist;
177
178                 int drawtoggle;
179
180                 bool editorenabled;
181                 int editortype;
182                 float editorsize;
183                 float editorrotation;
184                 float editorrotation2;
185
186                 float brightness;
187
188                 int quit;
189                 int tryquit;
190
191                 XYZ pathpoint[30];
192                 int numpathpoints;
193                 int numpathpointconnect[30];
194                 int pathpointconnect[30][30];
195                 int pathpointselected;
196
197                 int endgame;
198                 bool scoreadded;
199                 int numchallengelevels;
200
201                 bool console;
202                 int archiveselected;
203                 char consoletext[15][256];
204                 int consolechars[15];
205                 bool chatting;
206                 char displaytext[15][256];
207                 int displaychars[15];
208                 float displaytime[15];
209                 float displayblinkdelay;
210                 bool displayblink;
211                 int displayselected;
212                 bool consolekeydown;
213                 float consoleblinkdelay;
214                 bool consoleblink;
215                 int consoleselected;
216                 bool autocam;
217
218                 unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey;
219                 bool oldattackkey;
220
221                 static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
222                 static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
223                 void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
224                 bool AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
225                 void InitGame();
226                 void LoadStuff();
227                 void LoadingScreen();
228                 void FadeLoadingScreen(float howmuch);
229                 void Dispose();
230                 int DrawGLScene(StereoSide side);
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 #ifndef __forceinline
302 #  ifdef __GNUC__
303 #    define __forceinline inline __attribute__((always_inline))
304 #  endif
305 #endif
306
307 static __forceinline void swap_gl_buffers(void)
308 {
309     SDL_GL_SwapBuffers();
310 }
311
312 extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
313 //#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
314 #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
315 //#define STUBBED(x)
316
317 extern int numplayers;
318
319 extern int numdialogues;
320 const int max_dialogues = 20;
321 const int max_dialoguelength = 20;
322 extern int numdialogueboxes[max_dialogues];
323 extern int dialoguetype[max_dialogues];
324 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
325 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
326 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
327 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
328 extern char dialoguename[max_dialogues][max_dialoguelength][64];
329 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
330 extern XYZ participantlocation[max_dialogues][10];
331 extern int participantfocus[max_dialogues][max_dialoguelength];
332 extern int participantaction[max_dialogues][max_dialoguelength];
333 extern float participantrotation[max_dialogues][10];
334 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
335 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
336 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
337 extern int indialogue;
338 extern int whichdialogue;
339 extern int directing;
340 extern float dialoguetime;
341 extern int dialoguegonethrough[20];
342
343 enum maptypes {
344   mapkilleveryone, mapgosomewhere,
345   mapkillsomeone, mapkillmost // These two are unused
346 };
347
348 enum pathtypes {wpkeepwalking, wppause};
349
350 static const char *pathtypenames[] = {"keepwalking", "pause"};
351
352 enum editortypes {typeactive, typesitting, typesittingwall, typesleeping,
353                   typedead1, typedead2, typedead3, typedead4};
354
355 static const char *editortypenames[] = {
356   "active", "sitting", "sitting wall", "sleeping",
357   "dead1", "dead2", "dead3", "dead4"
358 };
359
360 #endif