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