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