]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
merge
[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 volume;
43 extern Objects objects;
44 extern int detail;
45 extern bool cellophane;
46 extern GLubyte bloodText[512*512*3];
47 extern GLubyte wolfbloodText[512*512*3];
48 extern bool ismotionblur;
49 extern bool trilinear;
50 extern bool osx;
51 extern bool musictoggle;
52 extern int environment;
53 extern bool ambientsound;
54 extern float multiplier;
55 extern int netdatanew;
56 extern float mapinfo;
57 extern bool stillloading;
58 extern TGAImageRec texture;
59 extern short vRefNum;
60 extern long dirID;
61 extern int mainmenu;
62 extern int oldmainmenu;
63 extern bool visibleloading;
64 extern float flashamount,flashr,flashg,flashb;
65 extern int flashdelay;
66 extern int whichjointstartarray[26];
67 extern int whichjointendarray[26];
68 extern int difficulty;
69 extern float tintr,tintg,tintb;
70 extern float slomospeed;
71 extern bool gamestarted;
72
73 extern int numdialogues;
74 extern int numdialogueboxes[20];
75 extern int dialoguetype[20];
76 extern int dialogueboxlocation[20][20];
77 extern float dialogueboxcolor[20][20][3];
78 extern int dialogueboxsound[20][20];
79 extern char dialoguetext[20][20][128];
80 extern char dialoguename[20][20][64];
81 extern XYZ dialoguecamera[20][20];
82 extern float dialoguecamerarotation[20][20];
83 extern float dialoguecamerarotation2[20][20];
84 extern int indialogue;
85 extern int whichdialogue;
86 extern float dialoguetime;
87
88 extern float accountcampaignhighscore[10];
89 extern float accountcampaignfasttime[10];
90 extern float accountcampaignscore[10];
91 extern float accountcampaigntime[10];
92
93 extern int accountcampaignchoicesmade[10];
94 extern int accountcampaignchoices[10][5000];
95
96 void LOG(const std::string &fmt, ...)
97 {
98     // !!! FIXME: write me.
99 }
100
101
102 void Game::Dispose()
103 {
104         int i,j;
105
106         LOGFUNC;
107
108         if(endgame==2){
109                 accountactive->endGame();
110                 endgame=0;
111         }
112
113         Account::saveFile(":Data:Users", accountactive);
114
115         //textures.clear();
116
117         LOG("Shutting down sound system...");
118
119         OPENAL_StopSound(OPENAL_ALL);
120
121 // this is causing problems on Linux, but we'll force an _exit() a little
122 //  later in the shutdown process.  --ryan.
123 #if !PLATFORM_LINUX
124
125         for (i=0; i < sounds_count; ++i)
126         {
127                 OPENAL_Sample_Free(samp[i]);
128         }
129
130         OPENAL_Close();
131         if (texture.data)
132         {
133                 free(texture.data);
134         }
135         texture.data = 0;
136 #endif
137 }
138
139
140 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha){
141     textures.push_back(TextureInfo(fileName,textureid,mipmap,hasalpha));
142     textures.back().load();
143 }
144
145 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize){
146     textures.push_back(TextureInfo(fileName,textureid,mipmap,array,skinsize));
147     textures.back().load();
148 }
149
150 void Game::LoadTextureData(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::LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload)
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         if(!reload)
242             for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++)
243                 if((i+1)%4||type==GL_RGB){
244                     array[tempnum]=texture.data[i];
245                     tempnum++;
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, GLubyte *array)
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                 glPushMatrix();
423                 //glScalef(.25,.25,.25);
424                 glBegin(GL_QUADS);
425                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
426                 glVertex3f(-1,          -1,      0.0f);
427                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
428                 glVertex3f(1,   -1,      0.0f);
429                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
430                 glVertex3f(1,   1, 0.0f);
431                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
432                 glVertex3f(-1,  1, 0.0f);
433                 glEnd();
434                 glPopMatrix();
435                 glEnable(GL_BLEND);
436                 glPushMatrix();
437                 //glScalef(.25,.25,.25);
438                 glBegin(GL_QUADS);
439                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
440                 glVertex3f(-1,          -1,      0.0f);
441                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
442                 glVertex3f(1,   -1,      0.0f);
443                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
444                 glVertex3f(1,   1, 0.0f);
445                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
446                 glVertex3f(-1,  1, 0.0f);
447                 glEnd();
448                 glPopMatrix();
449                 glDisable(GL_TEXTURE_2D);
450                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
451                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
452                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
453                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
454                 glDisable(GL_BLEND);
455                 glDepthMask(1);
456
457                 glEnable(GL_TEXTURE_2D);
458                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
459                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
460                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
461                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
462                 glDisable(GL_CULL_FACE);
463                 glDisable(GL_LIGHTING);
464                 glDepthMask(0);
465                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
466                 glPushMatrix();                                                                         // Store The Projection Matrix
467                 glLoadIdentity();                                                                       // Reset The Projection Matrix
468                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
469                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
470                 glPushMatrix();                                                                         // Store The Modelview Matrix
471                 glLoadIdentity();                                                               // Reset The Modelview Matrix
472                 glTranslatef(screenwidth/2,screenheight/2,0);
473                 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
474                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
475                 glEnable(GL_BLEND);
476                 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
477                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
478                 glPushMatrix();
479                 //glScalef(.25,.25,.25);
480                 glBegin(GL_QUADS);
481                 glTexCoord2f(0+.5,0+.5);
482                 glVertex3f(-1,          -1,      0.0f);
483                 glTexCoord2f(1+.5,0+.5);
484                 glVertex3f(1,   -1,      0.0f);
485                 glTexCoord2f(1+.5,1+.5);
486                 glVertex3f(1,   1, 0.0f);
487                 glTexCoord2f(0+.5,1+.5);
488                 glVertex3f(-1,  1, 0.0f);
489                 glEnd();
490                 glPopMatrix();
491                 glDisable(GL_TEXTURE_2D);
492                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
493                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
494                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
495                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
496                 glDisable(GL_BLEND);
497                 glDepthMask(1);
498
499                 glEnable(GL_TEXTURE_2D);
500                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
501                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
502                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
503                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
504                 glDisable(GL_CULL_FACE);
505                 glDisable(GL_LIGHTING);
506                 glDepthMask(0);
507                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
508                 glPushMatrix();                                                                         // Store The Projection Matrix
509                 glLoadIdentity();                                                                       // Reset The Projection Matrix
510                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
511                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
512                 glPushMatrix();                                                                         // Store The Modelview Matrix
513                 glLoadIdentity();                                                               // Reset The Modelview Matrix
514                 glTranslatef(screenwidth/2,screenheight/2,0);
515                 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
516                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
517                 glEnable(GL_BLEND);
518                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
519                 glPushMatrix();
520                 //glScalef(.25,.25,.25);
521                 glBegin(GL_QUADS);
522                 glTexCoord2f(0+.2,0+.8);
523                 glVertex3f(-1,          -1,      0.0f);
524                 glTexCoord2f(1+.2,0+.8);
525                 glVertex3f(1,   -1,      0.0f);
526                 glTexCoord2f(1+.2,1+.8);
527                 glVertex3f(1,   1, 0.0f);
528                 glTexCoord2f(0+.2,1+.8);
529                 glVertex3f(-1,  1, 0.0f);
530                 glEnd();
531                 glPopMatrix();
532                 glDisable(GL_TEXTURE_2D);
533                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
534                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
535                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
536                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
537                 glDisable(GL_BLEND);
538                 glDepthMask(1);
539
540                 //Text
541                 /*
542                 glEnable(GL_TEXTURE_2D);
543                 static char string[256]="";
544                 sprintf (string, "LOADING... %d%",(int)loadprogress);
545                 glColor4f(1,1,1,.2);
546                 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
547                 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
548                 text.glPrint(280,125,string,1,1,640,480);
549                 */
550
551                 if(flashamount>0){
552                         if(flashamount>1)flashamount=1;
553                         if(flashdelay<=0)flashamount-=multiplier;
554                         flashdelay--;
555                         if(flashamount<0)flashamount=0;
556                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
557                         glDisable(GL_CULL_FACE);
558                         glDisable(GL_LIGHTING);
559                         glDisable(GL_TEXTURE_2D);
560                         glDepthMask(0);
561                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
562                         glPushMatrix();                                                                         // Store The Projection Matrix
563                         glLoadIdentity();                                                                       // Reset The Projection Matrix
564                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
565                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
566                         glPushMatrix();                                                                         // Store The Modelview Matrix
567                         glLoadIdentity();                                                               // Reset The Modelview Matrix
568                         glScalef(screenwidth,screenheight,1);
569                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
570                         glEnable(GL_BLEND);
571                         glColor4f(flashr,flashg,flashb,flashamount);
572                         glBegin(GL_QUADS);
573                         glVertex3f(0,           0,       0.0f);
574                         glVertex3f(256, 0,       0.0f);
575                         glVertex3f(256, 256, 0.0f);
576                         glVertex3f(0,   256, 0.0f);
577                         glEnd();
578                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
579                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
580                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
581                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
582                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
583                         glEnable(GL_CULL_FACE);
584                         glDisable(GL_BLEND);
585                         glDepthMask(1);
586                 }
587
588                 swap_gl_buffers();
589         }
590 }
591
592 void Game::FadeLoadingScreen(float howmuch)
593 {
594         static float loadprogress,minprogress,maxprogress;
595
596         float size=1;
597         glLoadIdentity();
598         //Clear to black
599         glClearColor(0,0,0,1);
600         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
601
602         loadprogress=howmuch;
603
604         //loadprogress=abs(Random()%100);
605
606         //Background
607
608         //glEnable(GL_TEXTURE_2D);
609         glDisable(GL_TEXTURE_2D);
610         //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
611         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
612         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
613         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
614         glDisable(GL_CULL_FACE);
615         glDisable(GL_LIGHTING);
616         glDepthMask(0);
617         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
618         glPushMatrix();                                                                         // Store The Projection Matrix
619         glLoadIdentity();                                                                       // Reset The Projection Matrix
620         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
621         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
622         glPushMatrix();                                                                         // Store The Modelview Matrix
623         glLoadIdentity();                                                               // Reset The Modelview Matrix
624         glTranslatef(screenwidth/2,screenheight/2,0);
625         glScalef((float)screenwidth/2,(float)screenheight/2,1);
626         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
627         glDisable(GL_BLEND);
628         glColor4f(loadprogress/100,0,0,1);
629         glPushMatrix();
630         //glScalef(.25,.25,.25);
631         glBegin(GL_QUADS);
632         glTexCoord2f(0,0);
633         glVertex3f(-1,          -1,      0.0f);
634         glTexCoord2f(1,0);
635         glVertex3f(1,   -1,      0.0f);
636         glTexCoord2f(1,1);
637         glVertex3f(1,   1, 0.0f);
638         glTexCoord2f(0,1);
639         glVertex3f(-1,  1, 0.0f);
640         glEnd();
641         glPopMatrix();
642         glDisable(GL_TEXTURE_2D);
643         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
644         glPopMatrix();                                                                          // Restore The Old Projection Matrix
645         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
646         glPopMatrix();                                                                          // Restore The Old Projection Matrix
647         glDisable(GL_BLEND);
648         glDepthMask(1);
649         //Text
650         /*
651         glEnable(GL_TEXTURE_2D);
652         static char string[256]="";
653         sprintf (string, "LOADING... %d%",(int)loadprogress);
654         glColor4f(1,1,1,.2);
655         text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
656         glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
657         text.glPrint(280,125,string,1,1,640,480);
658         */
659         swap_gl_buffers();
660 }
661
662
663 void Game::InitGame()
664 {
665 #if PLATFORM_MACOSX
666         ProcessSerialNumber PSN;
667         ProcessInfoRec pinfo;
668         FSSpec pspec;
669         OSStatus err;
670         /* set up process serial number */
671         PSN.highLongOfPSN = 0;
672         PSN.lowLongOfPSN = kCurrentProcess;
673         /* set up info block */
674         pinfo.processInfoLength = sizeof(pinfo);
675         pinfo.processName = NULL;
676         pinfo.processAppSpec = &pspec;
677         /* grab the vrefnum and directory */
678         err = GetProcessInformation(&PSN, &pinfo);
679         if (err == noErr) {
680                 vRefNum = pspec.vRefNum;
681                 dirID = pspec.parID;
682         }
683 #endif
684
685         LOGFUNC;
686
687         autocam=0;
688
689         int i,j;
690
691         numchallengelevels=14;
692
693         accountactive=Account::loadFile(":Data:Users");
694
695         tintr=1;
696         tintg=1;
697         tintb=1;
698
699         whichjointstartarray[0]=righthip;
700         whichjointendarray[0]=rightfoot;
701
702         whichjointstartarray[1]=righthip;
703         whichjointendarray[1]=rightankle;
704
705         whichjointstartarray[2]=righthip;
706         whichjointendarray[2]=rightknee;
707
708         whichjointstartarray[3]=rightknee;
709         whichjointendarray[3]=rightankle;
710
711         whichjointstartarray[4]=rightankle;
712         whichjointendarray[4]=rightfoot;
713
714         whichjointstartarray[5]=lefthip;
715         whichjointendarray[5]=leftfoot;
716
717         whichjointstartarray[6]=lefthip;
718         whichjointendarray[6]=leftankle;
719
720         whichjointstartarray[7]=lefthip;
721         whichjointendarray[7]=leftknee;
722
723         whichjointstartarray[8]=leftknee;
724         whichjointendarray[8]=leftankle;
725
726         whichjointstartarray[9]=leftankle;
727         whichjointendarray[9]=leftfoot;
728
729         whichjointstartarray[10]=abdomen;
730         whichjointendarray[10]=rightshoulder;
731
732         whichjointstartarray[11]=abdomen;
733         whichjointendarray[11]=rightelbow;
734
735         whichjointstartarray[12]=abdomen;
736         whichjointendarray[12]=rightwrist;
737
738         whichjointstartarray[13]=abdomen;
739         whichjointendarray[13]=righthand;
740
741         whichjointstartarray[14]=rightshoulder;
742         whichjointendarray[14]=rightelbow;
743
744         whichjointstartarray[15]=rightelbow;
745         whichjointendarray[15]=rightwrist;
746
747         whichjointstartarray[16]=rightwrist;
748         whichjointendarray[16]=righthand;
749
750         whichjointstartarray[17]=abdomen;
751         whichjointendarray[17]=leftshoulder;
752
753         whichjointstartarray[18]=abdomen;
754         whichjointendarray[18]=leftelbow;
755
756         whichjointstartarray[19]=abdomen;
757         whichjointendarray[19]=leftwrist;
758
759         whichjointstartarray[20]=abdomen;
760         whichjointendarray[20]=lefthand;
761
762         whichjointstartarray[21]=leftshoulder;
763         whichjointendarray[21]=leftelbow;
764
765         whichjointstartarray[22]=leftelbow;
766         whichjointendarray[22]=leftwrist;
767
768         whichjointstartarray[23]=leftwrist;
769         whichjointendarray[23]=lefthand;
770
771         whichjointstartarray[24]=abdomen;
772         whichjointendarray[24]=neck;
773
774         whichjointstartarray[25]=neck;
775         whichjointendarray[25]=head;
776
777         FadeLoadingScreen(0);
778
779         stillloading=1;
780
781         texture.data = ( GLubyte* )malloc( 1024*1024*4 );
782
783         int temptexdetail=texdetail;
784         texdetail=1;
785         text.LoadFontTexture(":Data:Textures:Font.png");
786         text.BuildFont();
787         texdetail=temptexdetail;
788
789         FadeLoadingScreen(10);
790
791         if(detail==2){
792                 texdetail=1;
793         }
794         if(detail==1){
795                 texdetail=2;
796         }
797         if(detail==0){
798                 texdetail=4;
799         }
800
801         LOG("Initializing sound system...");
802
803     int output = -1;
804
805     #if PLATFORM_LINUX
806     extern bool cmdline(const char *cmd);
807     unsigned char rc = 0;
808     output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
809     if (cmdline("forceoss"))      //  ...but let user override that.
810         output = OPENAL_OUTPUT_OSS;
811     else if (cmdline("nosound"))
812         output = OPENAL_OUTPUT_NOSOUND;
813
814     OPENAL_SetOutput(output);
815         if ((rc = OPENAL_Init(44100, 32, 0)) == false)
816     {
817         // if we tried ALSA and failed, fall back to OSS.
818         if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
819         {
820             OPENAL_Close();
821             output = OPENAL_OUTPUT_OSS;
822             OPENAL_SetOutput(output);
823                 rc = OPENAL_Init(44100, 32, 0);
824         }
825     }
826
827     if (rc == false)
828     {
829         OPENAL_Close();
830         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
831         OPENAL_SetOutput(output);
832             rc = OPENAL_Init(44100, 32, 0);
833     }
834     #else
835         OPENAL_Init(44100, 32, 0);
836     #endif
837
838         OPENAL_SetSFXMasterVolume((int)(volume*255));
839         loadAllSounds();
840
841         if(musictoggle)
842           emit_stream_np(stream_music3);
843
844         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
845
846         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
847         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
848         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
849
850         temptexdetail=texdetail;
851         if(texdetail>2)texdetail=2;
852         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
853         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
854         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
855         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
856         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
857         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
858         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
859         texdetail=temptexdetail;
860
861         loaddistrib=0;
862         anim=0;
863
864         FadeLoadingScreen(95);
865
866
867         gameon=0;
868         mainmenu=1;
869
870         stillloading=0;
871         firstload=0;
872         oldmainmenu=0;
873
874         newdetail=detail;
875         newscreenwidth=screenwidth;
876         newscreenheight=screenheight;
877 }
878
879
880 void Game::LoadScreenTexture(){
881     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
882
883     if(!screentexture)
884         glGenTextures( 1, &screentexture );
885     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
886
887
888     glEnable(GL_TEXTURE_2D);
889     glBindTexture( GL_TEXTURE_2D, screentexture);
890     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
891     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
892
893     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
894 }
895
896 void Game::LoadStuff()
897 {
898         static float temptexdetail;
899         static float viewdistdetail;
900         static int i,j,texsize;
901         float megascale =1;
902
903         LOGFUNC;
904
905         visibleloading=1;
906
907         loadtime=0;
908
909         stillloading=1;
910
911         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
912
913         for(i=0;i<maxplayers;i++)
914         {
915                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
916                 {
917                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
918                 }
919                 player[i].skeleton.drawmodel.textureptr=0;;
920         }
921
922         //temptexdetail=texdetail;
923         //texdetail=1;
924         i=abs(Random()%4);
925         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
926         //texdetail=temptexdetail;
927
928         temptexdetail=texdetail;
929         texdetail=1;
930         text.LoadFontTexture(":Data:Textures:Font.png");
931         text.BuildFont();
932         texdetail=temptexdetail;
933
934         numsounds=71;
935
936         viewdistdetail=2;
937         viewdistance=50*megascale*viewdistdetail;
938
939         brightness=100;
940
941
942
943         if(detail==2){
944                 texdetail=1;
945         }
946         if(detail==1){
947                 texdetail=2;
948         }
949         if(detail==0){
950                 texdetail=4;
951         }
952
953         realtexdetail=texdetail;
954
955         /*texdetail/=4;
956         if(texdetail<1)texdetail=1;
957         realtexdetail=texdetail*4;
958         */
959         numplayers=1;
960
961
962
963         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
964
965         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
966
967         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
968         */
969
970
971         LOG("Loading weapon data...");
972
973         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
974         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
975         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
976         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
977         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
978         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
979         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
980
981         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
982         weapons.throwingknifemodel.Scale(.001,.001,.001);
983         //weapons.throwingknifemodel.Rotate(0,0,-90);
984         weapons.throwingknifemodel.Rotate(90,0,0);
985         weapons.throwingknifemodel.Rotate(0,90,0);
986         weapons.throwingknifemodel.flat=0;
987         weapons.throwingknifemodel.CalculateNormals(1);
988         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
989
990         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
991         weapons.swordmodel.Scale(.001,.001,.001);
992         //weapons.swordmodel.Rotate(0,0,-90);
993         weapons.swordmodel.Rotate(90,0,0);
994         weapons.swordmodel.Rotate(0,90,0);
995         weapons.swordmodel.Rotate(0,0,90);
996         weapons.swordmodel.flat=1;
997         weapons.swordmodel.CalculateNormals(1);
998         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
999
1000         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1001         weapons.staffmodel.Scale(.005,.005,.005);
1002         //weapons.staffmodel.Rotate(0,0,-90);
1003         weapons.staffmodel.Rotate(90,0,0);
1004         weapons.staffmodel.Rotate(0,90,0);
1005         weapons.staffmodel.Rotate(0,0,90);
1006         weapons.staffmodel.flat=1;
1007         weapons.staffmodel.CalculateNormals(1);
1008         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1009
1010         //temptexdetail=texdetail;
1011         //if(texdetail>4)texdetail=4;
1012         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1013
1014         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1015
1016         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1017
1018         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1019
1020
1021         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1022
1023         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1024
1025         /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1026
1027         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1028
1029         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1030
1031         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1032
1033         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1034
1035         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1036         //texdetail=temptexdetail;
1037         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1038
1039
1040
1041         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1042
1043         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1044
1045
1046         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1047
1048
1049         LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1050         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1051         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1052         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1053         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1054         LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1055         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1056         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1057         LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1058         LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1059         LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1060
1061         rotation=0;
1062         rotation2=0;
1063         ReSizeGLScene(90,.01);
1064
1065         viewer=0;
1066
1067
1068
1069
1070         if(detail)kTextureSize=1024;
1071         if(detail==1)kTextureSize=512;
1072         if(detail==0)kTextureSize=256;
1073
1074
1075         //drawmode=motionblurmode;
1076
1077         //Set up distant light
1078         light.color[0]=.95;
1079         light.color[1]=.95;
1080         light.color[2]=1;
1081         light.ambient[0]=.2;
1082         light.ambient[1]=.2;
1083         light.ambient[2]=.24;
1084         light.location.x=1;
1085         light.location.y=1;
1086         light.location.z=-.2;
1087         Normalise(&light.location);
1088
1089         LoadingScreen();
1090
1091         SetUpLighting();
1092
1093
1094         fadestart=.6;
1095         gravity=-10;
1096
1097         texscale=.2/megascale/viewdistdetail;
1098         terrain.scale=3*megascale*viewdistdetail;
1099
1100         viewer.x=terrain.size/2*terrain.scale;
1101         viewer.z=terrain.size/2*terrain.scale;
1102
1103         hawk.load((char *)":Data:Models:hawk.solid",1);
1104         hawk.Scale(.03,.03,.03);
1105         hawk.Rotate(90,1,1);
1106         hawk.CalculateNormals(0);
1107         hawk.ScaleNormals(-1,-1,-1);
1108         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1109         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1110         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1111
1112
1113         eye.load((char *)":Data:Models:eye.solid",1);
1114         eye.Scale(.03,.03,.03);
1115         eye.CalculateNormals(0);
1116
1117         cornea.load((char *)":Data:Models:cornea.solid",1);
1118         cornea.Scale(.03,.03,.03);
1119         cornea.CalculateNormals(0);
1120
1121         iris.load((char *)":Data:Models:iris.solid",1);
1122         iris.Scale(.03,.03,.03);
1123         iris.CalculateNormals(0);
1124
1125         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1126         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1127
1128         oldenvironment=-4;
1129
1130         gameon=1;
1131         mainmenu=0;
1132
1133         firstload=0;
1134         //if(targetlevel!=7)
1135                 Loadlevel(targetlevel);
1136
1137
1138         rabbitcoords=player[0].coords;
1139         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1140
1141         loadAllAnimations();
1142         //Fix knife stab, too lazy to do it manually
1143         XYZ moveamount;
1144         moveamount=0;
1145         moveamount.z=2;
1146         for(i=0;i<player[0].skeleton.num_joints;i++){
1147                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1148                         animation[knifesneakattackanim].position[i][j]+=moveamount;
1149                 }
1150         }
1151
1152         LoadingScreen();
1153
1154         for(i=0;i<player[0].skeleton.num_joints;i++){
1155                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1156                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1157                 }
1158         }
1159
1160         LoadingScreen();
1161
1162         for(i=0;i<player[0].skeleton.num_joints;i++){
1163                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1164                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1165                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1166                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1167         }
1168         animation[dead1anim].speed[0]=0.001;
1169         animation[dead2anim].speed[0]=0.001;
1170         animation[dead3anim].speed[0]=0.001;
1171         animation[dead4anim].speed[0]=0.001;
1172
1173         animation[dead1anim].speed[1]=0.001;
1174         animation[dead2anim].speed[1]=0.001;
1175         animation[dead3anim].speed[1]=0.001;
1176         animation[dead4anim].speed[1]=0.001;
1177
1178         for(i=0;i<player[0].skeleton.num_joints;i++){
1179                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1180                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1181                 }
1182         }
1183         LoadingScreen();
1184         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1185                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1186         }
1187
1188         LoadingScreen();
1189
1190         for(i=0;i<player[0].skeleton.num_joints;i++){
1191                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1192                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1193                 }
1194         }
1195         /*
1196         for(i=0;i<player[0].skeleton.num_joints;i++){
1197         for(j=0;j<animation[sleepanim].numframes;j++){
1198         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1199         }
1200         }
1201         */
1202         LoadingScreen();
1203         temptexdetail=texdetail;
1204         texdetail=1;
1205         texdetail=temptexdetail;
1206
1207         LoadingScreen();
1208
1209         //if(ismotionblur){
1210         if(!screentexture){
1211         LoadScreenTexture();
1212         }
1213
1214         if(targetlevel!=7){
1215                 emit_sound_at(fireendsound);
1216         }
1217
1218         stillloading=0;
1219         loading=0;
1220         changedelay=1;
1221
1222         visibleloading=0;
1223 }
1224