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