]> git.jsancho.org Git - lugaru.git/blob - Source/Game.h
major refactor of menu system, part 2
[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 namespace Game
156 {
157     //public:
158     extern GLuint terraintexture;
159     extern GLuint terraintexture2;
160     extern GLuint terraintexture3;
161     extern GLuint screentexture;
162     extern GLuint screentexture2;
163     extern GLuint logotexture;
164     extern GLuint loadscreentexture;
165     extern GLuint Maparrowtexture;
166     extern GLuint Mapboxtexture;
167     extern GLuint Mapcircletexture;
168     extern GLuint cursortexture;
169     extern GLuint Mainmenuitems[10];
170
171     extern int selected;
172     extern int keyselect;
173     extern int indemo;
174
175     extern bool won;
176
177     extern bool entername;
178
179     extern char registrationname[256];
180     extern float registrationnumber;
181
182     extern int newdetail;
183     extern int newscreenwidth;
184     extern int newscreenheight;
185
186     extern bool gameon;
187     extern float deltah,deltav;
188     extern int mousecoordh,mousecoordv;
189     extern int oldmousecoordh,oldmousecoordv;
190     extern float rotation,rotation2;
191     extern SkyBox skybox;
192     extern bool cameramode;
193     extern int olddrawmode;
194     extern int drawmode;
195     extern bool firstload;
196     extern bool oldbutton;
197
198     extern float leveltime;
199     extern float loadtime;
200
201     extern Model hawk;
202     extern XYZ hawkcoords;
203     extern XYZ realhawkcoords;
204     extern GLuint hawktexture;
205     extern float hawkrotation;
206     extern float hawkcalldelay;
207
208     extern Model eye;
209     extern Model iris;
210     extern Model cornea;
211
212     extern bool stealthloading;
213
214     extern std::vector<CampaignLevel> campaignlevels;
215     extern int whichchoice;
216     extern int actuallevel;
217     extern bool winhotspot;
218     extern bool windialogue;
219
220     extern bool minimap;
221
222     extern int musictype,oldmusictype,oldoldmusictype;
223     extern bool realthreat;
224
225     extern Model rabbit;
226     extern XYZ rabbitcoords;
227
228     extern XYZ mapcenter;
229     extern float mapradius;
230
231     extern Text* text;
232     extern float fps;
233
234     extern XYZ cameraloc;
235     extern float cameradist;
236
237     extern int drawtoggle;
238
239     extern bool editorenabled;
240     extern int editortype;
241     extern float editorsize;
242     extern float editorrotation;
243     extern float editorrotation2;
244
245     extern float brightness;
246
247     extern int quit;
248     extern int tryquit;
249
250     extern XYZ pathpoint[30];
251     extern int numpathpoints;
252     extern int numpathpointconnect[30];
253     extern int pathpointconnect[30][30];
254     extern int pathpointselected;
255
256     extern int endgame;
257     extern bool scoreadded;
258     extern int numchallengelevels;
259
260     extern bool console;
261     extern int archiveselected;
262     extern char consoletext[15][256];
263     extern int consolechars[15];
264     extern bool chatting;
265     extern char displaytext[15][256];
266     extern int displaychars[15];
267     extern float displaytime[15];
268     extern float displayblinkdelay;
269     extern bool displayblink;
270     extern int displayselected;
271     extern bool consolekeydown;
272     extern float consoleblinkdelay;
273     extern bool consoleblink;
274     extern int consoleselected;
275     extern bool autocam;
276
277     extern unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey;
278     extern unsigned short consolekey;
279     extern bool oldattackkey;
280
281     void LoadTexture(const string fileName, GLuint *textureid,int mipmap, bool hasalpha);
282     void LoadTextureSave(const string fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
283     void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
284     bool AddClothes(const char *fileName, GLubyte *array);
285     void InitGame();
286     void LoadScreenTexture();
287     void LoadStuff();
288     void LoadingScreen();
289     void LoadCampaign();
290     std::vector<std::string> ListCampaigns();
291     void FadeLoadingScreen(float howmuch);
292     void Dispose();
293     int DrawGLScene(StereoSide side);
294     void DrawMenu();
295     void DrawGL();
296     void LoadMenu();
297     //factored from Tick() -sf17k
298     void MenuTick();
299     void doTutorial();
300     void doDebugKeys();
301     void doJumpReversals();
302     void doAerialAcrobatics();
303     void doAttacks();
304     void doPlayerCollisions();
305     void doAI(int i);
306     //end factored
307     void Tick();
308     void TickOnce();
309     void TickOnceAfter();
310     void SetUpLighting();
311     void Loadlevel(int which);
312     void Loadlevel(const char *name);
313     void Setenvironment(int which);
314     GLvoid ReSizeGLScene(float fov, float near);
315     int findPathDist(int start,int end);
316     int checkcollide(XYZ startpoint, XYZ endpoint);
317     int checkcollide(XYZ startpoint, XYZ endpoint, int what);
318     extern int loading;
319     extern float talkdelay;
320     
321     void fireSound(int sound=fireendsound);
322     void setKeySelected();
323
324     extern int numboundaries;
325     extern XYZ boundary[360];
326
327     extern int whichlevel;
328     extern int oldenvironment;
329     extern int targetlevel;
330     extern float changedelay;
331
332     extern float musicvolume[4];
333     extern float oldmusicvolume[4];
334     extern int musicselected;
335     extern int change;
336     void newGame();
337     void deleteGame();
338     extern bool waiting;
339     //private:
340     int setKeySelected_thread(void*);
341     int thread(void *data);
342     void inputText(char* str, int* charselected, int* nb_chars);
343     void flash();
344     //bool waiting;
345     extern Account* accountactive;
346 }
347
348 #ifndef __forceinline
349 #  ifdef __GNUC__
350 #    define __forceinline inline __attribute__((always_inline))
351 #  endif
352 #endif
353
354 static __forceinline void swap_gl_buffers(void)
355 {
356     SDL_GL_SwapBuffers();
357 }
358
359 extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
360 //#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
361 #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
362 //#define STUBBED(x)
363
364 extern int numplayers;
365
366 extern int numdialogues;
367 const int max_dialogues = 20;
368 const int max_dialoguelength = 20;
369 extern int numdialogueboxes[max_dialogues];
370 extern int dialoguetype[max_dialogues];
371 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
372 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
373 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
374 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
375 extern char dialoguename[max_dialogues][max_dialoguelength][64];
376 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
377 extern XYZ participantlocation[max_dialogues][10];
378 extern int participantfocus[max_dialogues][max_dialoguelength];
379 extern int participantaction[max_dialogues][max_dialoguelength];
380 extern float participantrotation[max_dialogues][10];
381 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
382 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
383 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
384 extern int indialogue;
385 extern int whichdialogue;
386 extern int directing;
387 extern float dialoguetime;
388 extern int dialoguegonethrough[20];
389
390 enum maptypes {
391   mapkilleveryone, mapgosomewhere,
392   mapkillsomeone, mapkillmost // These two are unused
393 };
394
395 enum pathtypes {wpkeepwalking, wppause};
396
397 static const char *pathtypenames[] = {"keepwalking", "pause"};
398
399 enum editortypes {typeactive, typesitting, typesittingwall, typesleeping,
400                   typedead1, typedead2, typedead3, typedead4};
401
402 static const char *editortypenames[] = {
403   "active", "sitting", "sitting wall", "sleeping",
404   "dead1", "dead2", "dead3", "dead4"
405 };
406
407 #endif