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