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