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