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