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