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