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