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