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