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