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