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