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