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