]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Various SDL input and Game::* cleanups
[lugaru.git] / Source / GameInitDispose.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #include "Game.h"
23 #include "openal_wrapper.h"
24
25 extern float screenwidth,screenheight;
26 extern float viewdistance;
27 extern XYZ viewer;
28 extern XYZ lightlocation;
29 extern float lightambient[3],lightbrightness[3];
30 extern float fadestart;
31 extern float texscale;
32 extern float gravity;
33 extern Light light;
34 extern Animation animation[animation_count];
35 extern Skeleton testskeleton;
36 extern int numsounds;
37 extern OPENAL_SAMPLE    *samp[100];
38 extern int channels[100];
39 extern Terrain terrain;
40 extern Sprites sprites;
41 extern int kTextureSize;
42 extern float texdetail;
43 extern float realtexdetail;
44 extern float terraindetail;
45 extern float volume;
46 extern Objects objects;
47 extern int detail;
48 extern bool cellophane;
49 extern GLubyte bloodText[512*512*3];
50 extern GLubyte wolfbloodText[512*512*3];
51 extern bool ismotionblur;
52 extern bool trilinear;
53 extern bool osx;
54 extern bool musictoggle;
55 extern Weapons weapons;
56 extern Person player[maxplayers];
57 extern int numplayers;
58 extern int environment;
59 extern bool ambientsound;
60 extern float multiplier;
61 extern int netdatanew;
62 extern float mapinfo;
63 extern bool stillloading;
64 extern TGAImageRec texture;
65 extern short vRefNum;
66 extern long dirID;
67 extern int mainmenu;
68 extern int oldmainmenu;
69 extern bool visibleloading;
70 extern int loadscreencolor;
71 extern float flashamount,flashr,flashg,flashb;
72 extern int flashdelay;
73 extern int whichjointstartarray[26];
74 extern int whichjointendarray[26];
75 extern int difficulty;
76 extern float tintr,tintg,tintb;
77 extern float slomospeed;
78 extern char mapname[256];
79 extern bool gamestarted;
80
81 extern int 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)glGenTextures( 1, textureid );
397                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
398
399                 glBindTexture( GL_TEXTURE_2D, *textureid);
400                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
401                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
402                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
403                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
404
405                 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.sizeX, texture.sizeY, 0,
406                 //          GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, texture.data);
407
408                 //gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, texture.data );
409
410                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
411
412 //              textures.insert(std::make_pair(fname, *textureid));
413         }
414 //      else
415 //      {
416 //              *textureid = it->second;
417 //      }
418 }
419
420 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
421 {
422         GLuint          type;
423         int i;
424         int bytesPerPixel;
425
426         LOGFUNC;
427
428         LOG(std::string("Loading texture (S)...") + fileName);
429
430         //Load Image
431         unsigned char fileNamep[256];
432         CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
433         //Load Image
434         upload_image( fileNamep ,0);
435         //LoadTGA( fileName );
436
437 //      std::string fname(fileName);
438 //      std::transform(fname.begin(), fname.end(), tolower);
439 //      TexIter it = textures.find(fname);
440
441         //Is it valid?
442         if(1==1)
443         //if(textures.end() == it)
444         {
445                 bytesPerPixel=texture.bpp/8;
446
447                 //Alpha channel?
448                 if ( texture.bpp == 24 )
449                         type = GL_RGB;
450                 else
451                         type = GL_RGBA;
452
453                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
454
455                 if(!*textureid)glGenTextures( 1, textureid );
456                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
457
458                 glBindTexture( GL_TEXTURE_2D, *textureid);
459                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
460                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
461                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
462                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
463
464                 int tempnum=0;
465                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
466                         if((i+1)%4||type==GL_RGB){
467                                 array[tempnum]=texture.data[i];
468                                 tempnum++;
469                         }
470                 }
471
472                 *skinsize=texture.sizeX;
473
474                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
475
476 //              textures.insert(std::make_pair(fname, *textureid));
477         }
478 //      else
479 //      {
480 //              *textureid = it->second;
481 //      }
482 }
483
484 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
485 {
486         int i;
487         int bytesPerPixel;
488
489         LOGFUNC;
490
491         LOG(std::string("Loading (S)...") + fileName);
492
493         //Load Image
494         float temptexdetail=texdetail;
495         texdetail=1;
496         //upload_image( fileName );
497         //LoadTGA( fileName );
498
499         // Converting file to something os specific
500         char * fixedFN = ConvertFileName(fileName);
501
502         //Load Image
503         unsigned char fileNamep[256];
504         CopyCStringToPascal(fixedFN, fileNamep);
505         //Load Image
506         upload_image( fileNamep ,0);
507         texdetail=temptexdetail;
508
509         //Is it valid?
510         if(1==1){
511                 bytesPerPixel=texture.bpp/8;
512
513                 int tempnum=0;
514                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
515                         if((i+1)%4||bytesPerPixel==3){
516                                 array[tempnum]=texture.data[i];
517                                 tempnum++;
518                         }
519                 }
520         }
521 }
522
523 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
524 {
525         int i;
526         int bytesPerPixel;
527
528         LOGFUNC;
529
530         //upload_image( fileName );
531         //LoadTGA( fileName );
532         //Load Image
533         unsigned char fileNamep[256];
534         CopyCStringToPascal(fileName,fileNamep);
535         //Load Image
536         bool opened;
537         opened=upload_image( fileNamep ,1);
538
539         float alphanum;
540         //Is it valid?
541         if(opened){
542                 if(tintr>1)tintr=1;
543                 if(tintg>1)tintg=1;
544                 if(tintb>1)tintb=1;
545
546                 if(tintr<0)tintr=0;
547                 if(tintg<0)tintg=0;
548                 if(tintb<0)tintb=0;
549
550                 bytesPerPixel=texture.bpp/8;
551
552                 int tempnum=0;
553                 alphanum=255;
554                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
555                         if(bytesPerPixel==3)alphanum=255;
556                         else if((i+1)%4==0)alphanum=texture.data[i];
557                         //alphanum/=2;
558                         if((i+1)%4||bytesPerPixel==3){
559                                 if((i%4)==0)texture.data[i]*=tintr;
560                                 if((i%4)==1)texture.data[i]*=tintg;
561                                 if((i%4)==2)texture.data[i]*=tintb;
562                                 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
563                                 tempnum++;
564                         }
565                 }
566         }
567         else return 0;
568         return 1;
569 }
570
571
572 //***************> ResizeGLScene() <******/
573 GLvoid Game::ReSizeGLScene(float fov, float pnear)
574 {
575         if (screenheight==0)
576         {
577                 screenheight=1;
578         }
579
580         glViewport(0,0,screenwidth,screenheight);
581
582         glMatrixMode(GL_PROJECTION);
583         glLoadIdentity();
584
585         gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
586
587         glMatrixMode(GL_MODELVIEW);
588         glLoadIdentity();
589 }
590
591 void Game::LoadingScreen()
592 {
593         static float loadprogress,minprogress,maxprogress;
594         static AbsoluteTime time = {0,0};
595         static AbsoluteTime frametime = {0,0};
596         AbsoluteTime currTime = UpTime ();
597         double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
598
599         if (0 > deltaTime)      // if negative microseconds
600                 deltaTime /= -1000000.0;
601         else                            // else milliseconds
602                 deltaTime /= 1000.0;
603
604         multiplier=deltaTime;
605         if(multiplier<.001)multiplier=.001;
606         if(multiplier>10)multiplier=10;
607         if(multiplier>.05){
608                 frametime = currTime;   // reset for next time interval
609
610                 float size=1;
611                 glLoadIdentity();
612                 //Clear to black
613                 glClearColor(0,0,0,1);
614                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
615
616
617                 loadtime+=multiplier*4;
618
619                 loadprogress=loadtime;
620                 if(loadprogress>100)loadprogress=100;
621
622                 //loadprogress=abs(Random()%100);
623
624                 //Background
625
626                 glEnable(GL_TEXTURE_2D);
627                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
628                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
629                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
630                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
631                 glDisable(GL_CULL_FACE);
632                 glDisable(GL_LIGHTING);
633                 glDepthMask(0);
634                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
635                 glPushMatrix();                                                                         // Store The Projection Matrix
636                 glLoadIdentity();                                                                       // Reset The Projection Matrix
637                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
638                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
639                 glPushMatrix();                                                                         // Store The Modelview Matrix
640                 glLoadIdentity();                                                               // Reset The Modelview Matrix
641                 glTranslatef(screenwidth/2,screenheight/2,0);
642                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
643                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
644                 glDisable(GL_BLEND);
645                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
646                 //glColor4f(1,1,1,1);
647                 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
648                 if(loadscreencolor==1)glColor4f(1,0,0,1);
649                 if(loadscreencolor==2)glColor4f(0,1,0,1);
650                 if(loadscreencolor==3)glColor4f(0,0,1,1);
651                 if(loadscreencolor==4)glColor4f(1,1,0,1);
652                 if(loadscreencolor==5)glColor4f(1,0,1,1);
653                 */
654                 glPushMatrix();
655                 //glScalef(.25,.25,.25);
656                 glBegin(GL_QUADS);
657                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
658                 glVertex3f(-1,          -1,      0.0f);
659                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
660                 glVertex3f(1,   -1,      0.0f);
661                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
662                 glVertex3f(1,   1, 0.0f);
663                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
664                 glVertex3f(-1,  1, 0.0f);
665                 glEnd();
666                 glPopMatrix();
667                 glEnable(GL_BLEND);
668                 glPushMatrix();
669                 //glScalef(.25,.25,.25);
670                 glBegin(GL_QUADS);
671                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
672                 glVertex3f(-1,          -1,      0.0f);
673                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
674                 glVertex3f(1,   -1,      0.0f);
675                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
676                 glVertex3f(1,   1, 0.0f);
677                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
678                 glVertex3f(-1,  1, 0.0f);
679                 glEnd();
680                 glPopMatrix();
681                 glDisable(GL_TEXTURE_2D);
682                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
683                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
684                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
685                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
686                 glDisable(GL_BLEND);
687                 glDepthMask(1);
688
689                 glEnable(GL_TEXTURE_2D);
690                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
691                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
692                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
693                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
694                 glDisable(GL_CULL_FACE);
695                 glDisable(GL_LIGHTING);
696                 glDepthMask(0);
697                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
698                 glPushMatrix();                                                                         // Store The Projection Matrix
699                 glLoadIdentity();                                                                       // Reset The Projection Matrix
700                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
701                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
702                 glPushMatrix();                                                                         // Store The Modelview Matrix
703                 glLoadIdentity();                                                               // Reset The Modelview Matrix
704                 glTranslatef(screenwidth/2,screenheight/2,0);
705                 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
706                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
707                 glEnable(GL_BLEND);
708                 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
709                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
710                 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
711                 if(loadscreencolor==1)glColor4f(1,0,0,1);
712                 if(loadscreencolor==2)glColor4f(0,1,0,1);
713                 if(loadscreencolor==3)glColor4f(0,0,1,1);
714                 if(loadscreencolor==4)glColor4f(1,1,0,1);
715                 if(loadscreencolor==5)glColor4f(1,0,1,1);
716                 */
717                 glPushMatrix();
718                 //glScalef(.25,.25,.25);
719                 glBegin(GL_QUADS);
720                 glTexCoord2f(0+.5,0+.5);
721                 glVertex3f(-1,          -1,      0.0f);
722                 glTexCoord2f(1+.5,0+.5);
723                 glVertex3f(1,   -1,      0.0f);
724                 glTexCoord2f(1+.5,1+.5);
725                 glVertex3f(1,   1, 0.0f);
726                 glTexCoord2f(0+.5,1+.5);
727                 glVertex3f(-1,  1, 0.0f);
728                 glEnd();
729                 glPopMatrix();
730                 glDisable(GL_TEXTURE_2D);
731                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
732                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
733                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
734                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
735                 glDisable(GL_BLEND);
736                 glDepthMask(1);
737
738                 glEnable(GL_TEXTURE_2D);
739                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
740                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
741                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
742                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
743                 glDisable(GL_CULL_FACE);
744                 glDisable(GL_LIGHTING);
745                 glDepthMask(0);
746                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
747                 glPushMatrix();                                                                         // Store The Projection Matrix
748                 glLoadIdentity();                                                                       // Reset The Projection Matrix
749                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
750                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
751                 glPushMatrix();                                                                         // Store The Modelview Matrix
752                 glLoadIdentity();                                                               // Reset The Modelview Matrix
753                 glTranslatef(screenwidth/2,screenheight/2,0);
754                 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
755                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
756                 glEnable(GL_BLEND);
757                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
758                 glPushMatrix();
759                 //glScalef(.25,.25,.25);
760                 glBegin(GL_QUADS);
761                 glTexCoord2f(0+.2,0+.8);
762                 glVertex3f(-1,          -1,      0.0f);
763                 glTexCoord2f(1+.2,0+.8);
764                 glVertex3f(1,   -1,      0.0f);
765                 glTexCoord2f(1+.2,1+.8);
766                 glVertex3f(1,   1, 0.0f);
767                 glTexCoord2f(0+.2,1+.8);
768                 glVertex3f(-1,  1, 0.0f);
769                 glEnd();
770                 glPopMatrix();
771                 glDisable(GL_TEXTURE_2D);
772                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
773                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
774                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
775                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
776                 glDisable(GL_BLEND);
777                 glDepthMask(1);
778
779                 //Text
780                 /*
781                 glEnable(GL_TEXTURE_2D);
782                 static char string[256]="";
783                 sprintf (string, "LOADING... %d%",(int)loadprogress);
784                 glColor4f(1,1,1,.2);
785                 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
786                 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
787                 text.glPrint(280,125,string,1,1,640,480);
788                 */
789
790                 if(flashamount>0){
791                         if(flashamount>1)flashamount=1;
792                         if(flashdelay<=0)flashamount-=multiplier;
793                         flashdelay--;
794                         if(flashamount<0)flashamount=0;
795                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
796                         glDisable(GL_CULL_FACE);
797                         glDisable(GL_LIGHTING);
798                         glDisable(GL_TEXTURE_2D);
799                         glDepthMask(0);
800                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
801                         glPushMatrix();                                                                         // Store The Projection Matrix
802                         glLoadIdentity();                                                                       // Reset The Projection Matrix
803                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
804                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
805                         glPushMatrix();                                                                         // Store The Modelview Matrix
806                         glLoadIdentity();                                                               // Reset The Modelview Matrix
807                         glScalef(screenwidth,screenheight,1);
808                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
809                         glEnable(GL_BLEND);
810                         glColor4f(flashr,flashg,flashb,flashamount);
811                         glBegin(GL_QUADS);
812                         glVertex3f(0,           0,       0.0f);
813                         glVertex3f(256, 0,       0.0f);
814                         glVertex3f(256, 256, 0.0f);
815                         glVertex3f(0,   256, 0.0f);
816                         glEnd();
817                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
818                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
819                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
820                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
821                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
822                         glEnable(GL_CULL_FACE);
823                         glDisable(GL_BLEND);
824                         glDepthMask(1);
825                 }
826
827                 swap_gl_buffers();
828                 loadscreencolor=0;
829         }
830 }
831
832 void Game::FadeLoadingScreen(float howmuch)
833 {
834         static float loadprogress,minprogress,maxprogress;
835
836         float size=1;
837         glLoadIdentity();
838         //Clear to black
839         glClearColor(0,0,0,1);
840         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
841
842         loadprogress=howmuch;
843
844         //loadprogress=abs(Random()%100);
845
846         //Background
847
848         //glEnable(GL_TEXTURE_2D);
849         glDisable(GL_TEXTURE_2D);
850         //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
851         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
852         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
853         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
854         glDisable(GL_CULL_FACE);
855         glDisable(GL_LIGHTING);
856         glDepthMask(0);
857         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
858         glPushMatrix();                                                                         // Store The Projection Matrix
859         glLoadIdentity();                                                                       // Reset The Projection Matrix
860         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
861         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
862         glPushMatrix();                                                                         // Store The Modelview Matrix
863         glLoadIdentity();                                                               // Reset The Modelview Matrix
864         glTranslatef(screenwidth/2,screenheight/2,0);
865         glScalef((float)screenwidth/2,(float)screenheight/2,1);
866         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
867         glDisable(GL_BLEND);
868         glColor4f(loadprogress/100,0,0,1);
869         /*if(loadscreencolor==0)glColor4f(1,1,1,1);
870         if(loadscreencolor==1)glColor4f(1,0,0,1);
871         if(loadscreencolor==2)glColor4f(0,1,0,1);
872         if(loadscreencolor==3)glColor4f(0,0,1,1);
873         if(loadscreencolor==4)glColor4f(1,1,0,1);
874         if(loadscreencolor==5)glColor4f(1,0,1,1);
875         */
876         glPushMatrix();
877         //glScalef(.25,.25,.25);
878         glBegin(GL_QUADS);
879         glTexCoord2f(0,0);
880         glVertex3f(-1,          -1,      0.0f);
881         glTexCoord2f(1,0);
882         glVertex3f(1,   -1,      0.0f);
883         glTexCoord2f(1,1);
884         glVertex3f(1,   1, 0.0f);
885         glTexCoord2f(0,1);
886         glVertex3f(-1,  1, 0.0f);
887         glEnd();
888         glPopMatrix();
889         glDisable(GL_TEXTURE_2D);
890         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
891         glPopMatrix();                                                                          // Restore The Old Projection Matrix
892         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
893         glPopMatrix();                                                                          // Restore The Old Projection Matrix
894         glDisable(GL_BLEND);
895         glDepthMask(1);
896         //Text
897         /*
898         glEnable(GL_TEXTURE_2D);
899         static char string[256]="";
900         sprintf (string, "LOADING... %d%",(int)loadprogress);
901         glColor4f(1,1,1,.2);
902         text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
903         glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
904         text.glPrint(280,125,string,1,1,640,480);
905         */
906         swap_gl_buffers();
907         loadscreencolor=0;
908 }
909
910
911 void Game::InitGame()
912 {
913 #if PLATFORM_MACOSX
914         ProcessSerialNumber PSN;
915         ProcessInfoRec pinfo;
916         FSSpec pspec;
917         OSStatus err;
918         /* set up process serial number */
919         PSN.highLongOfPSN = 0;
920         PSN.lowLongOfPSN = kCurrentProcess;
921         /* set up info block */
922         pinfo.processInfoLength = sizeof(pinfo);
923         pinfo.processName = NULL;
924         pinfo.processAppSpec = &pspec;
925         /* grab the vrefnum and directory */
926         err = GetProcessInformation(&PSN, &pinfo);
927         if (err == noErr) {
928                 vRefNum = pspec.vRefNum;
929                 dirID = pspec.parID;
930         }
931 #endif
932
933         LOGFUNC;
934
935         autocam=0;
936
937         int i,j;
938
939         numchallengelevels=14;
940
941         accountactive=Account::loadFile(":Data:Users");
942
943         tintr=1;
944         tintg=1;
945         tintb=1;
946
947         whichjointstartarray[0]=righthip;
948         whichjointendarray[0]=rightfoot;
949
950         whichjointstartarray[1]=righthip;
951         whichjointendarray[1]=rightankle;
952
953         whichjointstartarray[2]=righthip;
954         whichjointendarray[2]=rightknee;
955
956         whichjointstartarray[3]=rightknee;
957         whichjointendarray[3]=rightankle;
958
959         whichjointstartarray[4]=rightankle;
960         whichjointendarray[4]=rightfoot;
961
962         whichjointstartarray[5]=lefthip;
963         whichjointendarray[5]=leftfoot;
964
965         whichjointstartarray[6]=lefthip;
966         whichjointendarray[6]=leftankle;
967
968         whichjointstartarray[7]=lefthip;
969         whichjointendarray[7]=leftknee;
970
971         whichjointstartarray[8]=leftknee;
972         whichjointendarray[8]=leftankle;
973
974         whichjointstartarray[9]=leftankle;
975         whichjointendarray[9]=leftfoot;
976
977         whichjointstartarray[10]=abdomen;
978         whichjointendarray[10]=rightshoulder;
979
980         whichjointstartarray[11]=abdomen;
981         whichjointendarray[11]=rightelbow;
982
983         whichjointstartarray[12]=abdomen;
984         whichjointendarray[12]=rightwrist;
985
986         whichjointstartarray[13]=abdomen;
987         whichjointendarray[13]=righthand;
988
989         whichjointstartarray[14]=rightshoulder;
990         whichjointendarray[14]=rightelbow;
991
992         whichjointstartarray[15]=rightelbow;
993         whichjointendarray[15]=rightwrist;
994
995         whichjointstartarray[16]=rightwrist;
996         whichjointendarray[16]=righthand;
997
998         whichjointstartarray[17]=abdomen;
999         whichjointendarray[17]=leftshoulder;
1000
1001         whichjointstartarray[18]=abdomen;
1002         whichjointendarray[18]=leftelbow;
1003
1004         whichjointstartarray[19]=abdomen;
1005         whichjointendarray[19]=leftwrist;
1006
1007         whichjointstartarray[20]=abdomen;
1008         whichjointendarray[20]=lefthand;
1009
1010         whichjointstartarray[21]=leftshoulder;
1011         whichjointendarray[21]=leftelbow;
1012
1013         whichjointstartarray[22]=leftelbow;
1014         whichjointendarray[22]=leftwrist;
1015
1016         whichjointstartarray[23]=leftwrist;
1017         whichjointendarray[23]=lefthand;
1018
1019         whichjointstartarray[24]=abdomen;
1020         whichjointendarray[24]=neck;
1021
1022         whichjointstartarray[25]=neck;
1023         whichjointendarray[25]=head;
1024
1025         FadeLoadingScreen(0);
1026
1027         stillloading=1;
1028
1029         texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1030
1031         int temptexdetail=texdetail;
1032         texdetail=1;
1033         text.LoadFontTexture(":Data:Textures:Font.png");
1034         text.BuildFont();
1035         texdetail=temptexdetail;
1036
1037         FadeLoadingScreen(10);
1038
1039         if(detail==2){
1040                 texdetail=1;
1041                 terraindetail=1;
1042         }
1043         if(detail==1){
1044                 texdetail=2;
1045                 terraindetail=1;
1046         }
1047         if(detail==0){
1048                 texdetail=4;
1049                 terraindetail=1;
1050                 //terraindetail=2;
1051         }
1052
1053         for (int it = 0; it < 100; ++it)
1054         {
1055                 channels[it] = -1;
1056                 samp[it] = NULL;
1057         }
1058         for (int it = 0; it < 20; ++it)
1059         {
1060                 strm[it] = NULL;
1061         }
1062
1063         LOG("Initializing sound system...");
1064
1065     int output = -1;
1066
1067     #if PLATFORM_LINUX
1068     extern bool cmdline(const char *cmd);
1069     unsigned char rc = 0;
1070     output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
1071     if (cmdline("forceoss"))      //  ...but let user override that.
1072         output = OPENAL_OUTPUT_OSS;
1073     else if (cmdline("nosound"))
1074         output = OPENAL_OUTPUT_NOSOUND;
1075
1076     OPENAL_SetOutput(output);
1077         if ((rc = OPENAL_Init(44100, 32, 0)) == false)
1078     {
1079         // if we tried ALSA and failed, fall back to OSS.
1080         if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
1081         {
1082             OPENAL_Close();
1083             output = OPENAL_OUTPUT_OSS;
1084             OPENAL_SetOutput(output);
1085                 rc = OPENAL_Init(44100, 32, 0);
1086         }
1087     }
1088
1089     if (rc == false)
1090     {
1091         OPENAL_Close();
1092         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
1093         OPENAL_SetOutput(output);
1094             rc = OPENAL_Init(44100, 32, 0);
1095     }
1096     #else
1097         OPENAL_Init(44100, 32, 0);
1098     #endif
1099
1100         OPENAL_SetSFXMasterVolume((int)(volume*255));
1101
1102         strm[stream_music3] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music3.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=0;}
1103 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music3], 4.0f, 1000.0f);
1104         OPENAL_Stream_SetMode(strm[stream_music3], OPENAL_LOOP_NORMAL);
1105
1106         if(musictoggle){
1107 //              PlaySoundEx( stream_music3, strm[stream_music3], NULL, true);
1108                 PlayStreamEx(stream_music3, strm[stream_music3], 0, true);
1109                 OPENAL_SetPaused(channels[stream_music3], false);
1110                 OPENAL_SetVolume(channels[stream_music3], 256);
1111         }
1112
1113         FadeLoadingScreen(20);
1114
1115         if(ambientsound){
1116                 strm[stream_wind] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:wind.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1117 //              OPENAL_Sample_SetMinMaxDistance(strm[stream_wind], 4.0f, 1000.0f);
1118                 OPENAL_Stream_SetMode(strm[stream_wind], OPENAL_LOOP_NORMAL);
1119
1120                 FadeLoadingScreen(30);
1121
1122                 strm[stream_desertambient] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:desertambient.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1123 //              OPENAL_Sample_SetMinMaxDistance(strm[stream_desertambient], 4.0f, 1000.0f);
1124                 OPENAL_Stream_SetMode(strm[stream_desertambient], OPENAL_LOOP_NORMAL);
1125         }
1126
1127         FadeLoadingScreen(40);
1128
1129         samp[firestartsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:firestart.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1130         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1131
1132         strm[stream_firesound] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:fire.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1133 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_firesound], 8.0f, 2000.0f);
1134         OPENAL_Stream_SetMode(strm[stream_firesound], OPENAL_LOOP_NORMAL);
1135
1136         FadeLoadingScreen(50);
1137
1138         samp[fireendsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:fireend.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
1139         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1140
1141         //if(musictoggle){
1142         strm[stream_music1grass] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1grass.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=1;}
1143 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1grass], 4.0f, 1000.0f);
1144         OPENAL_Stream_SetMode(strm[stream_music1grass], OPENAL_LOOP_NORMAL);
1145
1146         strm[stream_music1snow] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1snow.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=2;}
1147 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1snow], 4.0f, 1000.0f);
1148         OPENAL_Stream_SetMode(strm[stream_music1snow], OPENAL_LOOP_NORMAL);
1149
1150         FadeLoadingScreen(60);
1151
1152         strm[stream_music1desert] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1desert.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=3;}
1153 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1desert], 4.0f, 1000.0f);
1154         OPENAL_Stream_SetMode(strm[stream_music1desert], OPENAL_LOOP_NORMAL);
1155
1156         FadeLoadingScreen(80);
1157         strm[stream_music2] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music2.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=4;}
1158 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music2], 4.0f, 1000.0f);
1159         OPENAL_Stream_SetMode(strm[stream_music2], OPENAL_LOOP_NORMAL);
1160
1161         //}
1162
1163
1164         FadeLoadingScreen(90);
1165
1166
1167         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
1168
1169         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
1170         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
1171         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
1172
1173         temptexdetail=texdetail;
1174         if(texdetail>2)texdetail=2;
1175         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
1176         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
1177         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
1178         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
1179         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
1180         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
1181         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
1182         texdetail=temptexdetail;
1183
1184         loaddistrib=0;
1185         anim=0;
1186
1187         FadeLoadingScreen(95);
1188
1189
1190         gameon=0;
1191         mainmenu=1;
1192
1193         stillloading=0;
1194         firstload=0;
1195         oldmainmenu=0;
1196
1197         newdetail=detail;
1198         newscreenwidth=screenwidth;
1199         newscreenheight=screenheight;
1200 }
1201
1202
1203 void Game::LoadStuff()
1204 {
1205         static float temptexdetail;
1206         static float viewdistdetail;
1207         static int i,j,texsize;
1208         float megascale =1;
1209
1210         LOGFUNC;
1211
1212         visibleloading=1;
1213
1214         /*musicvolume[3]=512;
1215         PlaySoundEx( music4, samp[music4], NULL, true);
1216         OPENAL_SetPaused(channels[music4], false);
1217         OPENAL_SetVolume(channels[music4], 512);
1218         */
1219         loadtime=0;
1220
1221         stillloading=1;
1222
1223         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1224
1225         for(i=0;i<maxplayers;i++)
1226         {
1227                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
1228                 {
1229                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
1230                 }
1231                 player[i].skeleton.drawmodel.textureptr=0;;
1232         }
1233
1234         //temptexdetail=texdetail;
1235         //texdetail=1;
1236         i=abs(Random()%4);
1237         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
1238         //texdetail=temptexdetail;
1239
1240         temptexdetail=texdetail;
1241         texdetail=1;
1242         text.LoadFontTexture(":Data:Textures:Font.png");
1243         text.BuildFont();
1244         texdetail=temptexdetail;
1245
1246         numsounds=71;
1247
1248         viewdistdetail=2;
1249         viewdistance=50*megascale*viewdistdetail;
1250
1251         brightness=100;
1252
1253
1254
1255         if(detail==2){
1256                 texdetail=1;
1257                 terraindetail=1;
1258         }
1259         if(detail==1){
1260                 texdetail=2;
1261                 terraindetail=1;
1262         }
1263         if(detail==0){
1264                 texdetail=4;
1265                 terraindetail=1;
1266                 //terraindetail=2;
1267         }
1268
1269         realtexdetail=texdetail;
1270
1271         /*texdetail/=4;
1272         if(texdetail<1)texdetail=1;
1273         realtexdetail=texdetail*4;
1274         */
1275         numplayers=1;
1276
1277
1278
1279         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
1280
1281         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1282
1283         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1284         */
1285
1286
1287         LOG("Loading weapon data...");
1288
1289         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1290         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1291         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1292         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1293         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1294         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1295         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1296
1297         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1298         weapons.throwingknifemodel.Scale(.001,.001,.001);
1299         //weapons.throwingknifemodel.Rotate(0,0,-90);
1300         weapons.throwingknifemodel.Rotate(90,0,0);
1301         weapons.throwingknifemodel.Rotate(0,90,0);
1302         weapons.throwingknifemodel.flat=0;
1303         weapons.throwingknifemodel.CalculateNormals(1);
1304         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1305
1306         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1307         weapons.swordmodel.Scale(.001,.001,.001);
1308         //weapons.swordmodel.Rotate(0,0,-90);
1309         weapons.swordmodel.Rotate(90,0,0);
1310         weapons.swordmodel.Rotate(0,90,0);
1311         weapons.swordmodel.Rotate(0,0,90);
1312         weapons.swordmodel.flat=1;
1313         weapons.swordmodel.CalculateNormals(1);
1314         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1315
1316         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1317         weapons.staffmodel.Scale(.005,.005,.005);
1318         //weapons.staffmodel.Rotate(0,0,-90);
1319         weapons.staffmodel.Rotate(90,0,0);
1320         weapons.staffmodel.Rotate(0,90,0);
1321         weapons.staffmodel.Rotate(0,0,90);
1322         weapons.staffmodel.flat=1;
1323         weapons.staffmodel.CalculateNormals(1);
1324         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1325
1326         //temptexdetail=texdetail;
1327         //if(texdetail>4)texdetail=4;
1328         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1329
1330         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1331
1332         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1333
1334         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1335
1336
1337         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1338
1339         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1340
1341         /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1);
1342
1343         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1);
1344
1345         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1);
1346
1347         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1);
1348
1349         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1);
1350
1351         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1);
1352         //texdetail=temptexdetail;
1353         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1);*/
1354
1355
1356
1357         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1358
1359         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1360
1361
1362         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1363
1364
1365         LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1366         LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1367         LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1368         LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1369         LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1370         LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1371         LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1372         LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1373         LoadTexture(":Data:Textures:splinter.png",&sprites.splintertexture,1,1);
1374         LoadTexture(":Data:Textures:leaf.png",&sprites.leaftexture,1,1);
1375         LoadTexture(":Data:Textures:tooth.png",&sprites.toothtexture,1,1);
1376
1377         rotation=0;
1378         rotation2=0;
1379         ReSizeGLScene(90,.01);
1380
1381         viewer=0;
1382
1383
1384
1385
1386         if(detail)kTextureSize=1024;
1387         if(detail==1)kTextureSize=512;
1388         if(detail==0)kTextureSize=256;
1389
1390
1391         //drawmode=motionblurmode;
1392
1393         //Set up distant light
1394         light.color[0]=.95;
1395         light.color[1]=.95;
1396         light.color[2]=1;
1397         light.ambient[0]=.2;
1398         light.ambient[1]=.2;
1399         light.ambient[2]=.24;
1400         light.location.x=1;
1401         light.location.y=1;
1402         light.location.z=-.2;
1403         Normalise(&light.location);
1404
1405         LoadingScreen();
1406
1407         SetUpLighting();
1408
1409
1410         fadestart=.6;
1411         gravity=-10;
1412
1413         texscale=.2/megascale/viewdistdetail;
1414         terrain.scale=3*megascale*terraindetail*viewdistdetail;
1415
1416         viewer.x=terrain.size/2*terrain.scale;
1417         viewer.z=terrain.size/2*terrain.scale;
1418
1419         hawk.load((char *)":Data:Models:hawk.solid",1);
1420         hawk.Scale(.03,.03,.03);
1421         hawk.Rotate(90,1,1);
1422         hawk.CalculateNormals(0);
1423         hawk.ScaleNormals(-1,-1,-1);
1424         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1425         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1426         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1427
1428
1429         eye.load((char *)":Data:Models:eye.solid",1);
1430         eye.Scale(.03,.03,.03);
1431         eye.CalculateNormals(0);
1432
1433         cornea.load((char *)":Data:Models:cornea.solid",1);
1434         cornea.Scale(.03,.03,.03);
1435         cornea.CalculateNormals(0);
1436
1437         iris.load((char *)":Data:Models:iris.solid",1);
1438         iris.Scale(.03,.03,.03);
1439         iris.CalculateNormals(0);
1440
1441         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1442         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1443
1444         oldenvironment=-4;
1445
1446         gameon=1;
1447         mainmenu=0;
1448
1449         firstload=0;
1450         //if(targetlevel!=7)
1451                 Loadlevel(targetlevel);
1452
1453
1454         rabbitcoords=player[0].coords;
1455         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1456
1457         animation[runanim].Load((char *)":Data:Animations:Run",middleheight,neutral);
1458
1459         animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
1460         animation[stopanim].Load((char *)":Data:Animations:Stop",middleheight,neutral);
1461
1462         animation[jumpupanim].Load((char *)":Data:Animations:JumpUp",highheight,neutral);
1463         animation[jumpdownanim].Load((char *)":Data:Animations:JumpDown",highheight,neutral);
1464
1465         animation[landanim].Load((char *)":Data:Animations:Landing",lowheight,neutral);
1466         animation[landhardanim].Load((char *)":Data:Animations:Landhard",lowheight,neutral);
1467         animation[climbanim].Load((char *)":Data:Animations:Climb",lowheight,neutral);
1468         animation[hanganim].Load((char *)":Data:Animations:Hangon",lowheight,neutral);
1469         animation[spinkickanim].Load((char *)":Data:Animations:SpinKick",middleheight,normalattack);
1470
1471         animation[getupfromfrontanim].Load((char *)":Data:Animations:GetUpFromFront",lowheight,neutral);
1472         animation[getupfrombackanim].Load((char *)":Data:Animations:GetUpFromBack",lowheight,neutral);
1473         animation[crouchanim].Load((char *)":Data:Animations:Crouch",lowheight,neutral);
1474         animation[sneakanim].Load((char *)":Data:Animations:Sneak",lowheight,neutral);
1475         animation[rollanim].Load((char *)":Data:Animations:Roll",lowheight,neutral);
1476         animation[flipanim].Load((char *)":Data:Animations:Flip",highheight,neutral);
1477         animation[frontflipanim].Load((char *)":Data:Animations:Flip",highheight,neutral);
1478         animation[spinkickreversedanim].Load((char *)":Data:Animations:SpinKickCaught",middleheight,reversed);
1479
1480         animation[spinkickreversalanim].Load((char *)":Data:Animations:SpinKickCatch",middleheight,reversal);
1481         animation[lowkickanim].Load((char *)":Data:Animations:lowkick",middleheight,normalattack);
1482         animation[sweepanim].Load((char *)":Data:Animations:sweep",lowheight,normalattack);
1483         animation[sweepreversedanim].Load((char *)":Data:Animations:SweepCaught",lowheight,reversed);
1484         animation[sweepreversalanim].Load((char *)":Data:Animations:SweepCatch",middleheight,reversal);
1485         animation[rabbitkickanim].Load((char *)":Data:Animations:RabbitKick",middleheight,normalattack);
1486         animation[rabbitkickreversedanim].Load((char *)":Data:Animations:RabbitKickCaught",middleheight,reversed);
1487         animation[rabbitkickreversalanim].Load((char *)":Data:Animations:RabbitKickCatch",lowheight,reversal);
1488         animation[upunchanim].Load((char *)":Data:Animations:Upunch",middleheight,normalattack);
1489         animation[staggerbackhighanim].Load((char *)":Data:Animations:Staggerbackhigh",middleheight,neutral);
1490         animation[upunchreversedanim].Load((char *)":Data:Animations:UpunchCaught",middleheight,reversed);
1491
1492         animation[upunchreversalanim].Load((char *)":Data:Animations:UpunchCatch",middleheight,reversal);
1493         animation[hurtidleanim].Load((char *)":Data:Animations:Hurtidle",middleheight,neutral);
1494         animation[backhandspringanim].Load((char *)":Data:Animations:Backhandspring",middleheight,neutral);
1495         animation[fightidleanim].Load((char *)":Data:Animations:Fightidle",middleheight,neutral);
1496         animation[walkanim].Load((char *)":Data:Animations:Walk",middleheight,neutral);
1497
1498         animation[fightsidestep].Load((char *)":Data:Animations:Fightsidestep",middleheight,neutral);
1499         animation[killanim].Load((char *)":Data:Animations:Kill",middleheight,normalattack);
1500         animation[sneakattackanim].Load((char *)":Data:Animations:Sneakattack",middleheight,reversal);
1501         animation[sneakattackedanim].Load((char *)":Data:Animations:Sneakattacked",middleheight,reversed);
1502         animation[drawrightanim].Load((char *)":Data:Animations:drawright",middleheight,neutral);
1503         animation[knifeslashstartanim].Load((char *)":Data:Animations:slashstart",middleheight,normalattack);
1504         animation[crouchdrawrightanim].Load((char *)":Data:Animations:crouchdrawright",lowheight,neutral);
1505         animation[crouchstabanim].Load((char *)":Data:Animations:crouchstab",lowheight,normalattack);
1506
1507         animation[knifefollowanim].Load((char *)":Data:Animations:slashfollow",middleheight,reversal);
1508         animation[knifefollowedanim].Load((char *)":Data:Animations:slashfollowed",middleheight,reversed);
1509         animation[knifethrowanim].Load((char *)":Data:Animations:knifethrow",middleheight,normalattack);
1510         animation[removeknifeanim].Load((char *)":Data:Animations:removeknife",middleheight,neutral);
1511         animation[crouchremoveknifeanim].Load((char *)":Data:Animations:crouchremoveknife",lowheight,neutral);
1512         animation[jumpreversedanim].Load((char *)":Data:Animations:JumpCaught",middleheight,reversed);
1513         animation[jumpreversalanim].Load((char *)":Data:Animations:JumpCatch",middleheight,reversal);
1514         animation[staggerbackhardanim].Load((char *)":Data:Animations:Staggerbackhard",middleheight,neutral);
1515
1516         animation[dropkickanim].Load((char *)":Data:Animations:Dropkick",middleheight,normalattack);
1517         animation[winduppunchanim].Load((char *)":Data:Animations:Winduppunch",middleheight,normalattack);
1518         animation[winduppunchblockedanim].Load((char *)":Data:Animations:Winduppunchblocked",middleheight,normalattack);
1519         animation[blockhighleftanim].Load((char *)":Data:Animations:Blockhighleft",middleheight,normalattack);
1520         animation[blockhighleftstrikeanim].Load((char *)":Data:Animations:Blockhighleftstrike",middleheight,normalattack);
1521         animation[backflipanim].Load((char *)":Data:Animations:Backflip",highheight,neutral);
1522         animation[walljumpbackanim].Load((char *)":Data:Animations:Walljumpback",highheight,neutral);
1523         animation[walljumpfrontanim].Load((char *)":Data:Animations:Walljumpfront",highheight,neutral);
1524         animation[rightflipanim].Load((char *)":Data:Animations:Rightflip",highheight,neutral);
1525         animation[walljumprightanim].Load((char *)":Data:Animations:Walljumpright",highheight,neutral);
1526         animation[leftflipanim].Load((char *)":Data:Animations:Leftflip",highheight,neutral);
1527         animation[walljumpleftanim].Load((char *)":Data:Animations:Walljumpleft",highheight,neutral);
1528         animation[walljumprightkickanim].Load((char *)":Data:Animations:Walljumprightkick",highheight,neutral);
1529         animation[walljumpleftkickanim].Load((char *)":Data:Animations:Walljumpleftkick",highheight,neutral);
1530         animation[knifefightidleanim].Load((char *)":Data:Animations:Knifefightidle",middleheight,neutral);
1531         animation[knifesneakattackanim].Load((char *)":Data:Animations:Knifesneakattack",middleheight,reversal);
1532         animation[knifesneakattackedanim].Load((char *)":Data:Animations:Knifesneakattacked",middleheight,reversed);
1533         animation[swordfightidleanim].Load((char *)":Data:Animations:swordfightidle",middleheight,neutral);
1534         animation[drawleftanim].Load((char *)":Data:Animations:drawleft",middleheight,neutral);
1535         animation[swordslashanim].Load((char *)":Data:Animations:swordslash",middleheight,normalattack);
1536         animation[swordgroundstabanim].Load((char *)":Data:Animations:swordgroundstab",lowheight,normalattack);
1537         animation[dodgebackanim].Load((char *)":Data:Animations:dodgeback",middleheight,neutral);
1538         animation[swordsneakattackanim].Load((char *)":Data:Animations:Swordsneakattack",middleheight,reversal);
1539         animation[swordsneakattackedanim].Load((char *)":Data:Animations:Swordsneakattacked",middleheight,reversed);
1540         animation[swordslashreversedanim].Load((char *)":Data:Animations:swordslashCaught",middleheight,reversed);
1541         animation[swordslashreversalanim].Load((char *)":Data:Animations:swordslashCatch",middleheight,reversal);
1542         animation[knifeslashreversedanim].Load((char *)":Data:Animations:knifeslashCaught",middleheight,reversed);
1543         animation[knifeslashreversalanim].Load((char *)":Data:Animations:knifeslashCatch",middleheight,reversal);
1544         animation[swordfightidlebothanim].Load((char *)":Data:Animations:swordfightidleboth",middleheight,neutral);
1545         animation[swordslashparryanim].Load((char *)":Data:Animations:sworduprightparry",middleheight,normalattack);
1546         animation[swordslashparriedanim].Load((char *)":Data:Animations:swordslashparried",middleheight,normalattack);
1547         animation[wolfidle].Load((char *)":Data:Animations:Wolfidle",middleheight,neutral);
1548         animation[wolfcrouchanim].Load((char *)":Data:Animations:Wolfcrouch",lowheight,neutral);
1549         animation[wolflandanim].Load((char *)":Data:Animations:Wolflanding",lowheight,neutral);
1550         animation[wolflandhardanim].Load((char *)":Data:Animations:Wolflandhard",lowheight,neutral);
1551         animation[wolfrunanim].Load((char *)":Data:Animations:Wolfrun",middleheight,neutral);
1552         animation[wolfrunninganim].Load((char *)":Data:Animations:Wolfrunning",middleheight,neutral);
1553         animation[rabbitrunninganim].Load((char *)":Data:Animations:Rabbitrunning",middleheight,neutral);
1554         animation[wolfstopanim].Load((char *)":Data:Animations:Wolfstop",middleheight,neutral);
1555         animation[rabbittackleanim].Load((char *)":Data:Animations:Rabbittackle",middleheight,neutral);
1556         animation[rabbittacklinganim].Load((char *)":Data:Animations:Rabbittackling",middleheight,reversal);
1557         animation[rabbittackledbackanim].Load((char *)":Data:Animations:Rabbittackledback",middleheight,reversed);
1558         animation[rabbittackledfrontanim].Load((char *)":Data:Animations:Rabbittackledfront",middleheight,reversed);
1559         animation[wolfslapanim].Load((char *)":Data:Animations:Wolfslap",middleheight,normalattack);
1560         animation[staffhitanim].Load((char *)":Data:Animations:StaffHit",middleheight,normalattack);
1561         animation[staffgroundsmashanim].Load((char *)":Data:Animations:StaffGroundSmash",lowheight,normalattack);
1562         animation[staffspinhitanim].Load((char *)":Data:Animations:Spinwhack",middleheight,normalattack);
1563         animation[staffhitreversedanim].Load((char *)":Data:Animations:StaffHitCaught",middleheight,reversed);
1564         animation[staffhitreversalanim].Load((char *)":Data:Animations:StaffHitCatch",middleheight,reversal);
1565         animation[staffspinhitreversedanim].Load((char *)":Data:Animations:SpinWhackCaught",middleheight,reversed);
1566         animation[staffspinhitreversalanim].Load((char *)":Data:Animations:SpinWhackCatch",middleheight,reversal);
1567
1568         animation[sitanim].Load((char *)":Data:Animations:Sit",lowheight,neutral);
1569         animation[sleepanim].Load((char *)":Data:Animations:Sleep",lowheight,neutral);
1570         animation[talkidleanim].Load((char *)":Data:Animations:TalkIdle",middleheight,neutral);
1571
1572         animation[sitwallanim].Load((char *)":Data:Animations:Dying",lowheight,neutral);
1573         animation[dead1anim].Load((char *)":Data:Animations:Dead1",lowheight,neutral);
1574         animation[dead2anim].Load((char *)":Data:Animations:Dead2",lowheight,neutral);
1575         animation[dead3anim].Load((char *)":Data:Animations:Dead3",lowheight,neutral);
1576         animation[dead4anim].Load((char *)":Data:Animations:Dead4",lowheight,neutral);
1577         //Fix knife stab, too lazy to do it manually
1578         XYZ moveamount;
1579         moveamount=0;
1580         moveamount.z=2;
1581         for(i=0;i<player[0].skeleton.num_joints;i++){
1582                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1583                         animation[knifesneakattackanim].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                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1592                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1593                 }
1594         }
1595
1596         loadscreencolor=4;
1597         LoadingScreen();
1598
1599         for(i=0;i<player[0].skeleton.num_joints;i++){
1600                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1601                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1602                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1603                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1604         }
1605         animation[dead1anim].speed[0]=0.001;
1606         animation[dead2anim].speed[0]=0.001;
1607         animation[dead3anim].speed[0]=0.001;
1608         animation[dead4anim].speed[0]=0.001;
1609
1610         animation[dead1anim].speed[1]=0.001;
1611         animation[dead2anim].speed[1]=0.001;
1612         animation[dead3anim].speed[1]=0.001;
1613         animation[dead4anim].speed[1]=0.001;
1614
1615         for(i=0;i<player[0].skeleton.num_joints;i++){
1616                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1617                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1618                 }
1619         }
1620         loadscreencolor=4;
1621         LoadingScreen();
1622         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1623                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1624         }
1625
1626         loadscreencolor=4;
1627         LoadingScreen();
1628
1629         for(i=0;i<player[0].skeleton.num_joints;i++){
1630                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1631                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1632                 }
1633         }
1634         /*
1635         for(i=0;i<player[0].skeleton.num_joints;i++){
1636         for(j=0;j<animation[sleepanim].numframes;j++){
1637         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1638         }
1639         }
1640         */
1641         loadscreencolor=4;
1642         LoadingScreen();
1643         temptexdetail=texdetail;
1644         texdetail=1;
1645         texdetail=temptexdetail;
1646
1647         loadscreencolor=4;
1648         LoadingScreen();
1649
1650         //if(ismotionblur){
1651         if(!screentexture){
1652                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1653
1654                 glGenTextures( 1, &screentexture );
1655                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1656
1657
1658                 glEnable(GL_TEXTURE_2D);
1659                 glBindTexture( GL_TEXTURE_2D, screentexture);
1660                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1661                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1662
1663                 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1664         }
1665         //}
1666
1667         LoadSounds();
1668
1669         /*PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1670         OPENAL_SetVolume(channels[consolesuccesssound], 256);
1671         OPENAL_SetPaused(channels[consolesuccesssound], false);
1672         */
1673         if(targetlevel!=7){
1674                 float gLoc[3]={0,0,0};
1675                 float vel[3]={0,0,0};
1676                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1677                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1678                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1679                 OPENAL_SetVolume(channels[fireendsound], 256);
1680                 OPENAL_SetPaused(channels[fireendsound], false);
1681                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1682         }
1683
1684         stillloading=0;
1685         loading=0;
1686         changedelay=1;
1687
1688         visibleloading=0;
1689 }
1690