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