]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Hack around crash on shutdown.
[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                                 sprintf (tempstring, "%s-windows", registrationname);
1012                                 longnuma = MD5_string ( tempstring);    
1013                                 num1a = longnuma/100000000;
1014                                 num2a = longnuma%100000000;
1015                                 //if(num1a==num1&&num2a==num2)registered=1;
1016                                 if(numchars>2)registered=1;
1017                                 else registered=0;
1018                         }
1019                 }
1020                 fclose(tfile);
1021         }
1022         else registered=0;
1023
1024         accountactive=-1;
1025
1026         sprintf (mapname, ":Data:Users");
1027         tfile=fopen( mapname, "rb" );
1028         if(tfile)
1029         {
1030                 funpackf(tfile, "Bi", &numaccounts);
1031                 funpackf(tfile, "Bi", &accountactive);
1032                 if(numaccounts>0)
1033                 {
1034                         for(i=0;i<numaccounts;i++)
1035                         {
1036                                 funpackf(tfile, "Bf", &accountcampaigntime[i]);
1037                                 funpackf(tfile, "Bf", &accountcampaignscore[i]);
1038                                 funpackf(tfile, "Bf", &accountcampaignfasttime[i]);
1039                                 funpackf(tfile, "Bf", &accountcampaignhighscore[i]);
1040                                 funpackf(tfile, "Bi", &accountdifficulty[i]);
1041                                 funpackf(tfile, "Bi", &accountprogress[i]);
1042                                 funpackf(tfile, "Bi", &accountcampaignchoicesmade[i]);
1043                                 for(j=0;j<accountcampaignchoicesmade[i];j++)
1044                                 {
1045                                         funpackf(tfile, "Bi", &accountcampaignchoices[i][j]);
1046                                         if (accountcampaignchoices[i][j] >= 10)
1047                                         {
1048                                                 accountcampaignchoices[i][j] = 0;
1049                                         }
1050                                 }
1051                                 funpackf(tfile, "Bf", &accountpoints[i]);
1052                                 for(j=0;j<50;j++)
1053                                 {
1054                                         funpackf(tfile, "Bf", &accounthighscore[i][j]);
1055                                         funpackf(tfile, "Bf", &accountfasttime[i][j]);
1056                                 }
1057                                 for(j=0;j<60;j++)
1058                                 {
1059                                         funpackf(tfile, "Bb",  &accountunlocked[i][j]);
1060                                 }
1061                                 int temp;
1062                                 funpackf(tfile, "Bi",  &temp);
1063                                 if(temp>0)
1064                                 {
1065                                         for(j=0;j<temp;j++)
1066                                         {
1067                                                 funpackf(tfile, "Bb",  &accountname[i][j]);
1068                                         }
1069                                 }
1070                         }
1071                 }
1072
1073                 fclose(tfile);
1074         }
1075
1076         tintr=1;
1077         tintg=1;
1078         tintb=1;
1079
1080         whichjointstartarray[0]=righthip;
1081         whichjointendarray[0]=rightfoot;
1082
1083         whichjointstartarray[1]=righthip;
1084         whichjointendarray[1]=rightankle;
1085
1086         whichjointstartarray[2]=righthip;
1087         whichjointendarray[2]=rightknee;
1088
1089         whichjointstartarray[3]=rightknee;
1090         whichjointendarray[3]=rightankle;
1091
1092         whichjointstartarray[4]=rightankle;
1093         whichjointendarray[4]=rightfoot;
1094
1095         whichjointstartarray[5]=lefthip;
1096         whichjointendarray[5]=leftfoot;
1097
1098         whichjointstartarray[6]=lefthip;
1099         whichjointendarray[6]=leftankle;
1100
1101         whichjointstartarray[7]=lefthip;
1102         whichjointendarray[7]=leftknee;
1103
1104         whichjointstartarray[8]=leftknee;
1105         whichjointendarray[8]=leftankle;
1106
1107         whichjointstartarray[9]=leftankle;
1108         whichjointendarray[9]=leftfoot;
1109
1110         whichjointstartarray[10]=abdomen;
1111         whichjointendarray[10]=rightshoulder;
1112
1113         whichjointstartarray[11]=abdomen;
1114         whichjointendarray[11]=rightelbow;
1115
1116         whichjointstartarray[12]=abdomen;
1117         whichjointendarray[12]=rightwrist;
1118
1119         whichjointstartarray[13]=abdomen;
1120         whichjointendarray[13]=righthand;
1121
1122         whichjointstartarray[14]=rightshoulder;
1123         whichjointendarray[14]=rightelbow;
1124
1125         whichjointstartarray[15]=rightelbow;
1126         whichjointendarray[15]=rightwrist;
1127
1128         whichjointstartarray[16]=rightwrist;
1129         whichjointendarray[16]=righthand;
1130
1131         whichjointstartarray[17]=abdomen;
1132         whichjointendarray[17]=leftshoulder;
1133
1134         whichjointstartarray[18]=abdomen;
1135         whichjointendarray[18]=leftelbow;
1136
1137         whichjointstartarray[19]=abdomen;
1138         whichjointendarray[19]=leftwrist;
1139
1140         whichjointstartarray[20]=abdomen;
1141         whichjointendarray[20]=lefthand;
1142
1143         whichjointstartarray[21]=leftshoulder;
1144         whichjointendarray[21]=leftelbow;
1145
1146         whichjointstartarray[22]=leftelbow;
1147         whichjointendarray[22]=leftwrist;
1148
1149         whichjointstartarray[23]=leftwrist;
1150         whichjointendarray[23]=lefthand;
1151
1152         whichjointstartarray[24]=abdomen;
1153         whichjointendarray[24]=neck;
1154
1155         whichjointstartarray[25]=neck;
1156         whichjointendarray[25]=head;
1157
1158         FadeLoadingScreen(0);
1159
1160         stillloading=1;
1161
1162         texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1163
1164         int temptexdetail=texdetail;
1165         texdetail=1;
1166         text.LoadFontTexture(":Data:Textures:Font.png");
1167         text.BuildFont();
1168         texdetail=temptexdetail;
1169
1170         FadeLoadingScreen(10);
1171
1172         if(detail==2){
1173                 texdetail=1;
1174                 terraindetail=1;
1175         }
1176         if(detail==1){
1177                 texdetail=2;
1178                 terraindetail=1;
1179         }
1180         if(detail==0){
1181                 texdetail=4;
1182                 terraindetail=1;
1183                 //terraindetail=2;
1184         }
1185
1186         for (int it = 0; it < 100; ++it)
1187         {
1188                 channels[it] = -1;
1189                 samp[it] = NULL;
1190         }
1191         for (int it = 0; it < 20; ++it)
1192         {
1193                 strm[it] = NULL;
1194         }
1195
1196         LOG("Initializing sound system...");
1197
1198     int output = -1;
1199
1200     #if PLATFORM_LINUX
1201     extern bool cmdline(const char *cmd);
1202     unsigned char rc = 0;
1203     output = FSOUND_OUTPUT_ALSA;  // Try alsa first...
1204     if (cmdline("forceoss"))      //  ...but let user override that.
1205         output = FSOUND_OUTPUT_OSS;
1206     else if (cmdline("nosound"))
1207         output = FSOUND_OUTPUT_NOSOUND;
1208
1209     FSOUND_SetOutput(output);
1210         if ((rc = FSOUND_Init(44100, 32, 0)) == FALSE)
1211     {
1212         // if we tried ALSA and failed, fall back to OSS.
1213         if ( (output == FSOUND_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
1214         {
1215             FSOUND_Close();
1216             output = FSOUND_OUTPUT_OSS;
1217             FSOUND_SetOutput(output);
1218                 rc = FSOUND_Init(44100, 32, 0);
1219         }
1220     }
1221
1222     if (rc == FALSE)
1223     {
1224         FSOUND_Close();
1225         output = FSOUND_OUTPUT_NOSOUND;  // we tried! just do silence.
1226         FSOUND_SetOutput(output);
1227             rc = FSOUND_Init(44100, 32, 0);
1228     }
1229     #else
1230         FSOUND_Init(44100, 32, 0);
1231     #endif
1232
1233         FSOUND_SetSFXMasterVolume((int)(volume*255));
1234
1235         strm[stream_music3] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music3.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=0;}
1236 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music3], 4.0f, 1000.0f);    
1237         FSOUND_Stream_SetMode(strm[stream_music3], FSOUND_LOOP_NORMAL);
1238
1239         if(musictoggle){
1240 //              PlaySoundEx( stream_music3, strm[stream_music3], NULL, TRUE);
1241                 PlayStreamEx(stream_music3, strm[stream_music3], 0, TRUE);
1242                 FSOUND_SetPaused(channels[stream_music3], FALSE);
1243                 FSOUND_SetVolume(channels[stream_music3], 256);
1244         }
1245
1246         FadeLoadingScreen(20);
1247
1248         if(ambientsound){
1249                 strm[stream_wind] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:wind.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1250 //              FSOUND_Sample_SetMinMaxDistance(strm[stream_wind], 4.0f, 1000.0f);      
1251                 FSOUND_Stream_SetMode(strm[stream_wind], FSOUND_LOOP_NORMAL);
1252
1253                 FadeLoadingScreen(30);
1254
1255                 strm[stream_desertambient] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:desertambient.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1256 //              FSOUND_Sample_SetMinMaxDistance(strm[stream_desertambient], 4.0f, 1000.0f);     
1257                 FSOUND_Stream_SetMode(strm[stream_desertambient], FSOUND_LOOP_NORMAL);
1258         }
1259
1260         FadeLoadingScreen(40);
1261
1262         samp[firestartsound] = FSOUND_Sample_Load(FSOUND_FREE, ConvertFileName(":Data:Sounds:firestart.ogg"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1263         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1264
1265         strm[stream_firesound] = FSOUND_Stream_Open(":Data:Sounds:fire.ogg", FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1266 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_firesound], 8.0f, 2000.0f); 
1267         FSOUND_Stream_SetMode(strm[stream_firesound], FSOUND_LOOP_NORMAL);
1268
1269         FadeLoadingScreen(50);
1270
1271         samp[fireendsound] = FSOUND_Sample_Load(FSOUND_FREE, ConvertFileName(":Data:Sounds:fireend.ogg"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1272         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1273
1274         //if(musictoggle){
1275         strm[stream_music1grass] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music1grass.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=1;}
1276 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music1grass], 4.0f, 1000.0f);       
1277         FSOUND_Stream_SetMode(strm[stream_music1grass], FSOUND_LOOP_NORMAL);
1278
1279         strm[stream_music1snow] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music1snow.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=2;}
1280 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music1snow], 4.0f, 1000.0f);        
1281         FSOUND_Stream_SetMode(strm[stream_music1snow], FSOUND_LOOP_NORMAL);
1282
1283         FadeLoadingScreen(60);
1284
1285         strm[stream_music1desert] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music1desert.mp3"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=3;}
1286 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music1desert], 4.0f, 1000.0f);      
1287         FSOUND_Stream_SetMode(strm[stream_music1desert], FSOUND_LOOP_NORMAL);
1288
1289         FadeLoadingScreen(80);
1290         strm[stream_music2] = FSOUND_Stream_Open(ConvertFileName(":Data:Sounds:music2.ogg"), FSOUND_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=4;}
1291 //      FSOUND_Sample_SetMinMaxDistance(strm[stream_music2], 4.0f, 1000.0f);    
1292         FSOUND_Stream_SetMode(strm[stream_music2], FSOUND_LOOP_NORMAL);
1293
1294         //}
1295
1296
1297         FadeLoadingScreen(90);
1298
1299
1300         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
1301
1302         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
1303         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
1304         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
1305
1306         temptexdetail=texdetail;
1307         if(texdetail>2)texdetail=2;
1308         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
1309         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
1310         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
1311         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
1312         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
1313         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
1314         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
1315         texdetail=temptexdetail;
1316
1317         loaddistrib=0;
1318         anim=0;
1319
1320         FadeLoadingScreen(95);
1321
1322
1323         gameon=0;
1324         mainmenu=1;
1325
1326         stillloading=0;
1327         firstload=0;
1328         oldmainmenu=0;
1329
1330         newdetail=detail;
1331         newscreenwidth=screenwidth;
1332         newscreenheight=screenheight;
1333
1334         
1335         
1336         /*
1337         float gLoc[3]={0,0,0};
1338         float vel[3]={0,0,0};
1339         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
1340         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
1341         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1342         FSOUND_SetVolume(channels[firestartsound], 256);
1343         FSOUND_SetPaused(channels[firestartsound], FALSE);
1344         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1345
1346         flashr=1;
1347         flashg=0;
1348         flashb=0;
1349         flashamount=1;
1350         flashdelay=1;
1351         */
1352 }
1353
1354
1355 void Game::LoadStuff()                                                                          
1356 {
1357         static float temptexdetail;
1358         static float viewdistdetail;
1359         static int i,j,texsize; 
1360         float megascale =1;
1361
1362         LOGFUNC;
1363
1364         visibleloading=1;
1365
1366         /*musicvolume[3]=512;
1367         PlaySoundEx( music4, samp[music4], NULL, TRUE);
1368         FSOUND_SetPaused(channels[music4], FALSE);
1369         FSOUND_SetVolume(channels[music4], 512);
1370         */
1371         loadtime=0;
1372
1373         stillloading=1;
1374
1375         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1376
1377         newnetmessages=0;
1378
1379         for(i=0;i<maxplayers;i++)
1380         {
1381                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
1382                 {
1383                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
1384                 }
1385                 player[i].skeleton.drawmodel.textureptr=0;;
1386         }
1387
1388         //temptexdetail=texdetail;
1389         //texdetail=1;
1390         i=abs(Random()%4);
1391         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
1392         //texdetail=temptexdetail;
1393
1394         temptexdetail=texdetail;
1395         texdetail=1;
1396         text.LoadFontTexture(":Data:Textures:Font.png");
1397         text.BuildFont();
1398         texdetail=temptexdetail;
1399
1400         numsounds=71;           
1401
1402         viewdistdetail=2;
1403         viewdistance=50*megascale*viewdistdetail;
1404
1405         brightness=100;
1406
1407
1408
1409         if(detail==2){
1410                 texdetail=1;
1411                 terraindetail=1;
1412         }
1413         if(detail==1){
1414                 texdetail=2;
1415                 terraindetail=1;
1416         }
1417         if(detail==0){
1418                 texdetail=4;
1419                 terraindetail=1;
1420                 //terraindetail=2;
1421         }
1422
1423         realtexdetail=texdetail;
1424
1425         /*texdetail/=4;
1426         if(texdetail<1)texdetail=1;
1427         realtexdetail=texdetail*4;
1428         */
1429         numplayers=1;
1430
1431
1432
1433         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
1434
1435         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1436
1437         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1438         */
1439
1440
1441         LOG("Loading weapon data...");
1442
1443         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1444         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1445         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1446         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1447         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1448         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1449         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1450
1451         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1452         weapons.throwingknifemodel.Scale(.001,.001,.001);
1453         //weapons.throwingknifemodel.Rotate(0,0,-90);
1454         weapons.throwingknifemodel.Rotate(90,0,0);
1455         weapons.throwingknifemodel.Rotate(0,90,0);
1456         weapons.throwingknifemodel.flat=0;
1457         weapons.throwingknifemodel.CalculateNormals(1);
1458         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1459
1460         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1461         weapons.swordmodel.Scale(.001,.001,.001);
1462         //weapons.swordmodel.Rotate(0,0,-90);
1463         weapons.swordmodel.Rotate(90,0,0);
1464         weapons.swordmodel.Rotate(0,90,0);
1465         weapons.swordmodel.Rotate(0,0,90);
1466         weapons.swordmodel.flat=1;
1467         weapons.swordmodel.CalculateNormals(1);
1468         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1469
1470         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1471         weapons.staffmodel.Scale(.005,.005,.005);
1472         //weapons.staffmodel.Rotate(0,0,-90);
1473         weapons.staffmodel.Rotate(90,0,0);
1474         weapons.staffmodel.Rotate(0,90,0);
1475         weapons.staffmodel.Rotate(0,0,90);
1476         weapons.staffmodel.flat=1;
1477         weapons.staffmodel.CalculateNormals(1);
1478         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1479
1480         //temptexdetail=texdetail;
1481         //if(texdetail>4)texdetail=4;
1482         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1483
1484         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1485
1486         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1487
1488         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1489
1490
1491         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1492
1493         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1494
1495         /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1);
1496
1497         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1);
1498
1499         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1);
1500
1501         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1);
1502
1503         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1);
1504
1505         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1);
1506         //texdetail=temptexdetail;
1507         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1);*/
1508
1509
1510
1511         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1512
1513         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1514
1515
1516         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1517
1518
1519         LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1520         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1521         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1522         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1523         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1524         LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1525         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1526         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1527         LoadTexture(":Data:Textures:splinter.png",&sprites.splintertexture,1,1);
1528         LoadTexture(":Data:Textures:leaf.png",&sprites.leaftexture,1,1);
1529         LoadTexture(":Data:Textures:tooth.png",&sprites.toothtexture,1,1);
1530
1531         rotation=0;
1532         rotation2=0;
1533         ReSizeGLScene(90,.01);
1534
1535         viewer=0;
1536
1537
1538
1539
1540         if(detail)kTextureSize=1024;
1541         if(detail==1)kTextureSize=512;
1542         if(detail==0)kTextureSize=256;
1543
1544
1545         //drawmode=motionblurmode;
1546
1547         //Set up distant light
1548         light.color[0]=.95;
1549         light.color[1]=.95;
1550         light.color[2]=1;
1551         light.ambient[0]=.2;
1552         light.ambient[1]=.2;
1553         light.ambient[2]=.24;
1554         light.location.x=1;
1555         light.location.y=1;
1556         light.location.z=-.2;
1557         Normalise(&light.location);
1558
1559         LoadingScreen();
1560
1561         SetUpLighting();
1562
1563
1564         fadestart=.6;
1565         gravity=-10;
1566
1567         texscale=.2/megascale/viewdistdetail;
1568         terrain.scale=3*megascale*terraindetail*viewdistdetail;
1569
1570         viewer.x=terrain.size/2*terrain.scale;
1571         viewer.z=terrain.size/2*terrain.scale;
1572
1573         hawk.load((char *)":Data:Models:hawk.solid",1);
1574         hawk.Scale(.03,.03,.03);
1575         hawk.Rotate(90,1,1);
1576         hawk.CalculateNormals(0);
1577         hawk.ScaleNormals(-1,-1,-1);
1578         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1579         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1580         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1581
1582
1583         eye.load((char *)":Data:Models:eye.solid",1);
1584         eye.Scale(.03,.03,.03);
1585         eye.CalculateNormals(0);
1586
1587         cornea.load((char *)":Data:Models:cornea.solid",1);
1588         cornea.Scale(.03,.03,.03);
1589         cornea.CalculateNormals(0);
1590
1591         iris.load((char *)":Data:Models:iris.solid",1);
1592         iris.Scale(.03,.03,.03);
1593         iris.CalculateNormals(0);
1594
1595         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1596         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1597
1598         oldenvironment=-4;
1599
1600         gameon=1;
1601         mainmenu=0;
1602
1603         firstload=0;
1604         //if(targetlevel!=7)
1605                 Loadlevel(targetlevel);
1606
1607
1608         rabbitcoords=player[0].coords;
1609         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1610
1611         animation[runanim].Load((char *)":Data:Animations:Run",middleheight,neutral);
1612
1613         animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
1614         animation[stopanim].Load((char *)":Data:Animations:Stop",middleheight,neutral);
1615
1616         animation[jumpupanim].Load((char *)":Data:Animations:JumpUp",highheight,neutral);
1617         animation[jumpdownanim].Load((char *)":Data:Animations:JumpDown",highheight,neutral);
1618
1619         animation[landanim].Load((char *)":Data:Animations:Landing",lowheight,neutral);
1620         animation[landhardanim].Load((char *)":Data:Animations:Landhard",lowheight,neutral);
1621         animation[climbanim].Load((char *)":Data:Animations:Climb",lowheight,neutral);
1622         animation[hanganim].Load((char *)":Data:Animations:Hangon",lowheight,neutral);
1623         animation[spinkickanim].Load((char *)":Data:Animations:SpinKick",middleheight,normalattack);
1624
1625         animation[getupfromfrontanim].Load((char *)":Data:Animations:GetUpFromFront",lowheight,neutral);
1626         animation[getupfrombackanim].Load((char *)":Data:Animations:GetUpFromBack",lowheight,neutral);
1627         animation[crouchanim].Load((char *)":Data:Animations:Crouch",lowheight,neutral);
1628         animation[sneakanim].Load((char *)":Data:Animations:Sneak",lowheight,neutral);
1629         animation[rollanim].Load((char *)":Data:Animations:Roll",lowheight,neutral);
1630         animation[flipanim].Load((char *)":Data:Animations:Flip",highheight,neutral);
1631         animation[frontflipanim].Load((char *)":Data:Animations:Flip",highheight,neutral);
1632         animation[spinkickreversedanim].Load((char *)":Data:Animations:SpinKickCaught",middleheight,reversed);
1633
1634         animation[spinkickreversalanim].Load((char *)":Data:Animations:SpinKickCatch",middleheight,reversal);
1635         animation[lowkickanim].Load((char *)":Data:Animations:lowkick",middleheight,normalattack);
1636         animation[sweepanim].Load((char *)":Data:Animations:sweep",lowheight,normalattack);
1637         animation[sweepreversedanim].Load((char *)":Data:Animations:SweepCaught",lowheight,reversed);
1638         animation[sweepreversalanim].Load((char *)":Data:Animations:SweepCatch",middleheight,reversal);
1639         animation[rabbitkickanim].Load((char *)":Data:Animations:RabbitKick",middleheight,normalattack);
1640         animation[rabbitkickreversedanim].Load((char *)":Data:Animations:RabbitKickCaught",middleheight,reversed);
1641         animation[rabbitkickreversalanim].Load((char *)":Data:Animations:RabbitKickCatch",lowheight,reversal);
1642         animation[upunchanim].Load((char *)":Data:Animations:Upunch",middleheight,normalattack);
1643         animation[staggerbackhighanim].Load((char *)":Data:Animations:Staggerbackhigh",middleheight,neutral);
1644         animation[upunchreversedanim].Load((char *)":Data:Animations:UpunchCaught",middleheight,reversed);
1645
1646         animation[upunchreversalanim].Load((char *)":Data:Animations:UpunchCatch",middleheight,reversal);
1647         animation[hurtidleanim].Load((char *)":Data:Animations:Hurtidle",middleheight,neutral);
1648         animation[backhandspringanim].Load((char *)":Data:Animations:Backhandspring",middleheight,neutral);
1649         animation[fightidleanim].Load((char *)":Data:Animations:Fightidle",middleheight,neutral);
1650         animation[walkanim].Load((char *)":Data:Animations:Walk",middleheight,neutral);
1651
1652         animation[fightsidestep].Load((char *)":Data:Animations:Fightsidestep",middleheight,neutral);
1653         animation[killanim].Load((char *)":Data:Animations:Kill",middleheight,normalattack);
1654         animation[sneakattackanim].Load((char *)":Data:Animations:Sneakattack",middleheight,reversal);
1655         animation[sneakattackedanim].Load((char *)":Data:Animations:Sneakattacked",middleheight,reversed);
1656         animation[drawrightanim].Load((char *)":Data:Animations:drawright",middleheight,neutral);
1657         animation[knifeslashstartanim].Load((char *)":Data:Animations:slashstart",middleheight,normalattack);
1658         animation[crouchdrawrightanim].Load((char *)":Data:Animations:crouchdrawright",lowheight,neutral);
1659         animation[crouchstabanim].Load((char *)":Data:Animations:crouchstab",lowheight,normalattack);
1660
1661         animation[knifefollowanim].Load((char *)":Data:Animations:slashfollow",middleheight,reversal);
1662         animation[knifefollowedanim].Load((char *)":Data:Animations:slashfollowed",middleheight,reversed);
1663         animation[knifethrowanim].Load((char *)":Data:Animations:knifethrow",middleheight,normalattack);
1664         animation[removeknifeanim].Load((char *)":Data:Animations:removeknife",middleheight,neutral);
1665         animation[crouchremoveknifeanim].Load((char *)":Data:Animations:crouchremoveknife",lowheight,neutral);
1666         animation[jumpreversedanim].Load((char *)":Data:Animations:JumpCaught",middleheight,reversed);
1667         animation[jumpreversalanim].Load((char *)":Data:Animations:JumpCatch",middleheight,reversal);
1668         animation[staggerbackhardanim].Load((char *)":Data:Animations:Staggerbackhard",middleheight,neutral);
1669
1670         animation[dropkickanim].Load((char *)":Data:Animations:Dropkick",middleheight,normalattack);
1671         animation[winduppunchanim].Load((char *)":Data:Animations:Winduppunch",middleheight,normalattack);
1672         animation[winduppunchblockedanim].Load((char *)":Data:Animations:Winduppunchblocked",middleheight,normalattack);
1673         animation[blockhighleftanim].Load((char *)":Data:Animations:Blockhighleft",middleheight,normalattack);
1674         animation[blockhighleftstrikeanim].Load((char *)":Data:Animations:Blockhighleftstrike",middleheight,normalattack);
1675         animation[backflipanim].Load((char *)":Data:Animations:Backflip",highheight,neutral);
1676         animation[walljumpbackanim].Load((char *)":Data:Animations:Walljumpback",highheight,neutral);
1677         animation[walljumpfrontanim].Load((char *)":Data:Animations:Walljumpfront",highheight,neutral);
1678         animation[rightflipanim].Load((char *)":Data:Animations:Rightflip",highheight,neutral);
1679         animation[walljumprightanim].Load((char *)":Data:Animations:Walljumpright",highheight,neutral);
1680         animation[leftflipanim].Load((char *)":Data:Animations:Leftflip",highheight,neutral);
1681         animation[walljumpleftanim].Load((char *)":Data:Animations:Walljumpleft",highheight,neutral);
1682         animation[walljumprightkickanim].Load((char *)":Data:Animations:Walljumprightkick",highheight,neutral);
1683         animation[walljumpleftkickanim].Load((char *)":Data:Animations:Walljumpleftkick",highheight,neutral);
1684         animation[knifefightidleanim].Load((char *)":Data:Animations:Knifefightidle",middleheight,neutral);
1685         animation[knifesneakattackanim].Load((char *)":Data:Animations:Knifesneakattack",middleheight,reversal);
1686         animation[knifesneakattackedanim].Load((char *)":Data:Animations:Knifesneakattacked",middleheight,reversed);
1687         animation[swordfightidleanim].Load((char *)":Data:Animations:swordfightidle",middleheight,neutral);
1688         animation[drawleftanim].Load((char *)":Data:Animations:drawleft",middleheight,neutral);
1689         animation[swordslashanim].Load((char *)":Data:Animations:swordslash",middleheight,normalattack);
1690         animation[swordgroundstabanim].Load((char *)":Data:Animations:swordgroundstab",lowheight,normalattack);
1691         animation[dodgebackanim].Load((char *)":Data:Animations:dodgeback",middleheight,neutral);
1692         animation[swordsneakattackanim].Load((char *)":Data:Animations:Swordsneakattack",middleheight,reversal);
1693         animation[swordsneakattackedanim].Load((char *)":Data:Animations:Swordsneakattacked",middleheight,reversed);
1694         animation[swordslashreversedanim].Load((char *)":Data:Animations:swordslashCaught",middleheight,reversed);
1695         animation[swordslashreversalanim].Load((char *)":Data:Animations:swordslashCatch",middleheight,reversal);
1696         animation[knifeslashreversedanim].Load((char *)":Data:Animations:knifeslashCaught",middleheight,reversed);
1697         animation[knifeslashreversalanim].Load((char *)":Data:Animations:knifeslashCatch",middleheight,reversal);
1698         animation[swordfightidlebothanim].Load((char *)":Data:Animations:swordfightidleboth",middleheight,neutral);
1699         animation[swordslashparryanim].Load((char *)":Data:Animations:sworduprightparry",middleheight,normalattack);
1700         animation[swordslashparriedanim].Load((char *)":Data:Animations:swordslashparried",middleheight,normalattack);
1701         animation[wolfidle].Load((char *)":Data:Animations:Wolfidle",middleheight,neutral);
1702         animation[wolfcrouchanim].Load((char *)":Data:Animations:Wolfcrouch",lowheight,neutral);
1703         animation[wolflandanim].Load((char *)":Data:Animations:Wolflanding",lowheight,neutral);
1704         animation[wolflandhardanim].Load((char *)":Data:Animations:Wolflandhard",lowheight,neutral);
1705         animation[wolfrunanim].Load((char *)":Data:Animations:Wolfrun",middleheight,neutral);
1706         animation[wolfrunninganim].Load((char *)":Data:Animations:Wolfrunning",middleheight,neutral);
1707         animation[rabbitrunninganim].Load((char *)":Data:Animations:Rabbitrunning",middleheight,neutral);
1708         animation[wolfstopanim].Load((char *)":Data:Animations:Wolfstop",middleheight,neutral);
1709         animation[rabbittackleanim].Load((char *)":Data:Animations:Rabbittackle",middleheight,neutral);
1710         animation[rabbittacklinganim].Load((char *)":Data:Animations:Rabbittackling",middleheight,reversal);
1711         animation[rabbittackledbackanim].Load((char *)":Data:Animations:Rabbittackledback",middleheight,reversed);
1712         animation[rabbittackledfrontanim].Load((char *)":Data:Animations:Rabbittackledfront",middleheight,reversed);
1713         animation[wolfslapanim].Load((char *)":Data:Animations:Wolfslap",middleheight,normalattack);
1714         animation[staffhitanim].Load((char *)":Data:Animations:StaffHit",middleheight,normalattack);
1715         animation[staffgroundsmashanim].Load((char *)":Data:Animations:StaffGroundSmash",lowheight,normalattack);
1716         animation[staffspinhitanim].Load((char *)":Data:Animations:Spinwhack",middleheight,normalattack);
1717         animation[staffhitreversedanim].Load((char *)":Data:Animations:StaffHitCaught",middleheight,reversed);
1718         animation[staffhitreversalanim].Load((char *)":Data:Animations:StaffHitCatch",middleheight,reversal);
1719         animation[staffspinhitreversedanim].Load((char *)":Data:Animations:SpinWhackCaught",middleheight,reversed);
1720         animation[staffspinhitreversalanim].Load((char *)":Data:Animations:SpinWhackCatch",middleheight,reversal);
1721
1722         animation[sitanim].Load((char *)":Data:Animations:Sit",lowheight,neutral);
1723         animation[sleepanim].Load((char *)":Data:Animations:Sleep",lowheight,neutral);
1724         animation[talkidleanim].Load((char *)":Data:Animations:TalkIdle",middleheight,neutral);
1725
1726         animation[sitwallanim].Load((char *)":Data:Animations:Dying",lowheight,neutral);
1727         animation[dead1anim].Load((char *)":Data:Animations:Dead1",lowheight,neutral);
1728         animation[dead2anim].Load((char *)":Data:Animations:Dead2",lowheight,neutral);
1729         animation[dead3anim].Load((char *)":Data:Animations:Dead3",lowheight,neutral);
1730         animation[dead4anim].Load((char *)":Data:Animations:Dead4",lowheight,neutral);
1731         //Fix knife stab, too lazy to do it manually
1732         XYZ moveamount;
1733         moveamount=0;
1734         moveamount.z=2;
1735         for(i=0;i<player[0].skeleton.num_joints;i++){
1736                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1737                         animation[knifesneakattackanim].position[i][j]+=moveamount;
1738                 }       
1739         }
1740
1741         loadscreencolor=4;
1742         LoadingScreen();
1743
1744         for(i=0;i<player[0].skeleton.num_joints;i++){
1745                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1746                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1747                 }       
1748         }
1749
1750         loadscreencolor=4;
1751         LoadingScreen();
1752
1753         for(i=0;i<player[0].skeleton.num_joints;i++){
1754                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1755                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1756                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1757                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1758         }
1759         animation[dead1anim].speed[0]=0.001;
1760         animation[dead2anim].speed[0]=0.001;
1761         animation[dead3anim].speed[0]=0.001;
1762         animation[dead4anim].speed[0]=0.001;
1763
1764         animation[dead1anim].speed[1]=0.001;
1765         animation[dead2anim].speed[1]=0.001;
1766         animation[dead3anim].speed[1]=0.001;
1767         animation[dead4anim].speed[1]=0.001;
1768
1769         for(i=0;i<player[0].skeleton.num_joints;i++){
1770                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1771                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1772                 }       
1773         }
1774         loadscreencolor=4;
1775         LoadingScreen();
1776         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1777                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1778         }       
1779
1780         loadscreencolor=4;
1781         LoadingScreen();
1782
1783         for(i=0;i<player[0].skeleton.num_joints;i++){
1784                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1785                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1786                 }       
1787         }
1788         /*
1789         for(i=0;i<player[0].skeleton.num_joints;i++){
1790         for(j=0;j<animation[sleepanim].numframes;j++){
1791         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1792         }       
1793         }
1794         */
1795         loadscreencolor=4;
1796         LoadingScreen();
1797         temptexdetail=texdetail;
1798         texdetail=1;
1799         texdetail=temptexdetail;
1800
1801         loadscreencolor=4;
1802         LoadingScreen();
1803
1804         //if(ismotionblur){
1805         if(!screentexture){
1806                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1807
1808                 glGenTextures( 1, &screentexture );
1809                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1810
1811
1812                 glEnable(GL_TEXTURE_2D);
1813                 glBindTexture( GL_TEXTURE_2D, screentexture);
1814                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1815                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1816
1817                 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);                
1818         }
1819         //}
1820
1821         LoadSounds();
1822
1823         /*PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
1824         FSOUND_SetVolume(channels[consolesuccesssound], 256);
1825         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
1826         */
1827         if(targetlevel!=7){
1828                 float gLoc[3]={0,0,0};
1829                 float vel[3]={0,0,0};
1830                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1831                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1832                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1833                 FSOUND_SetVolume(channels[fireendsound], 256);
1834                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1835                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1836         }
1837
1838         stillloading=0;
1839         loading=0;
1840         changedelay=1;
1841
1842         visibleloading=0;
1843 }
1844
1845 Game::Game()
1846 {
1847         terraintexture = 0;
1848         terraintexture2 = 0;
1849         terraintexture3 = 0;
1850         screentexture = 0;
1851         screentexture2 = 0;
1852         logotexture = 0;
1853         loadscreentexture = 0;
1854         Maparrowtexture = 0;
1855         Mapboxtexture = 0;
1856         Mapcircletexture = 0;
1857         cursortexture = 0;
1858
1859         memset(Mainmenuitems, 0, sizeof(Mainmenuitems));
1860
1861         nummenuitems = 0;
1862
1863         memset(startx, 0, sizeof(startx));
1864         memset(starty, 0, sizeof(starty));
1865         memset(endx, 0, sizeof(endx));
1866         memset(endy, 0, sizeof(endy));
1867
1868         memset(selectedlong, 0, sizeof(selectedlong));
1869         memset(offsetx, 0, sizeof(offsetx));
1870         memset(offsety, 0, sizeof(offsety));
1871         memset(movex, 0, sizeof(movex));
1872         memset(movey, 0, sizeof(movey));
1873         memset(endy, 0, sizeof(endy));
1874
1875         transition = 0;
1876         anim = 0;
1877         selected = 0;
1878         loaddistrib = 0;
1879         keyselect = 0;
1880         indemo = 0;
1881         registered = 0;
1882
1883         won = 0;
1884
1885         entername = 0;
1886
1887         memset(menustring, 0, sizeof(menustring));
1888         memset(registrationname, 0, sizeof(registrationname));
1889         registrationnumber = 0;
1890
1891         newdetail = 0;
1892         newscreenwidth = 0;
1893         newscreenheight = 0;
1894
1895         gameon = 0;
1896         deltah = 0,deltav = 0;
1897         mousecoordh = 0,mousecoordv = 0;
1898         oldmousecoordh = 0,oldmousecoordv = 0;
1899         rotation = 0,rotation2 = 0;
1900
1901 //      SkyBox skybox;
1902
1903         cameramode = 0;
1904         cameratogglekeydown = 0;
1905         chattogglekeydown = 0;
1906         olddrawmode = 0;
1907         drawmode = 0;
1908         drawmodetogglekeydown = 0;
1909         explodetogglekeydown = 0;
1910         detailtogglekeydown = 0;
1911         firstload = 0;
1912         oldbutton = 0;
1913
1914         leveltime = 0;
1915         loadtime = 0;
1916
1917 //      Model hawk;
1918
1919 //      XYZ hawkcoords;
1920 //      XYZ realhawkcoords;
1921
1922         hawktexture = 0;
1923         hawkrotation = 0;
1924         hawkcalldelay = 0;
1925 /*
1926         Model eye;
1927         Model iris;
1928         Model cornea;
1929 */
1930         stealthloading = 0;
1931
1932         campaignnumlevels = 0;
1933
1934         memset(campaignmapname, 0, sizeof(campaignmapname));
1935         memset(campaigndescription, 0, sizeof(campaigndescription));
1936         memset(campaignchoosenext, 0, sizeof(campaignchoosenext));
1937         memset(campaignnumnext, 0, sizeof(campaignnumnext));
1938         memset(campaignnextlevel, 0, sizeof(campaignnextlevel));
1939         int campaignchoicesmade;
1940         memset(campaignchoices, 0, sizeof(campaignchoices));
1941         memset(campaignlocationx, 0, sizeof(campaignlocationx));
1942         memset(campaignlocationy, 0, sizeof(campaignlocationy));
1943         memset(campaignlocationy, 0, sizeof(campaignlocationy));
1944
1945         campaignchoicenum = 0;
1946
1947         memset(campaignchoicewhich, 0, sizeof(campaignchoicewhich));
1948
1949         whichchoice = 0;
1950
1951         numlevelspassed = 0;
1952
1953         memset(levelorder, 0, sizeof(levelorder));
1954         memset(levelvisible, 0, sizeof(levelvisible));
1955         memset(levelhighlight, 0, sizeof(levelhighlight));
1956
1957         minimap = 0;
1958
1959         musictype = 0,oldmusictype = 0,oldoldmusictype = 0;
1960         realthreat = 0;
1961
1962 //      Model rabbit;
1963 //      XYZ rabbitcoords;
1964
1965 //      XYZ mapcenter;
1966         mapradius = 0;
1967
1968 //      Text text;
1969         fps = 0;
1970
1971 //      XYZ cameraloc;
1972         cameradist = 0;
1973
1974         envtogglekeydown = 0;
1975         slomotogglekeydown = 0;
1976         texturesizetogglekeydown = 0;
1977         freezetogglekeydown = 0;
1978         drawtoggle = 0;
1979
1980         editorenabled = 0;
1981         editortype = 0;
1982         editorsize = 0;
1983         editorrotation = 0;
1984         editorrotation2 = 0;
1985
1986         brightness = 0;
1987
1988         quit = 0;
1989         tryquit = 0;
1990
1991 //      XYZ pathpoint[30];
1992         numpathpoints = 0;
1993         memset(numpathpointconnect, 0, sizeof(numpathpointconnect));
1994         memset(pathpointconnect, 0, sizeof(pathpointconnect));
1995         pathpointselected = 0;
1996
1997         endgame = 0;
1998         scoreadded = 0;
1999         numchallengelevels = 0;
2000
2001         console = 0;
2002         archiveselected = 0;
2003
2004         memset(consoletext, 0, sizeof(consoletext));
2005         memset(consolechars, 0, sizeof(consolechars));
2006         chatting = 0;
2007         memset(displaytext, 0, sizeof(displaytext));
2008         memset(displaychars, 0, sizeof(displaychars));
2009         memset(displaytime, 0, sizeof(displaytime));
2010         displayblinkdelay = 0;
2011         displayblink = 0;
2012         displayselected = 0;
2013         consolekeydown = 0;
2014         consoletogglekeydown = 0;
2015         consoleblinkdelay = 0;
2016         consoleblink = 0;
2017         consoleselected = 0;
2018         memset(togglekey, 0, sizeof(togglekey));
2019         memset(togglekeydelay, 0, sizeof(togglekeydelay));
2020         registernow = 0;
2021         autocam = 0;
2022
2023         crouchkey = 0,jumpkey = 0,forwardkey = 0,chatkey = 0,backkey = 0,leftkey = 0,rightkey = 0,drawkey = 0,throwkey = 0,attackkey = 0;
2024         oldattackkey = 0;
2025
2026         loading = 0;
2027         talkdelay = 0;
2028
2029         numboundaries = 0;
2030 //      XYZ boundary[360];
2031
2032         whichlevel = 0;
2033         oldenvironment = 0;
2034         targetlevel = 0;
2035         changedelay = 0;
2036
2037         memset(musicvolume, 0, sizeof(musicvolume));
2038         memset(oldmusicvolume, 0, sizeof(oldmusicvolume));
2039         musicselected = 0;
2040         change = 0;
2041 }
2042