]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Unify strms and samps
[lugaru.git] / Source / GameInitDispose.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #include "Game.h"
23 #include "openal_wrapper.h"
24 #include "Animation.h"
25
26 extern float screenwidth,screenheight;
27 extern float viewdistance;
28 extern XYZ viewer;
29 extern XYZ lightlocation;
30 extern float lightambient[3],lightbrightness[3];
31 extern float fadestart;
32 extern float texscale;
33 extern float gravity;
34 extern Light light;
35 extern Skeleton testskeleton;
36 extern int numsounds;
37 extern int channels[100];
38 extern Terrain terrain;
39 //extern Sprites sprites;
40 extern int kTextureSize;
41 extern float texdetail;
42 extern float realtexdetail;
43 extern float terraindetail;
44 extern float volume;
45 extern Objects objects;
46 extern int detail;
47 extern bool cellophane;
48 extern GLubyte bloodText[512*512*3];
49 extern GLubyte wolfbloodText[512*512*3];
50 extern bool ismotionblur;
51 extern bool trilinear;
52 extern bool osx;
53 extern bool musictoggle;
54 extern Weapons weapons;
55 extern Person player[maxplayers];
56 extern int numplayers;
57 extern int environment;
58 extern bool ambientsound;
59 extern float multiplier;
60 extern int netdatanew;
61 extern float mapinfo;
62 extern bool stillloading;
63 extern TGAImageRec texture;
64 extern short vRefNum;
65 extern long dirID;
66 extern int mainmenu;
67 extern int oldmainmenu;
68 extern bool visibleloading;
69 extern int loadscreencolor;
70 extern float flashamount,flashr,flashg,flashb;
71 extern int flashdelay;
72 extern int whichjointstartarray[26];
73 extern int whichjointendarray[26];
74 extern int difficulty;
75 extern float tintr,tintg,tintb;
76 extern float slomospeed;
77 extern char mapname[256];
78 extern bool gamestarted;
79
80 extern int numdialogues;
81 extern int numdialogueboxes[20];
82 extern int dialoguetype[20];
83 extern int dialogueboxlocation[20][20];
84 extern float dialogueboxcolor[20][20][3];
85 extern int dialogueboxsound[20][20];
86 extern char dialoguetext[20][20][128];
87 extern char dialoguename[20][20][64];
88 extern XYZ dialoguecamera[20][20];
89 extern float dialoguecamerarotation[20][20];
90 extern float dialoguecamerarotation2[20][20];
91 extern int indialogue;
92 extern int whichdialogue;
93 extern float dialoguetime;
94
95 extern float accountcampaignhighscore[10];
96 extern float accountcampaignfasttime[10];
97 extern float accountcampaignscore[10];
98 extern float accountcampaigntime[10];
99
100 extern int accountcampaignchoicesmade[10];
101 extern int accountcampaignchoices[10][5000];
102
103 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
104 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
105
106 void LOG(const std::string &fmt, ...)
107 {
108     // !!! FIXME: write me.
109 }
110
111
112 Game::TextureList Game::textures;
113
114 void Game::Dispose()
115 {
116         int i,j;
117
118         LOGFUNC;
119
120         if(endgame==2){
121                 accountactive->endGame();
122                 endgame=0;
123         }
124
125         Account::saveFile(":Data:Users", accountactive);
126
127         TexIter it = textures.begin();
128         for (; it != textures.end(); ++it)
129         {
130                 if (glIsTexture(it->second))
131                         glDeleteTextures(1, &it->second);
132         }
133         textures.clear();
134
135         LOG("Shutting down sound system...");
136
137         OPENAL_StopSound(OPENAL_ALL);
138
139 // this is causing problems on Linux, but we'll force an _exit() a little
140 //  later in the shutdown process.  --ryan.
141 #if !PLATFORM_LINUX
142
143         for (i=0; i < sounds_count; ++i)
144         {
145                 OPENAL_Sample_Free(samp[i]);
146         }
147
148         OPENAL_Close();
149         if (texture.data)
150         {
151                 free(texture.data);
152         }
153         texture.data = 0;
154 #endif
155 }
156
157
158 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
159 {
160         GLuint          type;
161
162         LOGFUNC;
163
164         LOG(std::string("Loading texture...") + fileName);
165
166         // Fix filename so that is os appropreate
167         char * fixedFN = ConvertFileName(fileName);
168
169         unsigned char fileNamep[256];
170         CopyCStringToPascal(fixedFN, fileNamep);
171         //Load Image
172         upload_image( fileNamep ,hasalpha);
173
174 //      std::string fname(fileName);
175 //      std::transform(fname.begin(), fname.end(), tolower);
176 //      TexIter it = textures.find(fname);
177
178         //Is it valid?
179         if(1==1)
180         //if(textures.end() == it)
181         {
182                 //Alpha channel?
183                 if ( texture.bpp == 24 )
184                         type = GL_RGB;
185                 else
186                         type = GL_RGBA;
187
188                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
189
190                 if(!*textureid)
191                         glGenTextures( 1, textureid );
192                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
193
194                 glBindTexture( GL_TEXTURE_2D, *textureid);
195                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
196                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
197                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
198                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
199                 
200                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
201         }
202 }
203
204 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
205 {
206         GLuint          type;
207         int i;
208         int bytesPerPixel;
209
210         LOGFUNC;
211
212         LOG(std::string("Loading texture (S)...") + fileName);
213
214         //Load Image
215         unsigned char fileNamep[256];
216         CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
217         //Load Image
218         upload_image( fileNamep ,0);
219         //LoadTGA( fileName );
220
221 //      std::string fname(fileName);
222 //      std::transform(fname.begin(), fname.end(), tolower);
223 //      TexIter it = textures.find(fname);
224
225         //Is it valid?
226         if(1==1)
227         //if(textures.end() == it)
228         {
229                 bytesPerPixel=texture.bpp/8;
230
231                 //Alpha channel?
232                 if ( texture.bpp == 24 )
233                         type = GL_RGB;
234                 else
235                         type = GL_RGBA;
236
237                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
238
239                 if(!*textureid)glGenTextures( 1, textureid );
240                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
241
242                 glBindTexture( GL_TEXTURE_2D, *textureid);
243                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
244                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
245                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
246                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
247
248                 int tempnum=0;
249                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
250                         if((i+1)%4||type==GL_RGB){
251                                 array[tempnum]=texture.data[i];
252                                 tempnum++;
253                         }
254                 }
255
256                 *skinsize=texture.sizeX;
257
258                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
259
260 //              textures.insert(std::make_pair(fname, *textureid));
261         }
262 //      else
263 //      {
264 //              *textureid = it->second;
265 //      }
266 }
267
268 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
269 {
270         int i;
271         int bytesPerPixel;
272
273         LOGFUNC;
274
275         LOG(std::string("Loading (S)...") + fileName);
276
277         //Load Image
278         float temptexdetail=texdetail;
279         texdetail=1;
280         //upload_image( fileName );
281         //LoadTGA( fileName );
282
283         // Converting file to something os specific
284         char * fixedFN = ConvertFileName(fileName);
285
286         //Load Image
287         unsigned char fileNamep[256];
288         CopyCStringToPascal(fixedFN, fileNamep);
289         //Load Image
290         upload_image( fileNamep ,0);
291         texdetail=temptexdetail;
292
293         //Is it valid?
294         if(1==1){
295                 bytesPerPixel=texture.bpp/8;
296
297                 int tempnum=0;
298                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
299                         if((i+1)%4||bytesPerPixel==3){
300                                 array[tempnum]=texture.data[i];
301                                 tempnum++;
302                         }
303                 }
304         }
305 }
306
307 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
308 {
309         int i;
310         int bytesPerPixel;
311
312         LOGFUNC;
313
314         //upload_image( fileName );
315         //LoadTGA( fileName );
316         //Load Image
317         unsigned char fileNamep[256];
318         CopyCStringToPascal(fileName,fileNamep);
319         //Load Image
320         bool opened;
321         opened=upload_image( fileNamep ,1);
322
323         float alphanum;
324         //Is it valid?
325         if(opened){
326                 if(tintr>1)tintr=1;
327                 if(tintg>1)tintg=1;
328                 if(tintb>1)tintb=1;
329
330                 if(tintr<0)tintr=0;
331                 if(tintg<0)tintg=0;
332                 if(tintb<0)tintb=0;
333
334                 bytesPerPixel=texture.bpp/8;
335
336                 int tempnum=0;
337                 alphanum=255;
338                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
339                         if(bytesPerPixel==3)alphanum=255;
340                         else if((i+1)%4==0)alphanum=texture.data[i];
341                         //alphanum/=2;
342                         if((i+1)%4||bytesPerPixel==3){
343                                 if((i%4)==0)texture.data[i]*=tintr;
344                                 if((i%4)==1)texture.data[i]*=tintg;
345                                 if((i%4)==2)texture.data[i]*=tintb;
346                                 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
347                                 tempnum++;
348                         }
349                 }
350         }
351         else return 0;
352         return 1;
353 }
354
355
356 //***************> ResizeGLScene() <******/
357 GLvoid Game::ReSizeGLScene(float fov, float pnear)
358 {
359         if (screenheight==0)
360         {
361                 screenheight=1;
362         }
363
364         glViewport(0,0,screenwidth,screenheight);
365
366         glMatrixMode(GL_PROJECTION);
367         glLoadIdentity();
368
369         gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
370
371         glMatrixMode(GL_MODELVIEW);
372         glLoadIdentity();
373 }
374
375 void Game::LoadingScreen()
376 {
377         static float loadprogress,minprogress,maxprogress;
378         static AbsoluteTime time = {0,0};
379         static AbsoluteTime frametime = {0,0};
380         AbsoluteTime currTime = UpTime ();
381         double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
382
383         if (0 > deltaTime)      // if negative microseconds
384                 deltaTime /= -1000000.0;
385         else                            // else milliseconds
386                 deltaTime /= 1000.0;
387
388         multiplier=deltaTime;
389         if(multiplier<.001)multiplier=.001;
390         if(multiplier>10)multiplier=10;
391         if(multiplier>.05){
392                 frametime = currTime;   // reset for next time interval
393
394                 float size=1;
395                 glLoadIdentity();
396                 //Clear to black
397                 glClearColor(0,0,0,1);
398                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
399
400
401                 loadtime+=multiplier*4;
402
403                 loadprogress=loadtime;
404                 if(loadprogress>100)loadprogress=100;
405
406                 //loadprogress=abs(Random()%100);
407
408                 //Background
409
410                 glEnable(GL_TEXTURE_2D);
411                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
412                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
413                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
414                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
415                 glDisable(GL_CULL_FACE);
416                 glDisable(GL_LIGHTING);
417                 glDepthMask(0);
418                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
419                 glPushMatrix();                                                                         // Store The Projection Matrix
420                 glLoadIdentity();                                                                       // Reset The Projection Matrix
421                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
422                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
423                 glPushMatrix();                                                                         // Store The Modelview Matrix
424                 glLoadIdentity();                                                               // Reset The Modelview Matrix
425                 glTranslatef(screenwidth/2,screenheight/2,0);
426                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
427                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
428                 glDisable(GL_BLEND);
429                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
430                 //glColor4f(1,1,1,1);
431                 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
432                 if(loadscreencolor==1)glColor4f(1,0,0,1);
433                 if(loadscreencolor==2)glColor4f(0,1,0,1);
434                 if(loadscreencolor==3)glColor4f(0,0,1,1);
435                 if(loadscreencolor==4)glColor4f(1,1,0,1);
436                 if(loadscreencolor==5)glColor4f(1,0,1,1);
437                 */
438                 glPushMatrix();
439                 //glScalef(.25,.25,.25);
440                 glBegin(GL_QUADS);
441                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
442                 glVertex3f(-1,          -1,      0.0f);
443                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
444                 glVertex3f(1,   -1,      0.0f);
445                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
446                 glVertex3f(1,   1, 0.0f);
447                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
448                 glVertex3f(-1,  1, 0.0f);
449                 glEnd();
450                 glPopMatrix();
451                 glEnable(GL_BLEND);
452                 glPushMatrix();
453                 //glScalef(.25,.25,.25);
454                 glBegin(GL_QUADS);
455                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
456                 glVertex3f(-1,          -1,      0.0f);
457                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
458                 glVertex3f(1,   -1,      0.0f);
459                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
460                 glVertex3f(1,   1, 0.0f);
461                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
462                 glVertex3f(-1,  1, 0.0f);
463                 glEnd();
464                 glPopMatrix();
465                 glDisable(GL_TEXTURE_2D);
466                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
467                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
468                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
469                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
470                 glDisable(GL_BLEND);
471                 glDepthMask(1);
472
473                 glEnable(GL_TEXTURE_2D);
474                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
475                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
476                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
477                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
478                 glDisable(GL_CULL_FACE);
479                 glDisable(GL_LIGHTING);
480                 glDepthMask(0);
481                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
482                 glPushMatrix();                                                                         // Store The Projection Matrix
483                 glLoadIdentity();                                                                       // Reset The Projection Matrix
484                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
485                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
486                 glPushMatrix();                                                                         // Store The Modelview Matrix
487                 glLoadIdentity();                                                               // Reset The Modelview Matrix
488                 glTranslatef(screenwidth/2,screenheight/2,0);
489                 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
490                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
491                 glEnable(GL_BLEND);
492                 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
493                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
494                 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
495                 if(loadscreencolor==1)glColor4f(1,0,0,1);
496                 if(loadscreencolor==2)glColor4f(0,1,0,1);
497                 if(loadscreencolor==3)glColor4f(0,0,1,1);
498                 if(loadscreencolor==4)glColor4f(1,1,0,1);
499                 if(loadscreencolor==5)glColor4f(1,0,1,1);
500                 */
501                 glPushMatrix();
502                 //glScalef(.25,.25,.25);
503                 glBegin(GL_QUADS);
504                 glTexCoord2f(0+.5,0+.5);
505                 glVertex3f(-1,          -1,      0.0f);
506                 glTexCoord2f(1+.5,0+.5);
507                 glVertex3f(1,   -1,      0.0f);
508                 glTexCoord2f(1+.5,1+.5);
509                 glVertex3f(1,   1, 0.0f);
510                 glTexCoord2f(0+.5,1+.5);
511                 glVertex3f(-1,  1, 0.0f);
512                 glEnd();
513                 glPopMatrix();
514                 glDisable(GL_TEXTURE_2D);
515                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
516                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
517                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
518                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
519                 glDisable(GL_BLEND);
520                 glDepthMask(1);
521
522                 glEnable(GL_TEXTURE_2D);
523                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
524                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
525                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
526                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
527                 glDisable(GL_CULL_FACE);
528                 glDisable(GL_LIGHTING);
529                 glDepthMask(0);
530                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
531                 glPushMatrix();                                                                         // Store The Projection Matrix
532                 glLoadIdentity();                                                                       // Reset The Projection Matrix
533                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
534                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
535                 glPushMatrix();                                                                         // Store The Modelview Matrix
536                 glLoadIdentity();                                                               // Reset The Modelview Matrix
537                 glTranslatef(screenwidth/2,screenheight/2,0);
538                 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
539                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
540                 glEnable(GL_BLEND);
541                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
542                 glPushMatrix();
543                 //glScalef(.25,.25,.25);
544                 glBegin(GL_QUADS);
545                 glTexCoord2f(0+.2,0+.8);
546                 glVertex3f(-1,          -1,      0.0f);
547                 glTexCoord2f(1+.2,0+.8);
548                 glVertex3f(1,   -1,      0.0f);
549                 glTexCoord2f(1+.2,1+.8);
550                 glVertex3f(1,   1, 0.0f);
551                 glTexCoord2f(0+.2,1+.8);
552                 glVertex3f(-1,  1, 0.0f);
553                 glEnd();
554                 glPopMatrix();
555                 glDisable(GL_TEXTURE_2D);
556                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
557                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
558                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
559                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
560                 glDisable(GL_BLEND);
561                 glDepthMask(1);
562
563                 //Text
564                 /*
565                 glEnable(GL_TEXTURE_2D);
566                 static char string[256]="";
567                 sprintf (string, "LOADING... %d%",(int)loadprogress);
568                 glColor4f(1,1,1,.2);
569                 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
570                 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
571                 text.glPrint(280,125,string,1,1,640,480);
572                 */
573
574                 if(flashamount>0){
575                         if(flashamount>1)flashamount=1;
576                         if(flashdelay<=0)flashamount-=multiplier;
577                         flashdelay--;
578                         if(flashamount<0)flashamount=0;
579                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
580                         glDisable(GL_CULL_FACE);
581                         glDisable(GL_LIGHTING);
582                         glDisable(GL_TEXTURE_2D);
583                         glDepthMask(0);
584                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
585                         glPushMatrix();                                                                         // Store The Projection Matrix
586                         glLoadIdentity();                                                                       // Reset The Projection Matrix
587                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
588                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
589                         glPushMatrix();                                                                         // Store The Modelview Matrix
590                         glLoadIdentity();                                                               // Reset The Modelview Matrix
591                         glScalef(screenwidth,screenheight,1);
592                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
593                         glEnable(GL_BLEND);
594                         glColor4f(flashr,flashg,flashb,flashamount);
595                         glBegin(GL_QUADS);
596                         glVertex3f(0,           0,       0.0f);
597                         glVertex3f(256, 0,       0.0f);
598                         glVertex3f(256, 256, 0.0f);
599                         glVertex3f(0,   256, 0.0f);
600                         glEnd();
601                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
602                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
603                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
604                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
605                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
606                         glEnable(GL_CULL_FACE);
607                         glDisable(GL_BLEND);
608                         glDepthMask(1);
609                 }
610
611                 swap_gl_buffers();
612                 loadscreencolor=0;
613         }
614 }
615
616 void Game::FadeLoadingScreen(float howmuch)
617 {
618         static float loadprogress,minprogress,maxprogress;
619
620         float size=1;
621         glLoadIdentity();
622         //Clear to black
623         glClearColor(0,0,0,1);
624         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
625
626         loadprogress=howmuch;
627
628         //loadprogress=abs(Random()%100);
629
630         //Background
631
632         //glEnable(GL_TEXTURE_2D);
633         glDisable(GL_TEXTURE_2D);
634         //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
635         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
636         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
637         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
638         glDisable(GL_CULL_FACE);
639         glDisable(GL_LIGHTING);
640         glDepthMask(0);
641         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
642         glPushMatrix();                                                                         // Store The Projection Matrix
643         glLoadIdentity();                                                                       // Reset The Projection Matrix
644         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
645         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
646         glPushMatrix();                                                                         // Store The Modelview Matrix
647         glLoadIdentity();                                                               // Reset The Modelview Matrix
648         glTranslatef(screenwidth/2,screenheight/2,0);
649         glScalef((float)screenwidth/2,(float)screenheight/2,1);
650         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
651         glDisable(GL_BLEND);
652         glColor4f(loadprogress/100,0,0,1);
653         /*if(loadscreencolor==0)glColor4f(1,1,1,1);
654         if(loadscreencolor==1)glColor4f(1,0,0,1);
655         if(loadscreencolor==2)glColor4f(0,1,0,1);
656         if(loadscreencolor==3)glColor4f(0,0,1,1);
657         if(loadscreencolor==4)glColor4f(1,1,0,1);
658         if(loadscreencolor==5)glColor4f(1,0,1,1);
659         */
660         glPushMatrix();
661         //glScalef(.25,.25,.25);
662         glBegin(GL_QUADS);
663         glTexCoord2f(0,0);
664         glVertex3f(-1,          -1,      0.0f);
665         glTexCoord2f(1,0);
666         glVertex3f(1,   -1,      0.0f);
667         glTexCoord2f(1,1);
668         glVertex3f(1,   1, 0.0f);
669         glTexCoord2f(0,1);
670         glVertex3f(-1,  1, 0.0f);
671         glEnd();
672         glPopMatrix();
673         glDisable(GL_TEXTURE_2D);
674         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
675         glPopMatrix();                                                                          // Restore The Old Projection Matrix
676         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
677         glPopMatrix();                                                                          // Restore The Old Projection Matrix
678         glDisable(GL_BLEND);
679         glDepthMask(1);
680         //Text
681         /*
682         glEnable(GL_TEXTURE_2D);
683         static char string[256]="";
684         sprintf (string, "LOADING... %d%",(int)loadprogress);
685         glColor4f(1,1,1,.2);
686         text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
687         glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
688         text.glPrint(280,125,string,1,1,640,480);
689         */
690         swap_gl_buffers();
691         loadscreencolor=0;
692 }
693
694
695 void Game::InitGame()
696 {
697 #if PLATFORM_MACOSX
698         ProcessSerialNumber PSN;
699         ProcessInfoRec pinfo;
700         FSSpec pspec;
701         OSStatus err;
702         /* set up process serial number */
703         PSN.highLongOfPSN = 0;
704         PSN.lowLongOfPSN = kCurrentProcess;
705         /* set up info block */
706         pinfo.processInfoLength = sizeof(pinfo);
707         pinfo.processName = NULL;
708         pinfo.processAppSpec = &pspec;
709         /* grab the vrefnum and directory */
710         err = GetProcessInformation(&PSN, &pinfo);
711         if (err == noErr) {
712                 vRefNum = pspec.vRefNum;
713                 dirID = pspec.parID;
714         }
715 #endif
716
717         LOGFUNC;
718
719         autocam=0;
720
721         int i,j;
722
723         numchallengelevels=14;
724
725         accountactive=Account::loadFile(":Data:Users");
726
727         tintr=1;
728         tintg=1;
729         tintb=1;
730
731         whichjointstartarray[0]=righthip;
732         whichjointendarray[0]=rightfoot;
733
734         whichjointstartarray[1]=righthip;
735         whichjointendarray[1]=rightankle;
736
737         whichjointstartarray[2]=righthip;
738         whichjointendarray[2]=rightknee;
739
740         whichjointstartarray[3]=rightknee;
741         whichjointendarray[3]=rightankle;
742
743         whichjointstartarray[4]=rightankle;
744         whichjointendarray[4]=rightfoot;
745
746         whichjointstartarray[5]=lefthip;
747         whichjointendarray[5]=leftfoot;
748
749         whichjointstartarray[6]=lefthip;
750         whichjointendarray[6]=leftankle;
751
752         whichjointstartarray[7]=lefthip;
753         whichjointendarray[7]=leftknee;
754
755         whichjointstartarray[8]=leftknee;
756         whichjointendarray[8]=leftankle;
757
758         whichjointstartarray[9]=leftankle;
759         whichjointendarray[9]=leftfoot;
760
761         whichjointstartarray[10]=abdomen;
762         whichjointendarray[10]=rightshoulder;
763
764         whichjointstartarray[11]=abdomen;
765         whichjointendarray[11]=rightelbow;
766
767         whichjointstartarray[12]=abdomen;
768         whichjointendarray[12]=rightwrist;
769
770         whichjointstartarray[13]=abdomen;
771         whichjointendarray[13]=righthand;
772
773         whichjointstartarray[14]=rightshoulder;
774         whichjointendarray[14]=rightelbow;
775
776         whichjointstartarray[15]=rightelbow;
777         whichjointendarray[15]=rightwrist;
778
779         whichjointstartarray[16]=rightwrist;
780         whichjointendarray[16]=righthand;
781
782         whichjointstartarray[17]=abdomen;
783         whichjointendarray[17]=leftshoulder;
784
785         whichjointstartarray[18]=abdomen;
786         whichjointendarray[18]=leftelbow;
787
788         whichjointstartarray[19]=abdomen;
789         whichjointendarray[19]=leftwrist;
790
791         whichjointstartarray[20]=abdomen;
792         whichjointendarray[20]=lefthand;
793
794         whichjointstartarray[21]=leftshoulder;
795         whichjointendarray[21]=leftelbow;
796
797         whichjointstartarray[22]=leftelbow;
798         whichjointendarray[22]=leftwrist;
799
800         whichjointstartarray[23]=leftwrist;
801         whichjointendarray[23]=lefthand;
802
803         whichjointstartarray[24]=abdomen;
804         whichjointendarray[24]=neck;
805
806         whichjointstartarray[25]=neck;
807         whichjointendarray[25]=head;
808
809         FadeLoadingScreen(0);
810
811         stillloading=1;
812
813         texture.data = ( GLubyte* )malloc( 1024*1024*4 );
814
815         int temptexdetail=texdetail;
816         texdetail=1;
817         text.LoadFontTexture(":Data:Textures:Font.png");
818         text.BuildFont();
819         texdetail=temptexdetail;
820
821         FadeLoadingScreen(10);
822
823         if(detail==2){
824                 texdetail=1;
825                 terraindetail=1;
826         }
827         if(detail==1){
828                 texdetail=2;
829                 terraindetail=1;
830         }
831         if(detail==0){
832                 texdetail=4;
833                 terraindetail=1;
834                 //terraindetail=2;
835         }
836
837         memset(channels, 0xff, sizeof(channels));
838
839         LOG("Initializing sound system...");
840
841     int output = -1;
842
843     #if PLATFORM_LINUX
844     extern bool cmdline(const char *cmd);
845     unsigned char rc = 0;
846     output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
847     if (cmdline("forceoss"))      //  ...but let user override that.
848         output = OPENAL_OUTPUT_OSS;
849     else if (cmdline("nosound"))
850         output = OPENAL_OUTPUT_NOSOUND;
851
852     OPENAL_SetOutput(output);
853         if ((rc = OPENAL_Init(44100, 32, 0)) == false)
854     {
855         // if we tried ALSA and failed, fall back to OSS.
856         if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
857         {
858             OPENAL_Close();
859             output = OPENAL_OUTPUT_OSS;
860             OPENAL_SetOutput(output);
861                 rc = OPENAL_Init(44100, 32, 0);
862         }
863     }
864
865     if (rc == false)
866     {
867         OPENAL_Close();
868         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
869         OPENAL_SetOutput(output);
870             rc = OPENAL_Init(44100, 32, 0);
871     }
872     #else
873         OPENAL_Init(44100, 32, 0);
874     #endif
875
876         OPENAL_SetSFXMasterVolume((int)(volume*255));
877         loadAllSounds();
878
879         if(musictoggle){
880                 PlayStreamEx(stream_music3, samp[stream_music3], 0, true);
881                 OPENAL_SetPaused(channels[stream_music3], false);
882                 OPENAL_SetVolume(channels[stream_music3], 256);
883         }
884
885         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
886
887         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
888         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
889         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
890
891         temptexdetail=texdetail;
892         if(texdetail>2)texdetail=2;
893         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
894         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
895         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
896         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
897         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
898         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
899         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
900         texdetail=temptexdetail;
901
902         loaddistrib=0;
903         anim=0;
904
905         FadeLoadingScreen(95);
906
907
908         gameon=0;
909         mainmenu=1;
910
911         stillloading=0;
912         firstload=0;
913         oldmainmenu=0;
914
915         newdetail=detail;
916         newscreenwidth=screenwidth;
917         newscreenheight=screenheight;
918 }
919
920
921 void Game::LoadStuff()
922 {
923         static float temptexdetail;
924         static float viewdistdetail;
925         static int i,j,texsize;
926         float megascale =1;
927
928         LOGFUNC;
929
930         visibleloading=1;
931
932         /*musicvolume[3]=512;
933         PlaySoundEx( music4, samp[music4], NULL, true);
934         OPENAL_SetPaused(channels[music4], false);
935         OPENAL_SetVolume(channels[music4], 512);
936         */
937         loadtime=0;
938
939         stillloading=1;
940
941         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
942
943         for(i=0;i<maxplayers;i++)
944         {
945                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
946                 {
947                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
948                 }
949                 player[i].skeleton.drawmodel.textureptr=0;;
950         }
951
952         //temptexdetail=texdetail;
953         //texdetail=1;
954         i=abs(Random()%4);
955         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
956         //texdetail=temptexdetail;
957
958         temptexdetail=texdetail;
959         texdetail=1;
960         text.LoadFontTexture(":Data:Textures:Font.png");
961         text.BuildFont();
962         texdetail=temptexdetail;
963
964         numsounds=71;
965
966         viewdistdetail=2;
967         viewdistance=50*megascale*viewdistdetail;
968
969         brightness=100;
970
971
972
973         if(detail==2){
974                 texdetail=1;
975                 terraindetail=1;
976         }
977         if(detail==1){
978                 texdetail=2;
979                 terraindetail=1;
980         }
981         if(detail==0){
982                 texdetail=4;
983                 terraindetail=1;
984                 //terraindetail=2;
985         }
986
987         realtexdetail=texdetail;
988
989         /*texdetail/=4;
990         if(texdetail<1)texdetail=1;
991         realtexdetail=texdetail*4;
992         */
993         numplayers=1;
994
995
996
997         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
998
999         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1000
1001         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1002         */
1003
1004
1005         LOG("Loading weapon data...");
1006
1007         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1008         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1009         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1010         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1011         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1012         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1013         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1014
1015         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1016         weapons.throwingknifemodel.Scale(.001,.001,.001);
1017         //weapons.throwingknifemodel.Rotate(0,0,-90);
1018         weapons.throwingknifemodel.Rotate(90,0,0);
1019         weapons.throwingknifemodel.Rotate(0,90,0);
1020         weapons.throwingknifemodel.flat=0;
1021         weapons.throwingknifemodel.CalculateNormals(1);
1022         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1023
1024         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1025         weapons.swordmodel.Scale(.001,.001,.001);
1026         //weapons.swordmodel.Rotate(0,0,-90);
1027         weapons.swordmodel.Rotate(90,0,0);
1028         weapons.swordmodel.Rotate(0,90,0);
1029         weapons.swordmodel.Rotate(0,0,90);
1030         weapons.swordmodel.flat=1;
1031         weapons.swordmodel.CalculateNormals(1);
1032         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1033
1034         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1035         weapons.staffmodel.Scale(.005,.005,.005);
1036         //weapons.staffmodel.Rotate(0,0,-90);
1037         weapons.staffmodel.Rotate(90,0,0);
1038         weapons.staffmodel.Rotate(0,90,0);
1039         weapons.staffmodel.Rotate(0,0,90);
1040         weapons.staffmodel.flat=1;
1041         weapons.staffmodel.CalculateNormals(1);
1042         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1043
1044         //temptexdetail=texdetail;
1045         //if(texdetail>4)texdetail=4;
1046         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1047
1048         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1049
1050         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1051
1052         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1053
1054
1055         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1056
1057         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1058
1059         /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1060
1061         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1062
1063         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1064
1065         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1066
1067         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1068
1069         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1070         //texdetail=temptexdetail;
1071         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1072
1073
1074
1075         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1076
1077         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1078
1079
1080         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1081
1082
1083         LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1084         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1085         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1086         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1087         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1088         LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1089         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1090         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1091         LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1092         LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1093         LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1094
1095         rotation=0;
1096         rotation2=0;
1097         ReSizeGLScene(90,.01);
1098
1099         viewer=0;
1100
1101
1102
1103
1104         if(detail)kTextureSize=1024;
1105         if(detail==1)kTextureSize=512;
1106         if(detail==0)kTextureSize=256;
1107
1108
1109         //drawmode=motionblurmode;
1110
1111         //Set up distant light
1112         light.color[0]=.95;
1113         light.color[1]=.95;
1114         light.color[2]=1;
1115         light.ambient[0]=.2;
1116         light.ambient[1]=.2;
1117         light.ambient[2]=.24;
1118         light.location.x=1;
1119         light.location.y=1;
1120         light.location.z=-.2;
1121         Normalise(&light.location);
1122
1123         LoadingScreen();
1124
1125         SetUpLighting();
1126
1127
1128         fadestart=.6;
1129         gravity=-10;
1130
1131         texscale=.2/megascale/viewdistdetail;
1132         terrain.scale=3*megascale*terraindetail*viewdistdetail;
1133
1134         viewer.x=terrain.size/2*terrain.scale;
1135         viewer.z=terrain.size/2*terrain.scale;
1136
1137         hawk.load((char *)":Data:Models:hawk.solid",1);
1138         hawk.Scale(.03,.03,.03);
1139         hawk.Rotate(90,1,1);
1140         hawk.CalculateNormals(0);
1141         hawk.ScaleNormals(-1,-1,-1);
1142         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1143         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1144         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1145
1146
1147         eye.load((char *)":Data:Models:eye.solid",1);
1148         eye.Scale(.03,.03,.03);
1149         eye.CalculateNormals(0);
1150
1151         cornea.load((char *)":Data:Models:cornea.solid",1);
1152         cornea.Scale(.03,.03,.03);
1153         cornea.CalculateNormals(0);
1154
1155         iris.load((char *)":Data:Models:iris.solid",1);
1156         iris.Scale(.03,.03,.03);
1157         iris.CalculateNormals(0);
1158
1159         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1160         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1161
1162         oldenvironment=-4;
1163
1164         gameon=1;
1165         mainmenu=0;
1166
1167         firstload=0;
1168         //if(targetlevel!=7)
1169                 Loadlevel(targetlevel);
1170
1171
1172         rabbitcoords=player[0].coords;
1173         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1174
1175         loadAllAnimations();
1176         //Fix knife stab, too lazy to do it manually
1177         XYZ moveamount;
1178         moveamount=0;
1179         moveamount.z=2;
1180         for(i=0;i<player[0].skeleton.num_joints;i++){
1181                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1182                         animation[knifesneakattackanim].position[i][j]+=moveamount;
1183                 }
1184         }
1185
1186         loadscreencolor=4;
1187         LoadingScreen();
1188
1189         for(i=0;i<player[0].skeleton.num_joints;i++){
1190                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1191                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1192                 }
1193         }
1194
1195         loadscreencolor=4;
1196         LoadingScreen();
1197
1198         for(i=0;i<player[0].skeleton.num_joints;i++){
1199                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1200                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1201                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1202                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1203         }
1204         animation[dead1anim].speed[0]=0.001;
1205         animation[dead2anim].speed[0]=0.001;
1206         animation[dead3anim].speed[0]=0.001;
1207         animation[dead4anim].speed[0]=0.001;
1208
1209         animation[dead1anim].speed[1]=0.001;
1210         animation[dead2anim].speed[1]=0.001;
1211         animation[dead3anim].speed[1]=0.001;
1212         animation[dead4anim].speed[1]=0.001;
1213
1214         for(i=0;i<player[0].skeleton.num_joints;i++){
1215                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1216                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1217                 }
1218         }
1219         loadscreencolor=4;
1220         LoadingScreen();
1221         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1222                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1223         }
1224
1225         loadscreencolor=4;
1226         LoadingScreen();
1227
1228         for(i=0;i<player[0].skeleton.num_joints;i++){
1229                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1230                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1231                 }
1232         }
1233         /*
1234         for(i=0;i<player[0].skeleton.num_joints;i++){
1235         for(j=0;j<animation[sleepanim].numframes;j++){
1236         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1237         }
1238         }
1239         */
1240         loadscreencolor=4;
1241         LoadingScreen();
1242         temptexdetail=texdetail;
1243         texdetail=1;
1244         texdetail=temptexdetail;
1245
1246         loadscreencolor=4;
1247         LoadingScreen();
1248
1249         //if(ismotionblur){
1250         if(!screentexture){
1251                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1252
1253                 glGenTextures( 1, &screentexture );
1254                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1255
1256
1257                 glEnable(GL_TEXTURE_2D);
1258                 glBindTexture( GL_TEXTURE_2D, screentexture);
1259                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1260                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1261
1262                 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1263         }
1264
1265         if(targetlevel!=7){
1266                 float gLoc[3]={0,0,0};
1267                 float vel[3]={0,0,0};
1268                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1269                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1270                 OPENAL_SetVolume(channels[fireendsound], 256);
1271                 OPENAL_SetPaused(channels[fireendsound], false);
1272         }
1273
1274         stillloading=0;
1275         loading=0;
1276         changedelay=1;
1277
1278         visibleloading=0;
1279 }
1280