]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Added in support for MSVC building for MSVC2005 and MSVC2008; Windows support is...
[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         /*char tempstring[256];
994         sprintf (tempstring, "%s", registrationname);
995         long num1;
996         long num2;
997         long num3;
998         long num4;
999         long long longnum;
1000         longnum = MD5_string ( tempstring);
1001         //longnum = 1111111111111111;
1002         num1 = longnum/100000000;
1003         num2 = longnum%100000000;
1004         sprintf (tempstring, "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
1005         */
1006
1007         FILE                    *tfile;
1008
1009         accountactive=-1;
1010
1011         sprintf (mapname, ":Data:Users");
1012         tfile=fopen( mapname, "rb" );
1013         if(tfile)
1014         {
1015                 funpackf(tfile, "Bi", &numaccounts);
1016                 funpackf(tfile, "Bi", &accountactive);
1017                 if(numaccounts>0)
1018                 {
1019                         for(i=0;i<numaccounts;i++)
1020                         {
1021                                 funpackf(tfile, "Bf", &accountcampaigntime[i]);
1022                                 funpackf(tfile, "Bf", &accountcampaignscore[i]);
1023                                 funpackf(tfile, "Bf", &accountcampaignfasttime[i]);
1024                                 funpackf(tfile, "Bf", &accountcampaignhighscore[i]);
1025                                 funpackf(tfile, "Bi", &accountdifficulty[i]);
1026                                 funpackf(tfile, "Bi", &accountprogress[i]);
1027                                 funpackf(tfile, "Bi", &accountcampaignchoicesmade[i]);
1028                                 for(j=0;j<accountcampaignchoicesmade[i];j++)
1029                                 {
1030                                         funpackf(tfile, "Bi", &accountcampaignchoices[i][j]);
1031                                         if (accountcampaignchoices[i][j] >= 10)
1032                                         {
1033                                                 accountcampaignchoices[i][j] = 0;
1034                                         }
1035                                 }
1036                                 funpackf(tfile, "Bf", &accountpoints[i]);
1037                                 for(j=0;j<50;j++)
1038                                 {
1039                                         funpackf(tfile, "Bf", &accounthighscore[i][j]);
1040                                         funpackf(tfile, "Bf", &accountfasttime[i][j]);
1041                                 }
1042                                 for(j=0;j<60;j++)
1043                                 {
1044                                         funpackf(tfile, "Bb",  &accountunlocked[i][j]);
1045                                 }
1046                                 int temp;
1047                                 funpackf(tfile, "Bi",  &temp);
1048                                 if(temp>0)
1049                                 {
1050                                         for(j=0;j<temp;j++)
1051                                         {
1052                                                 funpackf(tfile, "Bb",  &accountname[i][j]);
1053                                         }
1054                                 }
1055                         }
1056                 }
1057
1058                 fclose(tfile);
1059         }
1060
1061         tintr=1;
1062         tintg=1;
1063         tintb=1;
1064
1065         whichjointstartarray[0]=righthip;
1066         whichjointendarray[0]=rightfoot;
1067
1068         whichjointstartarray[1]=righthip;
1069         whichjointendarray[1]=rightankle;
1070
1071         whichjointstartarray[2]=righthip;
1072         whichjointendarray[2]=rightknee;
1073
1074         whichjointstartarray[3]=rightknee;
1075         whichjointendarray[3]=rightankle;
1076
1077         whichjointstartarray[4]=rightankle;
1078         whichjointendarray[4]=rightfoot;
1079
1080         whichjointstartarray[5]=lefthip;
1081         whichjointendarray[5]=leftfoot;
1082
1083         whichjointstartarray[6]=lefthip;
1084         whichjointendarray[6]=leftankle;
1085
1086         whichjointstartarray[7]=lefthip;
1087         whichjointendarray[7]=leftknee;
1088
1089         whichjointstartarray[8]=leftknee;
1090         whichjointendarray[8]=leftankle;
1091
1092         whichjointstartarray[9]=leftankle;
1093         whichjointendarray[9]=leftfoot;
1094
1095         whichjointstartarray[10]=abdomen;
1096         whichjointendarray[10]=rightshoulder;
1097
1098         whichjointstartarray[11]=abdomen;
1099         whichjointendarray[11]=rightelbow;
1100
1101         whichjointstartarray[12]=abdomen;
1102         whichjointendarray[12]=rightwrist;
1103
1104         whichjointstartarray[13]=abdomen;
1105         whichjointendarray[13]=righthand;
1106
1107         whichjointstartarray[14]=rightshoulder;
1108         whichjointendarray[14]=rightelbow;
1109
1110         whichjointstartarray[15]=rightelbow;
1111         whichjointendarray[15]=rightwrist;
1112
1113         whichjointstartarray[16]=rightwrist;
1114         whichjointendarray[16]=righthand;
1115
1116         whichjointstartarray[17]=abdomen;
1117         whichjointendarray[17]=leftshoulder;
1118
1119         whichjointstartarray[18]=abdomen;
1120         whichjointendarray[18]=leftelbow;
1121
1122         whichjointstartarray[19]=abdomen;
1123         whichjointendarray[19]=leftwrist;
1124
1125         whichjointstartarray[20]=abdomen;
1126         whichjointendarray[20]=lefthand;
1127
1128         whichjointstartarray[21]=leftshoulder;
1129         whichjointendarray[21]=leftelbow;
1130
1131         whichjointstartarray[22]=leftelbow;
1132         whichjointendarray[22]=leftwrist;
1133
1134         whichjointstartarray[23]=leftwrist;
1135         whichjointendarray[23]=lefthand;
1136
1137         whichjointstartarray[24]=abdomen;
1138         whichjointendarray[24]=neck;
1139
1140         whichjointstartarray[25]=neck;
1141         whichjointendarray[25]=head;
1142
1143         FadeLoadingScreen(0);
1144
1145         stillloading=1;
1146
1147         texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1148
1149         int temptexdetail=texdetail;
1150         texdetail=1;
1151         text.LoadFontTexture(":Data:Textures:Font.png");
1152         text.BuildFont();
1153         texdetail=temptexdetail;
1154
1155         FadeLoadingScreen(10);
1156
1157         if(detail==2){
1158                 texdetail=1;
1159                 terraindetail=1;
1160         }
1161         if(detail==1){
1162                 texdetail=2;
1163                 terraindetail=1;
1164         }
1165         if(detail==0){
1166                 texdetail=4;
1167                 terraindetail=1;
1168                 //terraindetail=2;
1169         }
1170
1171         for (int it = 0; it < 100; ++it)
1172         {
1173                 channels[it] = -1;
1174                 samp[it] = NULL;
1175         }
1176         for (int it = 0; it < 20; ++it)
1177         {
1178                 strm[it] = NULL;
1179         }
1180
1181         LOG("Initializing sound system...");
1182
1183     int output = -1;
1184
1185     #if PLATFORM_LINUX
1186     extern bool cmdline(const char *cmd);
1187     unsigned char rc = 0;
1188     output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
1189     if (cmdline("forceoss"))      //  ...but let user override that.
1190         output = OPENAL_OUTPUT_OSS;
1191     else if (cmdline("nosound"))
1192         output = OPENAL_OUTPUT_NOSOUND;
1193
1194     OPENAL_SetOutput(output);
1195         if ((rc = OPENAL_Init(44100, 32, 0)) == false)
1196     {
1197         // if we tried ALSA and failed, fall back to OSS.
1198         if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
1199         {
1200             OPENAL_Close();
1201             output = OPENAL_OUTPUT_OSS;
1202             OPENAL_SetOutput(output);
1203                 rc = OPENAL_Init(44100, 32, 0);
1204         }
1205     }
1206
1207     if (rc == false)
1208     {
1209         OPENAL_Close();
1210         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
1211         OPENAL_SetOutput(output);
1212             rc = OPENAL_Init(44100, 32, 0);
1213     }
1214     #else
1215         OPENAL_Init(44100, 32, 0);
1216     #endif
1217
1218         OPENAL_SetSFXMasterVolume((int)(volume*255));
1219
1220         strm[stream_music3] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music3.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=0;}
1221 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music3], 4.0f, 1000.0f);
1222         OPENAL_Stream_SetMode(strm[stream_music3], OPENAL_LOOP_NORMAL);
1223
1224         if(musictoggle){
1225 //              PlaySoundEx( stream_music3, strm[stream_music3], NULL, true);
1226                 PlayStreamEx(stream_music3, strm[stream_music3], 0, true);
1227                 OPENAL_SetPaused(channels[stream_music3], false);
1228                 OPENAL_SetVolume(channels[stream_music3], 256);
1229         }
1230
1231         FadeLoadingScreen(20);
1232
1233         if(ambientsound){
1234                 strm[stream_wind] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:wind.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1235 //              OPENAL_Sample_SetMinMaxDistance(strm[stream_wind], 4.0f, 1000.0f);
1236                 OPENAL_Stream_SetMode(strm[stream_wind], OPENAL_LOOP_NORMAL);
1237
1238                 FadeLoadingScreen(30);
1239
1240                 strm[stream_desertambient] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:desertambient.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1241 //              OPENAL_Sample_SetMinMaxDistance(strm[stream_desertambient], 4.0f, 1000.0f);
1242                 OPENAL_Stream_SetMode(strm[stream_desertambient], OPENAL_LOOP_NORMAL);
1243         }
1244
1245         FadeLoadingScreen(40);
1246
1247         samp[firestartsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:firestart.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1248         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1249
1250         strm[stream_firesound] = OPENAL_Stream_Open(":Data:Sounds:fire.ogg", OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1251 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_firesound], 8.0f, 2000.0f);
1252         OPENAL_Stream_SetMode(strm[stream_firesound], OPENAL_LOOP_NORMAL);
1253
1254         FadeLoadingScreen(50);
1255
1256         samp[fireendsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:fireend.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1257         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1258
1259         //if(musictoggle){
1260         strm[stream_music1grass] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1grass.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=1;}
1261 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1grass], 4.0f, 1000.0f);
1262         OPENAL_Stream_SetMode(strm[stream_music1grass], OPENAL_LOOP_NORMAL);
1263
1264         strm[stream_music1snow] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1snow.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=2;}
1265 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1snow], 4.0f, 1000.0f);
1266         OPENAL_Stream_SetMode(strm[stream_music1snow], OPENAL_LOOP_NORMAL);
1267
1268         FadeLoadingScreen(60);
1269
1270         strm[stream_music1desert] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1desert.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=3;}
1271 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1desert], 4.0f, 1000.0f);
1272         OPENAL_Stream_SetMode(strm[stream_music1desert], OPENAL_LOOP_NORMAL);
1273
1274         FadeLoadingScreen(80);
1275         strm[stream_music2] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music2.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=4;}
1276 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music2], 4.0f, 1000.0f);
1277         OPENAL_Stream_SetMode(strm[stream_music2], OPENAL_LOOP_NORMAL);
1278
1279         //}
1280
1281
1282         FadeLoadingScreen(90);
1283
1284
1285         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
1286
1287         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
1288         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
1289         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
1290
1291         temptexdetail=texdetail;
1292         if(texdetail>2)texdetail=2;
1293         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
1294         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
1295         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
1296         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
1297         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
1298         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
1299         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
1300         texdetail=temptexdetail;
1301
1302         loaddistrib=0;
1303         anim=0;
1304
1305         FadeLoadingScreen(95);
1306
1307
1308         gameon=0;
1309         mainmenu=1;
1310
1311         stillloading=0;
1312         firstload=0;
1313         oldmainmenu=0;
1314
1315         newdetail=detail;
1316         newscreenwidth=screenwidth;
1317         newscreenheight=screenheight;
1318
1319
1320
1321         /*
1322         float gLoc[3]={0,0,0};
1323         float vel[3]={0,0,0};
1324         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1325         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1326         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1327         OPENAL_SetVolume(channels[firestartsound], 256);
1328         OPENAL_SetPaused(channels[firestartsound], false);
1329         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1330
1331         flashr=1;
1332         flashg=0;
1333         flashb=0;
1334         flashamount=1;
1335         flashdelay=1;
1336         */
1337 }
1338
1339
1340 void Game::LoadStuff()
1341 {
1342         static float temptexdetail;
1343         static float viewdistdetail;
1344         static int i,j,texsize;
1345         float megascale =1;
1346
1347         LOGFUNC;
1348
1349         visibleloading=1;
1350
1351         /*musicvolume[3]=512;
1352         PlaySoundEx( music4, samp[music4], NULL, true);
1353         OPENAL_SetPaused(channels[music4], false);
1354         OPENAL_SetVolume(channels[music4], 512);
1355         */
1356         loadtime=0;
1357
1358         stillloading=1;
1359
1360         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1361
1362         newnetmessages=0;
1363
1364         for(i=0;i<maxplayers;i++)
1365         {
1366                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
1367                 {
1368                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
1369                 }
1370                 player[i].skeleton.drawmodel.textureptr=0;;
1371         }
1372
1373         //temptexdetail=texdetail;
1374         //texdetail=1;
1375         i=abs(Random()%4);
1376         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
1377         //texdetail=temptexdetail;
1378
1379         temptexdetail=texdetail;
1380         texdetail=1;
1381         text.LoadFontTexture(":Data:Textures:Font.png");
1382         text.BuildFont();
1383         texdetail=temptexdetail;
1384
1385         numsounds=71;
1386
1387         viewdistdetail=2;
1388         viewdistance=50*megascale*viewdistdetail;
1389
1390         brightness=100;
1391
1392
1393
1394         if(detail==2){
1395                 texdetail=1;
1396                 terraindetail=1;
1397         }
1398         if(detail==1){
1399                 texdetail=2;
1400                 terraindetail=1;
1401         }
1402         if(detail==0){
1403                 texdetail=4;
1404                 terraindetail=1;
1405                 //terraindetail=2;
1406         }
1407
1408         realtexdetail=texdetail;
1409
1410         /*texdetail/=4;
1411         if(texdetail<1)texdetail=1;
1412         realtexdetail=texdetail*4;
1413         */
1414         numplayers=1;
1415
1416
1417
1418         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
1419
1420         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1421
1422         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1423         */
1424
1425
1426         LOG("Loading weapon data...");
1427
1428         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1429         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1430         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1431         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1432         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1433         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1434         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1435
1436         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1437         weapons.throwingknifemodel.Scale(.001,.001,.001);
1438         //weapons.throwingknifemodel.Rotate(0,0,-90);
1439         weapons.throwingknifemodel.Rotate(90,0,0);
1440         weapons.throwingknifemodel.Rotate(0,90,0);
1441         weapons.throwingknifemodel.flat=0;
1442         weapons.throwingknifemodel.CalculateNormals(1);
1443         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1444
1445         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1446         weapons.swordmodel.Scale(.001,.001,.001);
1447         //weapons.swordmodel.Rotate(0,0,-90);
1448         weapons.swordmodel.Rotate(90,0,0);
1449         weapons.swordmodel.Rotate(0,90,0);
1450         weapons.swordmodel.Rotate(0,0,90);
1451         weapons.swordmodel.flat=1;
1452         weapons.swordmodel.CalculateNormals(1);
1453         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1454
1455         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1456         weapons.staffmodel.Scale(.005,.005,.005);
1457         //weapons.staffmodel.Rotate(0,0,-90);
1458         weapons.staffmodel.Rotate(90,0,0);
1459         weapons.staffmodel.Rotate(0,90,0);
1460         weapons.staffmodel.Rotate(0,0,90);
1461         weapons.staffmodel.flat=1;
1462         weapons.staffmodel.CalculateNormals(1);
1463         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1464
1465         //temptexdetail=texdetail;
1466         //if(texdetail>4)texdetail=4;
1467         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1468
1469         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1470
1471         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1472
1473         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1474
1475
1476         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1477
1478         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1479
1480         /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1);
1481
1482         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1);
1483
1484         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1);
1485
1486         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1);
1487
1488         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1);
1489
1490         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1);
1491         //texdetail=temptexdetail;
1492         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1);*/
1493
1494
1495
1496         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1497
1498         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1499
1500
1501         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1502
1503
1504         LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1505         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1506         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1507         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1508         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1509         LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1510         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1511         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1512         LoadTexture(":Data:Textures:splinter.png",&sprites.splintertexture,1,1);
1513         LoadTexture(":Data:Textures:leaf.png",&sprites.leaftexture,1,1);
1514         LoadTexture(":Data:Textures:tooth.png",&sprites.toothtexture,1,1);
1515
1516         rotation=0;
1517         rotation2=0;
1518         ReSizeGLScene(90,.01);
1519
1520         viewer=0;
1521
1522
1523
1524
1525         if(detail)kTextureSize=1024;
1526         if(detail==1)kTextureSize=512;
1527         if(detail==0)kTextureSize=256;
1528
1529
1530         //drawmode=motionblurmode;
1531
1532         //Set up distant light
1533         light.color[0]=.95;
1534         light.color[1]=.95;
1535         light.color[2]=1;
1536         light.ambient[0]=.2;
1537         light.ambient[1]=.2;
1538         light.ambient[2]=.24;
1539         light.location.x=1;
1540         light.location.y=1;
1541         light.location.z=-.2;
1542         Normalise(&light.location);
1543
1544         LoadingScreen();
1545
1546         SetUpLighting();
1547
1548
1549         fadestart=.6;
1550         gravity=-10;
1551
1552         texscale=.2/megascale/viewdistdetail;
1553         terrain.scale=3*megascale*terraindetail*viewdistdetail;
1554
1555         viewer.x=terrain.size/2*terrain.scale;
1556         viewer.z=terrain.size/2*terrain.scale;
1557
1558         hawk.load((char *)":Data:Models:hawk.solid",1);
1559         hawk.Scale(.03,.03,.03);
1560         hawk.Rotate(90,1,1);
1561         hawk.CalculateNormals(0);
1562         hawk.ScaleNormals(-1,-1,-1);
1563         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1564         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1565         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1566
1567
1568         eye.load((char *)":Data:Models:eye.solid",1);
1569         eye.Scale(.03,.03,.03);
1570         eye.CalculateNormals(0);
1571
1572         cornea.load((char *)":Data:Models:cornea.solid",1);
1573         cornea.Scale(.03,.03,.03);
1574         cornea.CalculateNormals(0);
1575
1576         iris.load((char *)":Data:Models:iris.solid",1);
1577         iris.Scale(.03,.03,.03);
1578         iris.CalculateNormals(0);
1579
1580         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1581         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1582
1583         oldenvironment=-4;
1584
1585         gameon=1;
1586         mainmenu=0;
1587
1588         firstload=0;
1589         //if(targetlevel!=7)
1590                 Loadlevel(targetlevel);
1591
1592
1593         rabbitcoords=player[0].coords;
1594         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1595
1596         animation[runanim].Load((char *)":Data:Animations:Run",middleheight,neutral);
1597
1598         animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
1599         animation[stopanim].Load((char *)":Data:Animations:Stop",middleheight,neutral);
1600
1601         animation[jumpupanim].Load((char *)":Data:Animations:JumpUp",highheight,neutral);
1602         animation[jumpdownanim].Load((char *)":Data:Animations:JumpDown",highheight,neutral);
1603
1604         animation[landanim].Load((char *)":Data:Animations:Landing",lowheight,neutral);
1605         animation[landhardanim].Load((char *)":Data:Animations:Landhard",lowheight,neutral);
1606         animation[climbanim].Load((char *)":Data:Animations:Climb",lowheight,neutral);
1607         animation[hanganim].Load((char *)":Data:Animations:Hangon",lowheight,neutral);
1608         animation[spinkickanim].Load((char *)":Data:Animations:SpinKick",middleheight,normalattack);
1609
1610         animation[getupfromfrontanim].Load((char *)":Data:Animations:GetUpFromFront",lowheight,neutral);
1611         animation[getupfrombackanim].Load((char *)":Data:Animations:GetUpFromBack",lowheight,neutral);
1612         animation[crouchanim].Load((char *)":Data:Animations:Crouch",lowheight,neutral);
1613         animation[sneakanim].Load((char *)":Data:Animations:Sneak",lowheight,neutral);
1614         animation[rollanim].Load((char *)":Data:Animations:Roll",lowheight,neutral);
1615         animation[flipanim].Load((char *)":Data:Animations:Flip",highheight,neutral);
1616         animation[frontflipanim].Load((char *)":Data:Animations:Flip",highheight,neutral);
1617         animation[spinkickreversedanim].Load((char *)":Data:Animations:SpinKickCaught",middleheight,reversed);
1618
1619         animation[spinkickreversalanim].Load((char *)":Data:Animations:SpinKickCatch",middleheight,reversal);
1620         animation[lowkickanim].Load((char *)":Data:Animations:lowkick",middleheight,normalattack);
1621         animation[sweepanim].Load((char *)":Data:Animations:sweep",lowheight,normalattack);
1622         animation[sweepreversedanim].Load((char *)":Data:Animations:SweepCaught",lowheight,reversed);
1623         animation[sweepreversalanim].Load((char *)":Data:Animations:SweepCatch",middleheight,reversal);
1624         animation[rabbitkickanim].Load((char *)":Data:Animations:RabbitKick",middleheight,normalattack);
1625         animation[rabbitkickreversedanim].Load((char *)":Data:Animations:RabbitKickCaught",middleheight,reversed);
1626         animation[rabbitkickreversalanim].Load((char *)":Data:Animations:RabbitKickCatch",lowheight,reversal);
1627         animation[upunchanim].Load((char *)":Data:Animations:Upunch",middleheight,normalattack);
1628         animation[staggerbackhighanim].Load((char *)":Data:Animations:Staggerbackhigh",middleheight,neutral);
1629         animation[upunchreversedanim].Load((char *)":Data:Animations:UpunchCaught",middleheight,reversed);
1630
1631         animation[upunchreversalanim].Load((char *)":Data:Animations:UpunchCatch",middleheight,reversal);
1632         animation[hurtidleanim].Load((char *)":Data:Animations:Hurtidle",middleheight,neutral);
1633         animation[backhandspringanim].Load((char *)":Data:Animations:Backhandspring",middleheight,neutral);
1634         animation[fightidleanim].Load((char *)":Data:Animations:Fightidle",middleheight,neutral);
1635         animation[walkanim].Load((char *)":Data:Animations:Walk",middleheight,neutral);
1636
1637         animation[fightsidestep].Load((char *)":Data:Animations:Fightsidestep",middleheight,neutral);
1638         animation[killanim].Load((char *)":Data:Animations:Kill",middleheight,normalattack);
1639         animation[sneakattackanim].Load((char *)":Data:Animations:Sneakattack",middleheight,reversal);
1640         animation[sneakattackedanim].Load((char *)":Data:Animations:Sneakattacked",middleheight,reversed);
1641         animation[drawrightanim].Load((char *)":Data:Animations:drawright",middleheight,neutral);
1642         animation[knifeslashstartanim].Load((char *)":Data:Animations:slashstart",middleheight,normalattack);
1643         animation[crouchdrawrightanim].Load((char *)":Data:Animations:crouchdrawright",lowheight,neutral);
1644         animation[crouchstabanim].Load((char *)":Data:Animations:crouchstab",lowheight,normalattack);
1645
1646         animation[knifefollowanim].Load((char *)":Data:Animations:slashfollow",middleheight,reversal);
1647         animation[knifefollowedanim].Load((char *)":Data:Animations:slashfollowed",middleheight,reversed);
1648         animation[knifethrowanim].Load((char *)":Data:Animations:knifethrow",middleheight,normalattack);
1649         animation[removeknifeanim].Load((char *)":Data:Animations:removeknife",middleheight,neutral);
1650         animation[crouchremoveknifeanim].Load((char *)":Data:Animations:crouchremoveknife",lowheight,neutral);
1651         animation[jumpreversedanim].Load((char *)":Data:Animations:JumpCaught",middleheight,reversed);
1652         animation[jumpreversalanim].Load((char *)":Data:Animations:JumpCatch",middleheight,reversal);
1653         animation[staggerbackhardanim].Load((char *)":Data:Animations:Staggerbackhard",middleheight,neutral);
1654
1655         animation[dropkickanim].Load((char *)":Data:Animations:Dropkick",middleheight,normalattack);
1656         animation[winduppunchanim].Load((char *)":Data:Animations:Winduppunch",middleheight,normalattack);
1657         animation[winduppunchblockedanim].Load((char *)":Data:Animations:Winduppunchblocked",middleheight,normalattack);
1658         animation[blockhighleftanim].Load((char *)":Data:Animations:Blockhighleft",middleheight,normalattack);
1659         animation[blockhighleftstrikeanim].Load((char *)":Data:Animations:Blockhighleftstrike",middleheight,normalattack);
1660         animation[backflipanim].Load((char *)":Data:Animations:Backflip",highheight,neutral);
1661         animation[walljumpbackanim].Load((char *)":Data:Animations:Walljumpback",highheight,neutral);
1662         animation[walljumpfrontanim].Load((char *)":Data:Animations:Walljumpfront",highheight,neutral);
1663         animation[rightflipanim].Load((char *)":Data:Animations:Rightflip",highheight,neutral);
1664         animation[walljumprightanim].Load((char *)":Data:Animations:Walljumpright",highheight,neutral);
1665         animation[leftflipanim].Load((char *)":Data:Animations:Leftflip",highheight,neutral);
1666         animation[walljumpleftanim].Load((char *)":Data:Animations:Walljumpleft",highheight,neutral);
1667         animation[walljumprightkickanim].Load((char *)":Data:Animations:Walljumprightkick",highheight,neutral);
1668         animation[walljumpleftkickanim].Load((char *)":Data:Animations:Walljumpleftkick",highheight,neutral);
1669         animation[knifefightidleanim].Load((char *)":Data:Animations:Knifefightidle",middleheight,neutral);
1670         animation[knifesneakattackanim].Load((char *)":Data:Animations:Knifesneakattack",middleheight,reversal);
1671         animation[knifesneakattackedanim].Load((char *)":Data:Animations:Knifesneakattacked",middleheight,reversed);
1672         animation[swordfightidleanim].Load((char *)":Data:Animations:swordfightidle",middleheight,neutral);
1673         animation[drawleftanim].Load((char *)":Data:Animations:drawleft",middleheight,neutral);
1674         animation[swordslashanim].Load((char *)":Data:Animations:swordslash",middleheight,normalattack);
1675         animation[swordgroundstabanim].Load((char *)":Data:Animations:swordgroundstab",lowheight,normalattack);
1676         animation[dodgebackanim].Load((char *)":Data:Animations:dodgeback",middleheight,neutral);
1677         animation[swordsneakattackanim].Load((char *)":Data:Animations:Swordsneakattack",middleheight,reversal);
1678         animation[swordsneakattackedanim].Load((char *)":Data:Animations:Swordsneakattacked",middleheight,reversed);
1679         animation[swordslashreversedanim].Load((char *)":Data:Animations:swordslashCaught",middleheight,reversed);
1680         animation[swordslashreversalanim].Load((char *)":Data:Animations:swordslashCatch",middleheight,reversal);
1681         animation[knifeslashreversedanim].Load((char *)":Data:Animations:knifeslashCaught",middleheight,reversed);
1682         animation[knifeslashreversalanim].Load((char *)":Data:Animations:knifeslashCatch",middleheight,reversal);
1683         animation[swordfightidlebothanim].Load((char *)":Data:Animations:swordfightidleboth",middleheight,neutral);
1684         animation[swordslashparryanim].Load((char *)":Data:Animations:sworduprightparry",middleheight,normalattack);
1685         animation[swordslashparriedanim].Load((char *)":Data:Animations:swordslashparried",middleheight,normalattack);
1686         animation[wolfidle].Load((char *)":Data:Animations:Wolfidle",middleheight,neutral);
1687         animation[wolfcrouchanim].Load((char *)":Data:Animations:Wolfcrouch",lowheight,neutral);
1688         animation[wolflandanim].Load((char *)":Data:Animations:Wolflanding",lowheight,neutral);
1689         animation[wolflandhardanim].Load((char *)":Data:Animations:Wolflandhard",lowheight,neutral);
1690         animation[wolfrunanim].Load((char *)":Data:Animations:Wolfrun",middleheight,neutral);
1691         animation[wolfrunninganim].Load((char *)":Data:Animations:Wolfrunning",middleheight,neutral);
1692         animation[rabbitrunninganim].Load((char *)":Data:Animations:Rabbitrunning",middleheight,neutral);
1693         animation[wolfstopanim].Load((char *)":Data:Animations:Wolfstop",middleheight,neutral);
1694         animation[rabbittackleanim].Load((char *)":Data:Animations:Rabbittackle",middleheight,neutral);
1695         animation[rabbittacklinganim].Load((char *)":Data:Animations:Rabbittackling",middleheight,reversal);
1696         animation[rabbittackledbackanim].Load((char *)":Data:Animations:Rabbittackledback",middleheight,reversed);
1697         animation[rabbittackledfrontanim].Load((char *)":Data:Animations:Rabbittackledfront",middleheight,reversed);
1698         animation[wolfslapanim].Load((char *)":Data:Animations:Wolfslap",middleheight,normalattack);
1699         animation[staffhitanim].Load((char *)":Data:Animations:StaffHit",middleheight,normalattack);
1700         animation[staffgroundsmashanim].Load((char *)":Data:Animations:StaffGroundSmash",lowheight,normalattack);
1701         animation[staffspinhitanim].Load((char *)":Data:Animations:Spinwhack",middleheight,normalattack);
1702         animation[staffhitreversedanim].Load((char *)":Data:Animations:StaffHitCaught",middleheight,reversed);
1703         animation[staffhitreversalanim].Load((char *)":Data:Animations:StaffHitCatch",middleheight,reversal);
1704         animation[staffspinhitreversedanim].Load((char *)":Data:Animations:SpinWhackCaught",middleheight,reversed);
1705         animation[staffspinhitreversalanim].Load((char *)":Data:Animations:SpinWhackCatch",middleheight,reversal);
1706
1707         animation[sitanim].Load((char *)":Data:Animations:Sit",lowheight,neutral);
1708         animation[sleepanim].Load((char *)":Data:Animations:Sleep",lowheight,neutral);
1709         animation[talkidleanim].Load((char *)":Data:Animations:TalkIdle",middleheight,neutral);
1710
1711         animation[sitwallanim].Load((char *)":Data:Animations:Dying",lowheight,neutral);
1712         animation[dead1anim].Load((char *)":Data:Animations:Dead1",lowheight,neutral);
1713         animation[dead2anim].Load((char *)":Data:Animations:Dead2",lowheight,neutral);
1714         animation[dead3anim].Load((char *)":Data:Animations:Dead3",lowheight,neutral);
1715         animation[dead4anim].Load((char *)":Data:Animations:Dead4",lowheight,neutral);
1716         //Fix knife stab, too lazy to do it manually
1717         XYZ moveamount;
1718         moveamount=0;
1719         moveamount.z=2;
1720         for(i=0;i<player[0].skeleton.num_joints;i++){
1721                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1722                         animation[knifesneakattackanim].position[i][j]+=moveamount;
1723                 }
1724         }
1725
1726         loadscreencolor=4;
1727         LoadingScreen();
1728
1729         for(i=0;i<player[0].skeleton.num_joints;i++){
1730                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1731                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1732                 }
1733         }
1734
1735         loadscreencolor=4;
1736         LoadingScreen();
1737
1738         for(i=0;i<player[0].skeleton.num_joints;i++){
1739                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1740                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1741                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1742                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1743         }
1744         animation[dead1anim].speed[0]=0.001;
1745         animation[dead2anim].speed[0]=0.001;
1746         animation[dead3anim].speed[0]=0.001;
1747         animation[dead4anim].speed[0]=0.001;
1748
1749         animation[dead1anim].speed[1]=0.001;
1750         animation[dead2anim].speed[1]=0.001;
1751         animation[dead3anim].speed[1]=0.001;
1752         animation[dead4anim].speed[1]=0.001;
1753
1754         for(i=0;i<player[0].skeleton.num_joints;i++){
1755                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1756                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1757                 }
1758         }
1759         loadscreencolor=4;
1760         LoadingScreen();
1761         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1762                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1763         }
1764
1765         loadscreencolor=4;
1766         LoadingScreen();
1767
1768         for(i=0;i<player[0].skeleton.num_joints;i++){
1769                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1770                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1771                 }
1772         }
1773         /*
1774         for(i=0;i<player[0].skeleton.num_joints;i++){
1775         for(j=0;j<animation[sleepanim].numframes;j++){
1776         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1777         }
1778         }
1779         */
1780         loadscreencolor=4;
1781         LoadingScreen();
1782         temptexdetail=texdetail;
1783         texdetail=1;
1784         texdetail=temptexdetail;
1785
1786         loadscreencolor=4;
1787         LoadingScreen();
1788
1789         //if(ismotionblur){
1790         if(!screentexture){
1791                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1792
1793                 glGenTextures( 1, &screentexture );
1794                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1795
1796
1797                 glEnable(GL_TEXTURE_2D);
1798                 glBindTexture( GL_TEXTURE_2D, screentexture);
1799                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1800                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1801
1802                 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1803         }
1804         //}
1805
1806         LoadSounds();
1807
1808         /*PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1809         OPENAL_SetVolume(channels[consolesuccesssound], 256);
1810         OPENAL_SetPaused(channels[consolesuccesssound], false);
1811         */
1812         if(targetlevel!=7){
1813                 float gLoc[3]={0,0,0};
1814                 float vel[3]={0,0,0};
1815                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1816                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1817                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1818                 OPENAL_SetVolume(channels[fireendsound], 256);
1819                 OPENAL_SetPaused(channels[fireendsound], false);
1820                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1821         }
1822
1823         stillloading=0;
1824         loading=0;
1825         changedelay=1;
1826
1827         visibleloading=0;
1828 }
1829
1830 Game::Game()
1831 {
1832         terraintexture = 0;
1833         terraintexture2 = 0;
1834         terraintexture3 = 0;
1835         screentexture = 0;
1836         screentexture2 = 0;
1837         logotexture = 0;
1838         loadscreentexture = 0;
1839         Maparrowtexture = 0;
1840         Mapboxtexture = 0;
1841         Mapcircletexture = 0;
1842         cursortexture = 0;
1843
1844         memset(Mainmenuitems, 0, sizeof(Mainmenuitems));
1845
1846         nummenuitems = 0;
1847
1848         memset(startx, 0, sizeof(startx));
1849         memset(starty, 0, sizeof(starty));
1850         memset(endx, 0, sizeof(endx));
1851         memset(endy, 0, sizeof(endy));
1852
1853         memset(selectedlong, 0, sizeof(selectedlong));
1854         memset(offsetx, 0, sizeof(offsetx));
1855         memset(offsety, 0, sizeof(offsety));
1856         memset(movex, 0, sizeof(movex));
1857         memset(movey, 0, sizeof(movey));
1858         memset(endy, 0, sizeof(endy));
1859
1860         transition = 0;
1861         anim = 0;
1862         selected = 0;
1863         loaddistrib = 0;
1864         keyselect = 0;
1865         indemo = 0;
1866
1867         won = 0;
1868
1869         entername = 0;
1870
1871         memset(menustring, 0, sizeof(menustring));
1872         memset(registrationname, 0, sizeof(registrationname));
1873         registrationnumber = 0;
1874
1875         newdetail = 0;
1876         newscreenwidth = 0;
1877         newscreenheight = 0;
1878
1879         gameon = 0;
1880         deltah = 0,deltav = 0;
1881         mousecoordh = 0,mousecoordv = 0;
1882         oldmousecoordh = 0,oldmousecoordv = 0;
1883         rotation = 0,rotation2 = 0;
1884
1885 //      SkyBox skybox;
1886
1887         cameramode = 0;
1888         cameratogglekeydown = 0;
1889         chattogglekeydown = 0;
1890         olddrawmode = 0;
1891         drawmode = 0;
1892         drawmodetogglekeydown = 0;
1893         explodetogglekeydown = 0;
1894         detailtogglekeydown = 0;
1895         firstload = 0;
1896         oldbutton = 0;
1897
1898         leveltime = 0;
1899         loadtime = 0;
1900
1901 //      Model hawk;
1902
1903 //      XYZ hawkcoords;
1904 //      XYZ realhawkcoords;
1905
1906         hawktexture = 0;
1907         hawkrotation = 0;
1908         hawkcalldelay = 0;
1909 /*
1910         Model eye;
1911         Model iris;
1912         Model cornea;
1913 */
1914         stealthloading = 0;
1915
1916         campaignnumlevels = 0;
1917
1918         memset(campaignmapname, 0, sizeof(campaignmapname));
1919         memset(campaigndescription, 0, sizeof(campaigndescription));
1920         memset(campaignchoosenext, 0, sizeof(campaignchoosenext));
1921         memset(campaignnumnext, 0, sizeof(campaignnumnext));
1922         memset(campaignnextlevel, 0, sizeof(campaignnextlevel));
1923         int campaignchoicesmade;
1924         memset(campaignchoices, 0, sizeof(campaignchoices));
1925         memset(campaignlocationx, 0, sizeof(campaignlocationx));
1926         memset(campaignlocationy, 0, sizeof(campaignlocationy));
1927         memset(campaignlocationy, 0, sizeof(campaignlocationy));
1928
1929         campaignchoicenum = 0;
1930
1931         memset(campaignchoicewhich, 0, sizeof(campaignchoicewhich));
1932
1933         whichchoice = 0;
1934
1935         numlevelspassed = 0;
1936
1937         memset(levelorder, 0, sizeof(levelorder));
1938         memset(levelvisible, 0, sizeof(levelvisible));
1939         memset(levelhighlight, 0, sizeof(levelhighlight));
1940
1941         minimap = 0;
1942
1943         musictype = 0,oldmusictype = 0,oldoldmusictype = 0;
1944         realthreat = 0;
1945
1946 //      Model rabbit;
1947 //      XYZ rabbitcoords;
1948
1949 //      XYZ mapcenter;
1950         mapradius = 0;
1951
1952 //      Text text;
1953         fps = 0;
1954
1955 //      XYZ cameraloc;
1956         cameradist = 0;
1957
1958         envtogglekeydown = 0;
1959         slomotogglekeydown = 0;
1960         texturesizetogglekeydown = 0;
1961         freezetogglekeydown = 0;
1962         drawtoggle = 0;
1963
1964         editorenabled = 0;
1965         editortype = 0;
1966         editorsize = 0;
1967         editorrotation = 0;
1968         editorrotation2 = 0;
1969
1970         brightness = 0;
1971
1972         quit = 0;
1973         tryquit = 0;
1974
1975 //      XYZ pathpoint[30];
1976         numpathpoints = 0;
1977         memset(numpathpointconnect, 0, sizeof(numpathpointconnect));
1978         memset(pathpointconnect, 0, sizeof(pathpointconnect));
1979         pathpointselected = 0;
1980
1981         endgame = 0;
1982         scoreadded = 0;
1983         numchallengelevels = 0;
1984
1985         console = 0;
1986         archiveselected = 0;
1987
1988         memset(consoletext, 0, sizeof(consoletext));
1989         memset(consolechars, 0, sizeof(consolechars));
1990         chatting = 0;
1991         memset(displaytext, 0, sizeof(displaytext));
1992         memset(displaychars, 0, sizeof(displaychars));
1993         memset(displaytime, 0, sizeof(displaytime));
1994         displayblinkdelay = 0;
1995         displayblink = 0;
1996         displayselected = 0;
1997         consolekeydown = 0;
1998         consoletogglekeydown = 0;
1999         consoleblinkdelay = 0;
2000         consoleblink = 0;
2001         consoleselected = 0;
2002         memset(togglekey, 0, sizeof(togglekey));
2003         memset(togglekeydelay, 0, sizeof(togglekeydelay));
2004         registernow = 0;
2005         autocam = 0;
2006
2007         crouchkey = 0,jumpkey = 0,forwardkey = 0,chatkey = 0,backkey = 0,leftkey = 0,rightkey = 0,drawkey = 0,throwkey = 0,attackkey = 0;
2008         oldattackkey = 0;
2009
2010         loading = 0;
2011         talkdelay = 0;
2012
2013         numboundaries = 0;
2014 //      XYZ boundary[360];
2015
2016         whichlevel = 0;
2017         oldenvironment = 0;
2018         targetlevel = 0;
2019         changedelay = 0;
2020
2021         memset(musicvolume, 0, sizeof(musicvolume));
2022         memset(oldmusicvolume, 0, sizeof(oldmusicvolume));
2023         musicselected = 0;
2024         change = 0;
2025 }
2026