]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
16d845a53b35d1ee0126818af9a8123ee56c81ae
[lugaru.git] / Source / GameDraw.cpp
1 #include "Game.h"       
2
3 using namespace std;
4
5 extern XYZ viewer;
6 extern int environment;
7 extern float texscale;
8 extern Light light;
9 extern Terrain terrain;
10 extern Sprites sprites;
11 extern float multiplier;
12 extern float sps;
13 extern float viewdistance;
14 extern float fadestart;
15 extern float screenwidth,screenheight;
16 extern int kTextureSize;
17 extern FRUSTUM frustum;
18 extern Light light;
19 extern Objects objects;
20 extern int detail;
21 extern float usermousesensitivity;
22 extern bool osx;
23 extern float camerashake;
24 extern Weapons weapons;
25 extern Person player[maxplayers];
26 extern int slomo;
27 extern float slomodelay;
28 extern bool ismotionblur;
29 extern float woozy;
30 extern float blackout;
31 extern bool damageeffects;
32 extern float volume;
33 extern int numplayers;
34 extern bool texttoggle;
35 extern float blurness;
36 extern float targetblurness;
37 extern float playerdist;
38 extern bool cellophane;
39 extern bool freeze;
40 extern float flashamount,flashr,flashg,flashb;
41 extern int flashdelay;
42 extern int netstate;
43 extern float motionbluramount;
44 extern bool isclient;
45 extern bool alwaysblur;
46 extern int test;
47 extern bool tilt2weird;
48 extern bool tiltweird;
49 extern bool midweird;
50 extern bool proportionweird;
51 extern bool vertexweird[6];
52 extern bool velocityblur;
53 extern bool buttons[3];
54 extern bool debugmode;
55 extern int mainmenu;
56 extern int oldmainmenu;
57 extern int bloodtoggle;
58 extern int difficulty;
59 extern bool decals;
60 // MODIFIED GWC
61 //extern int texdetail;
62 extern float texdetail;
63 extern bool musictoggle;
64 extern int bonus;
65 extern float bonusvalue;
66 extern float bonustotal;
67 extern float bonustime;
68 extern int oldbonus;
69 extern float startbonustotal;
70 extern float bonusnum[100];
71 extern int tutoriallevel;
72 extern float smoketex;
73 extern float tutorialstagetime;
74 extern float tutorialmaxtime;
75 extern int tutorialstage;
76 extern bool againbonus;
77 extern float damagedealt;
78 extern float damagetaken;
79 extern bool invertmouse;
80
81 extern int numhotspots;
82 extern int winhotspot;
83 extern int killhotspot;
84 extern XYZ hotspot[40];
85 extern int hotspottype[40];
86 extern float hotspotsize[40];
87 extern char hotspottext[40][256];
88 extern int currenthotspot;
89
90 extern int numaccounts;
91 extern int accountactive;
92 extern int accountdifficulty[10];
93 extern int accountprogress[10];
94 extern float accountpoints[10];
95 extern float accounthighscore[10][50];
96 extern float accountfasttime[10][50];
97 extern bool accountunlocked[10][60];
98 extern char accountname[10][256];
99
100 extern int numfalls;
101 extern int numflipfail;
102 extern int numseen;
103 extern int numstaffattack;
104 extern int numswordattack;
105 extern int numknifeattack;
106 extern int numunarmedattack;
107 extern int numescaped;
108 extern int numflipped;
109 extern int numwallflipped;
110 extern int numthrowkill;
111 extern int numafterkill;
112 extern int numreversals;
113 extern int numattacks;
114 extern int maxalarmed;
115 extern int numresponded;
116
117 extern bool campaign;
118 extern bool winfreeze;
119
120 extern float menupulse;
121
122 extern bool gamestart;
123
124 extern int numdialogues;
125 extern int numdialogueboxes[max_dialogues];
126 extern int dialoguetype[max_dialogues];
127 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
128 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
129 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
130 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
131 extern char dialoguename[max_dialogues][max_dialoguelength][64];
132 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
133 extern XYZ participantlocation[max_dialogues][10];
134 extern int participantfocus[max_dialogues][max_dialoguelength];
135 extern int participantaction[max_dialogues][max_dialoguelength];
136 extern float participantrotation[max_dialogues][10];
137 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
138 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
139 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
140 extern int indialogue;
141 extern int whichdialogue;
142 extern int directing;
143 extern float dialoguetime;
144 extern int dialoguegonethrough[20];
145
146 extern int accountcampaignchoicesmade[10];
147 extern int accountcampaignchoices[10][5000];
148
149 extern float accountcampaignhighscore[10];
150 extern float accountcampaignfasttime[10];
151 extern float accountcampaignscore[10];
152 extern float accountcampaigntime[10];
153
154 extern bool gamestarted;
155
156 extern FSOUND_SAMPLE    *samp[100];
157 extern int channels[100];
158 extern "C"      void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
159
160 /*********************> DrawGLScene() <*****/
161 long long Game::MD5_string (char *string){
162         char temp[256]="";
163         char temp2[256]="";
164         long long num=90814;
165
166         sprintf (temp, "%s",string);
167
168         int i=0;
169         while (i<256&&temp[i]!='\0'){
170                 if(temp[i]%3==0)num+=temp[i]*124;
171                 else if(temp[i]%3==1)num-=temp[i]*temp[i];
172                 else num*=temp[i];
173                 i++;
174         }
175
176         num=longlongabs(num);
177         if(num==0)num+=1452;
178
179         while(num<LONGLONGCONST(5000000000000000)){
180                 num*=1.85421521;
181         }
182
183         while(num>LONGLONGCONST(9900000000000000)){
184                 num/=1.235421521;
185         }
186
187         return num;
188
189         //return 1111111111111111;
190 }
191
192 int Game::DrawGLScene(void)
193 {       
194         static float texcoordwidth,texcoordheight;
195         static float texviewwidth, texviewheight;
196         static int i,j,k,l;
197         static GLubyte color;
198         static float newbrightness;
199         static float changespeed;
200         static XYZ checkpoint;
201         static float tempmult;
202         float tutorialopac;
203         static char string[256]="";
204         static char string2[256]="";
205         static char string3[256]="";
206
207         static float lastcheck;
208
209         lastcheck+=multiplier;
210
211         glColorMask( 1.0, 1.0, 1.0, 1.0 );
212         if(!registered)debugmode=0;
213
214
215         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
216                 tempmult=multiplier;
217                 multiplier=0;
218         }
219
220         if(!mainmenu){
221                 if(editorenabled){
222                         numboundaries=mapradius*2;
223                         if(numboundaries>360)numboundaries=360;
224                         for(i=0;i<numboundaries;i++){
225                                 boundary[i]=0;
226                                 boundary[i].z=1;
227                                 boundary[i]=mapcenter+DoRotation(boundary[i]*mapradius,0,i*(360/((float)(numboundaries))),0);
228                         }
229                 }
230
231                 SetUpLighting();
232
233                 static int changed;
234                 changed=0;
235
236                 olddrawmode=drawmode;
237                 if(ismotionblur&&!loading){
238                         if((findLengthfast(&player[0].velocity)>200)&&velocityblur&&!cameramode){
239                                 drawmode=motionblurmode;
240                                 motionbluramount=200/(findLengthfast(&player[0].velocity));
241                                 changed=1;
242                         }
243                         if(player[0].damage-player[0].superpermanentdamage>(player[0].damagetolerance-player[0].superpermanentdamage)*1/2&&damageeffects&&!cameramode){
244                                 drawmode=doublevisionmode;
245                                 changed=1;
246                         }
247                 }
248
249                 if(slomo&&!loading){
250                         if(ismotionblur)
251                                 drawmode=motionblurmode;
252                         motionbluramount=.2;
253                         slomodelay-=multiplier;
254                         if(slomodelay<0)slomo=0;
255                         camerashake=0;
256                         changed=1;
257                 }
258                 if((!changed&&!slomo)||loading){
259                         drawmode=normalmode;
260                         if(ismotionblur&&(/*fps>100||*/alwaysblur)){
261                                 if(olddrawmode!=realmotionblurmode)change=1;
262                                 else change=0;
263                                 drawmode=realmotionblurmode;
264                         }
265                         else if(olddrawmode==realmotionblurmode)change=2;
266                         else change=0;
267                 }
268
269                 if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted))drawmode=normalmode;
270                 if((freeze||winfreeze)&&ismotionblur&&!mainmenu)drawmode=radialzoommode;
271
272                 if(winfreeze||mainmenu)drawmode=normalmode;
273
274                 //drawmode=glowmode;
275                 if(drawmode==glowmode){
276                         RGBColor color2;
277                         color2.red=0;
278                         color2.green=0;
279                         color2.blue=0;
280 #if PLATFORM_MACOSX
281                         DSpContext_FadeGamma(NULL,200,&color2);
282 #endif
283                 }
284
285                 if(drawtoggle!=2)drawtoggle=1-drawtoggle;
286
287                 if(!texcoordwidth){
288
289                         texviewwidth=kTextureSize;
290                         if(texviewwidth>screenwidth)texviewwidth=screenwidth;
291                         texviewheight=kTextureSize;
292                         if(texviewheight>screenheight)texviewheight=screenheight;
293
294                         texcoordwidth=screenwidth/kTextureSize;
295                         texcoordheight=screenheight/kTextureSize;
296                         if(texcoordwidth>1)texcoordwidth=1;
297                         if(texcoordheight>1)texcoordheight=1;
298                 }
299
300                 glDrawBuffer(GL_BACK);
301                 glReadBuffer(GL_BACK);
302
303                 /*if(environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, (float)(abs(Random()%100))/50 );
304                 else glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
305                 */
306                 if(abs(blurness-targetblurness)<multiplier*10||abs(blurness-targetblurness)>2){
307                         blurness=targetblurness;
308                         targetblurness=(float)(abs(Random()%100))/40;
309                 }
310                 if(blurness<targetblurness)blurness+=multiplier*5;
311                 if(blurness>targetblurness)blurness-=multiplier*5;
312
313                 //glFinish();
314                 static XYZ terrainlight;
315                 static float distance;
316                 //if(drawmode==normalmode)ReSizeGLScene(90,.1);
317                 if(drawmode==normalmode)ReSizeGLScene(90,.1f);
318                 if(drawmode!=normalmode)glViewport(0,0,texviewwidth,texviewheight);     
319                 glDepthFunc(GL_LEQUAL);
320                 glDepthMask(1);
321                 glAlphaFunc(GL_GREATER, 0.0001f);
322                 glEnable(GL_ALPHA_TEST);
323                 glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
324                 glClear(GL_DEPTH_BUFFER_BIT);
325
326                 glMatrixMode (GL_MODELVIEW);
327                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
328                 glLoadIdentity ();
329                 if(!cameramode&&!freeze&&!winfreeze){
330                         glRotatef(float(Random()%100)/10*camerashake/*+(woozy*woozy)/10*/,0,0,1);
331                         glRotatef(rotation2+sin(woozy/2)*(player[0].damage/player[0].damagetolerance)*5,1,0,0);
332                         glRotatef(rotation+sin(woozy)*(player[0].damage/player[0].damagetolerance)*5,0,1,0);
333                 }
334                 if(cameramode||freeze||winfreeze){
335                         //glRotatef(float(Random()%100)/10*camerashake/*+(woozy*woozy)/10*/,0,0,1);
336                         glRotatef(rotation2,1,0,0);
337                         glRotatef(rotation,0,1,0);
338                 }
339
340                 if(environment==desertenvironment){
341                         glRotatef((float)(abs(Random()%100))/3000-1,1,0,0);
342                         glRotatef((float)(abs(Random()%100))/3000-1,0,1,0);
343                         //glRotatef(blurness/40-1,1,0,0);
344                         //glRotatef(blurness/40-1,0,1,0);
345                 }
346                 SetUpLight(&light,0);
347                 glPushMatrix();
348                 if(environment==desertenvironment&&detail==2)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness+.4 );
349                 if(environment==desertenvironment){
350                         glRotatef((float)(abs(Random()%100))/1000,1,0,0);
351                         glRotatef((float)(abs(Random()%100))/1000,0,1,0);
352                 }       
353                 skybox.draw();
354                 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
355                 glPopMatrix();
356                 glTranslatef(-viewer.x,-viewer.y,-viewer.z);
357                 frustum.GetFrustum();
358
359                 //Make Shadow
360                 static XYZ point;
361                 static float size,opacity,rotation;
362                 rotation=0;
363                 for(k=0;k<numplayers;k++){
364                         if(!player[k].skeleton.free&&player[k].playerdetail&&player[k].howactive<typesleeping)
365                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y+player[k].scale*3,player[k].coords.z,player[k].scale*7)&&player[k].occluded<25)
366                                         for(i=0;i<player[k].skeleton.num_joints;i++){
367                                                 if(player[k].skeleton.joints[i].label==leftknee||player[k].skeleton.joints[i].label==rightknee||player[k].skeleton.joints[i].label==groin){
368                                                         point=DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
369                                                         size=.4f;
370                                                         opacity=.4-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
371                                                         if(k!=0&&tutoriallevel==1){
372                                                                 opacity=.2+.2*sin(smoketex*6+i)-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
373                                                         }
374                                                         terrain.MakeDecal(shadowdecal,point,size,opacity,rotation);
375                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
376                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
377                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
378                                                                         if(objects.position[j].y<player[k].coords.y||objects.type[j]==tunneltype||objects.type[j]==weirdtype){
379                                                                                 point=DoRotation(DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
380                                                                                 size=.4f;
381                                                                                 opacity=.4f;
382                                                                                 if(k!=0&&tutoriallevel==1){
383                                                                                         opacity=.2+.2*sin(smoketex*6+i);
384                                                                                 }
385                                                                                 objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
386                                                                         }
387                                                                 }
388                                                 }
389                                         }
390                                         if((player[k].skeleton.free||player[k].howactive>=typesleeping)&&player[k].playerdetail)
391                                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y,player[k].coords.z,player[k].scale*5)&&player[k].occluded<25)
392                                                         for(i=0;i<player[k].skeleton.num_joints;i++){
393                                                                 if(player[k].skeleton.joints[i].label==leftknee||player[k].skeleton.joints[i].label==rightknee||player[k].skeleton.joints[i].label==groin||player[k].skeleton.joints[i].label==leftelbow||player[k].skeleton.joints[i].label==rightelbow||player[k].skeleton.joints[i].label==neck){
394                                                                         if(player[k].skeleton.free)point=player[k].skeleton.joints[i].position*player[k].scale+player[k].coords;
395                                                                         else point=DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
396                                                                         size=.4f;
397                                                                         opacity=.4-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/5;
398                                                                         if(k!=0&&tutoriallevel==1){
399                                                                                 opacity=.2+.2*sin(smoketex*6+i)-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
400                                                                         }
401                                                                         terrain.MakeDecal(shadowdecal,point,size,opacity*.7,rotation);
402                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
403                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
404                                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
405                                                                                         if(objects.position[j].y<player[k].coords.y||objects.type[j]==tunneltype||objects.type[j]==weirdtype){
406                                                                                                 if(player[k].skeleton.free)point=DoRotation(player[k].skeleton.joints[i].position*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
407                                                                                                 else point=DoRotation(DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
408                                                                                                 size=.4f;
409                                                                                                 opacity=.4f;
410                                                                                                 if(k!=0&&tutoriallevel==1){
411                                                                                                         opacity=.2+.2*sin(smoketex*6+i);
412                                                                                                 }
413                                                                                                 objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
414                                                                                         }
415                                                                                 }
416                                                                 }
417                                                         }
418
419                                                         if(!player[k].playerdetail)
420                                                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y,player[k].coords.z,player[k].scale*5))
421                                                                 {
422                                                                         point=player[k].coords;
423                                                                         size=.7;
424                                                                         opacity=.4-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/5;
425                                                                         terrain.MakeDecal(shadowdecal,point,size,opacity*.7,rotation);
426                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
427                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
428                                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
429                                                                                         point=DoRotation(player[k].coords-objects.position[j],0,-objects.rotation[j],0);
430                                                                                         size=.7;
431                                                                                         opacity=.4f;
432                                                                                         objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
433                                                                                 }
434                                                                 }
435                 }
436
437                 //Terrain
438                 glEnable(GL_TEXTURE_2D);
439                 glDepthMask(1);
440                 glEnable(GL_DEPTH_TEST);
441                 glEnable(GL_CULL_FACE);
442                 glDisable(GL_BLEND);
443                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
444                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
445                 glBindTexture( GL_TEXTURE_2D, terraintexture);
446                 terrain.draw(0);
447                 glBindTexture( GL_TEXTURE_2D, terraintexture2);
448                 terrain.draw(1);
449                 //glBindTexture( GL_TEXTURE_2D, terraintexture3);
450                 //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
451                 //terrain.draw(2);
452
453                 terrain.drawdecals();
454
455                 //Model
456                 glEnable(GL_CULL_FACE);
457                 glEnable(GL_LIGHTING);
458                 glDisable(GL_BLEND);
459                 glEnable(GL_TEXTURE_2D);
460                 glDepthMask(1);
461
462                 glEnable(GL_COLOR_MATERIAL);
463
464                 test=2;
465                 tilt2weird=0;
466                 tiltweird=0;
467                 midweird=0;
468                 proportionweird=0;
469                 vertexweird[0]=0;
470                 vertexweird[1]=0;
471                 vertexweird[2]=0;
472                 vertexweird[3]=0;
473                 vertexweird[4]=0;
474                 vertexweird[5]=0;
475
476                 if(!cellophane){
477                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
478                         glEnable(GL_CULL_FACE);
479                         glCullFace(GL_FRONT);
480                         glDepthMask(1);
481                         for(k=0;k<numplayers;k++){
482                                 if(k==0||tutoriallevel!=1){
483                                         glEnable(GL_BLEND);
484                                         glEnable(GL_LIGHTING);
485                                         terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
486                                         distance=findDistancefast(&viewer,&player[k].coords);
487                                         distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
488                                         glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
489                                         if(distance>=1)glDisable(GL_BLEND);
490                                         if(distance>=.5){
491                                                 checkpoint=DoRotation(player[k].skeleton.joints[abs(Random()%player[k].skeleton.num_joints)].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
492                                                 checkpoint.y+=1;
493                                                 if(!player[k].occluded==0)i=checkcollide(viewer,checkpoint,player[k].lastoccluded);
494                                                 if(i==-1||player[k].occluded==0)i=checkcollide(viewer,checkpoint);
495                                                 if(i!=-1){
496                                                         player[k].occluded+=1;
497                                                         player[k].lastoccluded=i;
498                                                 }
499                                                 else player[k].occluded=0;
500                                                 if(player[k].occluded<25)player[k].DrawSkeleton();
501                                         }
502                                 }
503                         }
504                 }
505
506                 if(!cameramode&&musictype==stream_music2)playerdist=findDistancefastflat(&player[0].coords,&viewer);
507                 else playerdist=-100;
508                 glPushMatrix();
509                 glCullFace(GL_BACK);
510                 glEnable(GL_TEXTURE_2D);
511                 objects.Draw();
512                 glPopMatrix();
513
514                 glPushMatrix();
515                 if(frustum.SphereInFrustum(realhawkcoords.x+hawk.boundingspherecenter.x,realhawkcoords.y+hawk.boundingspherecenter.y,realhawkcoords.z+hawk.boundingspherecenter.z,2)){   
516                         glAlphaFunc(GL_GREATER, 0.0001f);
517                         glDepthMask(1);
518                         glDisable(GL_CULL_FACE);
519                         glDisable(GL_LIGHTING);
520                         glEnable(GL_BLEND);
521                         glTranslatef(hawkcoords.x,hawkcoords.y,hawkcoords.z);
522                         glRotatef(hawkrotation,0,1,0);
523                         glTranslatef(25,0,0);
524                         distance=findDistancefast(&viewer,&realhawkcoords)*1.2;
525                         glColor4f(light.color[0],light.color[1],light.color[2],(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance);
526                         if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>1)glColor4f(light.color[0],light.color[1],light.color[2],1);
527                         if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>0)
528                                 hawk.drawdifftex(hawktexture);
529                 }
530                 glPopMatrix();
531
532                 //if(cellophane){
533                 /*glEnable(GL_CULL_FACE);
534                 glCullFace(GL_FRONT);
535                 glDepthMask(1);
536                 for(k=0;k<numplayers;k++){
537                 glEnable(GL_BLEND);
538                 glEnable(GL_LIGHTING);
539                 terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
540                 distance=findDistancefast(&viewer,&player[k].coords);
541                 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
542                 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
543                 if(distance>=1)glDisable(GL_BLEND);
544                 if(distance>0){
545                 checkpoint=DoRotation(player[k].skeleton.joints[abs(Random()%player[k].skeleton.num_joints)].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
546                 checkpoint.y+=1;
547                 if(checkcollide(viewer,checkpoint)){
548                 player[k].occluded+=1;
549                 }
550                 else player[k].occluded=0;
551                 if(player[k].occluded<25)player[k].DrawSkeleton();
552                 }
553                 }*/
554
555                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
556                 glEnable(GL_CULL_FACE);
557                 glCullFace(GL_FRONT);
558                 glDepthMask(1);
559                 for(k=0;k<numplayers;k++){
560                         if(!(k==0||tutoriallevel!=1)){
561                                 glEnable(GL_BLEND);
562                                 glEnable(GL_LIGHTING);
563                                 terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
564                                 distance=findDistancefast(&viewer,&player[k].coords);
565                                 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
566                                 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
567                                 if(distance>=1)glDisable(GL_BLEND);
568                                 if(distance>=.5){
569                                         checkpoint=DoRotation(player[k].skeleton.joints[abs(Random()%player[k].skeleton.num_joints)].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
570                                         checkpoint.y+=1;
571                                         if(!player[k].occluded==0)i=checkcollide(viewer,checkpoint,player[k].lastoccluded);
572                                         if(i==-1||player[k].occluded==0)i=checkcollide(viewer,checkpoint);
573                                         if(i!=-1){
574                                                 player[k].occluded+=1;
575                                                 player[k].lastoccluded=i;
576                                         }
577                                         else player[k].occluded=0;
578                                         if(player[k].occluded<25)player[k].DrawSkeleton();
579                                 }
580                         }
581                 }
582                 //}
583
584                 glPushMatrix();
585                 glEnable(GL_TEXTURE_2D);
586                 weapons.Draw();
587                 glPopMatrix();
588                 glCullFace(GL_BACK);
589
590                 glDisable(GL_COLOR_MATERIAL);
591
592                 glDisable(GL_LIGHTING);
593                 glDisable(GL_TEXTURE_2D);
594
595                 glDepthMask(0);
596
597                 sprites.Draw();
598
599                 if(editorenabled){
600                         glEnable(GL_BLEND);
601                         glDisable(GL_LIGHTING);
602                         glDisable(GL_TEXTURE_2D);
603                         glDisable(GL_COLOR_MATERIAL);
604                         glColor4f(1,1,0,1);
605
606                         for(k=0;k<numplayers;k++){
607                                 if(player[k].numwaypoints>1){
608                                         glBegin(GL_LINE_LOOP);
609                                         for(i=0;i<player[k].numwaypoints;i++){
610                                                 glVertex3f(player[k].waypoints[i].x,player[k].waypoints[i].y+.5,player[k].waypoints[i].z);
611                                         }
612                                         glEnd();
613                                 }
614                         }
615
616
617                         if(numpathpoints>1){
618                                 glColor4f(0,1,0,1);
619                                 for(k=0;k<numpathpoints;k++){
620                                         if(numpathpointconnect[k]){
621                                                 for(i=0;i<numpathpointconnect[k];i++){
622                                                         glBegin(GL_LINE_LOOP);
623                                                         glVertex3f(pathpoint[k].x,pathpoint[k].y+.5,pathpoint[k].z);
624                                                         glVertex3f(pathpoint[pathpointconnect[k][i]].x,pathpoint[pathpointconnect[k][i]].y+.5,pathpoint[pathpointconnect[k][i]].z);                                     
625                                                         glEnd();
626                                                 }
627                                         }
628                                 }
629                                 glColor4f(1,1,1,1);
630                                 glPointSize(4);
631                                 glBegin(GL_POINTS);
632                                 glVertex3f(pathpoint[pathpointselected].x,pathpoint[pathpointselected].y+.5,pathpoint[pathpointselected].z);
633                                 glEnd();
634                         }
635                 }
636
637                 //Text
638
639                 glEnable(GL_TEXTURE_2D);
640                 glColor4f(.5,.5,.5,1);
641                 if(!console){
642                         sprintf (string, " ",(int)(fps));
643                         text.glPrint(10,30,string,0,.8,screenwidth,screenheight);
644
645                         if(!tutoriallevel)
646                                 if(bonus>0&&bonustime<1&&!winfreeze&&indialogue==-1/*bonustime<4*/){
647                                         if(bonus==tracheotomy)sprintf (string, "Tracheotomy!");
648                                         else if(bonus==backstab)sprintf (string, "Backstabber!");
649                                         else if(bonus==spinecrusher)sprintf (string, "Spinecrusher!");
650                                         else if(bonus==ninja)sprintf (string, "Ninja Bonus!");
651                                         else if(bonus==style)sprintf (string, "Style Bonus!");
652                                         else if(bonus==cannon)sprintf (string, "Leg Cannon!");
653                                         else if(bonus==aimbonus)sprintf (string, "Nice Aim!");
654                                         else if(bonus==deepimpact)sprintf (string, "Heavy Impact!");
655                                         else if(bonus==touchofdeath)sprintf (string, "Touch of Death!");
656                                         else if(bonus==swordreversebonus)sprintf (string, "Sword Disarm!");
657                                         else if(bonus==staffreversebonus)sprintf (string, "Staff Disarm!");
658                                         else if(bonus==reverseko)sprintf (string, "Reversal KO!");
659                                         else if(bonus==solidhit)sprintf (string, "Solid Hit!");
660                                         else if(bonus==twoxcombo)sprintf (string, "2X Combo!");
661                                         else if(bonus==threexcombo)sprintf (string, "3X Combo!");
662                                         else if(bonus==fourxcombo)sprintf (string, "4X COMBO!");
663                                         else if(bonus==megacombo)sprintf (string, "MEGA COMBO!");
664                                         else if(bonus==Reversal)sprintf (string, "Reversal!");
665                                         else if(bonus==Stabbonus)sprintf (string, "Punctured!");
666                                         else if(bonus==Slicebonus)sprintf (string, "Sliced!");
667                                         else if(bonus==Bullseyebonus)sprintf (string, "Bullseye!");
668                                         else if(bonus==Slashbonus)sprintf (string, "Slashed!");
669                                         else if(bonus==Wolfbonus)sprintf (string, "WOLF SLAYER!");
670                                         else if(bonus==FinishedBonus)sprintf (string, "SLAIN!");
671                                         else if(bonus==TackleBonus)sprintf (string, "Tackle!");
672                                         else if(bonus==AboveBonus)sprintf (string, "Death from Above!");
673                                         else sprintf (string, "Excellent!");
674
675                                         glColor4f(0,0,0,1-bonustime);
676                                         text.glPrintOutline(1024/2-10*strlen(string)-4,768/16-4+768*4/5,string,1,2.5,1024,768);
677                                         glColor4f(1,0,0,1-bonustime);
678                                         text.glPrint(1024/2-10*strlen(string),768/16+768*4/5,string,1,2,1024,768);
679
680                                         sprintf (string, "%d",(int)bonusvalue);
681                                         glColor4f(0,0,0,1-bonustime);
682                                         text.glPrintOutline(1024/2-10*strlen(string)-4,768/16-4-20+768*4/5,string,1,2.5*.8,1024,768);
683                                         glColor4f(1,0,0,1-bonustime);
684                                         text.glPrint(1024/2-10*strlen(string),768/16-20+768*4/5,string,1,2*.8,1024,768);
685                                         glColor4f(.5,.5,.5,1);
686                                 }
687
688                                 if(tutoriallevel==1){
689                                         tutorialopac=tutorialmaxtime-tutorialstagetime;
690                                         if(tutorialopac>1)tutorialopac=1;
691                                         if(tutorialopac<0)tutorialopac=0;
692
693                                         sprintf (string, " ");
694                                         sprintf (string2, " ");
695                                         sprintf (string3, " ");
696                                         if(tutorialstage==0){
697                                                 sprintf (string, " ");
698                                                 sprintf (string2, " ");
699                                                 sprintf (string3, " ");
700                                         }
701                                         if(tutorialstage==1){
702                                                 sprintf (string, "Welcome to the Lugaru training level!");
703                                                 sprintf (string2, " ");
704                                                 sprintf (string3, " ");
705                                         }
706                                         if(tutorialstage==2){
707                                                 sprintf (string, "BASIC MOVEMENT:");
708                                                 sprintf (string2, " ");
709                                                 sprintf (string3, " ");
710                                         }
711                                         if(tutorialstage==3){
712                                                 sprintf (string, "You can move the mouse to rotate the camera.");
713                                                 sprintf (string2, " ");
714                                                 sprintf (string3, " ");
715                                         }
716                                         if(tutorialstage==4){
717                                                 sprintf (string, "Try using the %s, %s, %s and %s keys to move around.",KeyToChar(forwardkey),KeyToChar(leftkey),KeyToChar(backkey),KeyToChar(rightkey));
718                                                 sprintf (string2, "All movement is relative to the camera.");
719                                                 sprintf (string3, " ");
720                                         }
721                                         if(tutorialstage==5){
722                                                 sprintf (string, "Please press %s to jump.",KeyToChar(jumpkey));
723                                                 sprintf (string2, "You can hold it longer to jump higher.");
724                                                 sprintf (string3, " ");
725                                         }
726                                         if(tutorialstage==6){
727                                                 sprintf (string, "You can press %s to crouch.",KeyToChar(crouchkey));
728                                                 sprintf (string2, "You can jump higher from a crouching position.");
729                                                 sprintf (string3, " ");
730                                         }
731                                         if(tutorialstage==7){
732                                                 sprintf (string, "While running, you can press %s to roll.",KeyToChar(crouchkey));
733                                                 sprintf (string2, " ");
734                                                 sprintf (string3, " ");
735                                         }
736                                         if(tutorialstage==8){
737                                                 sprintf (string, "While crouching, you can sneak around silently");
738                                                 sprintf (string2, "using the movement keys.");
739                                                 sprintf (string3, " ");
740                                         }
741                                         if(tutorialstage==9){
742                                                 sprintf (string, "Release the crouch key while sneaking and hold the movement keys");
743                                                 sprintf (string2, "to run animal-style.");
744                                                 sprintf (string3, " ");
745                                         }
746                                         if(tutorialstage==10){
747                                                 sprintf (string, "ADVANCED MOVEMENT:");
748                                                 sprintf (string2, " ");
749                                                 sprintf (string3, " ");
750                                         }
751                                         if(tutorialstage==11){
752                                                 sprintf (string, "When you jump at a wall, you can hold %s again",KeyToChar(jumpkey));
753                                                 sprintf (string2, "during impact to perform a walljump.");
754                                                 sprintf (string3, "Be sure to use the movement keys to press against the wall");
755                                         }
756                                         if(tutorialstage==12){
757                                                 sprintf (string, "While in the air, you can press crouch to flip.",KeyToChar(jumpkey));
758                                                 sprintf (string2, "Walljumps and flips confuse enemies and give you more control.");
759                                                 sprintf (string3, " ");
760                                         }
761                                         if(tutorialstage==13){
762                                                 sprintf (string, "BASIC COMBAT:");
763                                                 sprintf (string2, " ");
764                                                 sprintf (string3, " ");
765                                         }
766                                         if(tutorialstage==14){
767                                                 sprintf (string, "There is now an imaginary enemy");
768                                                 sprintf (string2, "in the middle of the training area.");
769                                                 sprintf (string3, " ");
770                                         }
771                                         if(tutorialstage==15){
772                                                 if(attackkey==MAC_MOUSEBUTTON1)sprintf (string, "Click to attack when you are near an enemy.");
773                                                 else sprintf (string, "Press %s to attack when you are near an enemy.",KeyToChar(attackkey));
774                                                 sprintf (string2, "You can punch by standing still near an enemy and attacking.");
775                                                 sprintf (string3, " ");
776                                         }
777                                         if(tutorialstage==16){
778                                                 sprintf (string, "If you are close, you will perform a weak punch.");
779                                                 sprintf (string2, "The weak punch is excellent for starting attack combinations.");
780                                                 sprintf (string3, " ");
781                                         }
782                                         if(tutorialstage==17){
783                                                 sprintf (string, "Attacking while running results in a spin kick.");
784                                                 sprintf (string2, "This is one of your most powerful ground attacks.");
785                                                 sprintf (string3, " ");
786                                         }
787                                         if(tutorialstage==18){
788                                                 sprintf (string, "Sweep the enemy's legs out by attacking while crouched.");
789                                                 sprintf (string2, "This is a very fast attack, and easy to follow up.");
790                                                 sprintf (string3, " ");
791                                         }
792                                         if(tutorialstage==19){
793                                                 sprintf (string, "When an enemy is on the ground, you can deal some extra");
794                                                 sprintf (string2, "damage by running up and drop-kicking him.");
795                                                 sprintf (string3, "(Try knocking them down with a sweep first)");
796                                         }
797                                         if(tutorialstage==20){
798                                                 sprintf (string, "Your most powerful individual attack is the rabbit kick.");
799                                                 if(attackkey==MAC_MOUSEBUTTON1)sprintf (string2, "Run at the enemy while holding the mouse button, and press");
800                                                 else sprintf (string2, "Run at the enemy while holding %s, and press", KeyToChar(attackkey));
801                                                 sprintf (string3, "the jump key (%s) to attack.",KeyToChar(jumpkey));
802                                         }
803                                         if(tutorialstage==21){
804                                                 sprintf (string, "This attack is devastating if timed correctly.");
805                                                 sprintf (string2, "Even if timed incorrectly, it will knock the enemy over.");
806                                                 if(againbonus)sprintf (string3, "Try rabbit-kicking the imaginary enemy again.");
807                                                 else sprintf (string3, "Try rabbit-kicking the imaginary enemy.");
808                                         }
809                                         if(tutorialstage==22){
810                                                 sprintf (string, "If you sneak behind an enemy unnoticed, you can kill");
811                                                 sprintf (string2, "him instantly. Move close behind this enemy");
812                                                 sprintf (string3, "and attack.");
813                                         }
814                                         if(tutorialstage==23){
815                                                 sprintf (string, "Another important attack is the wall kick. When an enemy");
816                                                 sprintf (string2, "is near a wall, perform a walljump nearby and hold");
817                                                 sprintf (string3, "the attack key during impact with the wall.");
818                                         }
819                                         if(tutorialstage==24){
820                                                 sprintf (string, "You can tackle enemies by running at them animal-style");
821                                                 if(attackkey==MAC_MOUSEBUTTON1)sprintf (string2, "and pressing jump (%s) or attack(mouse button).",KeyToChar(jumpkey));
822                                                 else sprintf (string2, "and pressing jump (%s) or attack(%s).",KeyToChar(jumpkey),KeyToChar(attackkey));
823                                                 sprintf (string3, "This is especially useful when they are running away.");
824                                         }
825                                         if(tutorialstage==25){
826                                                 sprintf (string, "Dodge by pressing back and attack. Dodging is essential");
827                                                 sprintf (string2, "against enemies with swords or other long weapons.");
828                                                 sprintf (string3, " ");
829                                         }
830                                         if(tutorialstage==26){
831                                                 sprintf (string, "REVERSALS AND COUNTER-REVERSALS");
832                                                 sprintf (string2, " ");
833                                                 sprintf (string3, " ");
834                                         }
835                                         if(tutorialstage==27){
836                                                 sprintf (string, "The enemy can now reverse your attacks.");
837                                                 sprintf (string2, " ");
838                                                 sprintf (string3, " ");
839                                         }
840                                         if(tutorialstage==28){
841                                                 sprintf (string, "If you attack, you will notice that the enemy now sometimes");
842                                                 sprintf (string2, "catches your attack and uses it against you. Hold");
843                                                 sprintf (string3, "crouch (%s) after attacking to escape from reversals.",KeyToChar(crouchkey));
844                                         }
845                                         if(tutorialstage==29){
846                                                 sprintf (string, "Try escaping from two more reversals in a row.");
847                                                 sprintf (string2, " ");
848                                                 sprintf (string3, " ");
849                                         }
850                                         if(tutorialstage==30){
851                                                 sprintf (string, "Good!");
852                                                 sprintf (string2, " ");
853                                                 sprintf (string3, " ");
854                                         }
855                                         if(tutorialstage==31){
856                                                 sprintf (string, "To reverse an attack, you must tap crouch (%s) during the",KeyToChar(crouchkey));
857                                                 sprintf (string2, "enemy's attack. You must also be close to the enemy;");
858                                                 sprintf (string3, "this is especially important against armed opponents.");
859                                         }
860                                         if(tutorialstage==32){
861                                                 sprintf (string, "The enemy can attack in %d seconds.", (int)(tutorialmaxtime-tutorialstagetime));
862                                                 sprintf (string2, "This imaginary opponents attacks will be highlighted");
863                                                 sprintf (string3, "to make this easier.");
864                                         }
865                                         if(tutorialstage==33){
866                                                 sprintf (string, "Reverse three enemy attacks!");
867                                                 sprintf (string2, " ");
868                                                 sprintf (string3, " ");
869                                         }
870                                         if(tutorialstage==34){
871                                                 sprintf (string, "Reverse two more enemy attacks!");
872                                                 sprintf (string2, " ");
873                                                 sprintf (string3, " ");
874                                         }
875                                         if(tutorialstage==35){
876                                                 sprintf (string, "Reverse one more enemy attack!");
877                                                 sprintf (string2, " ");
878                                                 sprintf (string3, " ");
879                                         }
880                                         if(tutorialstage==36){
881                                                 sprintf (string, "Excellent!");
882                                                 sprintf (string2, " ");
883                                                 sprintf (string3, " ");
884                                         }
885                                         if(tutorialstage==37){
886                                                 sprintf (string, "Now spar with the enemy for %d more seconds.", (int)(tutorialmaxtime-tutorialstagetime));
887                                                 sprintf (string2, "Damage dealt: %d",(int)damagedealt);
888                                                 sprintf (string3, "Damage taken: %d.",(int)damagetaken);
889                                         }
890                                         if(tutorialstage==38){
891                                                 sprintf (string, "WEAPONS:");
892                                                 sprintf (string2, " ");
893                                                 sprintf (string3, " ");
894                                         }
895                                         if(tutorialstage==39){
896                                                 sprintf (string, "There is now an imaginary knife");
897                                                 sprintf (string2, "in the center of the training area.");
898                                                 sprintf (string3, " ");
899                                         }
900                                         if(tutorialstage==40){
901                                                 sprintf (string, "Stand, roll or handspring over the knife");
902                                                 sprintf (string2, "while pressing %s to pick it up.",KeyToChar(throwkey));
903                                                 sprintf (string3, "You can crouch and press the same key to drop it again.");
904                                         }
905                                         if(tutorialstage==41){
906                                                 sprintf (string, "You can equip and unequip weapons using the %s key.",KeyToChar(drawkey));
907                                                 sprintf (string2, "Sometimes it is best to keep them unequipped to");
908                                                 sprintf (string3, "prevent enemies from taking them. ");
909                                         }
910                                         if(tutorialstage==42){
911                                                 sprintf (string, "The knife is the smallest weapon and the least encumbering.");
912                                                 sprintf (string2, "You can equip or unequip it while standing, crouching,");
913                                                 sprintf (string3, "running or flipping.");
914                                         }
915                                         if(tutorialstage==43){
916                                                 sprintf (string, "You perform weapon attacks the same way as unarmed attacks,");
917                                                 sprintf (string2, "but sharp weapons cause permanent damage, instead of the");
918                                                 sprintf (string3, "temporary trauma from blunt weapons, fists and feet.");
919                                         }
920                                         if(tutorialstage==44){
921                                                 sprintf (string, "The enemy now has your knife!");
922                                                 sprintf (string2, "Please reverse two of his knife attacks.");
923                                                 sprintf (string3, " ");
924                                         }
925                                         if(tutorialstage==45){
926                                                 sprintf (string, "Please reverse one more of his knife attacks.");
927                                                 sprintf (string2, " ");
928                                                 sprintf (string3, " ");
929                                         }
930                                         if(tutorialstage==46){
931                                                 sprintf (string, "Now he has a sword!");
932                                                 sprintf (string2, "The sword has longer reach than your arms, so you");
933                                                 sprintf (string3, "must move close to reverse the sword slash.");
934                                         }
935                                         if(tutorialstage==47){
936                                                 sprintf (string, "Long weapons like the sword and staff are also useful for defense;");
937                                                 sprintf (string2, "you can parry enemy weapon attacks by pressing the attack key");
938                                                 sprintf (string3, "at the right time. Please try parrying the enemy's attacks!");
939                                         }
940                                         if(tutorialstage==48){
941                                                 sprintf (string, "The staff is like the sword, but has two main attacks.");
942                                                 sprintf (string2, "The standing smash is fast and effective, and the running");
943                                                 sprintf (string3, "spin smash is slower and more powerful.");
944                                         }
945                                         if(tutorialstage==49){
946                                                 sprintf (string, "When facing an enemy, you can throw the knife with %s.",KeyToChar(throwkey));
947                                                 sprintf (string2, "It is possible to throw the knife while flipping,");
948                                                 sprintf (string3, "but it is very inaccurate.");
949                                         }
950                                         if(tutorialstage==50){
951                                                 sprintf (string, "You now know everything you can learn from training.");
952                                                 sprintf (string2, "Everything else you must learn from experience!");
953                                                 sprintf (string3, " ");
954                                         }
955                                         if(tutorialstage==51){
956                                                 sprintf (string, "Walk out of the training area to return to the main menu.");
957                                                 sprintf (string2, " ");
958                                                 sprintf (string3, " ");
959                                         }
960
961                                         glColor4f(0,0,0,tutorialopac);
962                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string)*screenwidth/1024-4,screenheight/16-4+screenheight*4/5,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
963                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string2)*screenwidth/1024-4,screenheight/16-4+screenheight*4/5-20*screenwidth/1024,string2,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
964                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string3)*screenwidth/1024-4,screenheight/16-4+screenheight*4/5-40*screenwidth/1024,string3,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
965                                         glColor4f(1,1,1,tutorialopac);
966                                         text.glPrint(screenwidth/2-7.6*strlen(string)*screenwidth/1024,screenheight/16+screenheight*4/5,string,1,1.5*screenwidth/1024,screenwidth,screenheight);
967                                         text.glPrint(screenwidth/2-7.6*strlen(string2)*screenwidth/1024,screenheight/16+screenheight*4/5-20*screenwidth/1024,string2,1,1.5*screenwidth/1024,screenwidth,screenheight);
968                                         text.glPrint(screenwidth/2-7.6*strlen(string3)*screenwidth/1024,screenheight/16+screenheight*4/5-40*screenwidth/1024,string3,1,1.5*screenwidth/1024,screenwidth,screenheight);
969
970                                         sprintf (string, "Press 'tab' to skip to the next item.",KeyToChar(jumpkey));
971                                         sprintf (string2, "Press escape at any time to");
972                                         sprintf (string3, "pause or exit the tutorial.");
973
974                                         glColor4f(0,0,0,1);
975                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string)*screenwidth/1024*.8-4,0-4+screenheight*1/10,string,1,1.5*1.25*screenwidth/1024*.8,screenwidth,screenheight);
976                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string2)*screenwidth/1024*.8-4,0-4+screenheight*1/10-20*.8*screenwidth/1024,string2,1,1.5*1.25*screenwidth/1024*.8,screenwidth,screenheight);
977                                         text.glPrintOutline(screenwidth/2-7.6*strlen(string3)*screenwidth/1024*.8-4,0-4+screenheight*1/10-40*.8*screenwidth/1024,string3,1,1.5*1.25*screenwidth/1024*.8,screenwidth,screenheight);
978                                         glColor4f(0.5,0.5,0.5,1);
979                                         text.glPrint(screenwidth/2-7.6*strlen(string)*screenwidth/1024*.8,0+screenheight*1/10,string,1,1.5*screenwidth/1024*.8,screenwidth,screenheight);
980                                         text.glPrint(screenwidth/2-7.6*strlen(string2)*screenwidth/1024*.8,0+screenheight*1/10-20*.8*screenwidth/1024,string2,1,1.5*screenwidth/1024*.8,screenwidth,screenheight);
981                                         text.glPrint(screenwidth/2-7.6*strlen(string3)*screenwidth/1024*.8,0+screenheight*1/10-40*.8*screenwidth/1024,string3,1,1.5*screenwidth/1024*.8,screenwidth,screenheight);
982                                 }
983                                 //Hot spots     
984
985                                 if(numhotspots&&(bonustime>=1||bonus<=0||bonustime<0)&&!tutoriallevel){
986                                         int closest=-1;
987                                         float closestdist=-1;
988                                         float distance=0;
989                                         closest=currenthotspot;
990                                         for(i=0;i<numhotspots;i++){
991                                                 distance=findDistancefast(&player[0].coords,&hotspot[i]);
992                                                 if(closestdist==-1||distance<closestdist){
993                                                         if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i]&&((hotspottype[i]<=10&&hotspottype[i]>=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){
994                                                                 closestdist=distance;
995                                                                 closest=i;
996                                                         }
997                                                 }
998                                         }
999                                         if(closest!=-1)
1000                                                 currenthotspot=closest;
1001                                         if(currenthotspot!=-1){
1002                                                 if(hotspottype[closest]<=10){
1003                                                         if(findDistancefast(&player[0].coords,&hotspot[closest])<hotspotsize[closest])
1004                                                                 tutorialstagetime=0;
1005                                                         tutorialmaxtime=1;
1006                                                         tutorialopac=tutorialmaxtime-tutorialstagetime;
1007                                                         if(tutorialopac>1)tutorialopac=1;
1008                                                         if(tutorialopac<0)tutorialopac=0;
1009
1010                                                         sprintf (string, "%s", hotspottext[closest]);
1011
1012                                                         int lastline;
1013                                                         int line=0;
1014                                                         bool done=0;
1015                                                         lastline=0;
1016                                                         i=0;
1017                                                         while(!done){
1018                                                                 if(string[i]=='\n'||string[i]>'z'||string[i]<' '||string[i]=='\0'){
1019                                                                         glColor4f(0,0,0,tutorialopac);
1020                                                                         text.glPrintOutline(screenwidth/2-7.6*(i-lastline)*screenwidth/1024-4,screenheight/16-4+screenheight*4/5-20*screenwidth/1024*line,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight,lastline,i);
1021                                                                         glColor4f(1,1,1,tutorialopac);
1022                                                                         text.glPrint(screenwidth/2-7.6*(i-lastline)*screenwidth/1024,screenheight/16+screenheight*4/5-20*screenwidth/1024*line,string,1,1.5*screenwidth/1024,screenwidth,screenheight,lastline,i);
1023                                                                         lastline=i+1;
1024                                                                         line++;
1025                                                                         if(string[i]=='\0')done=1;
1026                                                                 }
1027                                                                 if(i>=255)done=1;
1028                                                                 i++;
1029                                                         }
1030                                                 }
1031                                                 else if (hotspottype[closest]>=20&&dialoguegonethrough[hotspottype[closest]-20]==0){
1032                                                         whichdialogue=hotspottype[closest]-20;
1033                                                         for(j=0;j<numdialogueboxes[whichdialogue];j++){
1034                                                                 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
1035                                                                 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
1036                                                                 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
1037                                                                 player[participantfocus[whichdialogue][j]].velocity=0;
1038                                                                 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
1039                                                                 player[participantfocus[whichdialogue][j]].targetframe=0;
1040                                                         }
1041                                                         directing=0;
1042                                                         indialogue=0;
1043                                                         dialoguegonethrough[whichdialogue]++;
1044                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
1045                                                                 static float gLoc[3];
1046                                                                 static float vel[3];
1047                                                                 gLoc[0]=player[participantfocus[whichdialogue][indialogue]].coords.x;
1048                                                                 gLoc[1]=player[participantfocus[whichdialogue][indialogue]].coords.y;
1049                                                                 gLoc[2]=player[participantfocus[whichdialogue][indialogue]].coords.z;
1050                                                                 vel[0]=0;
1051                                                                 vel[1]=0;
1052                                                                 vel[2]=0;
1053                                                                 int whichsoundplay;
1054                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
1055                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
1056                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
1057                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
1058                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
1059                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
1060                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
1061                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
1062                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
1063                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
1064                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
1065                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
1066                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
1067                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
1068                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
1069                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
1070                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
1071                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
1072                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
1073                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
1074                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
1075                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
1076                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
1077                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
1078                                                         }
1079                                                 }
1080                                         }
1081                                 }
1082
1083                                 if(indialogue!=-1&&!mainmenu){
1084                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1085                                         glDisable(GL_CULL_FACE);
1086                                         glDisable(GL_LIGHTING);
1087                                         glDisable(GL_TEXTURE_2D);
1088                                         glDepthMask(0);
1089                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1090                                         glPushMatrix();                                                                         // Store The Projection Matrix
1091                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1092                                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1093                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1094                                         glPushMatrix();                                                                         // Store The Modelview Matrix
1095                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1096                                         if(dialogueboxlocation[whichdialogue][indialogue]==1)glTranslatef(0,screenheight*3/4,0);
1097                                         glScalef(screenwidth,screenheight/4,1);
1098                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1099                                         glEnable(GL_BLEND);
1100
1101                                         glColor4f(dialogueboxcolor[whichdialogue][indialogue][0],dialogueboxcolor[whichdialogue][indialogue][1],dialogueboxcolor[whichdialogue][indialogue][2],0.7);
1102                                         glBegin(GL_QUADS);
1103                                         glVertex3f(0,           0,       0.0f);
1104                                         glVertex3f(1,   0,       0.0f);
1105                                         glVertex3f(1,   1, 0.0f);
1106                                         glVertex3f(0,   1, 0.0f);
1107                                         glEnd();
1108                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1109                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1110                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1111                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1112                                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1113                                         glEnable(GL_CULL_FACE);
1114                                         glDisable(GL_BLEND);
1115                                         glDepthMask(1);
1116                                         glEnable(GL_TEXTURE_2D);
1117
1118                                         tutorialopac=1;
1119
1120                                         float startx;
1121                                         float starty;
1122
1123                                         startx=screenwidth*1/5;
1124                                         if(dialogueboxlocation[whichdialogue][indialogue]==1)starty=screenheight/16+screenheight*4/5;
1125                                         if(dialogueboxlocation[whichdialogue][indialogue]==2)starty=screenheight*1/5-screenheight/16;
1126
1127 //                                      char tempname[64];
1128                                         char tempname[264];
1129                                         bool goodchar;
1130                                         int tempnum=0;
1131 //                                      for(i=0;i<64;i++){
1132                                         for(i=0;i<264;i++){
1133                                                 tempname[i]='\0';
1134                                         }
1135
1136                                         for(i=0;i<(int)strlen(dialoguename[whichdialogue][indialogue]);i++){
1137                                                 tempname[tempnum]=dialoguename[whichdialogue][indialogue][i];
1138                                                 goodchar=1;
1139                                                 if(dialoguename[whichdialogue][indialogue][i]=='#'||dialoguename[whichdialogue][indialogue][i]=='\0')goodchar=0;
1140                                                 //if(tempnum>2)if(tempname[tempnum-2]=='e'&&tempname[tempnum-1]=='r')goodchar=0;
1141                                                 //if(tempnum>2)if(tempname[tempnum]=='r'&&tempname[0]=='a')goodchar=0;
1142                                                 if(goodchar)tempnum++;
1143                                                 else tempname[tempnum]='\0';
1144                                         }
1145
1146                                         sprintf (string, "%s: ", tempname);
1147
1148                                         if(dialogueboxcolor[whichdialogue][indialogue][0]+dialogueboxcolor[whichdialogue][indialogue][1]+dialogueboxcolor[whichdialogue][indialogue][2]<1.5){
1149                                                 glColor4f(0,0,0,tutorialopac);
1150                                                 text.glPrintOutline(startx-2*7.6*strlen(string)*screenwidth/1024-4,starty-4,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
1151                                                 glColor4f(0.7,0.7,0.7,tutorialopac);
1152                                                 text.glPrint(startx-2*7.6*strlen(string)*screenwidth/1024,starty,string,1,1.5*screenwidth/1024,screenwidth,screenheight);
1153                                         }
1154                                         else
1155                                         {
1156                                                 glColor4f(0,0,0,tutorialopac);
1157                                                 text.glPrintOutline(startx-2*7.6*strlen(string)*screenwidth/1024-4,starty-4,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
1158
1159                                         }
1160
1161                                         tempnum=0;
1162                                         for(i=0;i<(int)strlen(dialoguetext[whichdialogue][indialogue])+1;i++){
1163                                                 tempname[tempnum]=dialoguetext[whichdialogue][indialogue][i];
1164                                                 if(dialoguetext[whichdialogue][indialogue][i]!='#')tempnum++;
1165                                         }
1166
1167
1168                                         sprintf (string, "%s", tempname);
1169
1170
1171                                         int lastline;
1172                                         int line=0;
1173                                         bool done=0;
1174                                         lastline=0;
1175                                         i=0;
1176                                         while(!done){
1177                                                 if(string[i]=='\n'||string[i]>'z'||string[i]<' '||string[i]=='\0'){
1178                                                         if(dialogueboxcolor[whichdialogue][indialogue][0]+dialogueboxcolor[whichdialogue][indialogue][1]+dialogueboxcolor[whichdialogue][indialogue][2]<1.5){
1179                                                                 glColor4f(0,0,0,tutorialopac);
1180                                                                 text.glPrintOutline(startx/*-7.6*(i-lastline)*screenwidth/1024*/-4,starty-4-20*screenwidth/1024*line,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight,lastline,i);
1181                                                                 glColor4f(1,1,1,tutorialopac);
1182                                                                 text.glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/,starty-20*screenwidth/1024*line,string,1,1.5*screenwidth/1024,screenwidth,screenheight,lastline,i);
1183                                                         }
1184                                                         else
1185                                                         {
1186                                                                 glColor4f(0,0,0,tutorialopac);
1187                                                                 text.glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/,starty-20*screenwidth/1024*line,string,1,1.5*screenwidth/1024,screenwidth,screenheight,lastline,i);
1188                                                         }
1189                                                         lastline=i+1;
1190                                                         line++;
1191                                                         if(string[i]=='\0')done=1;
1192                                                 }
1193                                                 if(i>=255)done=1;
1194                                                 i++;
1195                                         }
1196                                 }       
1197
1198                                 if(!tutoriallevel&&!winfreeze&&indialogue==-1&&!mainmenu){
1199                                         if(campaign){
1200                                                 if(!scoreadded)sprintf (string, "Score: %d", (int)accountcampaignscore[accountactive]+(int)bonustotal);//(int)bonustotal);
1201                                                 if(scoreadded)sprintf (string, "Score: %d", (int)accountcampaignscore[accountactive]);//(int)bonustotal);
1202                                         }
1203                                         if(!campaign)sprintf (string, "Score: %d", (int)bonustotal);
1204                                         glColor4f(0,0,0,1);
1205                                         text.glPrintOutline(1024/40-4,768/16-4+768*14/16,string,1,1.5*1.25,1024,768);
1206                                         glColor4f(1,0,0,1);
1207                                         text.glPrint(1024/40,768/16+768*14/16,string,1,1.5,1024,768);
1208                                 }
1209
1210                                 glColor4f(.5,.5,.5,1);
1211
1212
1213                                 if((texttoggle||editorenabled)&&debugmode&&!mainmenu){
1214                                         sprintf (string, "The framespersecond is %d.",(int)(fps));
1215                                         text.glPrint(10,30,string,0,.8,1024,768);
1216
1217                                         sprintf (string, "Name: %s", registrationname);
1218                                         text.glPrint(10,260,string,0,.8,1024,768);
1219
1220
1221                                         if(editorenabled)sprintf (string, "Map editor enabled.");
1222                                         if(!editorenabled)sprintf (string, "Map editor Disabled.");
1223                                         text.glPrint(10,60,string,0,.8,1024,768);
1224                                         if(editorenabled){
1225                                                 sprintf (string, "Object size: %f",editorsize);
1226                                                 text.glPrint(10,75,string,0,.8,1024,768);
1227                                                 if(editorrotation>=0)sprintf (string, "Object rotation: %f",editorrotation);
1228                                                 else sprintf (string, "Object rotation: Random");
1229                                                 text.glPrint(10,90,string,0,.8,1024,768);
1230                                                 if(editorrotation2>=0)sprintf (string, "Object rotation2: %f",editorrotation2);
1231                                                 else sprintf (string, "Object rotation2: Random");
1232                                                 text.glPrint(10,105,string,0,.8,1024,768);
1233                                                 sprintf (string, "Object type: %d",editortype);
1234                                                 text.glPrint(10,120,string,0,.8,1024,768);
1235                                                 if(editortype==boxtype)sprintf (string, "(box)");
1236                                                 if(editortype==treetrunktype)sprintf (string, "(tree)");
1237                                                 if(editortype==walltype)sprintf (string, "(wall)");
1238                                                 if(editortype==weirdtype)sprintf (string, "(weird)");
1239                                                 if(editortype==spiketype)sprintf (string, "(spike)");
1240                                                 if(editortype==rocktype)sprintf (string, "(rock)");
1241                                                 if(editortype==bushtype)sprintf (string, "(bush)");
1242                                                 if(editortype==tunneltype)sprintf (string, "(tunnel)");
1243                                                 if(editortype==chimneytype)sprintf (string, "(chimney)");
1244                                                 if(editortype==platformtype)sprintf (string, "(platform)");
1245                                                 if(editortype==cooltype)sprintf (string, "(cool)");
1246                                                 if(editortype==firetype)sprintf (string, "(fire)");
1247                                                 text.glPrint(130,120,string,0,.8,1024,768);
1248
1249                                                 sprintf (string, "Numplayers: %d",numplayers);
1250                                                 text.glPrint(10,155,string,0,.8,1024,768);
1251                                                 sprintf (string, "Player %d: numwaypoints: %d",numplayers,player[numplayers-1].numwaypoints);
1252                                                 text.glPrint(10,140,string,0,.8,1024,768);
1253                                         }
1254                                         /*sprintf (string, "Coords are: %f %f %f",player[0].coords.x,player[0].coords.y,player[0].coords.z);
1255                                         text.glPrint(10,200,string,0,.8,1024,768);*/
1256                                         sprintf (string, "Difficulty: %d",difficulty);
1257                                         text.glPrint(10,240,string,0,.8,1024,768);
1258                                         /*
1259                                         sprintf (string, "lasthotspot: %d",hotspottype[numhotspots-1]);
1260                                         text.glPrint(10,240,string,0,.8,1024,768);
1261                                         sprintf (string, "killhotspot: %d",killhotspot);
1262                                         text.glPrint(10,220,string,0,.8,1024,768);
1263                                         sprintf (string, "winhotspot: %d",winhotspot);
1264                                         text.glPrint(10,200,string,0,.8,1024,768);*/
1265
1266                                 }
1267                 }
1268
1269                 if(drawmode==glowmode){
1270                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1271                         glDisable(GL_CULL_FACE);
1272                         glDisable(GL_LIGHTING);
1273                         glDisable(GL_TEXTURE_2D);
1274                         glDepthMask(0);
1275                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1276                         glPushMatrix();                                                                         // Store The Projection Matrix
1277                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1278                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1279                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1280                         glPushMatrix();                                                                         // Store The Modelview Matrix
1281                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1282                         glScalef(screenwidth,screenheight,1);
1283                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1284                         glEnable(GL_BLEND);
1285                         glColor4f(0,0,0,.5);
1286                         glBegin(GL_QUADS);
1287                         glVertex3f(0,           0,       0.0f);
1288                         glVertex3f(256, 0,       0.0f);
1289                         glVertex3f(256, 256, 0.0f);
1290                         glVertex3f(0,   256, 0.0f);
1291                         glEnd();
1292                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1293                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1294                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1295                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1296                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1297                         glEnable(GL_CULL_FACE);
1298                         glDisable(GL_BLEND);
1299                         glDepthMask(1);
1300                 }
1301
1302                 if((((blackout&&damageeffects)||(player[0].bloodloss>0&&damageeffects&&player[0].blooddimamount>0)||player[0].dead)&&!cameramode)||console){
1303                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1304                         glDisable(GL_CULL_FACE);
1305                         glDisable(GL_LIGHTING);
1306                         glDisable(GL_TEXTURE_2D);
1307                         glDepthMask(0);
1308                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1309                         glPushMatrix();                                                                         // Store The Projection Matrix
1310                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1311                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1312                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1313                         glPushMatrix();                                                                         // Store The Modelview Matrix
1314                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1315                         glScalef(screenwidth,screenheight,1);
1316                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1317                         glEnable(GL_BLEND);
1318                         if(player[0].dead)blackout+=multiplier*3;
1319                         if(player[0].dead==1)blackout=.4f;
1320                         if(player[0].dead==2&&blackout>.6)blackout=.6;
1321                         glColor4f(0,0,0,blackout);
1322                         if(!player[0].dead){
1323                                 if((player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5))*.3<.3){
1324                                         glColor4f(0,0,0,player[0].blooddimamount*player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5)*.3);
1325                                         blackout=player[0].blooddimamount*player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5)*.3;
1326                                 }
1327                                 else {
1328                                         glColor4f(0,0,0,player[0].blooddimamount*.3);
1329                                         blackout=player[0].blooddimamount*.3;
1330                                 }
1331                         }
1332                         if(console)glColor4f(.7,0,0,.2);
1333                         glBegin(GL_QUADS);
1334                         glVertex3f(0,           0,       0.0f);
1335                         glVertex3f(256, 0,       0.0f);
1336                         glVertex3f(256, 256, 0.0f);
1337                         glVertex3f(0,   256, 0.0f);
1338                         glEnd();
1339                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1340                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1341                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1342                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1343                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1344                         glEnable(GL_CULL_FACE);
1345                         glDisable(GL_BLEND);
1346                         glDepthMask(1);
1347                 }
1348
1349                 if(flashamount>0&&damageeffects){
1350                         if(flashamount>1)flashamount=1;
1351                         if(flashdelay<=0)flashamount-=multiplier;
1352                         flashdelay--;
1353                         if(flashamount<0)flashamount=0;
1354                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1355                         glDisable(GL_CULL_FACE);
1356                         glDisable(GL_LIGHTING);
1357                         glDepthMask(0);
1358                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1359                         glPushMatrix();                                                                         // Store The Projection Matrix
1360                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1361                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1362                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1363                         glPushMatrix();                                                                         // Store The Modelview Matrix
1364                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1365                         glScalef(screenwidth,screenheight,1);
1366                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1367                         glEnable(GL_BLEND);
1368                         glColor4f(flashr,flashg,flashb,flashamount);
1369                         glBegin(GL_QUADS);
1370                         glVertex3f(0,           0,       0.0f);
1371                         glVertex3f(256, 0,       0.0f);
1372                         glVertex3f(256, 256, 0.0f);
1373                         glVertex3f(0,   256, 0.0f);
1374                         glEnd();
1375                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1376                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1377                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1378                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1379                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1380                         glEnable(GL_CULL_FACE);
1381                         glDisable(GL_BLEND);
1382                         glDepthMask(1);
1383                 }       
1384
1385                 if(!console){
1386                         displaytime[0]=0;
1387                         glEnable(GL_TEXTURE_2D);
1388                         glColor4f(1,1,1,1);
1389                         if(chatting){
1390                                 sprintf (string, " ]");
1391                                 text.glPrint(10,30+screenheight-330,string,0,1,screenwidth,screenheight);
1392                                 if(displayblink){
1393                                         sprintf (string, "_");
1394                                         text.glPrint(30+(float)(displayselected)*10,30+(screenheight-330),string,0,1,screenwidth,screenheight);
1395                                 }
1396                         }
1397                         for(i=0;i<15;i++){
1398                                 if((i!=0||chatting)&&displaytime[i]<4)
1399                                         for(j=0;j<displaychars[i];j++){
1400                                                 glColor4f(1,1,1,4-displaytime[i]);
1401                                                 if(j<displaychars[i]){
1402                                                         sprintf (string, "%c",displaytext[i][j]);
1403                                                         text.glPrint(30+j*10,30+i*20+(screenheight-330),string,0,1,screenwidth,screenheight);
1404                                                 }
1405                                         }
1406                         }
1407                 }
1408
1409                 if(minimap&&indialogue==-1){
1410                         float mapviewdist;
1411                         mapviewdist=20000;
1412
1413                         glDisable(GL_DEPTH_TEST);
1414                         glColor3f (1.0, 1.0, 1.0); // no coloring
1415
1416                         glEnable(GL_TEXTURE_2D);
1417                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1418                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1419                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1420                         glDisable(GL_CULL_FACE);
1421                         glDisable(GL_LIGHTING);
1422                         glDepthMask(0);
1423                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1424                         glPushMatrix();                                                                         // Store The Projection Matrix
1425                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1426                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1427                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1428                         glPushMatrix();                                                                         // Store The Modelview Matrix
1429                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1430                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1431                         glTranslatef(1.75,.25,0);
1432                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1433                         glEnable(GL_BLEND);
1434                         glColor4f(1,1,1,1);
1435                         glPushMatrix();
1436                         float opac;
1437                         opac=.7;
1438                         XYZ center;
1439                         float radius;
1440                         float distcheck;
1441                         center=0;
1442                         int numliveplayers=0;
1443                         for(i=0;i<numplayers;i++){
1444                                 if(!player[i].dead)numliveplayers++;
1445                         }
1446
1447                         int numadd;
1448                         numadd=0;
1449
1450                         for(i=0;i<objects.numobjects;i++){
1451                                 if(objects.type[i]==treetrunktype||objects.type[i]==boxtype){
1452                                         center+=objects.position[i];    
1453                                         numadd++;
1454                                 }
1455                         }
1456                         for(i=0;i<numplayers;i++){
1457                                 if(!player[i].dead)center+=player[i].coords;    
1458                         }
1459                         center/=numadd+numliveplayers;
1460
1461                         center=player[0].coords;
1462
1463                         float maxdistance=0;
1464                         float tempdist;
1465                         int whichclosest;
1466                         for(i=0;i<objects.numobjects;i++){
1467                                 tempdist=findDistancefast(&center,&objects.position[i]);
1468                                 if(tempdist>maxdistance){
1469                                         whichclosest=i;
1470                                         maxdistance=tempdist;
1471                                 }
1472                         }
1473                         for(i=0;i<numplayers;i++){
1474                                 if(!player[i].dead){
1475                                         tempdist=findDistancefast(&center,&player[i].coords);
1476                                         if(tempdist>maxdistance){
1477                                                 whichclosest=i;
1478                                                 maxdistance=tempdist;
1479                                         }
1480                                 }
1481                         }
1482                         radius=fast_sqrt(maxdistance);
1483
1484                         radius=110;
1485
1486                         glScalef(.25/radius*256*terrain.scale*.4,.25/radius*256*terrain.scale*.4,1);
1487                         glPushMatrix();
1488                         glScalef(1/(1/radius*256*terrain.scale*.4),1/(1/radius*256*terrain.scale*.4),1);
1489                         /*float startx,starty,endx,endy;
1490                         glBegin(GL_QUADS);
1491                         glTexCoord2f(1-(center.x-radius)/terrain.scale/256,(center.z-radius)/terrain.scale/256);
1492                         glVertex3f(-1,          -1,      0.0f);
1493                         glTexCoord2f(1-(center.x+radius)/terrain.scale/256,(center.z-radius)/terrain.scale/256);
1494                         glVertex3f(1,   -1,      0.0f);
1495                         glTexCoord2f(1-(center.x+radius)/terrain.scale/256,(center.z+radius)/terrain.scale/256);
1496                         glVertex3f(1,   1, 0.0f);
1497                         glTexCoord2f(1-(center.x-radius)/terrain.scale/256,(center.z+radius)/terrain.scale/256);
1498                         glVertex3f(-1,  1, 0.0f);
1499                         glEnd();*/
1500                         glPopMatrix();
1501                         glRotatef(player[0].lookrotation*-1+180,0,0,1);
1502                         glTranslatef(-(center.x/terrain.scale/256*-2+1),(center.z/terrain.scale/256*-2+1),0);
1503                         for(i=0;i<objects.numobjects;i++){
1504                                 if(objects.type[i]==treetrunktype){
1505                                         distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
1506                                         if(distcheck<mapviewdist){
1507                                                 glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
1508                                                 glColor4f(0,.3,0,opac*(1-distcheck/mapviewdist));
1509                                                 glPushMatrix();
1510                                                 glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
1511                                                 glRotatef(objects.rotation[i],0,0,1);
1512                                                 glScalef(.003,.003,.003);
1513                                                 glBegin(GL_QUADS);
1514                                                 glTexCoord2f(0,0);
1515                                                 glVertex3f(-1,          -1,      0.0f);
1516                                                 glTexCoord2f(1,0);
1517                                                 glVertex3f(1,   -1,      0.0f);
1518                                                 glTexCoord2f(1,1);
1519                                                 glVertex3f(1,   1, 0.0f);
1520                                                 glTexCoord2f(0,1);
1521                                                 glVertex3f(-1,  1, 0.0f);
1522                                                 glEnd();
1523                                                 glPopMatrix();
1524                                         }
1525                                 }
1526                                 if(objects.type[i]==boxtype){
1527                                         distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
1528                                         if(distcheck<mapviewdist){
1529                                                 glBindTexture( GL_TEXTURE_2D, Mapboxtexture);
1530                                                 glColor4f(.4,.4,.4,opac*(1-distcheck/mapviewdist));
1531                                                 glPushMatrix();
1532                                                 glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
1533                                                 glRotatef(objects.rotation[i],0,0,1);
1534                                                 glScalef(.01*objects.scale[i],.01*objects.scale[i],.01*objects.scale[i]);
1535                                                 glBegin(GL_QUADS);
1536                                                 glTexCoord2f(0,0);
1537                                                 glVertex3f(-1,          -1,      0.0f);
1538                                                 glTexCoord2f(1,0);
1539                                                 glVertex3f(1,   -1,      0.0f);
1540                                                 glTexCoord2f(1,1);
1541                                                 glVertex3f(1,   1, 0.0f);
1542                                                 glTexCoord2f(0,1);
1543                                                 glVertex3f(-1,  1, 0.0f);
1544                                                 glEnd();
1545                                                 glPopMatrix();
1546                                         }
1547                                 }
1548                         }
1549                         if(editorenabled){
1550                                 glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
1551                                 for(i=0;i<numboundaries;i++){
1552                                         glColor4f(0,0,0,opac/3);
1553                                         glPushMatrix();
1554                                         glTranslatef(boundary[i].x/terrain.scale/256*-2+1,boundary[i].z/terrain.scale/256*2-1,0);
1555                                         glScalef(.002,.002,.002);
1556                                         glBegin(GL_QUADS);
1557                                         glTexCoord2f(0,0);
1558                                         glVertex3f(-1,          -1,      0.0f);
1559                                         glTexCoord2f(1,0);
1560                                         glVertex3f(1,   -1,      0.0f);
1561                                         glTexCoord2f(1,1);
1562                                         glVertex3f(1,   1, 0.0f);
1563                                         glTexCoord2f(0,1);
1564                                         glVertex3f(-1,  1, 0.0f);
1565                                         glEnd();
1566                                         glPopMatrix();
1567                                 }
1568                         }
1569                         for(i=0;i<numplayers;i++){
1570                                 distcheck=findDistancefast(&player[0].coords,&player[i].coords);
1571                                 if(distcheck<mapviewdist){
1572                                         glPushMatrix();
1573                                         glBindTexture( GL_TEXTURE_2D, Maparrowtexture);
1574                                         if(i==0)glColor4f(1,1,1,opac);
1575                                         else if(player[i].dead==2||player[i].howactive>typesleeping)glColor4f(0,0,0,opac*(1-distcheck/mapviewdist));
1576                                         else if(player[i].dead)glColor4f(.3,.3,.3,opac*(1-distcheck/mapviewdist));
1577                                         else if(player[i].aitype==attacktypecutoff)glColor4f(1,0,0,opac*(1-distcheck/mapviewdist));
1578                                         else if(player[i].aitype==passivetype)glColor4f(0,1,0,opac*(1-distcheck/mapviewdist));
1579                                         else glColor4f(1,1,0,1);
1580                                         glTranslatef(player[i].coords.x/terrain.scale/256*-2+1,player[i].coords.z/terrain.scale/256*2-1,0);
1581                                         glRotatef(player[i].rotation+180,0,0,1);
1582                                         glScalef(.005,.005,.005);
1583                                         glBegin(GL_QUADS);
1584                                         glTexCoord2f(0,0);
1585                                         glVertex3f(-1,          -1,      0.0f);
1586                                         glTexCoord2f(1,0);
1587                                         glVertex3f(1,   -1,      0.0f);
1588                                         glTexCoord2f(1,1);
1589                                         glVertex3f(1,   1, 0.0f);
1590                                         glTexCoord2f(0,1);
1591                                         glVertex3f(-1,  1, 0.0f);
1592                                         glEnd();
1593                                         /*glBegin(GL_TRIANGLES);
1594                                         glTexCoord2f(0,0);
1595                                         glVertex3f(-1,          -1,      0.0f);
1596                                         glTexCoord2f(1,0);
1597                                         glVertex3f(1,   -1,      0.0f);
1598                                         glTexCoord2f(1,1);
1599                                         glVertex3f(0,   1, 0.0f);
1600                                         glEnd();*/
1601                                         glPopMatrix();
1602                                 }
1603                         }
1604                         /*glBegin(GL_QUADS);
1605                         glTexCoord2f(0,0);
1606                         glVertex3f(-1,          -1,      0.0f);
1607                         glTexCoord2f(1,0);
1608                         glVertex3f(1,   -1,      0.0f);
1609                         glTexCoord2f(1,1);
1610                         glVertex3f(1,   1, 0.0f);
1611                         glTexCoord2f(0,1);
1612                         glVertex3f(-1,  1, 0.0f);
1613                         glEnd();*/
1614                         glPopMatrix();
1615                         glDisable(GL_TEXTURE_2D);
1616                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1617                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1618                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1619                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1620                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1621                         glEnable(GL_CULL_FACE);
1622                         glDisable(GL_BLEND);
1623                         glDepthMask(1);
1624                 }
1625
1626                 /*if(loading){
1627                 loading=2;
1628                 drawmode=normalmode;
1629                 }*/
1630
1631
1632                 if(loading&&!stealthloading&&(!campaign||player[0].dead)){
1633                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1634                         glDisable(GL_CULL_FACE);
1635                         glDisable(GL_LIGHTING);
1636                         glDisable(GL_TEXTURE_2D);
1637                         glDepthMask(0);
1638                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1639                         glPushMatrix();                                                                         // Store The Projection Matrix
1640                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1641                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1642                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1643                         glPushMatrix();                                                                         // Store The Modelview Matrix
1644                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1645                         glScalef(screenwidth,screenheight,1);
1646                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1647                         glEnable(GL_BLEND);
1648                         glColor4f(0,0,0,.7);
1649                         glBegin(GL_QUADS);
1650                         glVertex3f(0,           0,       0.0f);
1651                         glVertex3f(256, 0,       0.0f);
1652                         glVertex3f(256, 256, 0.0f);
1653                         glVertex3f(0,   256, 0.0f);
1654                         glEnd();
1655                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1656                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1657                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1658                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1659                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1660                         glEnable(GL_CULL_FACE);
1661                         glDisable(GL_BLEND);
1662                         glDepthMask(1);
1663
1664                         //logo
1665                         glDisable(GL_DEPTH_TEST);
1666                         glColor3f (1.0, 1.0, 1.0); // no coloring
1667
1668                         glEnable(GL_TEXTURE_2D);
1669                         /*glBindTexture( GL_TEXTURE_2D, logotexture);
1670                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1671                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1672                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1673                         glDisable(GL_CULL_FACE);
1674                         glDisable(GL_LIGHTING);
1675                         glDepthMask(0);
1676                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1677                         glPushMatrix();                                                                         // Store The Projection Matrix
1678                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1679                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1680                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1681                         glPushMatrix();                                                                         // Store The Modelview Matrix
1682                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1683                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1684                         glTranslatef(1.8,1.25,0);
1685                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1686                         glEnable(GL_BLEND);
1687                         glColor4f(1,1,1,1);
1688                         glPushMatrix();
1689                         glScalef(.25,.25,.25);
1690                         glBegin(GL_QUADS);
1691                         glTexCoord2f(0,0);
1692                         glVertex3f(-1,          -1,      0.0f);
1693                         glTexCoord2f(1,0);
1694                         glVertex3f(1,   -1,      0.0f);
1695                         glTexCoord2f(1,1);
1696                         glVertex3f(1,   1, 0.0f);
1697                         glTexCoord2f(0,1);
1698                         glVertex3f(-1,  1, 0.0f);
1699                         glEnd();
1700                         glPopMatrix();
1701                         glDisable(GL_TEXTURE_2D);
1702                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1703                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1704                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1705                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1706                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1707                         glEnable(GL_CULL_FACE);
1708                         glDisable(GL_BLEND);
1709                         glDepthMask(1);*/
1710
1711                         //Minimap
1712
1713                         if(loading!=4){                         
1714                                 glEnable(GL_TEXTURE_2D);
1715                                 glColor4f(1,1,1,1);
1716                                 sprintf (string, "Loading...");
1717                                 text.glPrint(1024/2-90,768/2,string,1,2,1024,768);
1718                         }
1719                         loading=2;
1720                         //if(ismotionblur)drawmode=motionblurmode;
1721                         drawmode=normalmode;
1722                 }
1723
1724                 if(winfreeze&&!campaign){
1725                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1726                         glDisable(GL_CULL_FACE);
1727                         glDisable(GL_LIGHTING);
1728                         glDisable(GL_TEXTURE_2D);
1729                         glDepthMask(0);
1730                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1731                         glPushMatrix();                                                                         // Store The Projection Matrix
1732                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1733                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1734                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1735                         glPushMatrix();                                                                         // Store The Modelview Matrix
1736                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1737                         glScalef(screenwidth,screenheight,1);
1738                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1739                         glEnable(GL_BLEND);
1740                         glColor4f(0,0,0,.4);
1741                         glBegin(GL_QUADS);
1742                         glVertex3f(0,           0,       0.0f);
1743                         glVertex3f(256, 0,       0.0f);
1744                         glVertex3f(256, 256, 0.0f);
1745                         glVertex3f(0,   256, 0.0f);
1746                         glEnd();
1747                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1748                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1749                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1750                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1751                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1752                         glEnable(GL_CULL_FACE);
1753                         glDisable(GL_BLEND);
1754                         glDepthMask(1);
1755
1756                         //logo
1757                         glDisable(GL_DEPTH_TEST);
1758                         glColor3f (1.0, 1.0, 1.0); // no coloring
1759
1760                         glEnable(GL_TEXTURE_2D);
1761                         /*glBindTexture( GL_TEXTURE_2D, logotexture);
1762                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1763                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1764                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1765                         glDisable(GL_CULL_FACE);
1766                         glDisable(GL_LIGHTING);
1767                         glDepthMask(0);
1768                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1769                         glPushMatrix();                                                                         // Store The Projection Matrix
1770                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1771                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1772                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1773                         glPushMatrix();                                                                         // Store The Modelview Matrix
1774                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1775                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1776                         glTranslatef(1.8,1.25,0);
1777                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1778                         glEnable(GL_BLEND);
1779                         glColor4f(1,1,1,1);
1780                         glPushMatrix();
1781                         glScalef(.25,.25,.25);
1782                         glBegin(GL_QUADS);
1783                         glTexCoord2f(0,0);
1784                         glVertex3f(-1,          -1,      0.0f);
1785                         glTexCoord2f(1,0);
1786                         glVertex3f(1,   -1,      0.0f);
1787                         glTexCoord2f(1,1);
1788                         glVertex3f(1,   1, 0.0f);
1789                         glTexCoord2f(0,1);
1790                         glVertex3f(-1,  1, 0.0f);
1791                         glEnd();
1792                         glPopMatrix();
1793                         glDisable(GL_TEXTURE_2D);
1794                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1795                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1796                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1797                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1798                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1799                         glEnable(GL_CULL_FACE);
1800                         glDisable(GL_BLEND);
1801                         glDepthMask(1);*/
1802
1803                         //Awards
1804                         int numawards;
1805                         int awards[30];
1806                         numawards=0;
1807
1808                         if(damagetaken==0&&player[0].bloodloss==0){
1809                                 awards[numawards]=awardflawless;
1810                                 numawards++;
1811                         }
1812                         bool alldead;
1813                         alldead=1;
1814                         if(numplayers>1)
1815                                 for(i=1;i<numplayers;i++){              
1816                                         if(player[i].dead!=2)alldead=0;
1817                                 }
1818                                 if(alldead){
1819                                         awards[numawards]=awardalldead;
1820                                         numawards++;
1821                                 }
1822                                 alldead=1;
1823                                 if(numplayers>1)
1824                                         for(i=1;i<numplayers;i++){              
1825                                                 if(player[i].dead!=1)alldead=0;
1826                                         }
1827                                         if(alldead){
1828                                                 awards[numawards]=awardnodead;
1829                                                 numawards++;
1830                                         }
1831                                         if(numresponded==0&&!numthrowkill){
1832                                                 awards[numawards]=awardstealth;
1833                                                 numawards++;
1834                                         }
1835                                         if(numattacks==numstaffattack&&numattacks>0){
1836                                                 awards[numawards]=awardbojutsu;
1837                                                 numawards++;
1838                                         }
1839                                         if(numattacks==numswordattack&&numattacks>0){
1840                                                 awards[numawards]=awardswordsman;
1841                                                 numawards++;
1842                                         }
1843                                         if(numattacks==numknifeattack&&numattacks>0){
1844                                                 awards[numawards]=awardknifefighter;
1845                                                 numawards++;
1846                                         }
1847                                         if(numattacks==numunarmedattack&&numthrowkill==0&&weapons.numweapons>0){
1848                                                 awards[numawards]=awardkungfu;
1849                                                 numawards++;
1850                                         }
1851                                         if(numescaped>0){
1852                                                 awards[numawards]=awardevasion;
1853                                                 numawards++;
1854                                         }
1855                                         if(numflipfail==0&&numflipped+numwallflipped*2>20){
1856                                                 awards[numawards]=awardacrobat;
1857                                                 numawards++;
1858                                         }
1859                                         if(numthrowkill==numplayers-1){
1860                                                 awards[numawards]=awardlongrange;
1861                                                 numawards++;
1862                                         }
1863                                         alldead=1;
1864                                         if(numplayers>1)
1865                                                 for(i=1;i<numplayers;i++){              
1866                                                         if(player[i].dead!=2)alldead=0;
1867                                                 }
1868                                                 if(numafterkill>0&&alldead){
1869                                                         awards[numawards]=awardbrutal;
1870                                                         numawards++;
1871                                                 }
1872                                                 if(numreversals>((float)numattacks)*.8&&numreversals>3){
1873                                                         awards[numawards]=awardaikido;
1874                                                         numawards++;
1875                                                 }
1876                                                 if(maxalarmed==1&&numplayers>2){
1877                                                         awards[numawards]=awardstrategy;
1878                                                         numawards++;
1879                                                 }
1880                                                 if(numflipfail>3){
1881                                                         awards[numawards]=awardklutz;
1882                                                         numawards++;
1883                                                 }
1884
1885
1886                                                 //Win Screen Won Victory
1887
1888                                                 glEnable(GL_TEXTURE_2D);
1889                                                 glColor4f(1,1,1,1);
1890                                                 sprintf (string, "Level Cleared!");
1891                                                 text.glPrintOutlined(1024/2-strlen(string)*10,768*7/8,string,1,2,1024,768);
1892
1893                                                 sprintf (string, "Score:     %d",(int)(bonustotal-startbonustotal));
1894                                                 text.glPrintOutlined(1024/30,768*6/8,string,1,2,1024,768);
1895
1896                                                 if(!campaign)sprintf (string, "Press Escape to return to menu or Space to continue");
1897                                                 if(campaign)sprintf (string, "Press Escape or Space to continue");
1898                                                 text.glPrintOutlined(640/2-strlen(string)*5,480*1/16,string,1,1,640,480);
1899
1900                                                 char temp[255];
1901
1902                                                 for(i=0;i<255;i++)string[i]='\0';
1903                                                 sprintf (temp, "Time:      %d:",(int)(((int)leveltime-(int)(leveltime)%60)/60));
1904                                                 strcat(string,temp);
1905                                                 if((int)(leveltime)%60<10)strcat(string,"0");
1906                                                 sprintf (temp, "%d",(int)(leveltime)%60);
1907                                                 strcat(string,temp);
1908                                                 text.glPrintOutlined(1024/30,768*6/8-40,string,1,2,1024,768);
1909
1910                                                 for(i=0;i<numawards;i++){
1911                                                         if(i<6){
1912                                                                 if(awards[i]==awardklutz)sprintf (string, "Suicidal");
1913                                                                 if(awards[i]==awardflawless)sprintf (string, "Flawless!");
1914                                                                 if(awards[i]==awardalldead)sprintf (string, "Take no prisoners");
1915                                                                 if(awards[i]==awardnodead)sprintf (string, "Merciful");
1916                                                                 if(awards[i]==awardstealth)sprintf (string, "One with the shadows!");
1917                                                                 if(awards[i]==awardswordsman)sprintf (string, "Swordsman");
1918                                                                 if(awards[i]==awardkungfu)sprintf (string, "Unarmed!");
1919                                                                 if(awards[i]==awardknifefighter)sprintf (string, "Knife fighter");
1920                                                                 if(awards[i]==awardcoward)sprintf (string, "Coward");
1921                                                                 if(awards[i]==awardevasion)sprintf (string, "Escape artist");
1922                                                                 if(awards[i]==awardacrobat)sprintf (string, "Gymnast");
1923                                                                 if(awards[i]==awardlongrange)sprintf (string, "Blade slinger");
1924                                                                 if(awards[i]==awardbrutal)sprintf (string, "Brutal");
1925                                                                 if(awards[i]==awardhyper)sprintf (string, "Hyper");
1926                                                                 if(awards[i]==awardaikido)sprintf (string, "Aikido master!");
1927                                                                 if(awards[i]==awardrambo)sprintf (string, "Rambo");
1928                                                                 if(awards[i]==awardfast)sprintf (string, "Fast");
1929                                                                 if(awards[i]==awardrealfast)sprintf (string, "Real fast");
1930                                                                 if(awards[i]==awarddamnfast)sprintf (string, "Damn fast");
1931                                                                 if(awards[i]==awardstrategy)sprintf (string, "Divide and conquer");
1932                                                                 if(awards[i]==awardbojutsu)sprintf (string, "Bojutsu");
1933                                                                 text.glPrintOutlined(1024/30,768*6/8-90-40*i,string,1,2,1024,768);
1934                                                         }
1935                                                 }
1936
1937                                                 //drawmode=normalmode;
1938                 }
1939
1940                 if(drawmode!=normalmode){
1941                         glEnable(GL_TEXTURE_2D);
1942                         glFinish();
1943                         if(!drawtoggle||drawmode!=realmotionblurmode||(drawtoggle==2||change==1)){
1944                                 if(screentexture){
1945
1946                                         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
1947                                         GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
1948                                         glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
1949                                         //glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_SUBTRACT);
1950                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
1951                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
1952                                         glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
1953
1954                                         glBindTexture( GL_TEXTURE_2D, screentexture);
1955                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
1956                                 }
1957                         }
1958                         if((drawtoggle||change==1)&&drawmode==realmotionblurmode){
1959                                 if(screentexture2){
1960                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
1961                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
1962                                 }
1963                                 if(!screentexture2){
1964                                         glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1965
1966                                         glGenTextures( 1, &screentexture2 );
1967                                         glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1968
1969                                         glEnable(GL_TEXTURE_2D);
1970                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
1971                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1972                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1973
1974                                         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);                
1975                                 }
1976                         }
1977                         //glFlush();
1978                 }
1979
1980                 glClear(GL_DEPTH_BUFFER_BIT);
1981                 ReSizeGLScene(90,.1f);
1982                 glViewport(0,0,screenwidth,screenheight);       
1983
1984                 if(drawmode!=normalmode){
1985                         glDisable(GL_DEPTH_TEST);
1986                         if(drawmode==motionblurmode){
1987                                 glDrawBuffer(GL_FRONT);
1988                                 glReadBuffer(GL_BACK);
1989                                 //myassert(glGetError() == GL_NO_ERROR);
1990                                 //glFlush();
1991                         }
1992                         glColor3f (1.0, 1.0, 1.0); // no coloring
1993
1994                         glEnable(GL_TEXTURE_2D);
1995                         glBindTexture( GL_TEXTURE_2D, screentexture);
1996                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1997                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1998                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1999                         glDisable(GL_CULL_FACE);
2000                         glDisable(GL_LIGHTING);
2001                         glDepthMask(0);
2002                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2003                         glPushMatrix();                                                                         // Store The Projection Matrix
2004                         glLoadIdentity();                                                                       // Reset The Projection Matrix
2005                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2006                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2007                         glPushMatrix();                                                                         // Store The Modelview Matrix
2008                         glLoadIdentity();                                                               // Reset The Modelview Matrix
2009                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
2010                         glTranslatef(1,1,0);
2011                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2012                         glEnable(GL_BLEND);
2013                         if(drawmode==motionblurmode){
2014                                 if(motionbluramount<.2)motionbluramount=.2;
2015                                 //glColor4f(1,1,1,fast_sqrt(multiplier)*2.9*motionbluramount);
2016                                 glColor4f(1,1,1,motionbluramount);
2017                                 glPushMatrix();
2018                                 glBegin(GL_QUADS);
2019                                 glTexCoord2f(0,0);
2020                                 glVertex3f(-1,          -1,      0.0f);
2021                                 glTexCoord2f(texcoordwidth,0);
2022                                 glVertex3f(1,   -1,      0.0f);
2023                                 glTexCoord2f(texcoordwidth,texcoordheight);
2024                                 glVertex3f(1,   1, 0.0f);
2025                                 glTexCoord2f(0,texcoordheight);
2026                                 glVertex3f(-1,  1, 0.0f);
2027                                 glEnd();
2028                                 glPopMatrix();
2029                         }
2030                         if(drawmode==realmotionblurmode){
2031                                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2032                                 glClear(GL_COLOR_BUFFER_BIT);
2033                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2034                                 glBindTexture( GL_TEXTURE_2D, screentexture);
2035                                 glColor4f(1,1,1,.5);
2036                                 glPushMatrix();
2037                                 glBegin(GL_QUADS);
2038                                 glTexCoord2f(0,0);
2039                                 glVertex3f(-1,          -1,      0.0f);
2040                                 glTexCoord2f(texcoordwidth,0);
2041                                 glVertex3f(1,   -1,      0.0f);
2042                                 glTexCoord2f(texcoordwidth,texcoordheight);
2043                                 glVertex3f(1,   1, 0.0f);
2044                                 glTexCoord2f(0,texcoordheight);
2045                                 glVertex3f(-1,  1, 0.0f);
2046                                 glEnd();
2047                                 glPopMatrix();
2048                                 glBindTexture( GL_TEXTURE_2D, screentexture2);
2049                                 glColor4f(1,1,1,.5);
2050                                 glPushMatrix();
2051                                 glBegin(GL_QUADS);
2052                                 glTexCoord2f(0,0);
2053                                 glVertex3f(-1,          -1,      0.0f);
2054                                 glTexCoord2f(texcoordwidth,0);
2055                                 glVertex3f(1,   -1,      0.0f);
2056                                 glTexCoord2f(texcoordwidth,texcoordheight);
2057                                 glVertex3f(1,   1, 0.0f);
2058                                 glTexCoord2f(0,texcoordheight);
2059                                 glVertex3f(-1,  1, 0.0f);
2060                                 glEnd();
2061                                 glPopMatrix();
2062                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2063                         }
2064                         if(drawmode==doublevisionmode){
2065                                 static float crosseyedness;
2066                                 crosseyedness=abs(player[0].damage-player[0].superpermanentdamage-(player[0].damagetolerance-player[0].superpermanentdamage)*1/2)/30;
2067                                 if(crosseyedness>1)crosseyedness=1;
2068                                 if(crosseyedness<0)crosseyedness=0;
2069                                 glColor4f(1,1,1,1);
2070                                 glDisable(GL_BLEND);
2071                                 glPushMatrix();
2072                                 glScalef(1,1,1);
2073                                 glBegin(GL_QUADS);
2074                                 glTexCoord2f(0,0);
2075                                 glVertex3f(-1,          -1,      0.0f);
2076                                 glTexCoord2f(texcoordwidth,0);
2077                                 glVertex3f(1,   -1,      0.0f);
2078                                 glTexCoord2f(texcoordwidth,texcoordheight);
2079                                 glVertex3f(1,   1, 0.0f);
2080                                 glTexCoord2f(0,texcoordheight);
2081                                 glVertex3f(-1,  1, 0.0f);
2082                                 glEnd();
2083                                 glPopMatrix();
2084                                 if(crosseyedness){
2085                                         glColor4f(1,1,1,.5);
2086                                         glEnable(GL_BLEND);
2087                                         glPushMatrix();
2088                                         glTranslatef(.015*crosseyedness,0,0);
2089                                         glScalef(1,1,1);
2090                                         glBegin(GL_QUADS);
2091                                         glTexCoord2f(0,0);
2092                                         glVertex3f(-1,          -1,      0.0f);
2093                                         glTexCoord2f(texcoordwidth,0);
2094                                         glVertex3f(1,   -1,      0.0f);
2095                                         glTexCoord2f(texcoordwidth,texcoordheight);
2096                                         glVertex3f(1,   1, 0.0f);
2097                                         glTexCoord2f(0,texcoordheight);
2098                                         glVertex3f(-1,  1, 0.0f);
2099                                         glEnd();
2100                                         glPopMatrix();
2101                                 }
2102                         }
2103                         if(drawmode==glowmode){
2104                                 glColor4f(.5,.5,.5,.5);
2105                                 glEnable(GL_BLEND);
2106                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2107                                 glPushMatrix();
2108                                 glTranslatef(.01,0,0);
2109                                 glBegin(GL_QUADS);
2110                                 glTexCoord2f(0,0);
2111                                 glVertex3f(-1,          -1,      0.0f);
2112                                 glTexCoord2f(texcoordwidth,0);
2113                                 glVertex3f(1,   -1,      0.0f);
2114                                 glTexCoord2f(texcoordwidth,texcoordheight);
2115                                 glVertex3f(1,   1, 0.0f);
2116                                 glTexCoord2f(0,texcoordheight);
2117                                 glVertex3f(-1,  1, 0.0f);
2118                                 glEnd();
2119                                 glPopMatrix();
2120                                 glPushMatrix();
2121                                 glTranslatef(-.01,0,0);
2122                                 glBegin(GL_QUADS);
2123                                 glTexCoord2f(0,0);
2124                                 glVertex3f(-1,          -1,      0.0f);
2125                                 glTexCoord2f(texcoordwidth,0);
2126                                 glVertex3f(1,   -1,      0.0f);
2127                                 glTexCoord2f(texcoordwidth,texcoordheight);
2128                                 glVertex3f(1,   1, 0.0f);
2129                                 glTexCoord2f(0,texcoordheight);
2130                                 glVertex3f(-1,  1, 0.0f);
2131                                 glEnd();
2132                                 glPopMatrix();
2133                                 glPushMatrix();
2134                                 glTranslatef(.0,.01,0);
2135                                 glBegin(GL_QUADS);
2136                                 glTexCoord2f(0,0);
2137                                 glVertex3f(-1,          -1,      0.0f);
2138                                 glTexCoord2f(texcoordwidth,0);
2139                                 glVertex3f(1,   -1,      0.0f);
2140                                 glTexCoord2f(texcoordwidth,texcoordheight);
2141                                 glVertex3f(1,   1, 0.0f);
2142                                 glTexCoord2f(0,texcoordheight);
2143                                 glVertex3f(-1,  1, 0.0f);
2144                                 glEnd();
2145                                 glPopMatrix();
2146                                 glPushMatrix();
2147                                 glTranslatef(0,-.01,0);
2148                                 glBegin(GL_QUADS);
2149                                 glTexCoord2f(0,0);
2150                                 glVertex3f(-1,          -1,      0.0f);
2151                                 glTexCoord2f(texcoordwidth,0);
2152                                 glVertex3f(1,   -1,      0.0f);
2153                                 glTexCoord2f(texcoordwidth,texcoordheight);
2154                                 glVertex3f(1,   1, 0.0f);
2155                                 glTexCoord2f(0,texcoordheight);
2156                                 glVertex3f(-1,  1, 0.0f);
2157                                 glEnd();
2158                                 glPopMatrix();
2159                         }
2160                         if(drawmode==radialzoommode){
2161                                 for(i=0;i<3;i++){
2162                                         //glRotatef((float)i*.1,0,0,1);
2163                                         glColor4f(1,1,1,1/((float)i+1));
2164                                         glPushMatrix();
2165                                         glScalef(1+(float)i*.01,1+(float)i*.01,1);
2166                                         glBegin(GL_QUADS);
2167                                         glTexCoord2f(0,0);
2168                                         glVertex3f(-1,          -1,      0.0f);
2169                                         glTexCoord2f(texcoordwidth,0);
2170                                         glVertex3f(1,   -1,      0.0f);
2171                                         glTexCoord2f(texcoordwidth,texcoordheight);
2172                                         glVertex3f(1,   1, 0.0f);
2173                                         glTexCoord2f(0,texcoordheight);
2174                                         glVertex3f(-1,  1, 0.0f);
2175                                         glEnd();
2176                                         glPopMatrix();
2177                                 }
2178                         }
2179                         glDisable(GL_TEXTURE_2D);
2180                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2181                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2182                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2183                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2184                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
2185                         glEnable(GL_CULL_FACE);
2186                         glDisable(GL_BLEND);
2187                         glDepthMask(1);
2188                 }
2189
2190                 if(console){
2191                         glEnable(GL_TEXTURE_2D);
2192                         glColor4f(1,1,1,1);
2193                         if(console){
2194                                 int offset;
2195                                 offset=0;
2196                                 if(consoleselected>=60)offset=consoleselected-60;
2197                                 sprintf (string, " ]");
2198                                 text.glPrint(10,30,string,0,1,1024,768);
2199                                 if(consoleblink){
2200                                         sprintf (string, "_");
2201                                         text.glPrint(30+(float)(consoleselected)*10-offset*10,30,string,0,1,1024,768);
2202                                 }
2203                                 for(i=0;i<15;i++){
2204                                         for(j=0;j<consolechars[i];j++){
2205                                                 glColor4f(1,1,1,1-(float)(i)/16);
2206                                                 if(j<consolechars[i]){
2207                                                         sprintf (string, "%c",consoletext[i][j]);
2208                                                         text.glPrint(30+j*10-offset*10,30+i*20,string,0,1,1024,768);
2209                                                 }
2210                                         }
2211                                 }
2212                         }
2213                 }
2214         }
2215
2216         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||(mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)){
2217                 multiplier=tempmult;
2218         }
2219
2220         if(mainmenu){
2221 #if USE_SDL
2222         // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
2223         SDL_Delay(15);
2224 #endif
2225                 glDrawBuffer(GL_BACK);
2226                 glReadBuffer(GL_BACK);
2227                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2228                 ReSizeGLScene(90,.1f);
2229
2230                 int temptexdetail;
2231                 temptexdetail=texdetail;
2232                 if(texdetail>2)texdetail=2;
2233                 if(mainmenu!=oldmainmenu&&oldmainmenu!=0){
2234                         if(mainmenu==1){
2235                                 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
2236                                 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
2237                                 /*if(oldmainmenu==1||oldmainmenu==0){
2238                                 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
2239                                 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
2240                                 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
2241                                 loaddistrib=0;
2242                                 }*/
2243                         }
2244                         if(mainmenu==2){
2245                                 LoadTexture(":Data:Textures:Resume.png",&Mainmenuitems[1],0,0);
2246                                 LoadTexture(":Data:Textures:Endgame.png",&Mainmenuitems[3],0,0);
2247                                 /*if(oldmainmenu==2||oldmainmenu==0){
2248                                 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
2249                                 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
2250                                 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
2251                                 loaddistrib=0;
2252                                 }*/
2253                         }
2254                 }
2255                 if(lastcheck>.5||oldmainmenu!=mainmenu){
2256                         if(mainmenu==5){
2257                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
2258                                 //campaignnumlevels=0;
2259                                 //accountcampaignchoicesmade[accountactive]=0;
2260                                 ipstream.ignore(256,':');
2261                                 ipstream >> campaignnumlevels;
2262                                 for(i=0;i<campaignnumlevels;i++){
2263                                         ipstream.ignore(256,':');
2264                                         ipstream.ignore(256,':');
2265                                         ipstream.ignore(256,' ');
2266                                         ipstream >> campaignmapname[i];
2267                                         ipstream.ignore(256,':');
2268                                         ipstream >> campaigndescription[i];
2269                                         for(j=0;j<256;j++){
2270                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
2271                                         }
2272                                         ipstream.ignore(256,':');
2273                                         ipstream >> campaignchoosenext[i];
2274                                         ipstream.ignore(256,':');
2275                                         ipstream >> campaignnumnext[i];
2276                                         if(campaignnumnext[i])
2277                                                 for(j=0;j<campaignnumnext[i];j++){
2278                                                         ipstream.ignore(256,':');
2279                                                         ipstream >> campaignnextlevel[i][j];
2280                                                         campaignnextlevel[i][j]-=1;
2281                                                 }
2282                                                 ipstream.ignore(256,':');
2283                                                 ipstream >> campaignlocationx[i];
2284                                                 //campaignlocationx[i]-=30;
2285                                                 ipstream.ignore(256,':');
2286                                                 ipstream >> campaignlocationy[i];
2287                                                 //campaignlocationy[i]+=30;
2288                                 }
2289                                 ipstream.close();
2290
2291                                 for(i=0;i<campaignnumlevels;i++){
2292                                         levelvisible[i]=0;
2293                                         levelhighlight[i]=0;
2294                                 }
2295
2296                                 levelorder[0]=0;
2297                                 levelvisible[0]=1;
2298                                 if(accountcampaignchoicesmade[accountactive])
2299                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
2300                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
2301                                                 levelvisible[levelorder[i+1]]=1;
2302                                         }
2303                                         int whichlevelstart;
2304                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
2305                                         if(whichlevelstart<0){
2306                                                 accountcampaignscore[accountactive]=0;
2307                                                 accountcampaignfasttime[accountactive]=0;
2308                                                 campaignchoicenum=1;
2309                                                 campaignchoicewhich[0]=0;
2310                                         }
2311                                         else
2312                                         {
2313                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
2314                                                 if(campaignchoicenum==0){
2315                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
2316                                                         if(accountcampaignfasttime[accountactive]==0||accountcampaigntime[accountactive]<accountcampaignfasttime[accountactive])accountcampaignfasttime[accountactive]=accountcampaigntime[accountactive];              
2317                                                 }
2318                                                 if(campaignchoicenum)
2319                                                         for(i=0;i<campaignchoicenum;i++){
2320                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
2321                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2322                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2323                                                         }
2324                                         }
2325                                         /*levelorder[0]=0;
2326                                         levelorder[1]=1;
2327                                         levelorder[2]=2;
2328                                         levelorder[3]=3;*/
2329                         }
2330                 }
2331                 if(mainmenu==5){
2332                         lastcheck=0;
2333                 }
2334
2335                 texdetail=temptexdetail;
2336
2337                 /*if(mainmenu!=0)*/oldmainmenu=mainmenu;
2338
2339                 if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==119||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17){
2340                         glClear(GL_DEPTH_BUFFER_BIT);
2341                         glEnable(GL_ALPHA_TEST);
2342                         glAlphaFunc(GL_GREATER, 0.001f);
2343                         glEnable(GL_TEXTURE_2D);
2344                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2345                         glDisable(GL_CULL_FACE);
2346                         glDisable(GL_LIGHTING);
2347                         glDepthMask(0);
2348                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2349                         glPushMatrix();                                                                         // Store The Projection Matrix
2350                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
2351                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2352                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2353                                         glPushMatrix();                                                                         // Store The Modelview Matrix
2354                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
2355                                         glTranslatef(screenwidth/2,screenheight/2,0);
2356                                         glPushMatrix();
2357                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
2358                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2359                                                 glDisable(GL_BLEND);
2360                                                 glColor4f(0,0,0,1.0);
2361                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2362                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2363                                                 glDisable(GL_TEXTURE_2D);
2364                                                 glPushMatrix();
2365                                                         //glScalef(.25,.25,.25);
2366                                                         glBegin(GL_QUADS);
2367                                                         glTexCoord2f(0,0);
2368                                                         glVertex3f(-1,          -1,      0.0f);
2369                                                         glTexCoord2f(1,0);
2370                                                         glVertex3f(1,   -1,      0.0f);
2371                                                         glTexCoord2f(1,1);
2372                                                         glVertex3f(1,   1, 0.0f);
2373                                                         glTexCoord2f(0,1);
2374                                                         glVertex3f(-1,  1, 0.0f);
2375                                                         glEnd();
2376                                                 glPopMatrix();
2377                                                 glEnable(GL_BLEND);
2378                                                 glColor4f(0.4,0.4,0.4,1.0);
2379                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2380                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2381                                                 glEnable(GL_TEXTURE_2D);
2382                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
2383                                                 glPushMatrix();
2384                                                         //glScalef(.25,.25,.25);
2385                                                         glBegin(GL_QUADS);
2386                                                         glTexCoord2f(0,0);
2387                                                         glVertex3f(-1,          -1,      0.0f);
2388                                                         glTexCoord2f(1,0);
2389                                                         glVertex3f(1,   -1,      0.0f);
2390                                                         glTexCoord2f(1,1);
2391                                                         glVertex3f(1,   1, 0.0f);
2392                                                         glTexCoord2f(0,1);
2393                                                         glVertex3f(-1,  1, 0.0f);
2394                                                         glEnd();
2395                                                 glPopMatrix();
2396                                         glPopMatrix();
2397                                 glPopMatrix();
2398                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2399                         glPopMatrix();
2400                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2401
2402                         if(mainmenu==3){                        
2403                                 nummenuitems=12;
2404                                 if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)sprintf (menustring[0], "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
2405                                 else sprintf (menustring[0], "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
2406                                 startx[0]=10+20;
2407                                 starty[0]=440;
2408                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2409                                 endy[0]=starty[0]+20;
2410                                 movex[0]=0;
2411                                 movey[0]=0;
2412
2413                                 if(newdetail==2)sprintf (menustring[1], "Detail: High");
2414                                 else if(newdetail==1)sprintf (menustring[1], "Detail: Medium");
2415                                 else sprintf (menustring[1], "Detail: Low");
2416                                 startx[1]=10+60;
2417                                 starty[1]=405;
2418                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2419                                 endy[1]=starty[1]+20;
2420                                 movex[1]=0;
2421                                 movey[1]=0;
2422
2423                                 if(bloodtoggle==2)sprintf (menustring[2], "Blood: On, high detail (slower)");
2424                                 if(bloodtoggle==1)sprintf (menustring[2], "Blood: On, low detail");
2425                                 if(bloodtoggle==0)sprintf (menustring[2], "Blood: Off");
2426                                 startx[2]=10+70;
2427                                 starty[2]=370;
2428                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2429                                 endy[2]=starty[2]+20;
2430                                 movex[2]=0;
2431                                 movey[2]=0;
2432
2433                                 if(difficulty==2)sprintf (menustring[3], "Difficulty: Insane");
2434                                 if(difficulty==1)sprintf (menustring[3], "Difficulty: Difficult");
2435                                 if(difficulty==0)sprintf (menustring[3], "Difficulty: Easier");
2436                                 startx[3]=10+20-1000;
2437                                 starty[3]=335-1000;
2438                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2439                                 endy[3]=starty[3]+20;
2440                                 movex[3]=0;
2441                                 movey[3]=0;
2442
2443                                 if(ismotionblur==1)sprintf (menustring[4], "Blur Effects: Enabled (less compatible)");
2444                                 if(ismotionblur==0)sprintf (menustring[4], "Blur Effects: Disabled (more compatible)");
2445                                 startx[4]=10;
2446                                 starty[4]=335;
2447                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2448                                 endy[4]=starty[4]+20;
2449                                 movex[4]=0;
2450                                 movey[4]=0;
2451
2452                                 if(decals==1)sprintf (menustring[5], "Decals: Enabled (slower)");
2453                                 if(decals==0)sprintf (menustring[5], "Decals: Disabled");
2454                                 startx[5]=10+60;
2455                                 starty[5]=300;
2456                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2457                                 endy[5]=starty[5]+20;
2458                                 movex[5]=0;
2459                                 movey[5]=0;
2460
2461                                 if(musictoggle==1)sprintf (menustring[6], "Music: Enabled");
2462                                 if(musictoggle==0)sprintf (menustring[6], "Music: Disabled");
2463                                 startx[6]=10+70;
2464                                 starty[6]=265;
2465                                 endx[6]=startx[6]+strlen(menustring[6])*10;
2466                                 endy[6]=starty[6]+20;
2467                                 movex[6]=0;
2468                                 movey[6]=0;
2469
2470                                 if(invertmouse==1)sprintf (menustring[9], "Invert mouse: Yes");
2471                                 if(invertmouse==0)sprintf (menustring[9], "Invert mouse: No");
2472                                 startx[9]=10;
2473                                 starty[9]=230;
2474                                 endx[9]=startx[9]+strlen(menustring[9])*10;
2475                                 endy[9]=starty[9]+20;
2476                                 movex[9]=0;
2477                                 movey[9]=0;
2478
2479                                 sprintf (menustring[10], "Mouse Speed: %d", (int)(usermousesensitivity*5));
2480                                 startx[10]=20;
2481                                 starty[10]=195;
2482                                 endx[10]=startx[10]+strlen(menustring[10])*10;
2483                                 endy[10]=starty[10]+20;
2484                                 movex[10]=0;
2485                                 movey[10]=0;
2486                                 
2487                                 sprintf (menustring[11], "Volume: %d%", (int)(volume*100));
2488                                 startx[11]=10+60;
2489                                 starty[11]=155;
2490                                 endx[11]=startx[11]+strlen(menustring[11])*10;
2491                                 endy[11]=starty[11]+20;
2492                                 movex[11]=0;
2493                                 movey[11]=0;
2494                                 
2495                                 sprintf (menustring[7], "-Configure Controls-");
2496                                 startx[7]=10+15;
2497                                 starty[7]=100;
2498                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2499                                 endy[7]=starty[7]+20;
2500                                 movex[7]=0;
2501                                 movey[7]=0;
2502
2503                                 if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)sprintf (menustring[8], "Back");
2504                                 else sprintf (menustring[8], "Back (some changes take effect next time Lugaru is opened)");
2505                                 startx[8]=10;
2506                                 endx[8]=startx[8]+strlen(menustring[8])*10;
2507                                 starty[8]=10;
2508                                 endy[8]=starty[8]+20;
2509                                 movex[8]=0;
2510                                 movey[8]=0;
2511                         }
2512
2513                         if(mainmenu==4){                        
2514                                 nummenuitems=10;
2515                                 if(keyselect!=0)sprintf (menustring[0], "Forwards: %s",KeyToChar(forwardkey));
2516                                 else sprintf (menustring[0], "Forwards: _");
2517                                 startx[0]=10;
2518                                 starty[0]=400;
2519                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2520                                 endy[0]=starty[0]+20;
2521                                 movex[0]=0;
2522                                 movey[0]=0;
2523
2524                                 if(keyselect!=1)sprintf (menustring[1], "Back: %s",KeyToChar(backkey));
2525                                 else sprintf (menustring[1], "Back: _");
2526                                 startx[1]=10+40;
2527                                 starty[1]=360;
2528                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2529                                 endy[1]=starty[1]+20;
2530                                 movex[1]=0;
2531                                 movey[1]=0;
2532
2533                                 if(keyselect!=2)sprintf (menustring[2], "Left: %s",KeyToChar(leftkey));
2534                                 else sprintf (menustring[2], "Left: _");
2535                                 startx[2]=10+40;
2536                                 starty[2]=320;
2537                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2538                                 endy[2]=starty[2]+20;
2539                                 movex[2]=0;
2540                                 movey[2]=0;
2541
2542                                 if(keyselect!=3)sprintf (menustring[3], "Right: %s",KeyToChar(rightkey));
2543                                 else sprintf (menustring[3], "Right: _");
2544                                 startx[3]=10+30;
2545                                 starty[3]=280;
2546                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2547                                 endy[3]=starty[3]+20;
2548                                 movex[3]=0;
2549                                 movey[3]=0;
2550
2551                                 if(keyselect!=4)sprintf (menustring[4], "Crouch: %s",KeyToChar(crouchkey));
2552                                 else sprintf (menustring[4], "Crouch: _");
2553                                 startx[4]=10+20;
2554                                 starty[4]=240;
2555                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2556                                 endy[4]=starty[4]+20;
2557                                 movex[4]=0;
2558                                 movey[4]=0;
2559
2560                                 if(keyselect!=5)sprintf (menustring[5], "Jump: %s",KeyToChar(jumpkey));
2561                                 else sprintf (menustring[5], "Jump: _");
2562                                 startx[5]=10+40;
2563                                 starty[5]=200;
2564                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2565                                 endy[5]=starty[5]+20;
2566                                 movex[5]=0;
2567                                 movey[5]=0;
2568
2569                                 if(keyselect!=6)sprintf (menustring[6], "Draw: %s",KeyToChar(drawkey));
2570                                 else sprintf (menustring[6], "Draw: _");
2571                                 startx[6]=10+40;
2572                                 starty[6]=160;
2573                                 endx[6]=startx[6]+strlen(menustring[6])*10;
2574                                 endy[6]=starty[6]+20;
2575                                 movex[6]=0;
2576                                 movey[6]=0;
2577
2578                                 if(keyselect!=7)sprintf (menustring[7], "Throw: %s",KeyToChar(throwkey));
2579                                 else sprintf (menustring[7], "Throw: _");
2580                                 startx[7]=10+30;
2581                                 starty[7]=120;
2582                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2583                                 endy[7]=starty[7]+20;
2584                                 movex[7]=0;
2585                                 movey[7]=0;
2586
2587                                 if(keyselect!=8)sprintf (menustring[8], "Attack: %s",KeyToChar(attackkey));
2588                                 else sprintf (menustring[8], "Attack: _");
2589                                 startx[8]=10+20;
2590                                 starty[8]=80;
2591                                 endx[8]=startx[8]+strlen(menustring[8])*10;
2592                                 endy[8]=starty[8]+20;
2593                                 movex[8]=0;
2594                                 movey[8]=0;
2595
2596
2597
2598                                 sprintf (menustring[9], "Back");
2599                                 startx[9]=10;
2600                                 endx[9]=startx[9]+strlen(menustring[9])*10;
2601                                 starty[9]=10;
2602                                 endy[9]=starty[9]+20;
2603                                 movex[9]=0;
2604                                 movey[9]=0;
2605                         }
2606                         if(mainmenu==5){                        
2607                                 nummenuitems=7+accountcampaignchoicesmade[accountactive]+campaignchoicenum;
2608
2609                                 sprintf (menustring[0], "%s",accountname[accountactive]);
2610                                 startx[0]=5;
2611                                 starty[0]=400;
2612                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2613                                 endy[0]=starty[0]+20;
2614                                 movex[0]=0;
2615                                 movey[0]=0;
2616
2617                                 sprintf (menustring[1], "Tutorial");
2618                                 startx[1]=5;
2619                                 starty[1]=300;
2620                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2621                                 endy[1]=starty[1]+20;
2622                                 movex[1]=0;
2623                                 movey[1]=0;
2624
2625                                 sprintf (menustring[2], "Challenge");
2626                                 startx[2]=5;
2627                                 starty[2]=240;
2628                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2629                                 endy[2]=starty[2]+20;
2630                                 movex[2]=0;
2631                                 movey[2]=0;
2632
2633                                 sprintf (menustring[3], "Delete User");
2634                                 startx[3]=400;
2635                                 starty[3]=10;
2636                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2637                                 endy[3]=starty[3]+20;
2638                                 movex[3]=0;
2639                                 movey[3]=0;
2640
2641                                 sprintf (menustring[4], "Main Menu");
2642                                 startx[4]=5;
2643                                 starty[4]=10;
2644                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2645                                 endy[4]=starty[4]+20;
2646                                 movex[4]=0;
2647                                 movey[4]=0;
2648
2649                                 sprintf (menustring[5], "Change User");
2650                                 startx[5]=5;
2651                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2652                                 starty[5]=180;
2653                                 endy[5]=starty[5]+20;
2654                                 movex[5]=0;
2655                                 movey[5]=0;
2656
2657                                 //World
2658
2659                                 sprintf (menustring[6], "World");
2660                                 startx[6]=30+120;
2661                                 starty[6]=30+480-400-50;
2662                                 endx[6]=startx[6]+400;
2663                                 endy[6]=30+480-50;
2664                                 movex[6]=0;
2665                                 movey[6]=0;
2666
2667                                 if(accountcampaignchoicesmade[accountactive])
2668                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
2669                                                 sprintf (menustring[7+i], campaigndescription[levelorder[i]]);
2670                                                 startx[7+i]=30+120+campaignlocationx[levelorder[i]]*400/512;
2671                                                 starty[7+i]=30+30+(512-campaignlocationy[levelorder[i]])*400/512;
2672                                                 endx[7+i]=startx[7+i]+10;
2673                                                 endy[7+i]=starty[7+i]+10;
2674                                                 movex[7+i]=0;
2675                                                 movey[7+i]=0;
2676                                         }
2677
2678                                         if(campaignchoicenum>0)
2679                                                 for(i=accountcampaignchoicesmade[accountactive];i<accountcampaignchoicesmade[accountactive]+campaignchoicenum;i++){
2680                                                         sprintf (menustring[7+i], campaigndescription[levelorder[i]]);
2681                                                         startx[7+i]=30+120+campaignlocationx[campaignchoicewhich[i-(accountcampaignchoicesmade[accountactive])]]*400/512;
2682                                                         starty[7+i]=30+30+(512-campaignlocationy[campaignchoicewhich[i-(accountcampaignchoicesmade[accountactive])]])*400/512;
2683                                                         endx[7+i]=startx[7+i]+10;
2684                                                         endy[7+i]=starty[7+i]+10;
2685                                                         movex[7+i]=0;
2686                                                         movey[7+i]=0;
2687                                                 }
2688
2689                                                 /*sprintf (menustring[7], "Dot");
2690                                                 startx[7]=120+260*400/512;
2691                                                 starty[7]=30+(512-184)*400/512;
2692                                                 endx[7]=startx[7]+10;
2693                                                 endy[7]=starty[7]+10;
2694                                                 movex[7]=0;
2695                                                 movey[7]=0;
2696
2697                                                 sprintf (menustring[8], "Dot");
2698                                                 startx[8]=120+129*400/512;
2699                                                 starty[8]=30+(512-284)*400/512;
2700                                                 endx[8]=startx[8]+10;
2701                                                 endy[8]=starty[8]+10;
2702                                                 movex[8]=0;
2703                                                 movey[8]=0;
2704
2705                                                 sprintf (menustring[9], "Dot");
2706                                                 startx[9]=120+358*400/512;
2707                                                 starty[9]=30+(512-235)*400/512;
2708                                                 endx[9]=startx[9]+10;
2709                                                 endy[9]=starty[9]+10;
2710                                                 movex[9]=0;
2711                                                 movey[9]=0;
2712
2713                                                 sprintf (menustring[10], "Dot");
2714                                                 startx[10]=120+359*400/512;
2715                                                 starty[10]=30+(512-308)*400/512;
2716                                                 endx[10]=startx[10]+10;
2717                                                 endy[10]=starty[10]+10;
2718                                                 movex[10]=0;
2719                                                 movey[10]=0;
2720
2721                                                 sprintf (menustring[11], "Dot");
2722                                                 startx[11]=120+288*400/512;
2723                                                 starty[11]=30+(512-277)*400/512;
2724                                                 endx[11]=startx[11]+10;
2725                                                 endy[11]=starty[11]+10;
2726                                                 movex[11]=0;
2727                                                 movey[11]=0;*/
2728                         }
2729
2730                         if(mainmenu==6){                        
2731                                 nummenuitems=3;
2732
2733                                 sprintf (menustring[0], "Are you sure you want to delete this user?");
2734                                 startx[0]=10;
2735                                 starty[0]=400;
2736                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2737                                 endy[0]=starty[0]+20;
2738                                 movex[0]=0;
2739                                 movey[0]=0;
2740
2741                                 sprintf (menustring[1], "Yes");
2742                                 startx[1]=10;
2743                                 starty[1]=360;
2744                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2745                                 endy[1]=starty[1]+20;
2746                                 movex[1]=0;
2747                                 movey[1]=0;
2748
2749                                 sprintf (menustring[2], "No");
2750                                 startx[2]=10;
2751                                 starty[2]=320;
2752                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2753                                 endy[2]=starty[2]+20;
2754                                 movex[2]=0;
2755                                 movey[2]=0;
2756
2757                                 sprintf (menustring[3], "Extra 4");
2758                                 startx[3]=10;
2759                                 starty[3]=280;
2760                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2761                                 endy[3]=starty[3]+20;
2762                                 movex[3]=0;
2763                                 movey[3]=0;
2764
2765                                 sprintf (menustring[4], "Extra 5");
2766                                 startx[4]=10;
2767                                 starty[4]=240;
2768                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2769                                 endy[4]=starty[4]+20;
2770                                 movex[4]=0;
2771                                 movey[4]=0;
2772
2773                                 sprintf (menustring[5], "Back");
2774                                 startx[5]=10;
2775                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2776                                 starty[5]=10;
2777                                 endy[5]=starty[5]+20;
2778                                 movex[5]=0;
2779                                 movey[5]=0;
2780                         }
2781
2782                         if(mainmenu==7){                        
2783                                 nummenuitems=numaccounts+2;
2784
2785                                 int num;
2786
2787                                 if(numaccounts<8)
2788                                         sprintf (menustring[0], "New User");
2789                                 else
2790                                         sprintf (menustring[0], "No More Users");
2791                                 startx[0]=10;
2792                                 starty[0]=400;
2793                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2794                                 endy[0]=starty[0]+20;
2795                                 movex[0]=0;
2796                                 movey[0]=0;
2797
2798                                 if(entername)startx[0]+=10;
2799
2800
2801                                 num=1;
2802                                 if(numaccounts)
2803                                         for(i=0;i<numaccounts;i++){
2804                                                 sprintf (menustring[num], "%s",accountname[i]);
2805                                                 startx[num]=10;
2806                                                 starty[num]=360-20-20*num;
2807                                                 endx[num]=startx[num]+strlen(menustring[num])*10;
2808                                                 endy[num]=starty[num]+20;
2809                                                 movex[num]=0;
2810                                                 movey[num]=0;
2811
2812                                                 num++;
2813                                         }
2814
2815                                         sprintf (menustring[num], "Back");
2816                                         startx[num]=10;
2817                                         endx[num]=startx[num]+strlen(menustring[num])*10;
2818                                         starty[num]=10;
2819                                         endy[num]=starty[num]+20;
2820                                         movex[num]=0;
2821                                         movey[num]=0;
2822                         }
2823                         if(mainmenu==8){                        
2824                                 nummenuitems=3;
2825
2826                                 sprintf (menustring[0], "Easier");
2827                                 startx[0]=10;
2828                                 starty[0]=400;
2829                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2830                                 endy[0]=starty[0]+20;
2831                                 movex[0]=0;
2832                                 movey[0]=0;
2833
2834                                 sprintf (menustring[1], "Difficult");
2835                                 startx[1]=10;
2836                                 starty[1]=360;
2837                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2838                                 endy[1]=starty[1]+20;
2839                                 movex[1]=0;
2840                                 movey[1]=0;
2841
2842                                 sprintf (menustring[2], "Insane");
2843                                 startx[2]=10;
2844                                 starty[2]=320;
2845                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2846                                 endy[2]=starty[2]+20;
2847                                 movex[2]=0;
2848                                 movey[2]=0;
2849                         }
2850                         if(mainmenu==9){                        
2851                                 int tempncl;
2852                                 //tempncl=numchallengelevels;
2853                                 //numchallengelevels=9;
2854                                 nummenuitems=2+numchallengelevels;
2855                                 char temp[255];
2856
2857                                 for(j=0;j<numchallengelevels;j++){
2858                                         for(i=0;i<255;i++)menustring[j][i]='\0';
2859                                         sprintf (temp, "Level %d",j+1);
2860                                         strcpy(menustring[j],temp);
2861                                         for(i=0;i<17;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2862                                         menustring[j][17]='\0';
2863                                         sprintf (temp, "%d",(int)accounthighscore[accountactive][j]);
2864                                         strcat(menustring[j],temp);
2865                                         for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2866                                         menustring[j][32]='\0';
2867                                         sprintf (temp, "%d:",(int)(((int)accountfasttime[accountactive][j]-(int)(accountfasttime[accountactive][j])%60)/60));
2868                                         strcat(menustring[j],temp);
2869                                         if((int)(accountfasttime[accountactive][j])%60<10)strcat(menustring[j],"0");
2870                                         sprintf (temp, "%d",(int)(accountfasttime[accountactive][j])%60);
2871                                         strcat(menustring[j],temp);
2872
2873                                         startx[j]=10;
2874                                         starty[j]=400-j*25;
2875                                         endx[j]=startx[j]+strlen(menustring[j])*10;
2876                                         endy[j]=starty[j]+20;
2877                                         movex[j]=0;
2878                                         movey[j]=0;
2879                                 }
2880
2881                                 sprintf (menustring[numchallengelevels], "Back");
2882                                 startx[numchallengelevels]=10;
2883                                 endx[numchallengelevels]=startx[numchallengelevels]+strlen(menustring[numchallengelevels])*10;
2884                                 starty[numchallengelevels]=10;
2885                                 endy[numchallengelevels]=starty[numchallengelevels]+20;
2886                                 movex[numchallengelevels]=0;
2887                                 movey[numchallengelevels]=0;
2888
2889                                 sprintf (menustring[numchallengelevels+1], "             High Score      Best Time");
2890                                 startx[numchallengelevels+1]=10;
2891                                 starty[numchallengelevels+1]=440;
2892                                 endx[numchallengelevels+1]=startx[numchallengelevels+1]+strlen(menustring[numchallengelevels+1])*10;
2893                                 endy[numchallengelevels+1]=starty[numchallengelevels+1]+20;
2894                                 movex[numchallengelevels+1]=0;
2895                                 movey[numchallengelevels+1]=0;
2896
2897                                 //numchallengelevels=tempncl;
2898
2899                         }
2900                         if(mainmenu==11){                       
2901                                 nummenuitems=2+numchallengelevels;
2902                                 char temp[255];
2903
2904                                 for(j=0;j<numchallengelevels;j++){
2905                                         for(i=0;i<255;i++)menustring[j][i]='\0';
2906                                         sprintf (temp, "Level %d",j+1);
2907                                         strcpy(menustring[j],temp);
2908                                         for(i=0;i<17;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2909                                         menustring[j][17]='\0';
2910                                         sprintf (temp, "%d",(int)accounthighscore[accountactive][j]);
2911                                         strcat(menustring[j],temp);
2912                                         for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2913                                         menustring[j][32]='\0';
2914                                         sprintf (temp, "%d:",(int)(((int)accountfasttime[accountactive][j]-(int)(accountfasttime[accountactive][j])%60)/60));
2915                                         strcat(menustring[j],temp);
2916                                         if((int)(accountfasttime[accountactive][j])%60<10)strcat(menustring[j],"0");
2917                                         sprintf (temp, "%d",(int)(accountfasttime[accountactive][j])%60);
2918                                         strcat(menustring[j],temp);
2919
2920                                         startx[j]=10;
2921                                         starty[j]=360-j*40;
2922                                         endx[j]=startx[j]+strlen(menustring[j])*10;
2923                                         endy[j]=starty[j]+20;
2924                                         movex[j]=0;
2925                                         movey[j]=0;
2926                                 }
2927
2928                                 sprintf (menustring[numchallengelevels], "Back");
2929                                 startx[numchallengelevels]=10;
2930                                 endx[numchallengelevels]=startx[numchallengelevels]+strlen(menustring[numchallengelevels])*10;
2931                                 starty[numchallengelevels]=10;
2932                                 endy[numchallengelevels]=starty[numchallengelevels]+20;
2933                                 movex[numchallengelevels]=0;
2934                                 movey[numchallengelevels]=0;
2935
2936                                 sprintf (menustring[numchallengelevels+1], "             High Score      Best Time");
2937                                 startx[numchallengelevels+1]=10;
2938                                 starty[numchallengelevels+1]=400;
2939                                 endx[numchallengelevels+1]=startx[numchallengelevels+1]+strlen(menustring[numchallengelevels+1])*10;
2940                                 endy[numchallengelevels+1]=starty[numchallengelevels+1]+20;
2941                                 movex[numchallengelevels+1]=0;
2942                                 movey[numchallengelevels+1]=0;
2943
2944                         }
2945                         if(mainmenu==10){                       
2946                                 nummenuitems=6;
2947                                 char temp[255];
2948
2949                                 sprintf (menustring[0], "Congratulations!");
2950                                 startx[0]=220;
2951                                 starty[0]=330;
2952                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2953                                 endy[0]=starty[0]+20;
2954                                 movex[0]=0;
2955                                 movey[0]=0;
2956
2957                                 sprintf (menustring[1], "You have avenged your family and");
2958                                 startx[1]=140;
2959                                 starty[1]=300;
2960                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2961                                 endy[1]=starty[1]+20;
2962                                 movex[1]=0;
2963                                 movey[1]=0;
2964
2965                                 sprintf (menustring[2], "restored peace to the island of Lugaru.");
2966                                 startx[2]=110;
2967                                 starty[2]=270;
2968                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2969                                 endy[2]=starty[2]+20;
2970                                 movex[2]=0;
2971                                 movey[2]=0;
2972
2973                                 sprintf (menustring[3], "Back");
2974                                 startx[3]=10;
2975                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2976                                 starty[3]=10;
2977                                 endy[3]=starty[3]+20;
2978                                 movex[3]=0;
2979                                 movey[3]=0;
2980
2981                                 for(i=0;i<255;i++)menustring[4][i]='\0';
2982                                 sprintf (temp, "Your score:");
2983                                 strcpy(menustring[4],temp);
2984                                 for(i=0;i<20;i++)if(menustring[4][i]=='\0')menustring[4][i]=' ';
2985                                 menustring[4][20]='\0';
2986                                 sprintf (temp, "%d",(int)accountcampaignscore[accountactive]);
2987                                 strcat(menustring[4],temp);
2988                                 startx[4]=190;
2989                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2990                                 starty[4]=200;
2991                                 endy[4]=starty[4]+20;
2992                                 movex[4]=0;
2993                                 movey[4]=0;
2994                                 /*
2995                                 for(i=0;i<255;i++)menustring[5][i]='\0';
2996                                 sprintf (temp, "Your time:");
2997                                 strcpy(menustring[5],temp);
2998                                 for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
2999                                 menustring[5][20]='\0';
3000                                 sprintf (temp, "%d",(int)accountcampaigntime[accountactive]);
3001                                 strcat(menustring[5],temp);
3002                                 startx[5]=200;
3003                                 endx[5]=startx[5]+strlen(menustring[5])*10;
3004                                 starty[5]=180;
3005                                 endy[5]=starty[5]+20;
3006                                 movex[5]=0;
3007                                 movey[5]=0;
3008                                 */
3009                                 for(i=0;i<255;i++)menustring[5][i]='\0';
3010                                 sprintf (temp, "Highest score:");
3011                                 strcpy(menustring[5],temp);
3012                                 for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
3013                                 menustring[5][20]='\0';
3014                                 sprintf (temp, "%d",(int)accountcampaignhighscore[accountactive]);
3015                                 strcat(menustring[5],temp);
3016                                 startx[5]=190;
3017                                 endx[5]=startx[5]+strlen(menustring[5])*10;
3018                                 starty[5]=180;
3019                                 endy[5]=starty[5]+20;
3020                                 movex[5]=0;
3021                                 movey[5]=0;
3022                                 /*
3023                                 for(i=0;i<255;i++)menustring[7][i]='\0';
3024                                 sprintf (temp, "Lowest time:");
3025                                 strcpy(menustring[7],temp);
3026                                 for(i=0;i<20;i++)if(menustring[7][i]=='\0')menustring[7][i]=' ';
3027                                 menustring[7][20]='\0';
3028                                 sprintf (temp, "%d",(int)accountcampaignfasttime[accountactive]);
3029                                 strcat(menustring[7],temp);
3030                                 startx[7]=200;
3031                                 endx[7]=startx[7]+strlen(menustring[7])*10;
3032                                 starty[7]=130;
3033                                 endy[7]=starty[7]+20;
3034                                 movex[7]=0;
3035                                 movey[7]=0;*/
3036                         }
3037                 }
3038
3039                 if(mainmenu==12){       
3040                         menupulse+=multiplier*2;
3041
3042                         nummenuitems=6;
3043                         char temp[255];
3044
3045                         sprintf (menustring[0], "Register now for only $19.95!");
3046                         startx[0]=160;
3047                         starty[0]=270;
3048                         endx[0]=startx[0]+strlen(menustring[0])*10;
3049                         endy[0]=starty[0]+20;
3050                         movex[0]=0;
3051                         movey[0]=0;
3052
3053                         sprintf (menustring[1], "Confront raiders, wolves, and more!");
3054                         startx[1]=130;
3055                         starty[1]=240;
3056                         endx[1]=startx[1]+strlen(menustring[1])*10;
3057                         endy[1]=starty[1]+20;
3058                         movex[1]=0;
3059                         movey[1]=0;
3060
3061                         sprintf (menustring[2], "Fight using swords, staves and armor!");
3062                         startx[2]=125;
3063                         starty[2]=210;
3064                         endx[2]=startx[2]+strlen(menustring[2])*10;
3065                         endy[2]=starty[2]+20;
3066                         movex[2]=0;
3067                         movey[2]=0;
3068
3069                         if(!tryquit)sprintf (menustring[3], "Back");
3070                         else sprintf (menustring[3], "Quit");
3071                         startx[3]=10;
3072                         endx[3]=startx[3]+strlen(menustring[3])*10;
3073                         starty[3]=10;
3074                         endy[3]=starty[3]+20;
3075                         movex[3]=0;
3076                         movey[3]=0;
3077
3078                         sprintf (menustring[4], "Register now!");
3079                         startx[4]=250;
3080                         endx[4]=startx[4]+strlen(menustring[4])*10;
3081                         starty[4]=140;
3082                         endy[4]=starty[4]+20;
3083                         movex[4]=0;
3084                         movey[4]=0;
3085
3086                         sprintf (menustring[5], "Enter registration code!");
3087                         startx[5]=190;
3088                         endx[5]=startx[5]+strlen(menustring[5])*10;
3089                         starty[5]=120;
3090                         endy[5]=starty[5]+20;
3091                         movex[5]=0;
3092                         movey[5]=0;
3093                 }
3094
3095                 if(mainmenu==15){       
3096                         nummenuitems=2;
3097                         char temp[255];
3098
3099                         sprintf (menustring[0], "Thank you for supporting Wolfire Software!");
3100                         startx[0]=100;
3101                         starty[0]=270;
3102                         endx[0]=startx[0]+strlen(menustring[0])*10;
3103                         endy[0]=starty[0]+20;
3104                         movex[0]=0;
3105                         movey[0]=0;
3106
3107                         sprintf (menustring[1], "Back");
3108                         startx[1]=10;
3109                         endx[1]=startx[1]+strlen(menustring[1])*10;
3110                         starty[1]=10;
3111                         endy[1]=starty[1]+20;
3112                         movex[1]=0;
3113                         movey[1]=0;
3114                 }
3115
3116                 if(mainmenu==16){       
3117                         nummenuitems=5;
3118                         char temp[255];
3119
3120                         sprintf (menustring[0], "Sorry, that name/serial number combination is incorrect.");
3121                         startx[0]=40;
3122                         starty[0]=270;
3123                         endx[0]=startx[0]+strlen(menustring[0])*10;
3124                         endy[0]=starty[0]+20;
3125                         movex[0]=0;
3126                         movey[0]=0;
3127
3128                         sprintf (menustring[1], "Back");
3129                         startx[1]=10;
3130                         endx[1]=startx[1]+strlen(menustring[1])*10;
3131                         starty[1]=10;
3132                         endy[1]=starty[1]+20;
3133                         movex[1]=0;
3134                         movey[1]=0;
3135
3136                         sprintf (menustring[2], "Please make sure you are copying your name and serial");
3137                         startx[2]=50;
3138                         starty[2]=240;
3139                         endx[2]=startx[2]+strlen(menustring[2])*10;
3140                         endy[2]=starty[2]+20;
3141                         movex[2]=0;
3142                         movey[2]=0;
3143
3144                         sprintf (menustring[3], "number exactly as they appear in your email.");
3145                         startx[3]=90;
3146                         starty[3]=210;
3147                         endx[3]=startx[3]+strlen(menustring[3])*10;
3148                         endy[3]=starty[3]+20;
3149                         movex[3]=0;
3150                         movey[3]=0;
3151
3152                         sprintf (menustring[4], "Capitalization and punctuation matter!");
3153                         startx[4]=120;
3154                         starty[4]=180;
3155                         endx[4]=startx[4]+strlen(menustring[4])*10;
3156                         endy[4]=starty[4]+20;
3157                         movex[4]=0;
3158                         movey[4]=0;
3159                 }
3160
3161                 if(mainmenu==13){       
3162                         nummenuitems=2;
3163                         char temp[255];
3164
3165                         sprintf (menustring[0], "Please enter your name:");
3166                         startx[0]=50;
3167                         starty[0]=250;
3168                         endx[0]=startx[0]+strlen(menustring[0])*10;
3169                         endy[0]=starty[0]+20;
3170                         movex[0]=0;
3171                         movey[0]=0;
3172
3173                         sprintf (menustring[1], "Please enter your name:");
3174                         startx[1]=290;
3175                         starty[1]=250;
3176                         endx[1]=startx[1]+strlen(menustring[1])*10;
3177                         endy[1]=starty[1]+20;
3178                         movex[1]=0;
3179                         movey[1]=0;
3180                 }
3181
3182                 if(mainmenu==14){       
3183                         nummenuitems=2;
3184                         char temp[255];
3185
3186                         sprintf (menustring[0], "Please enter your number:");
3187                         startx[0]=30;
3188                         starty[0]=250;
3189                         endx[0]=startx[0]+strlen(menustring[0])*10;
3190                         endy[0]=starty[0]+20;
3191                         movex[0]=0;
3192                         movey[0]=0;
3193
3194                         sprintf (menustring[1], "Please enter your name:");
3195                         startx[1]=290;
3196                         starty[1]=250;
3197                         endx[1]=startx[1]+strlen(menustring[1])*10;
3198                         endy[1]=starty[1]+20;
3199                         movex[1]=0;
3200                         movey[1]=0;
3201                         /*
3202                         char tempstring[256];
3203                         sprintf (tempstring, "%s", registrationname);
3204                         long num1;
3205                         long num2;
3206                         long num3;
3207                         long num4;
3208                         long long longnum;
3209                         longnum = MD5_string ( tempstring);
3210                         //longnum = 1111111111111111;
3211                         num1 = longnum/100000000;
3212                         num2 = longnum%100000000;
3213                         sprintf (tempstring, "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
3214
3215                         sprintf (menustring[2], "%s", tempstring);
3216                         startx[2]=290;
3217                         starty[2]=230;
3218                         endx[2]=startx[2]+strlen(menustring[2])*10;
3219                         endy[2]=starty[2]+20;
3220                         movex[2]=0;
3221                         movey[2]=0;                             */      
3222                 }
3223
3224                 if(mainmenu==1||mainmenu==2){
3225                         nummenuitems=7;
3226                         startx[0]=150;
3227                         starty[0]=480-128;
3228                         endx[0]=150+256;
3229                         endy[0]=480;
3230                         movex[0]=0;
3231                         movey[0]=0;
3232
3233                         startx[1]=18;
3234                         starty[1]=480-152-32;
3235                         endx[1]=18+128;
3236                         endy[1]=480-152;
3237                         movex[1]=0;
3238                         movey[1]=0;
3239
3240                         startx[2]=18;
3241                         starty[2]=480-228-32;
3242                         endx[2]=2+128;
3243                         endy[2]=480-228;
3244                         movex[2]=0;
3245                         movey[2]=0;
3246
3247                         if(mainmenu==1){
3248                                 startx[3]=18;
3249                                 starty[3]=480-306-32;
3250                                 endx[3]=22+64;
3251                                 endy[3]=480-306;
3252                                 movex[3]=0;
3253                                 movey[3]=0;
3254                         }
3255
3256                         if(mainmenu==2){
3257                                 startx[3]=18;
3258                                 starty[3]=480-306-32;
3259                                 endx[3]=22+128;
3260                                 endy[3]=480-306;
3261                                 movex[3]=0;
3262                                 movey[3]=0;
3263                         }
3264
3265                         /*startx[4]=150;
3266                         starty[4]=480-256;
3267                         endx[4]=150+256;
3268                         endy[4]=480;
3269                         */
3270                         if(anim==0){
3271                                 startx[4]=380;
3272                                 starty[4]=480-140-256;
3273                                 endx[4]=380+256;
3274                                 endy[4]=480-140;
3275                                 movex[4]=80;
3276                                 movey[4]=0;
3277
3278                                 startx[5]=145;
3279                                 starty[5]=480-138-256;
3280                                 endx[5]=145+256;
3281                                 endy[5]=480-138;
3282                                 movex[5]=40;
3283                                 movey[5]=0;
3284
3285                                 startx[6]=254;
3286                                 starty[6]=480-144-256;
3287                                 endx[6]=254+256;
3288                                 endy[6]=480-144;
3289                                 movex[6]=20;
3290                                 movey[6]=0;
3291                         }
3292                         if(anim==1){
3293                                 startx[4]=180;
3294                                 starty[4]=480-140-256;
3295                                 endx[4]=180+256;
3296                                 endy[4]=480-140;
3297                                 movex[4]=80;
3298                                 movey[4]=0;
3299
3300                                 startx[5]=500;
3301                                 starty[5]=480-138-256;
3302                                 endx[5]=500+256;
3303                                 endy[5]=480-138;
3304                                 movex[5]=40;
3305                                 movey[5]=0;
3306
3307                                 startx[6]=340;
3308                                 starty[6]=480-144-256;
3309                                 endx[6]=340+256;
3310                                 endy[6]=480-144;
3311                                 movex[6]=20;
3312                                 movey[6]=0;
3313                         }
3314                         if(anim==2){
3315                                 startx[4]=460;
3316                                 starty[4]=480-140-256;
3317                                 endx[4]=460+256;
3318                                 endy[4]=480-140;
3319                                 movex[4]=50;
3320                                 movey[4]=0;
3321
3322                                 startx[5]=295;
3323                                 starty[5]=480-150-256;
3324                                 endx[5]=295+256;
3325                                 endy[5]=480-138;
3326                                 movex[5]=-10;
3327                                 movey[5]=0;
3328
3329                                 startx[6]=204;
3330                                 starty[6]=480-144-256;
3331                                 endx[6]=204+256;
3332                                 endy[6]=480-144;
3333                                 movex[6]=-30;
3334                                 movey[6]=0;
3335                         }
3336                         if(anim==3){
3337                                 startx[4]=150;
3338                                 starty[4]=480-140-256;
3339                                 endx[4]=200+256;
3340                                 endy[4]=480-140;
3341                                 movex[4]=80;
3342                                 movey[4]=0;
3343
3344                                 startx[5]=350;
3345                                 starty[5]=480-150-256;
3346                                 endx[5]=350+256;
3347                                 endy[5]=480-138;
3348                                 movex[5]=5;
3349                                 movey[5]=0;
3350
3351                                 startx[6]=500;
3352                                 starty[6]=480-144-256;
3353                                 endx[6]=500+256;
3354                                 endy[6]=480-144;
3355                                 movex[6]=-10;
3356                                 movey[6]=0;
3357                         }
3358                         if(anim==4){
3359                                 startx[4]=190;
3360                                 starty[4]=480-100-256;
3361                                 endx[4]=190+256;
3362                                 endy[4]=480-100;
3363                                 movex[4]=-30;
3364                                 movey[4]=0;
3365
3366                                 startx[5]=185;
3367                                 starty[5]=480-120-256;
3368                                 endx[5]=185+256;
3369                                 endy[5]=480-120;
3370                                 movex[5]=-5;
3371                                 movey[5]=0;
3372
3373                                 startx[6]=400;
3374                                 starty[6]=480-144-256;
3375                                 endx[6]=400+256;
3376                                 endy[6]=480-144;
3377                                 movex[6]=20;
3378                                 movey[6]=0;
3379                         }
3380                 }
3381
3382                 selected=-1;
3383
3384                 if(mainmenu==1||mainmenu==2)
3385                         for(i=1;i<4;i++){
3386                                 if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
3387                                         selected=i;
3388                                 }
3389                         }
3390
3391                         if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==11||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17)
3392                                 for(i=0;i<nummenuitems;i++){
3393                                         if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
3394                                                 if(mainmenu!=5)selected=i;
3395                                                 if(mainmenu==5&&(i!=0&&i!=6))selected=i;
3396                                                 if(mainmenu==9&&(i!=numchallengelevels+1))selected=i;
3397                                                 if(mainmenu==11&&(i!=numchallengelevels+1))selected=i;
3398                                         }
3399                                 }
3400
3401                                 if(nummenuitems>0)
3402                                         for(i=0;i<nummenuitems;i++){
3403                                                 if(selected==i)selectedlong[i]+=multiplier*5;
3404                                                 if(selectedlong[i]>1)selectedlong[i]=1;
3405                                                 if(selected!=i)selectedlong[i]-=multiplier*5;
3406                                                 if(selectedlong[i]<0)selectedlong[i]=0; 
3407                                                 //if(i>=4)selectedlong[i]=.3;           
3408                                                 if(i>=4&&(mainmenu==1||mainmenu==2))selectedlong[i]=0;  
3409                                         }
3410
3411                                         if(nummenuitems>0)
3412                                                 for(i=0;i<nummenuitems;i++){
3413                                                         offsetx[i]=(startx[i]+endx[i])/2-(mousecoordh/screenwidth*640);
3414                                                         offsety[i]=(starty[i]+endy[i])/2-(480-(mousecoordv/screenheight*480));
3415                                                         offsetx[i]*=.06f;
3416                                                         offsety[i]*=.06f;
3417                                                         offsetx[i]=0;
3418                                                         offsety[i]=0;
3419                                                         if(i>=4&&(mainmenu==1||mainmenu==2)){
3420                                                                 offsetx[i]=(startx[i]+endx[i]+movex[i]*transition)/2-(640+190)/2;
3421                                                                 offsety[i]=(starty[i]+endy[i]+movey[i]*transition)/2-(336+150)/2;
3422                                                                 offsetx[i]*=.06f;
3423                                                                 offsety[i]*=.06f;
3424                                                         }
3425                                                 }
3426
3427                                                 if(mainmenu==1||mainmenu==2){
3428                                                         glClear(GL_DEPTH_BUFFER_BIT);
3429                                                         glEnable(GL_ALPHA_TEST);
3430                                                         glAlphaFunc(GL_GREATER, 0.001f);
3431                                                         glEnable(GL_TEXTURE_2D);
3432                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3433                                                         glDisable(GL_CULL_FACE);
3434                                                         glDisable(GL_LIGHTING);
3435                                                         glDepthMask(0);
3436                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3437                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3438                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3439                                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3440                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3441                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3442                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3443                                                                         glTranslatef(screenwidth/2,screenheight/2,0);
3444                                                                         glPushMatrix();
3445                                                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
3446                                                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3447                                                                                 glDisable(GL_BLEND);
3448                                                                                 glColor4f(0,0,0,1.0);
3449                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3450                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3451                                                                                 glDisable(GL_TEXTURE_2D);
3452                                                                                 glPushMatrix();
3453                                                                                         //glScalef(.25,.25,.25);
3454                                                                                         glBegin(GL_QUADS);
3455                                                                                         glTexCoord2f(0,0);
3456                                                                                         glVertex3f(-1,          -1,      0.0f);
3457                                                                                         glTexCoord2f(1,0);
3458                                                                                         glVertex3f(1,   -1,      0.0f);
3459                                                                                         glTexCoord2f(1,1);
3460                                                                                         glVertex3f(1,   1, 0.0f);
3461                                                                                         glTexCoord2f(0,1);
3462                                                                                         glVertex3f(-1,  1, 0.0f);
3463                                                                                         glEnd();
3464                                                                                 glPopMatrix();
3465                                                                                 glEnable(GL_BLEND);
3466                                                                                 glColor4f(0.4,0.4,0.4,1.0);
3467                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3468                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3469                                                                                 glEnable(GL_TEXTURE_2D);
3470                                                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
3471                                                                                 glPushMatrix();
3472                                                                                         //glScalef(.25,.25,.25);
3473                                                                                         glBegin(GL_QUADS);
3474                                                                                         glTexCoord2f(0,0);
3475                                                                                         glVertex3f(-1,          -1,      0.0f);
3476                                                                                         glTexCoord2f(1,0);
3477                                                                                         glVertex3f(1,   -1,      0.0f);
3478                                                                                         glTexCoord2f(1,1);
3479                                                                                         glVertex3f(1,   1, 0.0f);
3480                                                                                         glTexCoord2f(0,1);
3481                                                                                         glVertex3f(-1,  1, 0.0f);
3482                                                                                         glEnd();
3483                                                                                 glPopMatrix();
3484                                                                         glPopMatrix();
3485                                                                 glPopMatrix();
3486                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3487                                                         glPopMatrix();
3488
3489                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3490                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3491                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3492                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3493                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3494                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3495                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3496                                                                         glPushMatrix();
3497                                                                                 glDisable(GL_TEXTURE_2D);
3498                                                                                 glColor4f(1,0,0,1);
3499                                                                                 /*glPushMatrix();
3500                                                                                 glBegin(GL_QUADS);
3501                                                                                 glTexCoord2f(0,0);
3502                                                                                 if(anim!=1)glVertex3f(190,      150,     0.0f);
3503                                                                                 if(anim==1)glVertex3f(190+movex[4]*transition,  150,     0.0f);
3504                                                                                 glTexCoord2f(1,0);
3505                                                                                 glVertex3f(640, 150,     0.0f);
3506                                                                                 glTexCoord2f(1,1);
3507                                                                                 glVertex3f(640, 336, 0.0f);
3508                                                                                 glTexCoord2f(0,1);
3509                                                                                 if(anim!=1)glVertex3f(190, 336, 0.0f);
3510                                                                                 if(anim==1)glVertex3f(190+movex[4]*transition, 336,      0.0f);
3511                                                                                 glEnd();
3512                                                                                 glPopMatrix();*/
3513                                                                         glPopMatrix();
3514                                                                 glPopMatrix();
3515                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3516                                                         glPopMatrix();
3517                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3518
3519                                                 }
3520
3521                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3522                                                 glPushMatrix();                                                                         // Store The Projection Matrix
3523                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3524                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3525                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3526                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3527                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3528                                                 glEnable(GL_TEXTURE_2D);
3529                                                 if(nummenuitems>0)
3530                                                 {
3531                                                         for(j=0;j<nummenuitems;j++)
3532                                                         {
3533                                                                 if(j<=3||(mainmenu!=1&&mainmenu!=2))
3534                                                                 {
3535                                                                         //glDisable(GL_BLEND);
3536                                                                         glEnable(GL_ALPHA_TEST);
3537                                                                         glEnable(GL_BLEND);
3538                                                                         //glDisable(GL_ALPHA_TEST);
3539                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3540                                                                         if(mainmenu==1||mainmenu==2)
3541                                                                         {
3542                                                                                 glColor4f(1,1,1,1);
3543                                                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3544                                                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[j]);
3545                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
3546                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
3547                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3548                                                                                 glPushMatrix();
3549                                                                                         glBegin(GL_QUADS);
3550                                                                                         glTexCoord2f(0,0);
3551                                                                                         glVertex3f(startx[j]+movex[j]*transition,       starty[j]+movey[j]*transition,   0.0f);
3552                                                                                         glTexCoord2f(1,0);
3553                                                                                         glVertex3f(endx[j]+movex[j]*transition,         starty[j]+movey[j]*transition,   0.0f);
3554                                                                                         glTexCoord2f(1,1);
3555                                                                                         glVertex3f(endx[j]+movex[j]*transition,         endy[j]+movey[j]*transition, 0.0f);
3556                                                                                         glTexCoord2f(0,1);
3557                                                                                         glVertex3f(startx[j]+movex[j]*transition,       endy[j]+movey[j]*transition, 0.0f);
3558                                                                                         glEnd();
3559                                                                                 glPopMatrix();
3560                                                                                 glEnable(GL_BLEND);
3561                                                                                 //glDisable(GL_ALPHA_TEST);
3562                                                                                 if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3563                                                                                 for(i=0;i<10;i++)
3564                                                                                 {
3565                                                                                         if(1-((float)i)/10-(1-selectedlong[j])>0)
3566                                                                                         {
3567                                                                                                 glColor4f(1,1,1,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3568                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3569                                                                                                 glPushMatrix();
3570                                                                                                         glBegin(GL_QUADS);
3571                                                                                                         glTexCoord2f(0,0);
3572                                                                                                         glVertex3f(startx[j]-((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,        starty[j]-((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition,    0.0f);
3573                                                                                                         glTexCoord2f(1,0);
3574                                                                                                         glVertex3f(endx[j]+((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,  starty[j]-((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition,    0.0f);
3575                                                                                                         glTexCoord2f(1,1);
3576                                                                                                         glVertex3f(endx[j]+((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,  endy[j]+((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition, 0.0f);
3577                                                                                                         glTexCoord2f(0,1);
3578                                                                                                         glVertex3f(startx[j]-((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition, endy[j]+((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition, 0.0f);
3579                                                                                                         glEnd();
3580                                                                                                 glPopMatrix();
3581                                                                                         }
3582                                                                                 }
3583                                                                         }
3584                                                                         if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==11||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17)
3585                                                                         {
3586                                                                                 if(mainmenu!=5||j<6)
3587                                                                                 {
3588                                                                                         glColor4f(1,0,0,1);
3589                                                                                         if(mainmenu==12&&j==4)glColor4f(1,(sin(menupulse)+1)/2,(sin(menupulse)+1)/2,1);
3590                                                                                         if(mainmenu==9&&j>accountprogress[accountactive]&&j<numchallengelevels)glColor4f(0.5,0,0,1);
3591                                                                                         if(mainmenu==11&&j>accountprogress[accountactive]&&j<numchallengelevels)glColor4f(0.5,0,0,1);
3592                                                                                         //if(1-((float)i)/10-(1-selectedlong[j])>0){
3593                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3594                                                                                         glPushMatrix();
3595                                                                                                 if((mainmenu!=7||j!=0||!entername)&&(mainmenu!=13||j!=1)&&(mainmenu!=14||j!=1))text.glPrint(startx[j],starty[j],menustring[j],0,1,640,480);
3596                                                                                                 else
3597                                                                                                 {
3598                                                                                                         if(displayblink){
3599                                                                                                                 sprintf (string, "_");
3600                                                                                                                 text.glPrint(startx[j]+(float)(displayselected)*10,starty[j],string,0,1,640,480);
3601                                                                                                         }
3602                                                                                                         k=0;
3603                                                                                                         for(l=0;l<displaychars[k];l++){
3604                                                                                                                 if(l<displaychars[k]){
3605                                                                                                                         sprintf (string, "%c",displaytext[k][l]);
3606                                                                                                                         text.glPrint(startx[j]+l*10,starty[j],string,0,1,640,480);
3607                                                                                                                 }
3608                                                                                                         }
3609                                                                                                 }
3610                                                                                         glPopMatrix();
3611                                                                                         /*}
3612                                                                                         else{
3613                                                                                         glPushMatrix();
3614                                                                                         sprintf (string, "Hooo!");
3615                                                                                         text.glPrint(startx[0],starty[0],string,0,1,640,480);
3616                                                                                         glPopMatrix();
3617                                                                                         }*/
3618                                                                                         glEnable(GL_BLEND);
3619                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3620                                                                                         for(i=0;i<15;i++)
3621                                                                                         {
3622                                                                                                 if(1-((float)i)/15-(1-selectedlong[j])>0)
3623                                                                                                 {
3624                                                                                                         glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3625                                                                                                         if(mainmenu==12&&j==4)glColor4f(1,(sin(menupulse)+1)/2,(sin(menupulse)+1)/2,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3626                                                                                                         if(mainmenu==9&&j>accountprogress[accountactive]&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3627                                                                                                         if(mainmenu==11&&j>accountprogress[accountactive]&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3628                                                                                                         if(mainmenu==3)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4-((/*1*/+((float)i)/70)*strlen(menustring[j]))*3,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3629                                                                                                         if(mainmenu==4)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3630                                                                                                         if(mainmenu==5)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3631                                                                                                         if(mainmenu==6)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3632                                                                                                         if(mainmenu==7&&(j!=0||!entername))text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3633                                                                                                         if(mainmenu==8)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3634                                                                                                         if(mainmenu==9)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3635                                                                                                         if(mainmenu==11)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3636                                                                                                         if(mainmenu==10)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3637                                                                                                         if(mainmenu==12)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3638                                                                                                         if(mainmenu==15)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3639                                                                                                         if(mainmenu==16)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3640                                                                                                         if(mainmenu==17)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3641                                                                                                         if(mainmenu==13&&j!=1)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3642                                                                                                         if(mainmenu==14&&j!=1)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3643                                                                                                         /*else{
3644                                                                                                         if(displayblink){
3645                                                                                                         sprintf (string, "_");
3646                                                                                                         text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4+(float)(displayselected)*10*(1+((float)i)/70),starty[j]+offsety[j]*((float)i)/4,string,0,1+((float)i)/70,640,480);
3647                                                                                                         }
3648                                                                                                         k=0;
3649                                                                                                         for(l=0;l<displaychars[k];l++){
3650                                                                                                         if(l<displaychars[k]){
3651                                                                                                         sprintf (string, "%c",displaytext[k][l]);
3652                                                                                                         text.glPrint(startx[j]-((float)k)+offsetx[j]*((float)k)/4+l*10*(1+((float)i)/70),starty[j]+offsety[j]*((float)i)/4,string,0,1+((float)i)/70,640,480);
3653                                                                                                         }
3654                                                                                                         }
3655                                                                                                         }*/
3656                                                                                                 }
3657                                                                                         }
3658                                                                                 }
3659                                                                                 else
3660                                                                                 {
3661                                                                                         glClear(GL_DEPTH_BUFFER_BIT);
3662                                                                                         glEnable(GL_ALPHA_TEST);
3663                                                                                         glAlphaFunc(GL_GREATER, 0.001f);
3664                                                                                         glEnable(GL_TEXTURE_2D);
3665                                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3666                                                                                         glDisable(GL_CULL_FACE);
3667                                                                                         glDisable(GL_LIGHTING);
3668                                                                                         if(j==6)glColor4f(1,1,1,1);
3669                                                                                         else glColor4f(1,0,0,1);
3670
3671                                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3672                                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3673                                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3674                                                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3675                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3676                                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3677                                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3678                                                                                                         glPushMatrix();
3679
3680                                                                                                                 //Draw world, draw map
3681                                                                                                                 glTranslatef(2,-5,0);
3682
3683                                                                                                                 if(j>6&&j<nummenuitems-1)
3684                                                                                                                 {
3685                                                                                                                         XYZ linestart,lineend,offset;
3686                                                                                                                         XYZ fac;
3687                                                                                                                         float startsize;
3688                                                                                                                         float endsize;
3689                                                                                                                         linestart=0;
3690                                                                                                                         lineend=0;
3691                                                                                                                         offset=0;
3692                                                                                                                         //float linestartx,lineendx,linestarty,lineendy,offsetx,offsety;
3693                                                                                                                         linestart.x=(startx[j]+endx[j])/2;
3694                                                                                                                         linestart.y=(starty[j]+endy[j])/2;
3695                                                                                                                         if(j>=6+accountcampaignchoicesmade[accountactive]){
3696                                                                                                                                 linestart.x=(startx[6+accountcampaignchoicesmade[accountactive]]+endx[6+accountcampaignchoicesmade[accountactive]])/2;
3697                                                                                                                                 linestart.y=(starty[6+accountcampaignchoicesmade[accountactive]]+endy[6+accountcampaignchoicesmade[accountactive]])/2;
3698                                                                                                                         }
3699                                                                                                                         lineend.x=(startx[j+1]+endx[j+1])/2;
3700                                                                                                                         lineend.y=(starty[j+1]+endy[j+1])/2;
3701                                                                                                                         offset=lineend-linestart;
3702                                                                                                                         fac=offset;
3703                                                                                                                         Normalise(&fac);
3704                                                                                                                         offset=DoRotation(offset,0,0,90);
3705                                                                                                                         Normalise(&offset);
3706                                                                                                                         glDisable(GL_TEXTURE_2D);                                                       
3707
3708                                                                                                                         if(j<6+accountcampaignchoicesmade[accountactive]){
3709                                                                                                                                 glColor4f(0.5,0,0,1);
3710                                                                                                                                 startsize=.5;
3711                                                                                                                                 endsize=.5;
3712                                                                                                                         }
3713                                                                                                                         if(j>=6+accountcampaignchoicesmade[accountactive]){
3714                                                                                                                                 glColor4f(1,0,0,1);
3715                                                                                                                                 endsize=1;
3716                                                                                                                                 startsize=.5;
3717                                                                                                                         }
3718
3719                                                                                                                         linestart+=fac*4*startsize;
3720                                                                                                                         lineend-=fac*4*endsize;
3721
3722                                                                                                                         if(!(j>7+accountcampaignchoicesmade[accountactive]+campaignchoicenum)){
3723                                                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3724                                                                                                                                 glPushMatrix();
3725                                                                                                                                         glBegin(GL_QUADS);
3726                                                                                                                                         glTexCoord2f(0,0);
3727                                                                                                                                         glVertex3f(linestart.x-offset.x*startsize,      linestart.y-offset.y*startsize,          0.0f);
3728                                                                                                                                         glTexCoord2f(1,0);
3729                                                                                                                                         glVertex3f(linestart.x+offset.x*startsize,      linestart.y+offset.y*startsize,          0.0f);
3730                                                                                                                                         glTexCoord2f(1,1);
3731                                                                                                                                         glVertex3f(lineend.x+offset.x*endsize,          lineend.y+offset.y*endsize, 0.0f);
3732                                                                                                                                         glTexCoord2f(0,1);
3733                                                                                                                                         glVertex3f(lineend.x-offset.x*endsize,          lineend.y-offset.y*endsize, 0.0f);
3734                                                                                                                                         glEnd();
3735                                                                                                                                 glPopMatrix();
3736                                                                                                                         }
3737                                                                                                                         glEnable(GL_TEXTURE_2D);
3738                                                                                                                 }
3739
3740
3741                                                                                                                 if(j==6)glBindTexture( GL_TEXTURE_2D, Mainmenuitems[7]);
3742                                                                                                                 else glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
3743                                                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
3744                                                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
3745                                                                                                                 if(j-7<accountcampaignchoicesmade[accountactive])glColor4f(0.5,0,0,1);
3746                                                                                                                 if(j-7>=accountcampaignchoicesmade[accountactive])glColor4f(1,0,0,1);
3747                                                                                                                 if(j==6)glColor4f(1,1,1,1);
3748                                                                                                                 XYZ midpoint;
3749                                                                                                                 float itemsize;
3750                                                                                                                 itemsize=abs(startx[j]-endx[j])/2;
3751                                                                                                                 midpoint=0;
3752                                                                                                                 midpoint.x=(startx[j]+endx[j])/2;
3753                                                                                                                 midpoint.y=(starty[j]+endy[j])/2;
3754                                                                                                                 if(j>6&&(j-7<accountcampaignchoicesmade[accountactive]))itemsize*=.5;
3755                                                                                                                 if(!(j-7>accountcampaignchoicesmade[accountactive]+campaignchoicenum))
3756                                                                                                                 {
3757                                                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3758                                                                                                                         glPushMatrix();
3759                                                                                                                                 glBegin(GL_QUADS);
3760                                                                                                                                 glTexCoord2f(0,0);
3761                                                                                                                                 glVertex3f(midpoint.x-itemsize+movex[j]*transition,     midpoint.y-itemsize+movey[j]*transition,         0.0f);
3762                                                                                                                                 glTexCoord2f(1,0);
3763                                                                                                                                 glVertex3f(midpoint.x+itemsize+movex[j]*transition,             midpoint.y-itemsize+movey[j]*transition,         0.0f);
3764                                                                                                                                 glTexCoord2f(1,1);
3765                                                                                                                                 glVertex3f(midpoint.x+itemsize+movex[j]*transition,             midpoint.y+itemsize+movey[j]*transition, 0.0f);
3766                                                                                                                                 glTexCoord2f(0,1);
3767                                                                                                                                 glVertex3f(midpoint.x-itemsize+movex[j]*transition,     midpoint.y+itemsize+movey[j]*transition, 0.0f);
3768                                                                                                                                 glEnd();
3769                                                                                                                         glPopMatrix();
3770                                                                                                                         glEnable(GL_BLEND);
3771                                                                                                                         //glDisable(GL_ALPHA_TEST);
3772                                                                                                                         if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3773                                                                                                                         for(i=0;i<10;i++)
3774                                                                                                                         {
3775                                                                                                                                 if(1-((float)i)/10-(1-selectedlong[j])>0)
3776                                                                                                                                 {
3777                                                                                                                                         glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3778                                                                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3779                                                                                                                                         glPushMatrix();
3780                                                                                                                                                 glBegin(GL_QUADS);
3781                                                                                                                                                 glTexCoord2f(0,0);
3782                                                                                                                                                 glVertex3f(midpoint.x-itemsize-((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,      midpoint.y-itemsize-((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition,          0.0f);
3783                                                                                                                                                 glTexCoord2f(1,0);
3784                                                                                                                                                 glVertex3f(midpoint.x+itemsize+((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,      midpoint.y-itemsize-((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition,          0.0f);
3785                                                                                                                                                 glTexCoord2f(1,1);
3786                                                                                                                                                 glVertex3f(midpoint.x+itemsize+((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,      midpoint.y+itemsize+((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition, 0.0f);
3787                                                                                                                                                 glTexCoord2f(0,1);
3788                                                                                                                                                 glVertex3f(midpoint.x-itemsize-((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition, midpoint.y+itemsize+((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition, 0.0f);
3789                                                                                                                                                 glEnd();
3790                                                                                                                                         glPopMatrix();
3791                                                                                                                                 }
3792                                                                                                                         }
3793                                                                                                                 }
3794                                                                                                         glPopMatrix();
3795                                                                                                 glPopMatrix();
3796                                                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3797                                                                                         glPopMatrix();
3798                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3799
3800                                                                                         if(j-7>=accountcampaignchoicesmade[accountactive]){
3801                                                                                                 //glColor4f(0,0,0,1);
3802                                                                                                 //text.glPrintOutline(startx[j]+10-1.5,starty[j]-4-1.5,menustring[j],0,0.6*1.25,640,480);
3803                                                                                                 //glColor4f(1,0,0,1);
3804                                                                                                 //text.glPrint(startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
3805                                                                                                 text.glPrintOutlined(0.9,0,0,startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
3806                                                                                                 glDisable(GL_DEPTH_TEST);
3807                                                                                         }
3808                                                                                 }
3809                                                                         }
3810                                                                 }
3811                                                         }
3812                                                 }
3813                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3814                                                 glPopMatrix();
3815                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3816                                                 glPopMatrix();
3817
3818                                                         if(mainmenu==1||mainmenu==2)
3819                                                                 if(transition<.1||transition>.9){
3820                                                                         glClear(GL_DEPTH_BUFFER_BIT);
3821                                                                         glEnable(GL_ALPHA_TEST);
3822                                                                         glAlphaFunc(GL_GREATER, 0.001f);
3823                                                                         glEnable(GL_TEXTURE_2D);
3824                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3825                                                                         glDisable(GL_CULL_FACE);
3826                                                                         glDisable(GL_LIGHTING);
3827                                                                         glDepthMask(0);
3828                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3829                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3830                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3831                                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3832                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3833                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3834                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3835                                                                                         glPushMatrix();
3836                                                                                                 glDisable(GL_TEXTURE_2D);
3837                                                                                                 if(transition<.1)glColor4f(1,0,0,1-(transition*10));
3838                                                                                                 if(transition>.9)glColor4f(1,0,0,1-((1-transition)*10));
3839                                                                                                 /*glPushMatrix();
3840                                                                                                 glBegin(GL_QUADS);
3841                                                                                                 glTexCoord2f(0,0);
3842                                                                                                 glVertex3f(190, 150,     0.0f);
3843                                                                                                 glTexCoord2f(1,0);
3844                                                                                                 glVertex3f(640, 150,     0.0f);
3845                                                                                                 glTexCoord2f(1,1);
3846                                                                                                 glVertex3f(640, 336, 0.0f);
3847                                                                                                 glTexCoord2f(0,1);
3848                                                                                                 glVertex3f(190, 336, 0.0f);
3849                                                                                                 glEnd();
3850                                                                                                 glPopMatrix();*/
3851                                                                                         glPopMatrix();
3852                                                                                 glPopMatrix();
3853                                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3854                                                                         glPopMatrix();
3855                                                                 }
3856
3857                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3858                                                                 glPushMatrix();                                                                         // Store The Projection Matrix
3859                                                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
3860                                                                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3861                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3862                                                                         glPushMatrix();                                                                         // Store The Modelview Matrix
3863                                                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3864                                                                                 glTranslatef(screenwidth/2,screenheight/2,0);
3865                                                                                 glPushMatrix();
3866                                                                                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
3867                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3868                                                                                         glEnable(GL_BLEND);
3869                                                                                         glEnable(GL_TEXTURE_2D);
3870                                                                                         glColor4f(1,1,1,1);
3871                                                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3872                                                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3873                                                                                 glPopMatrix();
3874                                                                                 glPushMatrix();
3875                                                                                         glTranslatef(mousecoordh-screenwidth/2,mousecoordv*-1+screenheight/2,0);
3876                                                                                         glScalef((float)screenwidth/64,(float)screenwidth/64,1);
3877                                                                                         glTranslatef(1,-1,0);
3878                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3879                                                                                         glColor4f(1,1,1,1);
3880                                                                                         glBindTexture( GL_TEXTURE_2D, cursortexture);
3881                                                                                         glPushMatrix();
3882                                                                                                 //glScalef(.25,.25,.25);
3883                                                                                                 glBegin(GL_QUADS);
3884                                                                                                 glTexCoord2f(0,0);
3885                                                                                                 glVertex3f(-1,          -1,      0.0f);
3886                                                                                                 glTexCoord2f(1,0);
3887                                                                                                 glVertex3f(1,   -1,      0.0f);
3888                                                                                                 glTexCoord2f(1,1);
3889                                                                                                 glVertex3f(1,   1, 0.0f);
3890                                                                                                 glTexCoord2f(0,1);
3891                                                                                                 glVertex3f(-1,  1, 0.0f);
3892                                                                                                 glEnd();
3893                                                                                         glPopMatrix();
3894                                                                                 glPopMatrix();
3895                                                                         glPopMatrix();
3896                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3897                                                                 glPopMatrix();
3898
3899
3900                                                                 if(flashamount>0)
3901                                                                 {
3902                                                                         if(flashamount>1)flashamount=1;
3903                                                                         if(flashdelay<=0)flashamount-=multiplier;
3904                                                                         flashdelay--;
3905                                                                         if(flashamount<0)flashamount=0;
3906                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3907                                                                         glDisable(GL_CULL_FACE);
3908                                                                         glDisable(GL_LIGHTING);
3909                                                                         glDisable(GL_TEXTURE_2D);
3910                                                                         glDepthMask(0);
3911                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3912                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3913                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3914                                                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3915                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3916                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3917                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3918                                                                                         glScalef(screenwidth,screenheight,1);
3919                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3920                                                                                         glEnable(GL_BLEND);
3921                                                                                         glColor4f(flashr,flashg,flashb,flashamount);
3922                                                                                         glBegin(GL_QUADS);
3923                                                                                         glVertex3f(0,           0,       0.0f);
3924                                                                                         glVertex3f(256, 0,       0.0f);
3925                                                                                         glVertex3f(256, 256, 0.0f);
3926                                                                                         glVertex3f(0,   256, 0.0f);
3927                                                                                         glEnd();
3928                                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3929                                                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
3930                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3931                                                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
3932                                                                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
3933                                                                         glEnable(GL_CULL_FACE);
3934                                                                         glDisable(GL_BLEND);
3935                                                                         glDepthMask(1);
3936                                                                 }       
3937         }
3938
3939         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)){
3940                 tempmult=multiplier;
3941                 multiplier=0;
3942         }
3943
3944
3945         //glFlush();
3946         if(drawmode!=motionblurmode||mainmenu){
3947         #if !USE_SDL
3948         // this prevents menus from rendering if you hit ESC during
3949         //  motion blur sequences...maybe SDL is buffering differently?
3950                 if(drawmode!=motionblurmode)
3951                         swap_gl_buffers();
3952         #else
3953                 swap_gl_buffers();
3954         #endif
3955         }
3956
3957         //myassert(glGetError() == GL_NO_ERROR);
3958         glDrawBuffer(GL_BACK);
3959         glReadBuffer(GL_BACK);
3960         //glFlush();
3961
3962         weapons.DoStuff();
3963
3964         if(drawtoggle==2)drawtoggle=0;
3965
3966         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
3967                 multiplier=tempmult;
3968         }
3969         //Jordan fixed your warning!
3970         return 0;
3971 }
3972