]> git.jsancho.org Git - lugaru.git/blob - Source/Game.h
431f3243e8f6622931416b17dae35a07ec4ba76b
[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 CampaignLevel
69 {
70 private:
71         int width;
72         struct Position
73         {
74                 int x;
75                 int y;
76         };
77 public: 
78         std::string mapname;
79         std::string description;
80         int choosenext;
81                 /*      
82                 0 = Immediately load next level at the end of this one.
83                 1 = Go back to the world map.
84                 2 = Don't bring up the Fiery loading screen. Maybe other things, I've not investigated.
85                 */
86         //int numnext; // 0 on final level. As David said: he meant to add story branching, but he eventually hadn't. 
87         std::vector<int> nextlevel;
88         Position location;
89         
90         CampaignLevel() : width(10) {
91                 choosenext = 1;
92                 location.x = 0;
93                 location.y = 0;
94         }
95         
96         int getStartX() {
97                 return 30+120+location.x*400/512;
98         }
99         
100         int getStartY() {
101                 return 30+30+(512-location.y)*400/512;
102         }
103         
104         int getEndX() {
105                 return getStartX()+width;
106         }
107         
108         int getEndY() {
109                 return getStartY()+width;
110         }
111         
112         XYZ getCenter() {
113                 XYZ center;
114                 center.x=getStartX()+width/2;
115                 center.y=getStartY()+width/2;
116                 return center;
117         }
118         
119         int getWidth() {
120                 return width;
121         }
122         
123         istream& operator<< (istream& is) {
124                 is.ignore(256,':');
125                 is.ignore(256,':');
126                 is.ignore(256,' ');
127                 is >> mapname;
128                 is.ignore(256,':');
129                 is >> description;
130                 for(int pos = description.find('_');pos!=string::npos;pos = description.find('_',pos)) {
131                         description.replace(pos,1,1,' ');
132                 }
133                 is.ignore(256,':');
134                 is >> choosenext;
135                 is.ignore(256,':');
136                 int numnext,next;
137                 is >> numnext;
138                 for(int j=0;j<numnext;j++) {
139                         is.ignore(256,':');
140                         is >> next;
141                         nextlevel.push_back(next-1);
142                 }
143                 is.ignore(256,':');
144                 is >> location.x;
145                 is.ignore(256,':');
146                 is >> location.y;
147                 return is;
148         }
149         
150         friend istream& operator>> (istream& is, CampaignLevel& cl) {
151                 return cl << is;
152         }
153 };
154
155 class Game
156 {
157         public:
158                 static std::vector<TextureInfo> textures;
159
160                 GLuint terraintexture;
161                 GLuint terraintexture2;
162                 GLuint terraintexture3;
163                 GLuint screentexture;
164                 GLuint screentexture2;
165                 GLuint logotexture;
166                 GLuint loadscreentexture;
167                 GLuint Maparrowtexture;
168                 GLuint Mapboxtexture;
169                 GLuint Mapcircletexture;
170                 GLuint cursortexture;
171                 GLuint Mainmenuitems[10];
172
173                 int nummenuitems;
174                 int startx[100];
175                 int starty[100];
176                 int endx[100];
177                 int endy[100];
178                 float selectedlong[100];
179                 int selected;
180                 int keyselect;
181                 int indemo;
182
183                 bool won;
184
185                 bool entername;
186
187                 char menustring[100][256];
188                 char registrationname[256];
189                 float registrationnumber;
190
191                 int newdetail;
192                 int newscreenwidth;
193                 int newscreenheight;
194
195                 bool gameon;
196                 float deltah,deltav;
197                 int mousecoordh,mousecoordv;
198                 int oldmousecoordh,oldmousecoordv;
199                 float rotation,rotation2;
200                 SkyBox skybox;
201                 bool cameramode;
202                 int olddrawmode;
203                 int drawmode;
204                 bool firstload;
205                 bool oldbutton;
206
207                 float leveltime;
208                 float loadtime;
209
210                 Model hawk;
211                 XYZ hawkcoords;
212                 XYZ realhawkcoords;
213                 GLuint hawktexture;
214                 float hawkrotation;
215                 float hawkcalldelay;
216
217                 Model eye;
218                 Model iris;
219                 Model cornea;
220
221                 bool stealthloading;
222
223                 std::vector<CampaignLevel> campaignlevels;
224                 int whichchoice;
225                 int actuallevel;
226
227                 bool minimap;
228
229                 int musictype,oldmusictype,oldoldmusictype;
230                 bool realthreat;
231
232                 Model rabbit;
233                 XYZ rabbitcoords;
234
235                 XYZ mapcenter;
236                 float mapradius;
237
238                 Text text;
239                 float fps;
240
241                 XYZ cameraloc;
242                 float cameradist;
243
244                 int drawtoggle;
245
246                 bool editorenabled;
247                 int editortype;
248                 float editorsize;
249                 float editorrotation;
250                 float editorrotation2;
251
252                 float brightness;
253
254                 int quit;
255                 int tryquit;
256
257                 XYZ pathpoint[30];
258                 int numpathpoints;
259                 int numpathpointconnect[30];
260                 int pathpointconnect[30][30];
261                 int pathpointselected;
262
263                 int endgame;
264                 bool scoreadded;
265                 int numchallengelevels;
266
267                 bool console;
268                 int archiveselected;
269                 char consoletext[15][256];
270                 int consolechars[15];
271                 bool chatting;
272                 char displaytext[15][256];
273                 int displaychars[15];
274                 float displaytime[15];
275                 float displayblinkdelay;
276                 bool displayblink;
277                 int displayselected;
278                 bool consolekeydown;
279                 float consoleblinkdelay;
280                 bool consoleblink;
281                 int consoleselected;
282                 bool autocam;
283
284                 unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey;
285                 bool oldattackkey;
286
287                 static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
288                 static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
289                 static void LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
290                 static void LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload);
291                 void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
292         bool AddClothes(const char *fileName, GLubyte *array);
293                 void InitGame();
294                 void LoadScreenTexture();
295                 void LoadStuff();
296                 void LoadingScreen();
297                 void LoadCampaign();
298                 static std::vector<std::string> ListCampaigns();
299                 void FadeLoadingScreen(float howmuch);
300                 void Dispose();
301                 int DrawGLScene(StereoSide side);
302                 void DrawMenu();
303                 void DrawGL();
304         //factored from Tick() -sf17k
305                 void MenuTick();
306         void doTutorial();
307         void doDebugKeys();
308                 void doJumpReversals();
309                 void doAerialAcrobatics();
310                 void doAttacks();
311                 void doPlayerCollisions();
312                 void doAI(int i);
313         //end factored
314                 void Tick();
315                 void TickOnce();
316                 void TickOnceAfter();
317                 void SetUpLighting();
318                 void Loadlevel(int which);
319                 void Loadlevel(const char *name);
320                 void Setenvironment(int which);
321                 GLvoid ReSizeGLScene(float fov, float near);
322                 int findPathDist(int start,int end);
323                 int checkcollide(XYZ startpoint, XYZ endpoint);
324                 int checkcollide(XYZ startpoint, XYZ endpoint, int what);
325                 int loading;
326                 float talkdelay;
327                 
328                 void fireSound(int sound=fireendsound);
329                 void setKeySelected();
330
331                 int numboundaries;
332                 XYZ boundary[360];
333
334                 int whichlevel;
335                 int oldenvironment;
336                 int targetlevel;
337                 float changedelay;
338
339                 float musicvolume[4];
340                 float oldmusicvolume[4];
341                 int musicselected;
342                 int change;
343                 Game();
344                 ~Game() {
345                         for(int i=0;i<10;i++){
346                                 if(Mainmenuitems[i])glDeleteTextures( 1, &Mainmenuitems[i] );
347                         }
348                         glDeleteTextures( 1, &cursortexture );
349                         glDeleteTextures( 1, &Maparrowtexture );
350                         glDeleteTextures( 1, &Mapboxtexture );
351                         glDeleteTextures( 1, &Mapcircletexture );
352                         glDeleteTextures( 1, &terraintexture );
353                         glDeleteTextures( 1, &terraintexture2 );
354                         if(screentexture>0)glDeleteTextures( 1, &screentexture );
355                         if(screentexture2>0)glDeleteTextures( 1, &screentexture2 );
356                         glDeleteTextures( 1, &hawktexture );
357                         glDeleteTextures( 1, &logotexture );
358                         glDeleteTextures( 1, &loadscreentexture );
359
360                         Dispose();
361                 }
362                 bool isWaiting() { return waiting; };
363         private:
364                 void setKeySelected_thread();
365                 static int thread(void *data);
366                 void inputText(char* str, int* charselected, int* nb_chars);
367                 void flash();
368                 bool waiting;
369                 //int mainmenu;
370                 Account* accountactive;
371 };
372
373 //keeps track of which textures are loaded
374 //TODO: delete them properly
375 struct TextureInfo {
376     bool isLoaded;
377     bool isSkin;
378     const char* fileName;
379     GLuint* ptextureid;
380     int mipmap;
381     bool hasalpha;
382     GLubyte* array;
383     int* skinsize;
384
385     void load() {
386         if(isSkin)
387             Game::LoadTextureSaveData(fileName,ptextureid,mipmap,array,skinsize,isLoaded);
388         else
389             Game::LoadTextureData(fileName,ptextureid,mipmap,hasalpha);
390         isLoaded=true;
391     }
392     TextureInfo(const char *_fileName, GLuint *_ptextureid,int _mipmap, bool _hasalpha):
393         isLoaded(false), isSkin(false), array(NULL), skinsize(NULL),
394         fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), hasalpha(_hasalpha) { }
395     TextureInfo(const char *_fileName, GLuint *_ptextureid, int _mipmap, GLubyte *_array, int *_skinsize):
396         isLoaded(false), isSkin(true), hasalpha(false),
397         fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), array(_array), skinsize(_skinsize) { }
398 };
399
400 #ifndef __forceinline
401 #  ifdef __GNUC__
402 #    define __forceinline inline __attribute__((always_inline))
403 #  endif
404 #endif
405
406 static __forceinline void swap_gl_buffers(void)
407 {
408     SDL_GL_SwapBuffers();
409 }
410
411 extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
412 //#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
413 #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
414 //#define STUBBED(x)
415
416 extern int numplayers;
417
418 extern int numdialogues;
419 const int max_dialogues = 20;
420 const int max_dialoguelength = 20;
421 extern int numdialogueboxes[max_dialogues];
422 extern int dialoguetype[max_dialogues];
423 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
424 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
425 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
426 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
427 extern char dialoguename[max_dialogues][max_dialoguelength][64];
428 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
429 extern XYZ participantlocation[max_dialogues][10];
430 extern int participantfocus[max_dialogues][max_dialoguelength];
431 extern int participantaction[max_dialogues][max_dialoguelength];
432 extern float participantrotation[max_dialogues][10];
433 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
434 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
435 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
436 extern int indialogue;
437 extern int whichdialogue;
438 extern int directing;
439 extern float dialoguetime;
440 extern int dialoguegonethrough[20];
441
442 enum maptypes {
443   mapkilleveryone, mapgosomewhere,
444   mapkillsomeone, mapkillmost // These two are unused
445 };
446
447 enum pathtypes {wpkeepwalking, wppause};
448
449 static const char *pathtypenames[] = {"keepwalking", "pause"};
450
451 enum editortypes {typeactive, typesitting, typesittingwall, typesleeping,
452                   typedead1, typedead2, typedead3, typedead4};
453
454 static const char *editortypenames[] = {
455   "active", "sitting", "sitting wall", "sleeping",
456   "dead1", "dead2", "dead3", "dead4"
457 };
458
459 #endif