]> git.jsancho.org Git - lugaru.git/blob - Source/Game.h
d634ecaa6f353024e78e9749633c8839caf36f1a
[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                 GLuint terraintexture;
159                 GLuint terraintexture2;
160                 GLuint terraintexture3;
161                 GLuint screentexture;
162                 GLuint screentexture2;
163                 GLuint logotexture;
164                 GLuint loadscreentexture;
165                 GLuint Maparrowtexture;
166                 GLuint Mapboxtexture;
167                 GLuint Mapcircletexture;
168                 GLuint cursortexture;
169                 GLuint Mainmenuitems[10];
170
171                 int nummenuitems;
172                 int startx[100];
173                 int starty[100];
174                 int endx[100];
175                 int endy[100];
176                 float selectedlong[100];
177                 int selected;
178                 int keyselect;
179                 int indemo;
180
181                 bool won;
182
183                 bool entername;
184
185                 char menustring[100][256];
186                 char registrationname[256];
187                 float registrationnumber;
188
189                 int newdetail;
190                 int newscreenwidth;
191                 int newscreenheight;
192
193                 bool gameon;
194                 float deltah,deltav;
195                 int mousecoordh,mousecoordv;
196                 int oldmousecoordh,oldmousecoordv;
197                 float rotation,rotation2;
198                 SkyBox skybox;
199                 bool cameramode;
200                 int olddrawmode;
201                 int drawmode;
202                 bool firstload;
203                 bool oldbutton;
204
205                 float leveltime;
206                 float loadtime;
207
208                 Model hawk;
209                 XYZ hawkcoords;
210                 XYZ realhawkcoords;
211                 GLuint hawktexture;
212                 float hawkrotation;
213                 float hawkcalldelay;
214
215                 Model eye;
216                 Model iris;
217                 Model cornea;
218
219                 bool stealthloading;
220
221                 std::vector<CampaignLevel> campaignlevels;
222                 int whichchoice;
223                 int actuallevel;
224                 bool winhotspot;
225                 bool windialogue;
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                 unsigned short consolekey;
286                 bool oldattackkey;
287
288                 static void LoadTexture(const string fileName, GLuint *textureid,int mipmap, bool hasalpha);
289                 static void LoadTextureSave(const string fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
290                 void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
291         bool AddClothes(const char *fileName, GLubyte *array);
292                 void InitGame();
293                 void LoadScreenTexture();
294                 void LoadStuff();
295                 void LoadingScreen();
296                 void LoadCampaign();
297                 static std::vector<std::string> ListCampaigns();
298                 void FadeLoadingScreen(float howmuch);
299                 void Dispose();
300                 int DrawGLScene(StereoSide side);
301                 void DrawMenu();
302                 void DrawGL();
303         //factored from Tick() -sf17k
304                 void MenuTick();
305         void doTutorial();
306         void doDebugKeys();
307                 void doJumpReversals();
308                 void doAerialAcrobatics();
309                 void doAttacks();
310                 void doPlayerCollisions();
311                 void doAI(int i);
312         //end factored
313                 void Tick();
314                 void TickOnce();
315                 void TickOnceAfter();
316                 void SetUpLighting();
317                 void Loadlevel(int which);
318                 void Loadlevel(const char *name);
319                 void Setenvironment(int which);
320                 GLvoid ReSizeGLScene(float fov, float near);
321                 int findPathDist(int start,int end);
322                 int checkcollide(XYZ startpoint, XYZ endpoint);
323                 int checkcollide(XYZ startpoint, XYZ endpoint, int what);
324                 int loading;
325                 float talkdelay;
326                 
327                 void fireSound(int sound=fireendsound);
328                 void setKeySelected();
329
330                 int numboundaries;
331                 XYZ boundary[360];
332
333                 int whichlevel;
334                 int oldenvironment;
335                 int targetlevel;
336                 float changedelay;
337
338                 float musicvolume[4];
339                 float oldmusicvolume[4];
340                 int musicselected;
341                 int change;
342                 Game();
343                 ~Game() {
344                         for(int i=0;i<10;i++){
345                                 if(Mainmenuitems[i])glDeleteTextures( 1, &Mainmenuitems[i] );
346                         }
347                         glDeleteTextures( 1, &cursortexture );
348                         glDeleteTextures( 1, &Maparrowtexture );
349                         glDeleteTextures( 1, &Mapboxtexture );
350                         glDeleteTextures( 1, &Mapcircletexture );
351                         glDeleteTextures( 1, &terraintexture );
352                         glDeleteTextures( 1, &terraintexture2 );
353                         if(screentexture>0)glDeleteTextures( 1, &screentexture );
354                         if(screentexture2>0)glDeleteTextures( 1, &screentexture2 );
355                         glDeleteTextures( 1, &hawktexture );
356                         glDeleteTextures( 1, &logotexture );
357                         glDeleteTextures( 1, &loadscreentexture );
358
359                         Dispose();
360                 }
361                 bool isWaiting() { return waiting; };
362         private:
363                 void setKeySelected_thread();
364                 static int thread(void *data);
365                 void inputText(char* str, int* charselected, int* nb_chars);
366                 void flash();
367                 bool waiting;
368                 //int mainmenu;
369                 Account* accountactive;
370 };
371
372 #ifndef __forceinline
373 #  ifdef __GNUC__
374 #    define __forceinline inline __attribute__((always_inline))
375 #  endif
376 #endif
377
378 static __forceinline void swap_gl_buffers(void)
379 {
380     SDL_GL_SwapBuffers();
381 }
382
383 extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
384 //#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
385 #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
386 //#define STUBBED(x)
387
388 extern int numplayers;
389
390 extern int numdialogues;
391 const int max_dialogues = 20;
392 const int max_dialoguelength = 20;
393 extern int numdialogueboxes[max_dialogues];
394 extern int dialoguetype[max_dialogues];
395 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
396 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
397 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
398 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
399 extern char dialoguename[max_dialogues][max_dialoguelength][64];
400 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
401 extern XYZ participantlocation[max_dialogues][10];
402 extern int participantfocus[max_dialogues][max_dialoguelength];
403 extern int participantaction[max_dialogues][max_dialoguelength];
404 extern float participantrotation[max_dialogues][10];
405 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
406 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
407 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
408 extern int indialogue;
409 extern int whichdialogue;
410 extern int directing;
411 extern float dialoguetime;
412 extern int dialoguegonethrough[20];
413
414 enum maptypes {
415   mapkilleveryone, mapgosomewhere,
416   mapkillsomeone, mapkillmost // These two are unused
417 };
418
419 enum pathtypes {wpkeepwalking, wppause};
420
421 static const char *pathtypenames[] = {"keepwalking", "pause"};
422
423 enum editortypes {typeactive, typesitting, typesittingwall, typesleeping,
424                   typedead1, typedead2, typedead3, typedead4};
425
426 static const char *editortypenames[] = {
427   "active", "sitting", "sitting wall", "sleeping",
428   "dead1", "dead2", "dead3", "dead4"
429 };
430
431 #endif