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