]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
d966a35d2f80692ba73518fffb51fafee7ca97cb
[lugaru.git] / Source / GameInitDispose.cpp
1 #include "Game.h"       
2 extern float screenwidth,screenheight;
3 extern float viewdistance;
4 extern XYZ viewer;
5 extern XYZ lightlocation;
6 extern float lightambient[3],lightbrightness[3];
7 extern float fadestart;
8 extern float texscale;
9 extern float gravity;
10 extern Light light;
11 extern Animation animation[animation_count];
12 extern Skeleton testskeleton;
13 extern int numsounds;
14 extern FSOUND_SAMPLE    *samp[100];
15 extern int channels[100];
16 extern Terrain terrain;
17 extern Sprites sprites;
18 extern int kTextureSize;
19 extern float texdetail;
20 extern float realtexdetail;
21 extern float terraindetail;
22 extern float volume;
23 extern Objects objects;
24 extern int detail;
25 extern bool cellophane;
26 extern GLubyte bloodText[512*512*3];
27 extern GLubyte wolfbloodText[512*512*3];
28 extern bool ismotionblur;
29 extern bool trilinear;
30 #ifdef WIN32
31 extern HDC hDC;
32 #else
33 extern AGLContext gaglContext;
34 #endif
35 extern bool osx;
36 extern bool musictoggle;
37 extern Weapons weapons;
38 extern Person player[maxplayers];
39 extern int numplayers;
40 extern int environment;
41 extern bool ambientsound;
42 extern float multiplier;
43 extern int newnetmessages;
44 extern int netdatanew;
45 extern float mapinfo;
46 extern bool stillloading;
47 extern TGAImageRec texture;
48 extern short vRefNum;
49 extern long dirID;
50 extern int mainmenu;
51 extern int oldmainmenu;
52 extern bool visibleloading;
53 extern int loadscreencolor;
54 extern float flashamount,flashr,flashg,flashb;
55 extern int flashdelay;
56 extern int whichjointstartarray[26];
57 extern int whichjointendarray[26];
58 extern int difficulty;
59 extern float tintr,tintg,tintb;
60 extern float slomospeed;
61 extern char mapname[256];
62 extern bool gamestarted;
63
64 extern int numaccounts;
65 extern int accountactive;
66 extern int accountdifficulty[10];
67 extern int accountprogress[10];
68 extern float accountpoints[10];
69 extern float accounthighscore[10][50];
70 extern float accountfasttime[10][50];
71 extern bool accountunlocked[10][60];
72 extern char accountname[10][256];
73
74 extern int numdialogues;
75 extern int numdialogueboxes[20];
76 extern int dialoguetype[20];
77 extern int dialogueboxlocation[20][20];
78 extern float dialogueboxcolor[20][20][3];
79 extern int dialogueboxsound[20][20];
80 extern char dialoguetext[20][20][128];
81 extern char dialoguename[20][20][64];
82 extern XYZ dialoguecamera[20][20];
83 extern float dialoguecamerarotation[20][20];
84 extern float dialoguecamerarotation2[20][20];
85 extern int indialogue;
86 extern int whichdialogue;
87 extern float dialoguetime;
88
89 extern float accountcampaignhighscore[10];
90 extern float accountcampaignfasttime[10];
91 extern float accountcampaignscore[10];
92 extern float accountcampaigntime[10];
93
94 extern int accountcampaignchoicesmade[10];
95 extern int accountcampaignchoices[10][5000];
96
97 extern FSOUND_STREAM * strm[10];
98
99 extern "C"      void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
100 extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
101
102 Game::TextureList Game::textures;
103
104 void Game::Dispose()
105 {
106         int i,j;
107
108         LOGFUNC;
109
110         if(endgame==2){
111                 accountcampaignchoicesmade[accountactive]=0;
112                 accountcampaignscore[accountactive]=0;
113                 accountcampaigntime[accountactive]=0;
114                 endgame=0;
115         }
116
117
118         sprintf (mapname, ":Data:Users");
119
120         FILE                    *tfile;
121         tfile=fopen( mapname, "wb" );
122         if (tfile)
123         {
124                 fpackf(tfile, "Bi", numaccounts);
125                 fpackf(tfile, "Bi", accountactive);
126                 if(numaccounts>0)
127                 {
128                         for(i=0;i<numaccounts;i++)
129                         {
130                                 fpackf(tfile, "Bf", accountcampaigntime[i]);
131                                 fpackf(tfile, "Bf", accountcampaignscore[i]);
132                                 fpackf(tfile, "Bf", accountcampaignfasttime[i]);
133                                 fpackf(tfile, "Bf", accountcampaignhighscore[i]);
134                                 fpackf(tfile, "Bi", accountdifficulty[i]);
135                                 fpackf(tfile, "Bi", accountprogress[i]);
136                                 fpackf(tfile, "Bi", accountcampaignchoicesmade[i]);
137                                 for(j=0;j<accountcampaignchoicesmade[i];j++)
138                                 {
139                                         fpackf(tfile, "Bi", accountcampaignchoices[i][j]);
140                                 }
141                                 fpackf(tfile, "Bf", accountpoints[i]);
142                                 for(j=0;j<50;j++)
143                                 {
144                                         fpackf(tfile, "Bf", accounthighscore[i][j]);
145                                         fpackf(tfile, "Bf", accountfasttime[i][j]);
146                                 }
147                                 for(j=0;j<60;j++)
148                                 {
149                                         fpackf(tfile, "Bb",  accountunlocked[i][j]);
150                                 }
151                                 fpackf(tfile, "Bi",  strlen(accountname[i]));
152                                 if(strlen(accountname[i])>0)
153                                 {
154                                         for(j=0;j<(int)strlen(accountname[i]);j++)
155                                         {
156                                                 fpackf(tfile, "Bb",  accountname[i][j]);
157                                         }
158                                 }
159                         }
160                 }
161
162                 fclose(tfile);
163         }
164
165         TexIter it = textures.begin();
166         for (; it != textures.end(); ++it)
167         {
168                 if (glIsTexture(it->second))
169                         glDeleteTextures(1, &it->second);
170         }
171         textures.clear();
172
173         LOG("Shutting down sound system...");
174
175         FSOUND_StopSound(FSOUND_ALL);
176
177 #define streamcount 20
178 #define samplecount 100
179
180         for (i=0; i < samplecount; ++i)
181         {
182                 FSOUND_Sample_Free(samp[i]);
183         }
184
185         for (i=0; i < streamcount; ++i)
186         {
187                 FSOUND_Stream_Close(strm[i]);
188         }
189
190         FSOUND_Close();
191         if (texture.data)
192         {
193                 free(texture.data);
194         }
195         texture.data = 0;
196 }
197
198
199 //void Game::LoadSounds();
200 void Game::LoadSounds()
201 {
202         LOGFUNC;
203
204         LOG(std::string("Loading sounds..."));
205
206         FSOUND_3D_SetDopplerFactor(0);
207
208         FSOUND_SetSFXMasterVolume((int)(volume*255));
209         
210         samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
211         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
212
213         samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
214         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
215
216         samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
217         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
218
219         samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
220         FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
221
222         samp[landsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:land.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
223         FSOUND_Sample_SetMinMaxDistance(samp[landsound], 4.0f, 1000.0f);        
224
225         samp[jumpsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:jump.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
226         FSOUND_Sample_SetMinMaxDistance(samp[jumpsound], 4.0f, 1000.0f);        
227
228         samp[hawksound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:hawk.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
229         FSOUND_Sample_SetMinMaxDistance(samp[hawksound], 40.0f, 10000.0f);      
230
231         samp[whooshsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:whoosh.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
232         FSOUND_Sample_SetMinMaxDistance(samp[whooshsound], 4.0f, 1000.0f);      
233         FSOUND_Sample_SetMode(samp[whooshsound], FSOUND_LOOP_NORMAL);
234
235         samp[landsound1] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:land1.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
236         FSOUND_Sample_SetMinMaxDistance(samp[landsound1], 4.0f, 1000.0f);       
237
238
239
240         samp[landsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:land2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
241         FSOUND_Sample_SetMinMaxDistance(samp[landsound2], 4.0f, 1000.0f);       
242
243         samp[breaksound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:broken.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
244         FSOUND_Sample_SetMinMaxDistance(samp[breaksound], 8.0f, 2000.0f);       
245
246         samp[lowwhooshsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:Lowwhoosh.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
247         FSOUND_Sample_SetMinMaxDistance(samp[lowwhooshsound], 8.0f, 2000.0f);   
248
249         samp[midwhooshsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:midwhoosh.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
250         FSOUND_Sample_SetMinMaxDistance(samp[midwhooshsound], 8.0f, 2000.0f);   
251
252         samp[highwhooshsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:highwhoosh.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
253         FSOUND_Sample_SetMinMaxDistance(samp[highwhooshsound], 8.0f, 2000.0f);  
254
255         samp[movewhooshsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:movewhoosh.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
256         FSOUND_Sample_SetMinMaxDistance(samp[movewhooshsound], 8.0f, 2000.0f);  
257
258         samp[heavyimpactsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:heavyimpact.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
259         FSOUND_Sample_SetMinMaxDistance(samp[heavyimpactsound], 8.0f, 2000.0f); 
260
261         samp[whooshhitsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:Whooshhit.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
262         FSOUND_Sample_SetMinMaxDistance(samp[whooshhitsound], 8.0f, 2000.0f);   
263
264         samp[thudsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:thud.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
265         FSOUND_Sample_SetMinMaxDistance(samp[thudsound], 8.0f, 2000.0f);        
266
267         samp[alarmsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:alarm.ogg", FSOUND_2D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
268         FSOUND_Sample_SetMinMaxDistance(samp[alarmsound], 8.0f, 2000.0f);       
269
270         samp[breaksound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:break.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
271         FSOUND_Sample_SetMinMaxDistance(samp[breaksound2], 8.0f, 2000.0f);      
272
273         samp[knifedrawsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:knifedraw.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
274         FSOUND_Sample_SetMinMaxDistance(samp[knifedrawsound], 8.0f, 2000.0f);
275
276         samp[knifesheathesound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:knifesheathe.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
277         FSOUND_Sample_SetMinMaxDistance(samp[knifesheathesound], 8.0f, 2000.0f);
278
279         samp[fleshstabsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:Fleshstab.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
280         FSOUND_Sample_SetMinMaxDistance(samp[fleshstabsound], 8.0f, 2000.0f);
281
282         samp[fleshstabremovesound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:Fleshstabremove.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
283         FSOUND_Sample_SetMinMaxDistance(samp[fleshstabremovesound], 8.0f, 2000.0f);
284
285         samp[knifeswishsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:knifeswish.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
286         FSOUND_Sample_SetMinMaxDistance(samp[knifeswishsound], 8.0f, 2000.0f);
287
288         samp[knifeslicesound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:knifeslice.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
289         FSOUND_Sample_SetMinMaxDistance(samp[knifeslicesound], 8.0f, 2000.0f);
290
291         samp[swordslicesound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:swordslice.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
292         FSOUND_Sample_SetMinMaxDistance(samp[swordslicesound], 8.0f, 2000.0f);
293
294         samp[skidsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:skid.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
295         FSOUND_Sample_SetMinMaxDistance(samp[skidsound], 8.0f, 2000.0f);
296
297         samp[snowskidsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:snowskid.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
298         FSOUND_Sample_SetMinMaxDistance(samp[snowskidsound], 8.0f, 2000.0f);
299
300         samp[bushrustle] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:bushrustle.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
301         FSOUND_Sample_SetMinMaxDistance(samp[bushrustle], 4.0f, 1000.0f);       
302
303         samp[clank1sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:clank1.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
304         FSOUND_Sample_SetMinMaxDistance(samp[clank1sound], 8.0f, 2000.0f);
305
306         samp[clank2sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:clank2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
307         FSOUND_Sample_SetMinMaxDistance(samp[clank2sound], 8.0f, 2000.0f);
308
309         samp[clank3sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:clank3.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
310         FSOUND_Sample_SetMinMaxDistance(samp[clank3sound], 8.0f, 2000.0f);
311
312         samp[clank4sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:clank4.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
313         FSOUND_Sample_SetMinMaxDistance(samp[clank4sound], 8.0f, 2000.0f);
314
315         samp[consolesuccesssound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:consolesuccess.ogg", FSOUND_2D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
316         FSOUND_Sample_SetMinMaxDistance(samp[consolesuccesssound], 4.0f, 1000.0f);      
317
318         samp[consolefailsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:consolefail.ogg", FSOUND_2D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
319         FSOUND_Sample_SetMinMaxDistance(samp[consolefailsound], 4.0f, 1000.0f); 
320
321         samp[metalhitsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:MetalHit.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
322         FSOUND_Sample_SetMinMaxDistance(samp[metalhitsound], 8.0f, 2000.0f);
323
324         samp[clawslicesound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:clawslice.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
325         FSOUND_Sample_SetMinMaxDistance(samp[clawslicesound], 8.0f, 2000.0f);
326
327         samp[splattersound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:splatter.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
328         FSOUND_Sample_SetMinMaxDistance(samp[splattersound], 8.0f, 2000.0f);
329
330         samp[growlsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:Growl.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
331         FSOUND_Sample_SetMinMaxDistance(samp[growlsound], 1000.0f, 2000.0f);
332
333         samp[growl2sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:Growl2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
334         FSOUND_Sample_SetMinMaxDistance(samp[growl2sound], 1000.0f, 2000.0f);
335
336         samp[barksound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:bark.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
337         FSOUND_Sample_SetMinMaxDistance(samp[barksound], 1000.0f, 2000.0f);
338
339         samp[bark2sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:bark2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
340         FSOUND_Sample_SetMinMaxDistance(samp[bark2sound], 1000.0f, 2000.0f);
341
342         samp[bark3sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:bark3.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
343         FSOUND_Sample_SetMinMaxDistance(samp[bark3sound], 1000.0f, 2000.0f);
344
345         samp[snarlsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:snarl.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
346         FSOUND_Sample_SetMinMaxDistance(samp[snarlsound], 1000.0f, 2000.0f);
347
348
349         samp[snarl2sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:snarl2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
350         FSOUND_Sample_SetMinMaxDistance(samp[snarl2sound], 1000.0f, 2000.0f);
351
352         samp[barkgrowlsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:barkgrowl.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
353         FSOUND_Sample_SetMinMaxDistance(samp[barkgrowlsound], 1000.0f, 2000.0f);
354
355         samp[rabbitattacksound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitattack.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
356         FSOUND_Sample_SetMinMaxDistance(samp[rabbitattacksound], 1000.0f, 2000.0f);
357
358         samp[rabbitattack2sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitattack2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
359         FSOUND_Sample_SetMinMaxDistance(samp[rabbitattack2sound], 1000.0f, 2000.0f);
360
361         samp[rabbitattack3sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitattack3.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
362         FSOUND_Sample_SetMinMaxDistance(samp[rabbitattack3sound], 1000.0f, 2000.0f);
363
364         samp[rabbitattack4sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitattack4.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
365         FSOUND_Sample_SetMinMaxDistance(samp[rabbitattack4sound], 1000.0f, 2000.0f);
366
367         samp[rabbitpainsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitpain.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
368         FSOUND_Sample_SetMinMaxDistance(samp[rabbitpainsound], 1000.0f, 2000.0f);
369
370         samp[rabbitpain1sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitpain2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
371         FSOUND_Sample_SetMinMaxDistance(samp[rabbitpain1sound], 1000.0f, 2000.0f);
372
373         /*samp[rabbitpain2sound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitpain2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
374         FSOUND_Sample_SetMinMaxDistance(samp[rabbitpain2sound], 1000.0f, 2000.0f);
375         */
376         samp[rabbitchitter] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitchitter.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
377         FSOUND_Sample_SetMinMaxDistance(samp[rabbitchitter], 1000.0f, 2000.0f);
378
379         samp[rabbitchitter2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:rabbitchitter2.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
380         FSOUND_Sample_SetMinMaxDistance(samp[rabbitchitter2], 1000.0f, 2000.0f);
381
382         samp[swordstaffsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:swordstaff.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
383         FSOUND_Sample_SetMinMaxDistance(samp[swordstaffsound], 8.0f, 2000.0f);
384
385         samp[staffbodysound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:staffbody.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
386         FSOUND_Sample_SetMinMaxDistance(samp[staffbodysound], 8.0f, 2000.0f);
387
388         samp[staffheadsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:staffhead.ogg", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
389         FSOUND_Sample_SetMinMaxDistance(samp[staffheadsound], 8.0f, 2000.0f);
390
391         samp[staffbreaksound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:staffbreak.wav", FSOUND_HW3D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
392         FSOUND_Sample_SetMinMaxDistance(samp[staffbreaksound], 8.0f, 2000.0f);
393
394
395
396 }
397
398 void Game::LoadTexture(char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
399 {
400         GLuint          type;
401
402         LOGFUNC;
403
404         LOG(std::string("Loading texture...") + fileName);
405
406         unsigned char fileNamep[256];
407         CopyCStringToPascal(fileName,fileNamep);
408         //Load Image
409         upload_image( fileNamep ,hasalpha); 
410
411 //      std::string fname(fileName);
412 //      std::transform(fname.begin(), fname.end(), tolower);
413 //      TexIter it = textures.find(fname);
414
415         //Is it valid?
416         if(1==1)
417         //if(textures.end() == it)
418         {
419                 //Alpha channel?
420                 if ( texture.bpp == 24 )
421                         type = GL_RGB;
422                 else
423                         type = GL_RGBA;
424
425                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
426
427                 if(!*textureid)glGenTextures( 1, textureid );
428                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
429
430                 glBindTexture( GL_TEXTURE_2D, *textureid);
431                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
432                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
433                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
434                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
435
436                 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.sizeX, texture.sizeY, 0,
437                 //          GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, texture.data);
438
439                 //gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, texture.data );
440
441                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
442
443 //              textures.insert(std::make_pair(fname, *textureid));
444         }
445 //      else
446 //      {
447 //              *textureid = it->second;
448 //      }
449 }
450
451 void Game::LoadTextureSave(char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
452 {
453         GLuint          type;
454         int i;
455         int bytesPerPixel;
456
457         LOGFUNC;
458
459         LOG(std::string("Loading texture (S)...") + fileName);
460
461         //Load Image
462         unsigned char fileNamep[256];
463         CopyCStringToPascal(fileName,fileNamep);
464         //Load Image
465         upload_image( fileNamep ,0); 
466         //LoadTGA( fileName ); 
467
468 //      std::string fname(fileName);
469 //      std::transform(fname.begin(), fname.end(), tolower);
470 //      TexIter it = textures.find(fname);
471
472         //Is it valid?
473         if(1==1)
474         //if(textures.end() == it)
475         {
476                 bytesPerPixel=texture.bpp/8;
477
478                 //Alpha channel?
479                 if ( texture.bpp == 24 )
480                         type = GL_RGB;
481                 else
482                         type = GL_RGBA;
483
484                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
485
486                 if(!*textureid)glGenTextures( 1, textureid );
487                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
488
489                 glBindTexture( GL_TEXTURE_2D, *textureid);
490                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
491                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
492                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
493                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
494
495                 int tempnum=0;
496                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
497                         if((i+1)%4||type==GL_RGB){
498                                 array[tempnum]=texture.data[i];
499                                 tempnum++;
500                         }
501                 }
502
503                 *skinsize=texture.sizeX;
504
505                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
506
507 //              textures.insert(std::make_pair(fname, *textureid));
508         }
509 //      else
510 //      {
511 //              *textureid = it->second;
512 //      }
513 }
514
515 void Game::LoadSave(char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
516 {
517         int i;
518         int bytesPerPixel;
519
520         LOGFUNC;
521
522         LOG(std::string("Loading (S)...") + fileName);
523
524         //Load Image
525         float temptexdetail=texdetail;
526         texdetail=1;
527         //upload_image( fileName ); 
528         //LoadTGA( fileName ); 
529         //Load Image
530         unsigned char fileNamep[256];
531         CopyCStringToPascal(fileName,fileNamep);
532         //Load Image
533         upload_image( fileNamep ,0); 
534         texdetail=temptexdetail;
535
536         //Is it valid?
537         if(1==1){
538                 bytesPerPixel=texture.bpp/8;
539
540                 int tempnum=0;
541                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
542                         if((i+1)%4||bytesPerPixel==3){
543                                 array[tempnum]=texture.data[i];
544                                 tempnum++;
545                         }
546                 }
547         }
548 }
549
550 bool Game::AddClothes(char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
551 {
552         int i;
553         int bytesPerPixel;
554
555         LOGFUNC;
556
557         //upload_image( fileName ); 
558         //LoadTGA( fileName ); 
559         //Load Image
560         unsigned char fileNamep[256];
561         CopyCStringToPascal(fileName,fileNamep);
562         //Load Image
563         bool opened;
564         opened=upload_image( fileNamep ,1); 
565
566         float alphanum;
567         //Is it valid?
568         if(opened){
569                 if(tintr>1)tintr=1;
570                 if(tintg>1)tintg=1;
571                 if(tintb>1)tintb=1;
572
573                 if(tintr<0)tintr=0;
574                 if(tintg<0)tintg=0;
575                 if(tintb<0)tintb=0;
576
577                 bytesPerPixel=texture.bpp/8;
578
579                 int tempnum=0;
580                 alphanum=255;
581                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
582                         if(bytesPerPixel==3)alphanum=255;
583                         else if((i+1)%4==0)alphanum=texture.data[i];
584                         //alphanum/=2;
585                         if((i+1)%4||bytesPerPixel==3){
586                                 if((i%4)==0)texture.data[i]*=tintr;
587                                 if((i%4)==1)texture.data[i]*=tintg;
588                                 if((i%4)==2)texture.data[i]*=tintb;
589                                 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
590                                 tempnum++;
591                         }
592                 }
593         }
594         else return 0;
595         return 1;
596 }
597
598
599 //***************> ResizeGLScene() <******/
600 GLvoid Game::ReSizeGLScene(float fov, float pnear)
601 {
602         if (screenheight==0)
603         {
604                 screenheight=1;
605         }
606
607         glViewport(0,0,screenwidth,screenheight);
608
609         glMatrixMode(GL_PROJECTION);
610         glLoadIdentity();
611
612         gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
613
614         glMatrixMode(GL_MODELVIEW);                                                     
615         glLoadIdentity();                                                                       
616 }
617
618 void Game::LoadingScreen()                                                                              
619 {
620         static float loadprogress,minprogress,maxprogress;
621         static AbsoluteTime time = {0,0};
622         static AbsoluteTime frametime = {0,0};
623         AbsoluteTime currTime = UpTime ();
624         double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
625
626         if (0 > deltaTime)      // if negative microseconds
627                 deltaTime /= -1000000.0;
628         else                            // else milliseconds
629                 deltaTime /= 1000.0;
630
631         multiplier=deltaTime;
632         if(multiplier<.001)multiplier=.001;
633         if(multiplier>10)multiplier=10;
634         if(multiplier>.05){
635                 frametime = currTime;   // reset for next time interval
636
637                 float size=1;
638                 glLoadIdentity();
639                 //Clear to black
640                 glClearColor(0,0,0,1);
641                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
642
643
644                 loadtime+=multiplier*4;
645
646                 loadprogress=loadtime;
647                 if(loadprogress>100)loadprogress=100;
648
649                 //loadprogress=abs(Random()%100);
650
651                 //Background
652
653                 glEnable(GL_TEXTURE_2D);
654                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
655                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
656                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
657                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
658                 glDisable(GL_CULL_FACE);
659                 glDisable(GL_LIGHTING);
660                 glDepthMask(0);
661                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
662                 glPushMatrix();                                                                         // Store The Projection Matrix
663                 glLoadIdentity();                                                                       // Reset The Projection Matrix
664                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
665                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
666                 glPushMatrix();                                                                         // Store The Modelview Matrix
667                 glLoadIdentity();                                                               // Reset The Modelview Matrix
668                 glTranslatef(screenwidth/2,screenheight/2,0);
669                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
670                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
671                 glDisable(GL_BLEND);
672                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
673                 //glColor4f(1,1,1,1);
674                 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
675                 if(loadscreencolor==1)glColor4f(1,0,0,1);
676                 if(loadscreencolor==2)glColor4f(0,1,0,1);
677                 if(loadscreencolor==3)glColor4f(0,0,1,1);
678                 if(loadscreencolor==4)glColor4f(1,1,0,1);
679                 if(loadscreencolor==5)glColor4f(1,0,1,1);
680                 */
681                 glPushMatrix();
682                 //glScalef(.25,.25,.25);
683                 glBegin(GL_QUADS);
684                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
685                 glVertex3f(-1,          -1,      0.0f);
686                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
687                 glVertex3f(1,   -1,      0.0f);
688                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
689                 glVertex3f(1,   1, 0.0f);
690                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
691                 glVertex3f(-1,  1, 0.0f);
692                 glEnd();
693                 glPopMatrix();
694                 glEnable(GL_BLEND);
695                 glPushMatrix();
696                 //glScalef(.25,.25,.25);
697                 glBegin(GL_QUADS);
698                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
699                 glVertex3f(-1,          -1,      0.0f);
700                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
701                 glVertex3f(1,   -1,      0.0f);
702                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
703                 glVertex3f(1,   1, 0.0f);
704                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
705                 glVertex3f(-1,  1, 0.0f);
706                 glEnd();
707                 glPopMatrix();
708                 glDisable(GL_TEXTURE_2D);
709                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
710                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
711                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
712                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
713                 glDisable(GL_BLEND);
714                 glDepthMask(1);
715
716                 glEnable(GL_TEXTURE_2D);
717                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
718                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
719                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
720                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
721                 glDisable(GL_CULL_FACE);
722                 glDisable(GL_LIGHTING);
723                 glDepthMask(0);
724                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
725                 glPushMatrix();                                                                         // Store The Projection Matrix
726                 glLoadIdentity();                                                                       // Reset The Projection Matrix
727                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
728                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
729                 glPushMatrix();                                                                         // Store The Modelview Matrix
730                 glLoadIdentity();                                                               // Reset The Modelview Matrix
731                 glTranslatef(screenwidth/2,screenheight/2,0);
732                 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
733                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
734                 glEnable(GL_BLEND);
735                 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
736                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
737                 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
738                 if(loadscreencolor==1)glColor4f(1,0,0,1);
739                 if(loadscreencolor==2)glColor4f(0,1,0,1);
740                 if(loadscreencolor==3)glColor4f(0,0,1,1);
741                 if(loadscreencolor==4)glColor4f(1,1,0,1);
742                 if(loadscreencolor==5)glColor4f(1,0,1,1);
743                 */
744                 glPushMatrix();
745                 //glScalef(.25,.25,.25);
746                 glBegin(GL_QUADS);
747                 glTexCoord2f(0+.5,0+.5);
748                 glVertex3f(-1,          -1,      0.0f);
749                 glTexCoord2f(1+.5,0+.5);
750                 glVertex3f(1,   -1,      0.0f);
751                 glTexCoord2f(1+.5,1+.5);
752                 glVertex3f(1,   1, 0.0f);
753                 glTexCoord2f(0+.5,1+.5);
754                 glVertex3f(-1,  1, 0.0f);
755                 glEnd();
756                 glPopMatrix();
757                 glDisable(GL_TEXTURE_2D);
758                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
759                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
760                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
761                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
762                 glDisable(GL_BLEND);
763                 glDepthMask(1);
764
765                 glEnable(GL_TEXTURE_2D);
766                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
767                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
768                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
769                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
770                 glDisable(GL_CULL_FACE);
771                 glDisable(GL_LIGHTING);
772                 glDepthMask(0);
773                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
774                 glPushMatrix();                                                                         // Store The Projection Matrix
775                 glLoadIdentity();                                                                       // Reset The Projection Matrix
776                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
777                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
778                 glPushMatrix();                                                                         // Store The Modelview Matrix
779                 glLoadIdentity();                                                               // Reset The Modelview Matrix
780                 glTranslatef(screenwidth/2,screenheight/2,0);
781                 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
782                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
783                 glEnable(GL_BLEND);
784                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
785                 glPushMatrix();
786                 //glScalef(.25,.25,.25);
787                 glBegin(GL_QUADS);
788                 glTexCoord2f(0+.2,0+.8);
789                 glVertex3f(-1,          -1,      0.0f);
790                 glTexCoord2f(1+.2,0+.8);
791                 glVertex3f(1,   -1,      0.0f);
792                 glTexCoord2f(1+.2,1+.8);
793                 glVertex3f(1,   1, 0.0f);
794                 glTexCoord2f(0+.2,1+.8);
795                 glVertex3f(-1,  1, 0.0f);
796                 glEnd();
797                 glPopMatrix();
798                 glDisable(GL_TEXTURE_2D);
799                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
800                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
801                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
802                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
803                 glDisable(GL_BLEND);
804                 glDepthMask(1);
805
806                 //Text
807                 /*
808                 glEnable(GL_TEXTURE_2D);
809                 static char string[256]="";
810                 sprintf (string, "LOADING... %d%",(int)loadprogress);
811                 glColor4f(1,1,1,.2);
812                 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
813                 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
814                 text.glPrint(280,125,string,1,1,640,480);
815                 */
816
817                 if(flashamount>0){
818                         if(flashamount>1)flashamount=1;
819                         if(flashdelay<=0)flashamount-=multiplier;
820                         flashdelay--;
821                         if(flashamount<0)flashamount=0;
822                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
823                         glDisable(GL_CULL_FACE);
824                         glDisable(GL_LIGHTING);
825                         glDisable(GL_TEXTURE_2D);
826                         glDepthMask(0);
827                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
828                         glPushMatrix();                                                                         // Store The Projection Matrix
829                         glLoadIdentity();                                                                       // Reset The Projection Matrix
830                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
831                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
832                         glPushMatrix();                                                                         // Store The Modelview Matrix
833                         glLoadIdentity();                                                               // Reset The Modelview Matrix
834                         glScalef(screenwidth,screenheight,1);
835                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
836                         glEnable(GL_BLEND);
837                         glColor4f(flashr,flashg,flashb,flashamount);
838                         glBegin(GL_QUADS);
839                         glVertex3f(0,           0,       0.0f);
840                         glVertex3f(256, 0,       0.0f);
841                         glVertex3f(256, 256, 0.0f);
842                         glVertex3f(0,   256, 0.0f);
843                         glEnd();
844                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
845                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
846                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
847                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
848                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
849                         glEnable(GL_CULL_FACE);
850                         glDisable(GL_BLEND);
851                         glDepthMask(1);
852                 }       
853
854 #ifdef WIN32
855                 SwapBuffers( hDC);
856 #else
857                 aglSwapBuffers(gaglContext);
858 #endif
859
860                 loadscreencolor=0;
861         }
862 }
863
864 void Game::FadeLoadingScreen(float howmuch)                                                                             
865 {
866         static float loadprogress,minprogress,maxprogress;
867
868         float size=1;
869         glLoadIdentity();
870         //Clear to black
871         glClearColor(0,0,0,1);
872         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
873
874         loadprogress=howmuch;
875
876         //loadprogress=abs(Random()%100);
877
878         //Background
879
880         //glEnable(GL_TEXTURE_2D);
881         glDisable(GL_TEXTURE_2D);
882         //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
883         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
884         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
885         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
886         glDisable(GL_CULL_FACE);
887         glDisable(GL_LIGHTING);
888         glDepthMask(0);
889         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
890         glPushMatrix();                                                                         // Store The Projection Matrix
891         glLoadIdentity();                                                                       // Reset The Projection Matrix
892         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
893         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
894         glPushMatrix();                                                                         // Store The Modelview Matrix
895         glLoadIdentity();                                                               // Reset The Modelview Matrix
896         glTranslatef(screenwidth/2,screenheight/2,0);
897         glScalef((float)screenwidth/2,(float)screenheight/2,1);
898         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
899         glDisable(GL_BLEND);
900         glColor4f(loadprogress/100,0,0,1);
901         /*if(loadscreencolor==0)glColor4f(1,1,1,1);
902         if(loadscreencolor==1)glColor4f(1,0,0,1);
903         if(loadscreencolor==2)glColor4f(0,1,0,1);
904         if(loadscreencolor==3)glColor4f(0,0,1,1);
905         if(loadscreencolor==4)glColor4f(1,1,0,1);
906         if(loadscreencolor==5)glColor4f(1,0,1,1);
907         */
908         glPushMatrix();
909         //glScalef(.25,.25,.25);
910         glBegin(GL_QUADS);
911         glTexCoord2f(0,0);
912         glVertex3f(-1,          -1,      0.0f);
913         glTexCoord2f(1,0);
914         glVertex3f(1,   -1,      0.0f);
915         glTexCoord2f(1,1);
916         glVertex3f(1,   1, 0.0f);
917         glTexCoord2f(0,1);
918         glVertex3f(-1,  1, 0.0f);
919         glEnd();
920         glPopMatrix();
921         glDisable(GL_TEXTURE_2D);
922         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
923         glPopMatrix();                                                                          // Restore The Old Projection Matrix
924         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
925         glPopMatrix();                                                                          // Restore The Old Projection Matrix
926         glDisable(GL_BLEND);
927         glDepthMask(1);
928         //Text
929         /*
930         glEnable(GL_TEXTURE_2D);
931         static char string[256]="";
932         sprintf (string, "LOADING... %d%",(int)loadprogress);
933         glColor4f(1,1,1,.2);
934         text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
935         glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
936         text.glPrint(280,125,string,1,1,640,480);
937         */
938 #ifdef WIN32
939         SwapBuffers( hDC);
940 #else
941         aglSwapBuffers(gaglContext); // send swap command
942 #endif
943
944         loadscreencolor=0;
945 }
946
947
948 void Game::InitGame()                                                                           
949 {
950 #ifndef WIN32
951         ProcessSerialNumber PSN;
952         ProcessInfoRec pinfo;
953         FSSpec pspec;
954         OSStatus err;
955         /* set up process serial number */
956         PSN.highLongOfPSN = 0;
957         PSN.lowLongOfPSN = kCurrentProcess;
958         /* set up info block */
959         pinfo.processInfoLength = sizeof(pinfo);
960         pinfo.processName = NULL;
961         pinfo.processAppSpec = &pspec;
962         /* grab the vrefnum and directory */
963         err = GetProcessInformation(&PSN, &pinfo);
964         if (err == noErr) {
965                 vRefNum = pspec.vRefNum;
966                 dirID = pspec.parID;
967         }
968 #endif
969
970         LOGFUNC;
971
972         autocam=0;
973
974         int i,j;
975
976         numchallengelevels=14;
977
978         registered=0;
979
980         /*char tempstring[256];
981         sprintf (tempstring, "%s", registrationname);
982         long num1;
983         long num2;
984         long num3;
985         long num4;
986         long long longnum;
987         longnum = MD5_string ( tempstring);
988         //longnum = 1111111111111111;
989         num1 = longnum/100000000;
990         num2 = longnum%100000000;
991         sprintf (tempstring, "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
992         */
993
994         FILE                    *tfile;
995         tfile=fopen( ":Data:Sounds:flame.ogg", "rb" );
996         if(tfile)
997         {
998                 long num1;
999                 long num2;
1000                 long long longnum;
1001                 long long longnuma;
1002                 long num1a;
1003                 long num2a;
1004
1005                 int numchars;
1006                 funpackf(tfile, "Bb", &registered);
1007                 if(registered)
1008                 {
1009                         funpackf(tfile, "Bi", &numchars);
1010                         if(numchars>0)
1011                         {
1012                                 for(j=0;j<numchars;j++)
1013                                 {
1014                                         funpackf(tfile, "Bb",  &registrationname[j]);
1015                                 }
1016                                 registrationname[numchars]='\0';
1017                                 funpackf(tfile, "Bi", &num1);
1018                                 funpackf(tfile, "Bi", &num2);
1019                                 longnum=num2+num1*100000000;
1020
1021                                 char tempstring[256];
1022                                 sprintf (tempstring, "%s-windows", registrationname);
1023                                 longnuma = MD5_string ( tempstring);    
1024                                 num1a = longnuma/100000000;
1025                                 num2a = longnuma%100000000;
1026                                 //if(num1a==num1&&num2a==num2)registered=1;
1027                                 if(numchars>2)registered=1;
1028                                 else registered=0;
1029                         }
1030                 }
1031                 fclose(tfile);
1032         }
1033         else registered=0;
1034
1035         accountactive=-1;
1036
1037         sprintf (mapname, ":Data:Users");
1038         tfile=fopen( mapname, "rb" );
1039         if(tfile)
1040         {
1041                 funpackf(tfile, "Bi", &numaccounts);
1042                 funpackf(tfile, "Bi", &accountactive);
1043                 if(numaccounts>0)
1044                 {
1045                         for(i=0;i<numaccounts;i++)
1046                         {
1047                                 funpackf(tfile, "Bf", &accountcampaigntime[i]);
1048                                 funpackf(tfile, "Bf", &accountcampaignscore[i]);
1049                                 funpackf(tfile, "Bf", &accountcampaignfasttime[i]);
1050                                 funpackf(tfile, "Bf", &accountcampaignhighscore[i]);
1051                                 funpackf(tfile, "Bi", &accountdifficulty[i]);
1052                                 funpackf(tfile, "Bi", &accountprogress[i]);
1053                                 funpackf(tfile, "Bi", &accountcampaignchoicesmade[i]);
1054                                 for(j=0;j<accountcampaignchoicesmade[i];j++)
1055                                 {
1056                                         funpackf(tfile, "Bi", &accountcampaignchoices[i][j]);
1057                                         if (accountcampaignchoices[i][j] >= 10)
1058                                         {
1059                                                 accountcampaignchoices[i][j] = 0;
1060                                         }
1061                                 }
1062                                 funpackf(tfile, "Bf", &accountpoints[i]);
1063                                 for(j=0;j<50;j++)
1064                                 {
1065                                         funpackf(tfile, "Bf", &accounthighscore[i][j]);
1066                                         funpackf(tfile, "Bf", &accountfasttime[i][j]);
1067                                 }
1068                                 for(j=0;j<60;j++)
1069                                 {
1070                                         funpackf(tfile, "Bb",  &accountunlocked[i][j]);
1071                                 }
1072                                 int temp;
1073                                 funpackf(tfile, "Bi",  &temp);
1074                                 if(temp>0)
1075                                 {
1076                                         for(j=0;j<temp;j++)
1077                                         {
1078                                                 funpackf(tfile, "Bb",  &accountname[i][j]);
1079                                         }
1080                                 }
1081                         }
1082                 }
1083
1084                 fclose(tfile);
1085         }
1086
1087         tintr=1;
1088         tintg=1;
1089         tintb=1;
1090
1091         whichjointstartarray[0]=righthip;
1092         whichjointendarray[0]=rightfoot;
1093
1094         whichjointstartarray[1]=righthip;
1095         whichjointendarray[1]=rightankle;
1096
1097         whichjointstartarray[2]=righthip;
1098         whichjointendarray[2]=rightknee;
1099
1100         whichjointstartarray[3]=rightknee;
1101         whichjointendarray[3]=rightankle;
1102
1103         whichjointstartarray[4]=rightankle;
1104         whichjointendarray[4]=rightfoot;
1105
1106         whichjointstartarray[5]=lefthip;
1107         whichjointendarray[5]=leftfoot;
1108
1109         whichjointstartarray[6]=lefthip;
1110         whichjointendarray[6]=leftankle;
1111
1112         whichjointstartarray[7]=lefthip;
1113         whichjointendarray[7]=leftknee;
1114
1115         whichjointstartarray[8]=leftknee;
1116         whichjointendarray[8]=leftankle;
1117
1118         whichjointstartarray[9]=leftankle;
1119         whichjointendarray[9]=leftfoot;
1120
1121         whichjointstartarray[10]=abdomen;
1122         whichjointendarray[10]=rightshoulder;
1123
1124         whichjointstartarray[11]=abdomen;
1125         whichjointendarray[11]=rightelbow;
1126
1127         whichjointstartarray[12]=abdomen;
1128         whichjointendarray[12]=rightwrist;
1129
1130         whichjointstartarray[13]=abdomen;
1131         whichjointendarray[13]=righthand;
1132
1133         whichjointstartarray[14]=rightshoulder;
1134         whichjointendarray[14]=rightelbow;
1135
1136         whichjointstartarray[15]=rightelbow;
1137         whichjointendarray[15]=rightwrist;
1138
1139         whichjointstartarray[16]=rightwrist;
1140         whichjointendarray[16]=righthand;
1141
1142         whichjointstartarray[17]=abdomen;
1143         whichjointendarray[17]=leftshoulder;
1144
1145         whichjointstartarray[18]=abdomen;
1146         whichjointendarray[18]=leftelbow;
1147
1148         whichjointstartarray[19]=abdomen;
1149         whichjointendarray[19]=leftwrist;
1150
1151         whichjointstartarray[20]=abdomen;
1152         whichjointendarray[20]=lefthand;
1153
1154         whichjointstartarray[21]=leftshoulder;
1155         whichjointendarray[21]=leftelbow;
1156
1157         whichjointstartarray[22]=leftelbow;
1158         whichjointendarray[22]=leftwrist;
1159
1160         whichjointstartarray[23]=leftwrist;
1161         whichjointendarray[23]=lefthand;
1162
1163         whichjointstartarray[24]=abdomen;
1164         whichjointendarray[24]=neck;
1165
1166         whichjointstartarray[25]=neck;
1167         whichjointendarray[25]=head;
1168
1169         FadeLoadingScreen(0);
1170
1171         stillloading=1;
1172
1173         texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1174
1175         int temptexdetail=texdetail;
1176         texdetail=1;
1177         text.LoadFontTexture(":Data:Textures:Font.png");
1178         text.BuildFont();
1179         texdetail=temptexdetail;
1180
1181         FadeLoadingScreen(10);
1182
1183         if(detail==2){
1184                 texdetail=1;
1185                 terraindetail=1;
1186         }
1187         if(detail==1){
1188                 texdetail=2;
1189                 terraindetail=1;
1190         }
1191         if(detail==0){
1192                 texdetail=4;
1193                 terraindetail=1;
1194                 //terraindetail=2;
1195         }
1196
1197         for (int it = 0; it < 100; ++it)
1198         {
1199                 channels[it] = -1;
1200                 samp[it] = NULL;
1201         }
1202         for (int it = 0; it < 20; ++it)
1203         {
1204                 strm[it] = NULL;
1205         }
1206
1207         LOG("Initializing sound system...");
1208
1209         FSOUND_Init(44100, 32, 0);
1210
1211         FSOUND_SetSFXMasterVolume((int)(volume*255));
1212
1213         strm[stream_music3] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music3.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=0;}
1214 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music3], 4.0f, 1000.0f);    
1215         FSOUND_Stream_SetMode(strm[stream_music3], FSOUND_LOOP_NORMAL);
1216
1217         if(musictoggle){
1218 //              PlaySoundEx( stream_music3, strm[stream_music3], NULL, TRUE);
1219                 PlayStreamEx(stream_music3, strm[stream_music3], 0, TRUE);
1220                 FSOUND_SetPaused(channels[stream_music3], FALSE);
1221                 FSOUND_SetVolume(channels[stream_music3], 256);
1222         }
1223
1224         FadeLoadingScreen(20);
1225
1226         if(ambientsound){
1227                 strm[stream_wind] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:wind.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1228 //              FSOUND_Sample_SetMinMaxDistance(strm[stream_wind], 4.0f, 1000.0f);      
1229                 FSOUND_Stream_SetMode(strm[stream_wind], FSOUND_LOOP_NORMAL);
1230
1231                 FadeLoadingScreen(30);
1232
1233                 strm[stream_desertambient] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:desertambient.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1234 //              FSOUND_Sample_SetMinMaxDistance(strm[stream_desertambient], 4.0f, 1000.0f);     
1235                 FSOUND_Stream_SetMode(strm[stream_desertambient], FSOUND_LOOP_NORMAL);
1236         }
1237
1238         FadeLoadingScreen(40);
1239
1240         samp[firestartsound] = FSOUND_Sample_Load(FSOUND_FREE, ConvertFileName(":Data:Sounds:firestart.ogg"), FSOUND_2D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1241         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1242
1243         strm[stream_firesound] = FSOUND_Stream_Open(":Data:Sounds:fire.ogg", FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1244 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_firesound], 8.0f, 2000.0f); 
1245         FSOUND_Stream_SetMode(strm[stream_firesound], FSOUND_LOOP_NORMAL);
1246
1247         FadeLoadingScreen(50);
1248
1249         samp[fireendsound] = FSOUND_Sample_Load(FSOUND_FREE, ConvertFileName(":Data:Sounds:fireend.ogg"), FSOUND_2D, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1250         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1251
1252         //if(musictoggle){
1253         strm[stream_music1grass] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music1grass.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=1;}
1254 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music1grass], 4.0f, 1000.0f);       
1255         FSOUND_Stream_SetMode(strm[stream_music1grass], FSOUND_LOOP_NORMAL);
1256
1257         strm[stream_music1snow] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music1snow.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=2;}
1258 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music1snow], 4.0f, 1000.0f);        
1259         FSOUND_Stream_SetMode(strm[stream_music1snow], FSOUND_LOOP_NORMAL);
1260
1261         FadeLoadingScreen(60);
1262
1263         strm[stream_music1desert] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music1desert.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=3;}
1264 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music1desert], 4.0f, 1000.0f);      
1265         FSOUND_Stream_SetMode(strm[stream_music1desert], FSOUND_LOOP_NORMAL);
1266
1267         FadeLoadingScreen(80);
1268         strm[stream_music2] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music2.ogg"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=4;}
1269 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music2], 4.0f, 1000.0f);    
1270         FSOUND_Stream_SetMode(strm[stream_music2], FSOUND_LOOP_NORMAL);
1271
1272         //}
1273
1274
1275         FadeLoadingScreen(90);
1276
1277
1278         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
1279
1280         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
1281         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
1282         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
1283
1284         temptexdetail=texdetail;
1285         if(texdetail>2)texdetail=2;
1286         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
1287         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
1288         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
1289         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
1290         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
1291         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
1292         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
1293         texdetail=temptexdetail;
1294
1295         loaddistrib=0;
1296         anim=0;
1297
1298         FadeLoadingScreen(95);
1299
1300
1301         gameon=0;
1302         mainmenu=1;
1303
1304         stillloading=0;
1305         firstload=0;
1306         oldmainmenu=0;
1307
1308         newdetail=detail;
1309         newscreenwidth=screenwidth;
1310         newscreenheight=screenheight;
1311
1312         
1313         
1314         /*
1315         float gLoc[3]={0,0,0};
1316         float vel[3]={0,0,0};
1317         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
1318         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
1319         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1320         FSOUND_SetVolume(channels[firestartsound], 256);
1321         FSOUND_SetPaused(channels[firestartsound], FALSE);
1322         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1323
1324         flashr=1;
1325         flashg=0;
1326         flashb=0;
1327         flashamount=1;
1328         flashdelay=1;
1329         */
1330 }
1331
1332
1333 void Game::LoadStuff()                                                                          
1334 {
1335         static float temptexdetail;
1336         static float viewdistdetail;
1337         static int i,j,texsize; 
1338         float megascale =1;
1339
1340         LOGFUNC;
1341
1342         visibleloading=1;
1343
1344         /*musicvolume[3]=512;
1345         PlaySoundEx( music4, samp[music4], NULL, TRUE);
1346         FSOUND_SetPaused(channels[music4], FALSE);
1347         FSOUND_SetVolume(channels[music4], 512);
1348         */
1349         loadtime=0;
1350
1351         stillloading=1;
1352
1353         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1354
1355         newnetmessages=0;
1356
1357         for(i=0;i<maxplayers;i++)
1358         {
1359                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
1360                 {
1361                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
1362                 }
1363                 player[i].skeleton.drawmodel.textureptr=0;;
1364         }
1365
1366         //temptexdetail=texdetail;
1367         //texdetail=1;
1368         i=abs(Random()%4);
1369         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
1370         //texdetail=temptexdetail;
1371
1372         temptexdetail=texdetail;
1373         texdetail=1;
1374         text.LoadFontTexture(":Data:Textures:Font.png");
1375         text.BuildFont();
1376         texdetail=temptexdetail;
1377
1378         numsounds=71;           
1379
1380         viewdistdetail=2;
1381         viewdistance=50*megascale*viewdistdetail;
1382
1383         brightness=100;
1384
1385
1386
1387         if(detail==2){
1388                 texdetail=1;
1389                 terraindetail=1;
1390         }
1391         if(detail==1){
1392                 texdetail=2;
1393                 terraindetail=1;
1394         }
1395         if(detail==0){
1396                 texdetail=4;
1397                 terraindetail=1;
1398                 //terraindetail=2;
1399         }
1400
1401         realtexdetail=texdetail;
1402
1403         /*texdetail/=4;
1404         if(texdetail<1)texdetail=1;
1405         realtexdetail=texdetail*4;
1406         */
1407         numplayers=1;
1408
1409
1410
1411         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
1412
1413         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1414
1415         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1416         */
1417
1418
1419         LOG("Loading weapon data...");
1420
1421         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1422         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1423         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1424         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1425         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1426         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1427         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1428
1429         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1430         weapons.throwingknifemodel.Scale(.001,.001,.001);
1431         //weapons.throwingknifemodel.Rotate(0,0,-90);
1432         weapons.throwingknifemodel.Rotate(90,0,0);
1433         weapons.throwingknifemodel.Rotate(0,90,0);
1434         weapons.throwingknifemodel.flat=0;
1435         weapons.throwingknifemodel.CalculateNormals(1);
1436         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1437
1438         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1439         weapons.swordmodel.Scale(.001,.001,.001);
1440         //weapons.swordmodel.Rotate(0,0,-90);
1441         weapons.swordmodel.Rotate(90,0,0);
1442         weapons.swordmodel.Rotate(0,90,0);
1443         weapons.swordmodel.Rotate(0,0,90);
1444         weapons.swordmodel.flat=1;
1445         weapons.swordmodel.CalculateNormals(1);
1446         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1447
1448         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1449         weapons.staffmodel.Scale(.005,.005,.005);
1450         //weapons.staffmodel.Rotate(0,0,-90);
1451         weapons.staffmodel.Rotate(90,0,0);
1452         weapons.staffmodel.Rotate(0,90,0);
1453         weapons.staffmodel.Rotate(0,0,90);
1454         weapons.staffmodel.flat=1;
1455         weapons.staffmodel.CalculateNormals(1);
1456         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1457
1458         //temptexdetail=texdetail;
1459         //if(texdetail>4)texdetail=4;
1460         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1461
1462         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1463
1464         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1465
1466         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1467
1468
1469         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1470
1471         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1472
1473         /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1);
1474
1475         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1);
1476
1477         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1);
1478
1479         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1);
1480
1481         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1);
1482
1483         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1);
1484         //texdetail=temptexdetail;
1485         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1);*/
1486
1487
1488
1489         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1490
1491         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1492
1493
1494         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1495
1496
1497         LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1498         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1499         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1500         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1501         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1502         LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1503         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1504         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1505         LoadTexture(":Data:Textures:splinter.png",&sprites.splintertexture,1,1);
1506         LoadTexture(":Data:Textures:leaf.png",&sprites.leaftexture,1,1);
1507         LoadTexture(":Data:Textures:tooth.png",&sprites.toothtexture,1,1);
1508
1509         rotation=0;
1510         rotation2=0;
1511         ReSizeGLScene(90,.01);
1512
1513         viewer=0;
1514
1515
1516
1517
1518         if(detail)kTextureSize=1024;
1519         if(detail==1)kTextureSize=512;
1520         if(detail==0)kTextureSize=256;
1521
1522
1523         //drawmode=motionblurmode;
1524
1525         //Set up distant light
1526         light.color[0]=.95;
1527         light.color[1]=.95;
1528         light.color[2]=1;
1529         light.ambient[0]=.2;
1530         light.ambient[1]=.2;
1531         light.ambient[2]=.24;
1532         light.location.x=1;
1533         light.location.y=1;
1534         light.location.z=-.2;
1535         Normalise(&light.location);
1536
1537         LoadingScreen();
1538
1539         SetUpLighting();
1540
1541
1542         fadestart=.6;
1543         gravity=-10;
1544
1545         texscale=.2/megascale/viewdistdetail;
1546         terrain.scale=3*megascale*terraindetail*viewdistdetail;
1547
1548         viewer.x=terrain.size/2*terrain.scale;
1549         viewer.z=terrain.size/2*terrain.scale;
1550
1551         hawk.load((char *)":Data:Models:hawk.solid",1);
1552         hawk.Scale(.03,.03,.03);
1553         hawk.Rotate(90,1,1);
1554         hawk.CalculateNormals(0);
1555         hawk.ScaleNormals(-1,-1,-1);
1556         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1557         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1558         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1559
1560
1561         eye.load((char *)":Data:Models:eye.solid",1);
1562         eye.Scale(.03,.03,.03);
1563         eye.CalculateNormals(0);
1564
1565         cornea.load((char *)":Data:Models:cornea.solid",1);
1566         cornea.Scale(.03,.03,.03);
1567         cornea.CalculateNormals(0);
1568
1569         iris.load((char *)":Data:Models:iris.solid",1);
1570         iris.Scale(.03,.03,.03);
1571         iris.CalculateNormals(0);
1572
1573         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1574         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1575
1576         oldenvironment=-4;
1577
1578         gameon=1;
1579         mainmenu=0;
1580
1581         firstload=0;
1582         //if(targetlevel!=7)
1583                 Loadlevel(targetlevel);
1584
1585
1586         rabbitcoords=player[0].coords;
1587         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1588
1589         animation[runanim].Load((char *)":Data:Animations:Run",middleheight,neutral);
1590
1591         animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
1592         animation[stopanim].Load((char *)":Data:Animations:Stop",middleheight,neutral);
1593
1594         animation[jumpupanim].Load((char *)":Data:Animations:JumpUp",highheight,neutral);
1595         animation[jumpdownanim].Load((char *)":Data:Animations:JumpDown",highheight,neutral);
1596
1597         animation[landanim].Load((char *)":Data:Animations:Landing",lowheight,neutral);
1598         animation[landhardanim].Load((char *)":Data:Animations:Landhard",lowheight,neutral);
1599         animation[climbanim].Load((char *)":Data:Animations:Climb",lowheight,neutral);
1600         animation[hanganim].Load((char *)":Data:Animations:Hangon",lowheight,neutral);
1601         animation[spinkickanim].Load((char *)":Data:Animations:SpinKick",middleheight,normalattack);
1602
1603         animation[getupfromfrontanim].Load((char *)":Data:Animations:GetUpFromFront",lowheight,neutral);
1604         animation[getupfrombackanim].Load((char *)":Data:Animations:GetUpFromBack",lowheight,neutral);
1605         animation[crouchanim].Load((char *)":Data:Animations:Crouch",lowheight,neutral);
1606         animation[sneakanim].Load((char *)":Data:Animations:Sneak",lowheight,neutral);
1607         animation[rollanim].Load((char *)":Data:Animations:Roll",lowheight,neutral);
1608         animation[flipanim].Load((char *)":Data:Animations:Flip",highheight,neutral);
1609         animation[frontflipanim].Load((char *)":Data:Animations:Flip",highheight,neutral);
1610         animation[spinkickreversedanim].Load((char *)":Data:Animations:SpinKickCaught",middleheight,reversed);
1611
1612         animation[spinkickreversalanim].Load((char *)":Data:Animations:SpinKickCatch",middleheight,reversal);
1613         animation[lowkickanim].Load((char *)":Data:Animations:lowkick",middleheight,normalattack);
1614         animation[sweepanim].Load((char *)":Data:Animations:sweep",lowheight,normalattack);
1615         animation[sweepreversedanim].Load((char *)":Data:Animations:SweepCaught",lowheight,reversed);
1616         animation[sweepreversalanim].Load((char *)":Data:Animations:SweepCatch",middleheight,reversal);
1617         animation[rabbitkickanim].Load((char *)":Data:Animations:RabbitKick",middleheight,normalattack);
1618         animation[rabbitkickreversedanim].Load((char *)":Data:Animations:RabbitKickCaught",middleheight,reversed);
1619         animation[rabbitkickreversalanim].Load((char *)":Data:Animations:RabbitKickCatch",lowheight,reversal);
1620         animation[upunchanim].Load((char *)":Data:Animations:Upunch",middleheight,normalattack);
1621         animation[staggerbackhighanim].Load((char *)":Data:Animations:Staggerbackhigh",middleheight,neutral);
1622         animation[upunchreversedanim].Load((char *)":Data:Animations:UpunchCaught",middleheight,reversed);
1623
1624         animation[upunchreversalanim].Load((char *)":Data:Animations:UpunchCatch",middleheight,reversal);
1625         animation[hurtidleanim].Load((char *)":Data:Animations:Hurtidle",middleheight,neutral);
1626         animation[backhandspringanim].Load((char *)":Data:Animations:Backhandspring",middleheight,neutral);
1627         animation[fightidleanim].Load((char *)":Data:Animations:Fightidle",middleheight,neutral);
1628         animation[walkanim].Load((char *)":Data:Animations:Walk",middleheight,neutral);
1629
1630         animation[fightsidestep].Load((char *)":Data:Animations:Fightsidestep",middleheight,neutral);
1631         animation[killanim].Load((char *)":Data:Animations:Kill",middleheight,normalattack);
1632         animation[sneakattackanim].Load((char *)":Data:Animations:Sneakattack",middleheight,reversal);
1633         animation[sneakattackedanim].Load((char *)":Data:Animations:Sneakattacked",middleheight,reversed);
1634         animation[drawrightanim].Load((char *)":Data:Animations:drawright",middleheight,neutral);
1635         animation[knifeslashstartanim].Load((char *)":Data:Animations:slashstart",middleheight,normalattack);
1636         animation[crouchdrawrightanim].Load((char *)":Data:Animations:crouchdrawright",lowheight,neutral);
1637         animation[crouchstabanim].Load((char *)":Data:Animations:crouchstab",lowheight,normalattack);
1638
1639         animation[knifefollowanim].Load((char *)":Data:Animations:slashfollow",middleheight,reversal);
1640         animation[knifefollowedanim].Load((char *)":Data:Animations:slashfollowed",middleheight,reversed);
1641         animation[knifethrowanim].Load((char *)":Data:Animations:knifethrow",middleheight,normalattack);
1642         animation[removeknifeanim].Load((char *)":Data:Animations:removeknife",middleheight,neutral);
1643         animation[crouchremoveknifeanim].Load((char *)":Data:Animations:crouchremoveknife",lowheight,neutral);
1644         animation[jumpreversedanim].Load((char *)":Data:Animations:JumpCaught",middleheight,reversed);
1645         animation[jumpreversalanim].Load((char *)":Data:Animations:JumpCatch",middleheight,reversal);
1646         animation[staggerbackhardanim].Load((char *)":Data:Animations:Staggerbackhard",middleheight,neutral);
1647
1648         animation[dropkickanim].Load((char *)":Data:Animations:Dropkick",middleheight,normalattack);
1649         animation[winduppunchanim].Load((char *)":Data:Animations:Winduppunch",middleheight,normalattack);
1650         animation[winduppunchblockedanim].Load((char *)":Data:Animations:Winduppunchblocked",middleheight,normalattack);
1651         animation[blockhighleftanim].Load((char *)":Data:Animations:Blockhighleft",middleheight,normalattack);
1652         animation[blockhighleftstrikeanim].Load((char *)":Data:Animations:Blockhighleftstrike",middleheight,normalattack);
1653         animation[backflipanim].Load((char *)":Data:Animations:Backflip",highheight,neutral);
1654         animation[walljumpbackanim].Load((char *)":Data:Animations:Walljumpback",highheight,neutral);
1655         animation[walljumpfrontanim].Load((char *)":Data:Animations:Walljumpfront",highheight,neutral);
1656         animation[rightflipanim].Load((char *)":Data:Animations:Rightflip",highheight,neutral);
1657         animation[walljumprightanim].Load((char *)":Data:Animations:Walljumpright",highheight,neutral);
1658         animation[leftflipanim].Load((char *)":Data:Animations:Leftflip",highheight,neutral);
1659         animation[walljumpleftanim].Load((char *)":Data:Animations:Walljumpleft",highheight,neutral);
1660         animation[walljumprightkickanim].Load((char *)":Data:Animations:Walljumprightkick",highheight,neutral);
1661         animation[walljumpleftkickanim].Load((char *)":Data:Animations:Walljumpleftkick",highheight,neutral);
1662         animation[knifefightidleanim].Load((char *)":Data:Animations:Knifefightidle",middleheight,neutral);
1663         animation[knifesneakattackanim].Load((char *)":Data:Animations:Knifesneakattack",middleheight,reversal);
1664         animation[knifesneakattackedanim].Load((char *)":Data:Animations:Knifesneakattacked",middleheight,reversed);
1665         animation[swordfightidleanim].Load((char *)":Data:Animations:swordfightidle",middleheight,neutral);
1666         animation[drawleftanim].Load((char *)":Data:Animations:drawleft",middleheight,neutral);
1667         animation[swordslashanim].Load((char *)":Data:Animations:swordslash",middleheight,normalattack);
1668         animation[swordgroundstabanim].Load((char *)":Data:Animations:swordgroundstab",lowheight,normalattack);
1669         animation[dodgebackanim].Load((char *)":Data:Animations:dodgeback",middleheight,neutral);
1670         animation[swordsneakattackanim].Load((char *)":Data:Animations:Swordsneakattack",middleheight,reversal);
1671         animation[swordsneakattackedanim].Load((char *)":Data:Animations:Swordsneakattacked",middleheight,reversed);
1672         animation[swordslashreversedanim].Load((char *)":Data:Animations:swordslashCaught",middleheight,reversed);
1673         animation[swordslashreversalanim].Load((char *)":Data:Animations:swordslashCatch",middleheight,reversal);
1674         animation[knifeslashreversedanim].Load((char *)":Data:Animations:knifeslashCaught",middleheight,reversed);
1675         animation[knifeslashreversalanim].Load((char *)":Data:Animations:knifeslashCatch",middleheight,reversal);
1676         animation[swordfightidlebothanim].Load((char *)":Data:Animations:swordfightidleboth",middleheight,neutral);
1677         animation[swordslashparryanim].Load((char *)":Data:Animations:sworduprightparry",middleheight,normalattack);
1678         animation[swordslashparriedanim].Load((char *)":Data:Animations:swordslashparried",middleheight,normalattack);
1679         animation[wolfidle].Load((char *)":Data:Animations:Wolfidle",middleheight,neutral);
1680         animation[wolfcrouchanim].Load((char *)":Data:Animations:Wolfcrouch",lowheight,neutral);
1681         animation[wolflandanim].Load((char *)":Data:Animations:Wolflanding",lowheight,neutral);
1682         animation[wolflandhardanim].Load((char *)":Data:Animations:Wolflandhard",lowheight,neutral);
1683         animation[wolfrunanim].Load((char *)":Data:Animations:Wolfrun",middleheight,neutral);
1684         animation[wolfrunninganim].Load((char *)":Data:Animations:Wolfrunning",middleheight,neutral);
1685         animation[rabbitrunninganim].Load((char *)":Data:Animations:Rabbitrunning",middleheight,neutral);
1686         animation[wolfstopanim].Load((char *)":Data:Animations:Wolfstop",middleheight,neutral);
1687         animation[rabbittackleanim].Load((char *)":Data:Animations:Rabbittackle",middleheight,neutral);
1688         animation[rabbittacklinganim].Load((char *)":Data:Animations:Rabbittackling",middleheight,reversal);
1689         animation[rabbittackledbackanim].Load((char *)":Data:Animations:Rabbittackledback",middleheight,reversed);
1690         animation[rabbittackledfrontanim].Load((char *)":Data:Animations:Rabbittackledfront",middleheight,reversed);
1691         animation[wolfslapanim].Load((char *)":Data:Animations:Wolfslap",middleheight,normalattack);
1692         animation[staffhitanim].Load((char *)":Data:Animations:StaffHit",middleheight,normalattack);
1693         animation[staffgroundsmashanim].Load((char *)":Data:Animations:StaffGroundSmash",lowheight,normalattack);
1694         animation[staffspinhitanim].Load((char *)":Data:Animations:Spinwhack",middleheight,normalattack);
1695         animation[staffhitreversedanim].Load((char *)":Data:Animations:StaffHitCaught",middleheight,reversed);
1696         animation[staffhitreversalanim].Load((char *)":Data:Animations:StaffHitCatch",middleheight,reversal);
1697         animation[staffspinhitreversedanim].Load((char *)":Data:Animations:SpinWhackCaught",middleheight,reversed);
1698         animation[staffspinhitreversalanim].Load((char *)":Data:Animations:SpinWhackCatch",middleheight,reversal);
1699
1700         animation[sitanim].Load((char *)":Data:Animations:Sit",lowheight,neutral);
1701         animation[sleepanim].Load((char *)":Data:Animations:Sleep",lowheight,neutral);
1702         animation[talkidleanim].Load((char *)":Data:Animations:TalkIdle",middleheight,neutral);
1703
1704         animation[sitwallanim].Load((char *)":Data:Animations:Dying",lowheight,neutral);
1705         animation[dead1anim].Load((char *)":Data:Animations:Dead1",lowheight,neutral);
1706         animation[dead2anim].Load((char *)":Data:Animations:Dead2",lowheight,neutral);
1707         animation[dead3anim].Load((char *)":Data:Animations:Dead3",lowheight,neutral);
1708         animation[dead4anim].Load((char *)":Data:Animations:Dead4",lowheight,neutral);
1709         //Fix knife stab, too lazy to do it manually
1710         XYZ moveamount;
1711         moveamount=0;
1712         moveamount.z=2;
1713         for(i=0;i<player[0].skeleton.num_joints;i++){
1714                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1715                         animation[knifesneakattackanim].position[i][j]+=moveamount;
1716                 }       
1717         }
1718
1719         loadscreencolor=4;
1720         LoadingScreen();
1721
1722         for(i=0;i<player[0].skeleton.num_joints;i++){
1723                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1724                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1725                 }       
1726         }
1727
1728         loadscreencolor=4;
1729         LoadingScreen();
1730
1731         for(i=0;i<player[0].skeleton.num_joints;i++){
1732                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1733                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1734                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1735                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1736         }
1737         animation[dead1anim].speed[0]=0.001;
1738         animation[dead2anim].speed[0]=0.001;
1739         animation[dead3anim].speed[0]=0.001;
1740         animation[dead4anim].speed[0]=0.001;
1741
1742         animation[dead1anim].speed[1]=0.001;
1743         animation[dead2anim].speed[1]=0.001;
1744         animation[dead3anim].speed[1]=0.001;
1745         animation[dead4anim].speed[1]=0.001;
1746
1747         for(i=0;i<player[0].skeleton.num_joints;i++){
1748                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1749                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1750                 }       
1751         }
1752         loadscreencolor=4;
1753         LoadingScreen();
1754         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1755                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1756         }       
1757
1758         loadscreencolor=4;
1759         LoadingScreen();
1760
1761         for(i=0;i<player[0].skeleton.num_joints;i++){
1762                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1763                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1764                 }       
1765         }
1766         /*
1767         for(i=0;i<player[0].skeleton.num_joints;i++){
1768         for(j=0;j<animation[sleepanim].numframes;j++){
1769         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1770         }       
1771         }
1772         */
1773         loadscreencolor=4;
1774         LoadingScreen();
1775         temptexdetail=texdetail;
1776         texdetail=1;
1777         texdetail=temptexdetail;
1778
1779         loadscreencolor=4;
1780         LoadingScreen();
1781
1782         //if(ismotionblur){
1783         if(!screentexture){
1784                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1785
1786                 glGenTextures( 1, &screentexture );
1787                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1788
1789
1790                 glEnable(GL_TEXTURE_2D);
1791                 glBindTexture( GL_TEXTURE_2D, screentexture);
1792                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1793                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1794
1795                 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);                
1796         }
1797         //}
1798
1799         LoadSounds();
1800
1801         /*PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
1802         FSOUND_SetVolume(channels[consolesuccesssound], 256);
1803         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
1804         */
1805         if(targetlevel!=7){
1806                 float gLoc[3]={0,0,0};
1807                 float vel[3]={0,0,0};
1808                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1809                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1810                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1811                 FSOUND_SetVolume(channels[fireendsound], 256);
1812                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1813                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1814         }
1815
1816         stillloading=0;
1817         loading=0;
1818         changedelay=1;
1819
1820         visibleloading=0;
1821 }
1822
1823 Game::Game()
1824 {
1825         terraintexture = 0;
1826         terraintexture2 = 0;
1827         terraintexture3 = 0;
1828         screentexture = 0;
1829         screentexture2 = 0;
1830         logotexture = 0;
1831         loadscreentexture = 0;
1832         Maparrowtexture = 0;
1833         Mapboxtexture = 0;
1834         Mapcircletexture = 0;
1835         cursortexture = 0;
1836
1837         memset(Mainmenuitems, 0, sizeof(Mainmenuitems));
1838
1839         nummenuitems = 0;
1840
1841         memset(startx, 0, sizeof(startx));
1842         memset(starty, 0, sizeof(starty));
1843         memset(endx, 0, sizeof(endx));
1844         memset(endy, 0, sizeof(endy));
1845
1846         memset(selectedlong, 0, sizeof(selectedlong));
1847         memset(offsetx, 0, sizeof(offsetx));
1848         memset(offsety, 0, sizeof(offsety));
1849         memset(movex, 0, sizeof(movex));
1850         memset(movey, 0, sizeof(movey));
1851         memset(endy, 0, sizeof(endy));
1852
1853         transition = 0;
1854         anim = 0;
1855         selected = 0;
1856         loaddistrib = 0;
1857         keyselect = 0;
1858         indemo = 0;
1859         registered = 0;
1860
1861         won = 0;
1862
1863         entername = 0;
1864
1865         memset(menustring, 0, sizeof(menustring));
1866         memset(registrationname, 0, sizeof(registrationname));
1867         registrationnumber = 0;
1868
1869         newdetail = 0;
1870         newscreenwidth = 0;
1871         newscreenheight = 0;
1872
1873         gameon = 0;
1874         deltah = 0,deltav = 0;
1875         mousecoordh = 0,mousecoordv = 0;
1876         oldmousecoordh = 0,oldmousecoordv = 0;
1877         rotation = 0,rotation2 = 0;
1878
1879 //      SkyBox skybox;
1880
1881         cameramode = 0;
1882         cameratogglekeydown = 0;
1883         chattogglekeydown = 0;
1884         olddrawmode = 0;
1885         drawmode = 0;
1886         drawmodetogglekeydown = 0;
1887         explodetogglekeydown = 0;
1888         detailtogglekeydown = 0;
1889         firstload = 0;
1890         oldbutton = 0;
1891
1892         leveltime = 0;
1893         loadtime = 0;
1894
1895 //      Model hawk;
1896
1897 //      XYZ hawkcoords;
1898 //      XYZ realhawkcoords;
1899
1900         hawktexture = 0;
1901         hawkrotation = 0;
1902         hawkcalldelay = 0;
1903 /*
1904         Model eye;
1905         Model iris;
1906         Model cornea;
1907 */
1908         stealthloading = 0;
1909
1910         campaignnumlevels = 0;
1911
1912         memset(campaignmapname, 0, sizeof(campaignmapname));
1913         memset(campaigndescription, 0, sizeof(campaigndescription));
1914         memset(campaignchoosenext, 0, sizeof(campaignchoosenext));
1915         memset(campaignnumnext, 0, sizeof(campaignnumnext));
1916         memset(campaignnextlevel, 0, sizeof(campaignnextlevel));
1917         int campaignchoicesmade;
1918         memset(campaignchoices, 0, sizeof(campaignchoices));
1919         memset(campaignlocationx, 0, sizeof(campaignlocationx));
1920         memset(campaignlocationy, 0, sizeof(campaignlocationy));
1921         memset(campaignlocationy, 0, sizeof(campaignlocationy));
1922
1923         campaignchoicenum = 0;
1924
1925         memset(campaignchoicewhich, 0, sizeof(campaignchoicewhich));
1926
1927         whichchoice = 0;
1928
1929         numlevelspassed = 0;
1930
1931         memset(levelorder, 0, sizeof(levelorder));
1932         memset(levelvisible, 0, sizeof(levelvisible));
1933         memset(levelhighlight, 0, sizeof(levelhighlight));
1934
1935         minimap = 0;
1936
1937         musictype = 0,oldmusictype = 0,oldoldmusictype = 0;
1938         realthreat = 0;
1939
1940 //      Model rabbit;
1941 //      XYZ rabbitcoords;
1942
1943 //      XYZ mapcenter;
1944         mapradius = 0;
1945
1946 //      Text text;
1947         fps = 0;
1948
1949 //      XYZ cameraloc;
1950         cameradist = 0;
1951
1952         envtogglekeydown = 0;
1953         slomotogglekeydown = 0;
1954         texturesizetogglekeydown = 0;
1955         freezetogglekeydown = 0;
1956         drawtoggle = 0;
1957
1958         editorenabled = 0;
1959         editortype = 0;
1960         editorsize = 0;
1961         editorrotation = 0;
1962         editorrotation2 = 0;
1963
1964         brightness = 0;
1965
1966         quit = 0;
1967         tryquit = 0;
1968
1969 //      XYZ pathpoint[30];
1970         numpathpoints = 0;
1971         memset(numpathpointconnect, 0, sizeof(numpathpointconnect));
1972         memset(pathpointconnect, 0, sizeof(pathpointconnect));
1973         pathpointselected = 0;
1974
1975         endgame = 0;
1976         scoreadded = 0;
1977         numchallengelevels = 0;
1978
1979         console = 0;
1980         archiveselected = 0;
1981
1982         memset(consoletext, 0, sizeof(consoletext));
1983         memset(consolechars, 0, sizeof(consolechars));
1984         chatting = 0;
1985         memset(displaytext, 0, sizeof(displaytext));
1986         memset(displaychars, 0, sizeof(displaychars));
1987         memset(displaytime, 0, sizeof(displaytime));
1988         displayblinkdelay = 0;
1989         displayblink = 0;
1990         displayselected = 0;
1991         consolekeydown = 0;
1992         consoletogglekeydown = 0;
1993         consoleblinkdelay = 0;
1994         consoleblink = 0;
1995         consoleselected = 0;
1996         memset(togglekey, 0, sizeof(togglekey));
1997         memset(togglekeydelay, 0, sizeof(togglekeydelay));
1998         registernow = 0;
1999         autocam = 0;
2000
2001         crouchkey = 0,jumpkey = 0,forwardkey = 0,chatkey = 0,backkey = 0,leftkey = 0,rightkey = 0,drawkey = 0,throwkey = 0,attackkey = 0;
2002         oldattackkey = 0;
2003
2004         loading = 0;
2005         talkdelay = 0;
2006
2007         numboundaries = 0;
2008 //      XYZ boundary[360];
2009
2010         whichlevel = 0;
2011         oldenvironment = 0;
2012         targetlevel = 0;
2013         changedelay = 0;
2014
2015         memset(musicvolume, 0, sizeof(musicvolume));
2016         memset(oldmusicvolume, 0, sizeof(oldmusicvolume));
2017         musicselected = 0;
2018         change = 0;
2019 }