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