2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
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.
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.
15 See the GNU General Public License for more details.
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.
23 #include "openal_wrapper.h"
24 #include "Animation.h"
26 extern float screenwidth,screenheight;
27 extern float viewdistance;
29 extern XYZ lightlocation;
30 extern float lightambient[3],lightbrightness[3];
31 extern float fadestart;
32 extern float texscale;
35 extern Skeleton testskeleton;
37 extern Terrain terrain;
38 //extern Sprites sprites;
39 extern int kTextureSize;
40 extern float texdetail;
41 extern float realtexdetail;
42 extern float terraindetail;
44 extern Objects objects;
46 extern bool cellophane;
47 extern GLubyte bloodText[512*512*3];
48 extern GLubyte wolfbloodText[512*512*3];
49 extern bool ismotionblur;
50 extern bool trilinear;
52 extern bool musictoggle;
53 extern int environment;
54 extern bool ambientsound;
55 extern float multiplier;
56 extern int netdatanew;
58 extern bool stillloading;
59 extern TGAImageRec texture;
63 extern int oldmainmenu;
64 extern bool visibleloading;
65 extern int loadscreencolor;
66 extern float flashamount,flashr,flashg,flashb;
67 extern int flashdelay;
68 extern int whichjointstartarray[26];
69 extern int whichjointendarray[26];
70 extern int difficulty;
71 extern float tintr,tintg,tintb;
72 extern float slomospeed;
73 extern bool gamestarted;
75 extern int numdialogues;
76 extern int numdialogueboxes[20];
77 extern int dialoguetype[20];
78 extern int dialogueboxlocation[20][20];
79 extern float dialogueboxcolor[20][20][3];
80 extern int dialogueboxsound[20][20];
81 extern char dialoguetext[20][20][128];
82 extern char dialoguename[20][20][64];
83 extern XYZ dialoguecamera[20][20];
84 extern float dialoguecamerarotation[20][20];
85 extern float dialoguecamerarotation2[20][20];
86 extern int indialogue;
87 extern int whichdialogue;
88 extern float dialoguetime;
90 extern float accountcampaignhighscore[10];
91 extern float accountcampaignfasttime[10];
92 extern float accountcampaignscore[10];
93 extern float accountcampaigntime[10];
95 extern int accountcampaignchoicesmade[10];
96 extern int accountcampaignchoices[10][5000];
98 void LOG(const std::string &fmt, ...)
100 // !!! FIXME: write me.
104 Game::TextureList Game::textures;
113 accountactive->endGame();
117 Account::saveFile(":Data:Users", accountactive);
119 TexIter it = textures.begin();
120 for (; it != textures.end(); ++it)
122 if (glIsTexture(it->second))
123 glDeleteTextures(1, &it->second);
127 LOG("Shutting down sound system...");
129 OPENAL_StopSound(OPENAL_ALL);
131 // this is causing problems on Linux, but we'll force an _exit() a little
132 // later in the shutdown process. --ryan.
135 for (i=0; i < sounds_count; ++i)
137 OPENAL_Sample_Free(samp[i]);
150 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
156 LOG(std::string("Loading texture...") + fileName);
158 // Fix filename so that is os appropreate
159 char * fixedFN = ConvertFileName(fileName);
161 unsigned char fileNamep[256];
162 CopyCStringToPascal(fixedFN, fileNamep);
164 upload_image( fileNamep ,hasalpha);
166 // std::string fname(fileName);
167 // std::transform(fname.begin(), fname.end(), tolower);
168 // TexIter it = textures.find(fname);
172 //if(textures.end() == it)
175 if ( texture.bpp == 24 )
180 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
183 glGenTextures( 1, textureid );
184 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
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 );
192 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
196 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
204 LOG(std::string("Loading texture (S)...") + fileName);
207 unsigned char fileNamep[256];
208 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
210 upload_image( fileNamep ,0);
211 //LoadTGA( fileName );
213 // std::string fname(fileName);
214 // std::transform(fname.begin(), fname.end(), tolower);
215 // TexIter it = textures.find(fname);
219 //if(textures.end() == it)
221 bytesPerPixel=texture.bpp/8;
224 if ( texture.bpp == 24 )
229 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
231 if(!*textureid)glGenTextures( 1, textureid );
232 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
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 );
241 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
242 if((i+1)%4||type==GL_RGB){
243 array[tempnum]=texture.data[i];
248 *skinsize=texture.sizeX;
250 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
252 // textures.insert(std::make_pair(fname, *textureid));
256 // *textureid = it->second;
260 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
267 LOG(std::string("Loading (S)...") + fileName);
270 float temptexdetail=texdetail;
272 //upload_image( fileName );
273 //LoadTGA( fileName );
275 // Converting file to something os specific
276 char * fixedFN = ConvertFileName(fileName);
279 unsigned char fileNamep[256];
280 CopyCStringToPascal(fixedFN, fileNamep);
282 upload_image( fileNamep ,0);
283 texdetail=temptexdetail;
287 bytesPerPixel=texture.bpp/8;
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];
299 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
306 //upload_image( fileName );
307 //LoadTGA( fileName );
309 unsigned char fileNamep[256];
310 CopyCStringToPascal(fileName,fileNamep);
313 opened=upload_image( fileNamep ,1);
326 bytesPerPixel=texture.bpp/8;
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];
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);
348 //***************> ResizeGLScene() <******/
349 GLvoid Game::ReSizeGLScene(float fov, float pnear)
356 glViewport(0,0,screenwidth,screenheight);
358 glMatrixMode(GL_PROJECTION);
361 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
363 glMatrixMode(GL_MODELVIEW);
367 void Game::LoadingScreen()
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);
375 if (0 > deltaTime) // if negative microseconds
376 deltaTime /= -1000000.0;
377 else // else milliseconds
380 multiplier=deltaTime;
381 if(multiplier<.001)multiplier=.001;
382 if(multiplier>10)multiplier=10;
384 frametime = currTime; // reset for next time interval
389 glClearColor(0,0,0,1);
390 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
393 loadtime+=multiplier*4;
395 loadprogress=loadtime;
396 if(loadprogress>100)loadprogress=100;
398 //loadprogress=abs(Random()%100);
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);
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);
421 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
422 //glColor4f(1,1,1,1);
423 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
424 if(loadscreencolor==1)glColor4f(1,0,0,1);
425 if(loadscreencolor==2)glColor4f(0,1,0,1);
426 if(loadscreencolor==3)glColor4f(0,0,1,1);
427 if(loadscreencolor==4)glColor4f(1,1,0,1);
428 if(loadscreencolor==5)glColor4f(1,0,1,1);
431 //glScalef(.25,.25,.25);
433 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
434 glVertex3f(-1, -1, 0.0f);
435 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
436 glVertex3f(1, -1, 0.0f);
437 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
438 glVertex3f(1, 1, 0.0f);
439 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
440 glVertex3f(-1, 1, 0.0f);
445 //glScalef(.25,.25,.25);
447 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
448 glVertex3f(-1, -1, 0.0f);
449 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
450 glVertex3f(1, -1, 0.0f);
451 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
452 glVertex3f(1, 1, 0.0f);
453 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
454 glVertex3f(-1, 1, 0.0f);
457 glDisable(GL_TEXTURE_2D);
458 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
459 glPopMatrix(); // Restore The Old Projection Matrix
460 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
461 glPopMatrix(); // Restore The Old Projection Matrix
465 glEnable(GL_TEXTURE_2D);
466 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
467 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
468 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
469 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
470 glDisable(GL_CULL_FACE);
471 glDisable(GL_LIGHTING);
473 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
474 glPushMatrix(); // Store The Projection Matrix
475 glLoadIdentity(); // Reset The Projection Matrix
476 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
477 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
478 glPushMatrix(); // Store The Modelview Matrix
479 glLoadIdentity(); // Reset The Modelview Matrix
480 glTranslatef(screenwidth/2,screenheight/2,0);
481 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
482 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
484 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
485 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
486 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
487 if(loadscreencolor==1)glColor4f(1,0,0,1);
488 if(loadscreencolor==2)glColor4f(0,1,0,1);
489 if(loadscreencolor==3)glColor4f(0,0,1,1);
490 if(loadscreencolor==4)glColor4f(1,1,0,1);
491 if(loadscreencolor==5)glColor4f(1,0,1,1);
494 //glScalef(.25,.25,.25);
496 glTexCoord2f(0+.5,0+.5);
497 glVertex3f(-1, -1, 0.0f);
498 glTexCoord2f(1+.5,0+.5);
499 glVertex3f(1, -1, 0.0f);
500 glTexCoord2f(1+.5,1+.5);
501 glVertex3f(1, 1, 0.0f);
502 glTexCoord2f(0+.5,1+.5);
503 glVertex3f(-1, 1, 0.0f);
506 glDisable(GL_TEXTURE_2D);
507 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
508 glPopMatrix(); // Restore The Old Projection Matrix
509 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
510 glPopMatrix(); // Restore The Old Projection Matrix
514 glEnable(GL_TEXTURE_2D);
515 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
516 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
517 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
518 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
519 glDisable(GL_CULL_FACE);
520 glDisable(GL_LIGHTING);
522 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
523 glPushMatrix(); // Store The Projection Matrix
524 glLoadIdentity(); // Reset The Projection Matrix
525 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
526 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
527 glPushMatrix(); // Store The Modelview Matrix
528 glLoadIdentity(); // Reset The Modelview Matrix
529 glTranslatef(screenwidth/2,screenheight/2,0);
530 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
531 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
533 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
535 //glScalef(.25,.25,.25);
537 glTexCoord2f(0+.2,0+.8);
538 glVertex3f(-1, -1, 0.0f);
539 glTexCoord2f(1+.2,0+.8);
540 glVertex3f(1, -1, 0.0f);
541 glTexCoord2f(1+.2,1+.8);
542 glVertex3f(1, 1, 0.0f);
543 glTexCoord2f(0+.2,1+.8);
544 glVertex3f(-1, 1, 0.0f);
547 glDisable(GL_TEXTURE_2D);
548 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
549 glPopMatrix(); // Restore The Old Projection Matrix
550 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
551 glPopMatrix(); // Restore The Old Projection Matrix
557 glEnable(GL_TEXTURE_2D);
558 static char string[256]="";
559 sprintf (string, "LOADING... %d%",(int)loadprogress);
561 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
562 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
563 text.glPrint(280,125,string,1,1,640,480);
567 if(flashamount>1)flashamount=1;
568 if(flashdelay<=0)flashamount-=multiplier;
570 if(flashamount<0)flashamount=0;
571 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
572 glDisable(GL_CULL_FACE);
573 glDisable(GL_LIGHTING);
574 glDisable(GL_TEXTURE_2D);
576 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
577 glPushMatrix(); // Store The Projection Matrix
578 glLoadIdentity(); // Reset The Projection Matrix
579 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
580 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
581 glPushMatrix(); // Store The Modelview Matrix
582 glLoadIdentity(); // Reset The Modelview Matrix
583 glScalef(screenwidth,screenheight,1);
584 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
586 glColor4f(flashr,flashg,flashb,flashamount);
588 glVertex3f(0, 0, 0.0f);
589 glVertex3f(256, 0, 0.0f);
590 glVertex3f(256, 256, 0.0f);
591 glVertex3f(0, 256, 0.0f);
593 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
594 glPopMatrix(); // Restore The Old Projection Matrix
595 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
596 glPopMatrix(); // Restore The Old Projection Matrix
597 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
598 glEnable(GL_CULL_FACE);
608 void Game::FadeLoadingScreen(float howmuch)
610 static float loadprogress,minprogress,maxprogress;
615 glClearColor(0,0,0,1);
616 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
618 loadprogress=howmuch;
620 //loadprogress=abs(Random()%100);
624 //glEnable(GL_TEXTURE_2D);
625 glDisable(GL_TEXTURE_2D);
626 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
627 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
628 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
629 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
630 glDisable(GL_CULL_FACE);
631 glDisable(GL_LIGHTING);
633 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
634 glPushMatrix(); // Store The Projection Matrix
635 glLoadIdentity(); // Reset The Projection Matrix
636 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
637 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
638 glPushMatrix(); // Store The Modelview Matrix
639 glLoadIdentity(); // Reset The Modelview Matrix
640 glTranslatef(screenwidth/2,screenheight/2,0);
641 glScalef((float)screenwidth/2,(float)screenheight/2,1);
642 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
644 glColor4f(loadprogress/100,0,0,1);
645 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
646 if(loadscreencolor==1)glColor4f(1,0,0,1);
647 if(loadscreencolor==2)glColor4f(0,1,0,1);
648 if(loadscreencolor==3)glColor4f(0,0,1,1);
649 if(loadscreencolor==4)glColor4f(1,1,0,1);
650 if(loadscreencolor==5)glColor4f(1,0,1,1);
653 //glScalef(.25,.25,.25);
656 glVertex3f(-1, -1, 0.0f);
658 glVertex3f(1, -1, 0.0f);
660 glVertex3f(1, 1, 0.0f);
662 glVertex3f(-1, 1, 0.0f);
665 glDisable(GL_TEXTURE_2D);
666 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
667 glPopMatrix(); // Restore The Old Projection Matrix
668 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
669 glPopMatrix(); // Restore The Old Projection Matrix
674 glEnable(GL_TEXTURE_2D);
675 static char string[256]="";
676 sprintf (string, "LOADING... %d%",(int)loadprogress);
678 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
679 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
680 text.glPrint(280,125,string,1,1,640,480);
687 void Game::InitGame()
690 ProcessSerialNumber PSN;
691 ProcessInfoRec pinfo;
694 /* set up process serial number */
695 PSN.highLongOfPSN = 0;
696 PSN.lowLongOfPSN = kCurrentProcess;
697 /* set up info block */
698 pinfo.processInfoLength = sizeof(pinfo);
699 pinfo.processName = NULL;
700 pinfo.processAppSpec = &pspec;
701 /* grab the vrefnum and directory */
702 err = GetProcessInformation(&PSN, &pinfo);
704 vRefNum = pspec.vRefNum;
715 numchallengelevels=14;
717 accountactive=Account::loadFile(":Data:Users");
723 whichjointstartarray[0]=righthip;
724 whichjointendarray[0]=rightfoot;
726 whichjointstartarray[1]=righthip;
727 whichjointendarray[1]=rightankle;
729 whichjointstartarray[2]=righthip;
730 whichjointendarray[2]=rightknee;
732 whichjointstartarray[3]=rightknee;
733 whichjointendarray[3]=rightankle;
735 whichjointstartarray[4]=rightankle;
736 whichjointendarray[4]=rightfoot;
738 whichjointstartarray[5]=lefthip;
739 whichjointendarray[5]=leftfoot;
741 whichjointstartarray[6]=lefthip;
742 whichjointendarray[6]=leftankle;
744 whichjointstartarray[7]=lefthip;
745 whichjointendarray[7]=leftknee;
747 whichjointstartarray[8]=leftknee;
748 whichjointendarray[8]=leftankle;
750 whichjointstartarray[9]=leftankle;
751 whichjointendarray[9]=leftfoot;
753 whichjointstartarray[10]=abdomen;
754 whichjointendarray[10]=rightshoulder;
756 whichjointstartarray[11]=abdomen;
757 whichjointendarray[11]=rightelbow;
759 whichjointstartarray[12]=abdomen;
760 whichjointendarray[12]=rightwrist;
762 whichjointstartarray[13]=abdomen;
763 whichjointendarray[13]=righthand;
765 whichjointstartarray[14]=rightshoulder;
766 whichjointendarray[14]=rightelbow;
768 whichjointstartarray[15]=rightelbow;
769 whichjointendarray[15]=rightwrist;
771 whichjointstartarray[16]=rightwrist;
772 whichjointendarray[16]=righthand;
774 whichjointstartarray[17]=abdomen;
775 whichjointendarray[17]=leftshoulder;
777 whichjointstartarray[18]=abdomen;
778 whichjointendarray[18]=leftelbow;
780 whichjointstartarray[19]=abdomen;
781 whichjointendarray[19]=leftwrist;
783 whichjointstartarray[20]=abdomen;
784 whichjointendarray[20]=lefthand;
786 whichjointstartarray[21]=leftshoulder;
787 whichjointendarray[21]=leftelbow;
789 whichjointstartarray[22]=leftelbow;
790 whichjointendarray[22]=leftwrist;
792 whichjointstartarray[23]=leftwrist;
793 whichjointendarray[23]=lefthand;
795 whichjointstartarray[24]=abdomen;
796 whichjointendarray[24]=neck;
798 whichjointstartarray[25]=neck;
799 whichjointendarray[25]=head;
801 FadeLoadingScreen(0);
805 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
807 int temptexdetail=texdetail;
809 text.LoadFontTexture(":Data:Textures:Font.png");
811 texdetail=temptexdetail;
813 FadeLoadingScreen(10);
829 LOG("Initializing sound system...");
834 extern bool cmdline(const char *cmd);
835 unsigned char rc = 0;
836 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
837 if (cmdline("forceoss")) // ...but let user override that.
838 output = OPENAL_OUTPUT_OSS;
839 else if (cmdline("nosound"))
840 output = OPENAL_OUTPUT_NOSOUND;
842 OPENAL_SetOutput(output);
843 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
845 // if we tried ALSA and failed, fall back to OSS.
846 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
849 output = OPENAL_OUTPUT_OSS;
850 OPENAL_SetOutput(output);
851 rc = OPENAL_Init(44100, 32, 0);
858 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
859 OPENAL_SetOutput(output);
860 rc = OPENAL_Init(44100, 32, 0);
863 OPENAL_Init(44100, 32, 0);
866 OPENAL_SetSFXMasterVolume((int)(volume*255));
870 emit_stream_np(stream_music3);
872 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
874 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
875 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
876 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
878 temptexdetail=texdetail;
879 if(texdetail>2)texdetail=2;
880 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
881 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
882 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
883 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
884 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
885 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
886 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
887 texdetail=temptexdetail;
892 FadeLoadingScreen(95);
903 newscreenwidth=screenwidth;
904 newscreenheight=screenheight;
908 void Game::LoadStuff()
910 static float temptexdetail;
911 static float viewdistdetail;
912 static int i,j,texsize;
923 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
925 for(i=0;i<maxplayers;i++)
927 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
929 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
931 player[i].skeleton.drawmodel.textureptr=0;;
934 //temptexdetail=texdetail;
937 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
938 //texdetail=temptexdetail;
940 temptexdetail=texdetail;
942 text.LoadFontTexture(":Data:Textures:Font.png");
944 texdetail=temptexdetail;
949 viewdistance=50*megascale*viewdistdetail;
969 realtexdetail=texdetail;
972 if(texdetail<1)texdetail=1;
973 realtexdetail=texdetail*4;
979 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
981 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
983 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
987 LOG("Loading weapon data...");
989 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
990 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
991 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
992 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
993 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
994 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
995 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
997 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
998 weapons.throwingknifemodel.Scale(.001,.001,.001);
999 //weapons.throwingknifemodel.Rotate(0,0,-90);
1000 weapons.throwingknifemodel.Rotate(90,0,0);
1001 weapons.throwingknifemodel.Rotate(0,90,0);
1002 weapons.throwingknifemodel.flat=0;
1003 weapons.throwingknifemodel.CalculateNormals(1);
1004 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1006 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1007 weapons.swordmodel.Scale(.001,.001,.001);
1008 //weapons.swordmodel.Rotate(0,0,-90);
1009 weapons.swordmodel.Rotate(90,0,0);
1010 weapons.swordmodel.Rotate(0,90,0);
1011 weapons.swordmodel.Rotate(0,0,90);
1012 weapons.swordmodel.flat=1;
1013 weapons.swordmodel.CalculateNormals(1);
1014 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1016 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1017 weapons.staffmodel.Scale(.005,.005,.005);
1018 //weapons.staffmodel.Rotate(0,0,-90);
1019 weapons.staffmodel.Rotate(90,0,0);
1020 weapons.staffmodel.Rotate(0,90,0);
1021 weapons.staffmodel.Rotate(0,0,90);
1022 weapons.staffmodel.flat=1;
1023 weapons.staffmodel.CalculateNormals(1);
1024 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1026 //temptexdetail=texdetail;
1027 //if(texdetail>4)texdetail=4;
1028 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1030 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1032 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1034 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1037 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1039 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1041 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1043 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1045 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1047 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1049 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1051 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1052 //texdetail=temptexdetail;
1053 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1057 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1059 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1062 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1065 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1066 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1067 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1068 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1069 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1070 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1071 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1072 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1073 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1074 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1075 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1079 ReSizeGLScene(90,.01);
1086 if(detail)kTextureSize=1024;
1087 if(detail==1)kTextureSize=512;
1088 if(detail==0)kTextureSize=256;
1091 //drawmode=motionblurmode;
1093 //Set up distant light
1097 light.ambient[0]=.2;
1098 light.ambient[1]=.2;
1099 light.ambient[2]=.24;
1102 light.location.z=-.2;
1103 Normalise(&light.location);
1113 texscale=.2/megascale/viewdistdetail;
1114 terrain.scale=3*megascale*terraindetail*viewdistdetail;
1116 viewer.x=terrain.size/2*terrain.scale;
1117 viewer.z=terrain.size/2*terrain.scale;
1119 hawk.load((char *)":Data:Models:hawk.solid",1);
1120 hawk.Scale(.03,.03,.03);
1121 hawk.Rotate(90,1,1);
1122 hawk.CalculateNormals(0);
1123 hawk.ScaleNormals(-1,-1,-1);
1124 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1125 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1126 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1129 eye.load((char *)":Data:Models:eye.solid",1);
1130 eye.Scale(.03,.03,.03);
1131 eye.CalculateNormals(0);
1133 cornea.load((char *)":Data:Models:cornea.solid",1);
1134 cornea.Scale(.03,.03,.03);
1135 cornea.CalculateNormals(0);
1137 iris.load((char *)":Data:Models:iris.solid",1);
1138 iris.Scale(.03,.03,.03);
1139 iris.CalculateNormals(0);
1141 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1142 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1150 //if(targetlevel!=7)
1151 Loadlevel(targetlevel);
1154 rabbitcoords=player[0].coords;
1155 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1157 loadAllAnimations();
1158 //Fix knife stab, too lazy to do it manually
1162 for(i=0;i<player[0].skeleton.num_joints;i++){
1163 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1164 animation[knifesneakattackanim].position[i][j]+=moveamount;
1171 for(i=0;i<player[0].skeleton.num_joints;i++){
1172 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1173 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1180 for(i=0;i<player[0].skeleton.num_joints;i++){
1181 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1182 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1183 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1184 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1186 animation[dead1anim].speed[0]=0.001;
1187 animation[dead2anim].speed[0]=0.001;
1188 animation[dead3anim].speed[0]=0.001;
1189 animation[dead4anim].speed[0]=0.001;
1191 animation[dead1anim].speed[1]=0.001;
1192 animation[dead2anim].speed[1]=0.001;
1193 animation[dead3anim].speed[1]=0.001;
1194 animation[dead4anim].speed[1]=0.001;
1196 for(i=0;i<player[0].skeleton.num_joints;i++){
1197 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1198 animation[swordsneakattackanim].position[i][j]+=moveamount;
1203 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1204 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1210 for(i=0;i<player[0].skeleton.num_joints;i++){
1211 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1212 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1216 for(i=0;i<player[0].skeleton.num_joints;i++){
1217 for(j=0;j<animation[sleepanim].numframes;j++){
1218 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1224 temptexdetail=texdetail;
1226 texdetail=temptexdetail;
1233 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1235 glGenTextures( 1, &screentexture );
1236 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1239 glEnable(GL_TEXTURE_2D);
1240 glBindTexture( GL_TEXTURE_2D, screentexture);
1241 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1242 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1244 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1248 emit_sound_at(fireendsound);