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