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