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