]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
The damage bar now appear in the option menu
[lugaru.git] / Source / GameDraw.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #include "Game.h"
23 #include "openal_wrapper.h"
24
25 using namespace std;
26
27 extern XYZ viewer;
28 extern int environment;
29 extern float texscale;
30 extern Light light;
31 extern Terrain terrain;
32 extern Sprites sprites;
33 extern float multiplier;
34 extern float sps;
35 extern float viewdistance;
36 extern float fadestart;
37 extern float screenwidth,screenheight;
38 extern int kTextureSize;
39 extern FRUSTUM frustum;
40 extern Light light;
41 extern Objects objects;
42 extern int detail;
43 extern float usermousesensitivity;
44 extern bool osx;
45 extern float camerashake;
46 extern Weapons weapons;
47 extern Person player[maxplayers];
48 extern int slomo;
49 extern float slomodelay;
50 extern bool ismotionblur;
51 extern float woozy;
52 extern float blackout;
53 extern bool damageeffects;
54 extern float volume;
55 extern int numplayers;
56 extern bool texttoggle;
57 extern float blurness;
58 extern float targetblurness;
59 extern float playerdist;
60 extern bool cellophane;
61 extern bool freeze;
62 extern float flashamount,flashr,flashg,flashb;
63 extern int flashdelay;
64 extern int netstate;
65 extern float motionbluramount;
66 extern bool isclient;
67 extern bool alwaysblur;
68 extern int test;
69 extern bool tilt2weird;
70 extern bool tiltweird;
71 extern bool midweird;
72 extern bool proportionweird;
73 extern bool vertexweird[6];
74 extern bool velocityblur;
75 extern bool buttons[3];
76 extern bool debugmode;
77 extern int mainmenu;
78 extern int oldmainmenu;
79 extern int bloodtoggle;
80 extern int difficulty;
81 extern bool decals;
82 // MODIFIED GWC
83 //extern int texdetail;
84 extern float texdetail;
85 extern bool musictoggle;
86 extern int bonus;
87 extern float bonusvalue;
88 extern float bonustotal;
89 extern float bonustime;
90 extern int oldbonus;
91 extern float startbonustotal;
92 extern float bonusnum[100];
93 extern int tutoriallevel;
94 extern float smoketex;
95 extern float tutorialstagetime;
96 extern float tutorialmaxtime;
97 extern int tutorialstage;
98 extern bool againbonus;
99 extern float damagedealt;
100 extern float damagetaken;
101 extern bool invertmouse;
102
103 extern int numhotspots;
104 extern int winhotspot;
105 extern int killhotspot;
106 extern XYZ hotspot[40];
107 extern int hotspottype[40];
108 extern float hotspotsize[40];
109 extern char hotspottext[40][256];
110 extern int currenthotspot;
111
112 extern int numaccounts;
113 extern int accountactive;
114 extern int accountdifficulty[10];
115 extern int accountprogress[10];
116 extern float accountpoints[10];
117 extern float accounthighscore[10][50];
118 extern float accountfasttime[10][50];
119 extern bool accountunlocked[10][60];
120 extern char accountname[10][256];
121
122 extern int numfalls;
123 extern int numflipfail;
124 extern int numseen;
125 extern int numstaffattack;
126 extern int numswordattack;
127 extern int numknifeattack;
128 extern int numunarmedattack;
129 extern int numescaped;
130 extern int numflipped;
131 extern int numwallflipped;
132 extern int numthrowkill;
133 extern int numafterkill;
134 extern int numreversals;
135 extern int numattacks;
136 extern int maxalarmed;
137 extern int numresponded;
138
139 extern bool campaign;
140 extern bool winfreeze;
141
142 extern float menupulse;
143
144 extern bool gamestart;
145
146 extern int numdialogues;
147 extern int numdialogueboxes[max_dialogues];
148 extern int dialoguetype[max_dialogues];
149 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
150 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
151 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
152 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
153 extern char dialoguename[max_dialogues][max_dialoguelength][64];
154 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
155 extern XYZ participantlocation[max_dialogues][10];
156 extern int participantfocus[max_dialogues][max_dialoguelength];
157 extern int participantaction[max_dialogues][max_dialoguelength];
158 extern float participantrotation[max_dialogues][10];
159 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
160 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
161 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
162 extern int indialogue;
163 extern int whichdialogue;
164 extern int directing;
165 extern float dialoguetime;
166 extern int dialoguegonethrough[20];
167
168 extern int accountcampaignchoicesmade[10];
169 extern int accountcampaignchoices[10][5000];
170
171 extern float accountcampaignhighscore[10];
172 extern float accountcampaignfasttime[10];
173 extern float accountcampaignscore[10];
174 extern float accountcampaigntime[10];
175
176 extern bool gamestarted;
177
178 extern bool showdamagebar;
179
180 extern OPENAL_SAMPLE    *samp[100];
181 extern int channels[100];
182 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
183
184 /*********************> DrawGLScene() <*****/
185 long long Game::MD5_string (char *string){
186         char temp[256]="";
187         char temp2[256]="";
188         long long num=90814;
189
190         sprintf (temp, "%s",string);
191
192         int i=0;
193         while (i<256&&temp[i]!='\0'){
194                 if(temp[i]%3==0)num+=temp[i]*124;
195                 else if(temp[i]%3==1)num-=temp[i]*temp[i];
196                 else num*=temp[i];
197                 i++;
198         }
199
200         num=longlongabs(num);
201         if(num==0)num+=1452;
202
203         while(num<LONGLONGCONST(5000000000000000)){
204                 num*=1.85421521;
205         }
206
207         while(num>LONGLONGCONST(9900000000000000)){
208                 num/=1.235421521;
209         }
210
211         return num;
212
213         //return 1111111111111111;
214 }
215
216 int Game::DrawGLScene(StereoSide side)
217 {       
218         static float texcoordwidth,texcoordheight;
219         static float texviewwidth, texviewheight;
220         static int i,j,k,l;
221         static GLubyte color;
222         static float newbrightness;
223         static float changespeed;
224         static XYZ checkpoint;
225         static float tempmult;
226         float tutorialopac;
227         static char string[256]="";
228         static char string2[256]="";
229         static char string3[256]="";
230
231         static float lastcheck;
232
233         lastcheck+=multiplier;
234
235         if ( stereomode == stereoAnaglyph ) {
236                 switch(side) {
237                         case stereoLeft: glColorMask( 0.0, 1.0, 1.0, 1.0 ); break;
238                         case stereoRight: glColorMask( 1.0, 0.0, 0.0, 1.0 ); break;
239                 }
240         } else {
241                 glColorMask( 1.0, 1.0, 1.0, 1.0 );
242                 
243                 if ( stereomode == stereoHorizontalInterlaced || stereomode == stereoVerticalInterlaced ) {
244                         glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01);
245                 }
246         }
247
248         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
249                 tempmult=multiplier;
250                 multiplier=0;
251         }
252
253         if(!mainmenu){
254                 if(editorenabled){
255                         numboundaries=mapradius*2;
256                         if(numboundaries>360)numboundaries=360;
257                         for(i=0;i<numboundaries;i++){
258                                 boundary[i]=0;
259                                 boundary[i].z=1;
260                                 boundary[i]=mapcenter+DoRotation(boundary[i]*mapradius,0,i*(360/((float)(numboundaries))),0);
261                         }
262                 }
263
264                 SetUpLighting();
265
266                 static int changed;
267                 changed=0;
268
269                 olddrawmode=drawmode;
270                 if(ismotionblur&&!loading){
271                         if((findLengthfast(&player[0].velocity)>200)&&velocityblur&&!cameramode){
272                                 drawmode=motionblurmode;
273                                 motionbluramount=200/(findLengthfast(&player[0].velocity));
274                                 changed=1;
275                         }
276                         if(player[0].damage-player[0].superpermanentdamage>(player[0].damagetolerance-player[0].superpermanentdamage)*1/2&&damageeffects&&!cameramode){
277                                 drawmode=doublevisionmode;
278                                 changed=1;
279                         }
280                 }
281
282                 if(slomo&&!loading){
283                         if(ismotionblur)
284                                 drawmode=motionblurmode;
285                         motionbluramount=.2;
286                         slomodelay-=multiplier;
287                         if(slomodelay<0)slomo=0;
288                         camerashake=0;
289                         changed=1;
290                 }
291                 if((!changed&&!slomo)||loading){
292                         drawmode=normalmode;
293                         if(ismotionblur&&(/*fps>100||*/alwaysblur)){
294                                 if(olddrawmode!=realmotionblurmode)change=1;
295                                 else change=0;
296                                 drawmode=realmotionblurmode;
297                         }
298                         else if(olddrawmode==realmotionblurmode)change=2;
299                         else change=0;
300                 }
301
302                 if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted))drawmode=normalmode;
303                 if((freeze||winfreeze)&&ismotionblur&&!mainmenu)drawmode=radialzoommode;
304
305                 if(winfreeze||mainmenu)drawmode=normalmode;
306
307                 //drawmode=glowmode;
308                 if(drawmode==glowmode){
309                         RGBColor color2;
310                         color2.red=0;
311                         color2.green=0;
312                         color2.blue=0;
313 #if PLATFORM_MACOSX
314                         DSpContext_FadeGamma(NULL,200,&color2);
315 #endif
316                 }
317
318                 if(drawtoggle!=2)drawtoggle=1-drawtoggle;
319
320                 if(!texcoordwidth){
321
322                         texviewwidth=kTextureSize;
323                         if(texviewwidth>screenwidth)texviewwidth=screenwidth;
324                         texviewheight=kTextureSize;
325                         if(texviewheight>screenheight)texviewheight=screenheight;
326
327                         texcoordwidth=screenwidth/kTextureSize;
328                         texcoordheight=screenheight/kTextureSize;
329                         if(texcoordwidth>1)texcoordwidth=1;
330                         if(texcoordheight>1)texcoordheight=1;
331                 }
332
333                 glDrawBuffer(GL_BACK);
334                 glReadBuffer(GL_BACK);
335
336                 /*if(environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, (float)(abs(Random()%100))/50 );
337                 else glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
338                 */
339                 if(abs(blurness-targetblurness)<multiplier*10||abs(blurness-targetblurness)>2){
340                         blurness=targetblurness;
341                         targetblurness=(float)(abs(Random()%100))/40;
342                 }
343                 if(blurness<targetblurness)blurness+=multiplier*5;
344                 if(blurness>targetblurness)blurness-=multiplier*5;
345
346                 //glFinish();
347                 static XYZ terrainlight;
348                 static float distance;
349                 //if(drawmode==normalmode)ReSizeGLScene(90,.1);
350                 if(drawmode==normalmode)ReSizeGLScene(90,.1f);
351                 if(drawmode!=normalmode)glViewport(0,0,texviewwidth,texviewheight);     
352                 glDepthFunc(GL_LEQUAL);
353                 glDepthMask(1);
354                 glAlphaFunc(GL_GREATER, 0.0001f);
355                 glEnable(GL_ALPHA_TEST);
356                 glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
357                 glClear(GL_DEPTH_BUFFER_BIT);
358
359                 glMatrixMode (GL_MODELVIEW);
360                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
361                 glLoadIdentity ();
362                 
363                 // Move the camera for the current eye's point of view.
364                 // Reverse the movement if we're reversing stereo
365                 glTranslatef((stereoseparation/2) * side * (stereoreverse  ? -1 : 1), 0, 0);
366                 
367                 if(!cameramode&&!freeze&&!winfreeze){
368                         glRotatef(float(Random()%100)/10*camerashake/*+(woozy*woozy)/10*/,0,0,1);
369                         glRotatef(rotation2+sin(woozy/2)*(player[0].damage/player[0].damagetolerance)*5,1,0,0);
370                         glRotatef(rotation+sin(woozy)*(player[0].damage/player[0].damagetolerance)*5,0,1,0);
371                 }
372                 if(cameramode||freeze||winfreeze){
373                         //glRotatef(float(Random()%100)/10*camerashake/*+(woozy*woozy)/10*/,0,0,1);
374                         glRotatef(rotation2,1,0,0);
375                         glRotatef(rotation,0,1,0);
376                 }
377
378                 if(environment==desertenvironment){
379                         glRotatef((float)(abs(Random()%100))/3000-1,1,0,0);
380                         glRotatef((float)(abs(Random()%100))/3000-1,0,1,0);
381                         //glRotatef(blurness/40-1,1,0,0);
382                         //glRotatef(blurness/40-1,0,1,0);
383                 }
384                 SetUpLight(&light,0);
385                 glPushMatrix();
386                 if(environment==desertenvironment&&detail==2)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness+.4 );
387                 if(environment==desertenvironment){
388                         glRotatef((float)(abs(Random()%100))/1000,1,0,0);
389                         glRotatef((float)(abs(Random()%100))/1000,0,1,0);
390                 }       
391                 skybox.draw();
392                 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
393                 glPopMatrix();
394                 glTranslatef(-viewer.x,-viewer.y,-viewer.z);
395                 frustum.GetFrustum();
396
397                 //Make Shadow
398                 static XYZ point;
399                 static float size,opacity,rotation;
400                 rotation=0;
401                 for(k=0;k<numplayers;k++){
402                         if(!player[k].skeleton.free&&player[k].playerdetail&&player[k].howactive<typesleeping)
403                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y+player[k].scale*3,player[k].coords.z,player[k].scale*7)&&player[k].occluded<25)
404                                         for(i=0;i<player[k].skeleton.num_joints;i++){
405                                                 if(player[k].skeleton.joints[i].label==leftknee||player[k].skeleton.joints[i].label==rightknee||player[k].skeleton.joints[i].label==groin){
406                                                         point=DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
407                                                         size=.4f;
408                                                         opacity=.4-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
409                                                         if(k!=0&&tutoriallevel==1){
410                                                                 opacity=.2+.2*sin(smoketex*6+i)-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
411                                                         }
412                                                         terrain.MakeDecal(shadowdecal,point,size,opacity,rotation);
413                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
414                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
415                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
416                                                                         if(objects.position[j].y<player[k].coords.y||objects.type[j]==tunneltype||objects.type[j]==weirdtype){
417                                                                                 point=DoRotation(DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
418                                                                                 size=.4f;
419                                                                                 opacity=.4f;
420                                                                                 if(k!=0&&tutoriallevel==1){
421                                                                                         opacity=.2+.2*sin(smoketex*6+i);
422                                                                                 }
423                                                                                 objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
424                                                                         }
425                                                                 }
426                                                 }
427                                         }
428                                         if((player[k].skeleton.free||player[k].howactive>=typesleeping)&&player[k].playerdetail)
429                                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y,player[k].coords.z,player[k].scale*5)&&player[k].occluded<25)
430                                                         for(i=0;i<player[k].skeleton.num_joints;i++){
431                                                                 if(player[k].skeleton.joints[i].label==leftknee||player[k].skeleton.joints[i].label==rightknee||player[k].skeleton.joints[i].label==groin||player[k].skeleton.joints[i].label==leftelbow||player[k].skeleton.joints[i].label==rightelbow||player[k].skeleton.joints[i].label==neck){
432                                                                         if(player[k].skeleton.free)point=player[k].skeleton.joints[i].position*player[k].scale+player[k].coords;
433                                                                         else point=DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
434                                                                         size=.4f;
435                                                                         opacity=.4-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/5;
436                                                                         if(k!=0&&tutoriallevel==1){
437                                                                                 opacity=.2+.2*sin(smoketex*6+i)-player[k].skeleton.joints[i].position.y*player[k].scale/5-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/10;
438                                                                         }
439                                                                         terrain.MakeDecal(shadowdecal,point,size,opacity*.7,rotation);
440                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
441                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
442                                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
443                                                                                         if(objects.position[j].y<player[k].coords.y||objects.type[j]==tunneltype||objects.type[j]==weirdtype){
444                                                                                                 if(player[k].skeleton.free)point=DoRotation(player[k].skeleton.joints[i].position*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
445                                                                                                 else point=DoRotation(DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords-objects.position[j],0,-objects.rotation[j],0);
446                                                                                                 size=.4f;
447                                                                                                 opacity=.4f;
448                                                                                                 if(k!=0&&tutoriallevel==1){
449                                                                                                         opacity=.2+.2*sin(smoketex*6+i);
450                                                                                                 }
451                                                                                                 objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
452                                                                                         }
453                                                                                 }
454                                                                 }
455                                                         }
456
457                                                         if(!player[k].playerdetail)
458                                                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y,player[k].coords.z,player[k].scale*5))
459                                                                 {
460                                                                         point=player[k].coords;
461                                                                         size=.7;
462                                                                         opacity=.4-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/5;
463                                                                         terrain.MakeDecal(shadowdecal,point,size,opacity*.7,rotation);
464                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
465                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
466                                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
467                                                                                         point=DoRotation(player[k].coords-objects.position[j],0,-objects.rotation[j],0);
468                                                                                         size=.7;
469                                                                                         opacity=.4f;
470                                                                                         objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
471                                                                                 }
472                                                                 }
473                 }
474
475                 //Terrain
476                 glEnable(GL_TEXTURE_2D);
477                 glDepthMask(1);
478                 glEnable(GL_DEPTH_TEST);
479                 glEnable(GL_CULL_FACE);
480                 glDisable(GL_BLEND);
481                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
482                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
483                 glBindTexture( GL_TEXTURE_2D, terraintexture);
484                 terrain.draw(0);
485                 glBindTexture( GL_TEXTURE_2D, terraintexture2);
486                 terrain.draw(1);
487                 //glBindTexture( GL_TEXTURE_2D, terraintexture3);
488                 //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
489                 //terrain.draw(2);
490
491                 terrain.drawdecals();
492
493                 //Model
494                 glEnable(GL_CULL_FACE);
495                 glEnable(GL_LIGHTING);
496                 glDisable(GL_BLEND);
497                 glEnable(GL_TEXTURE_2D);
498                 glDepthMask(1);
499
500                 glEnable(GL_COLOR_MATERIAL);
501
502                 test=2;
503                 tilt2weird=0;
504                 tiltweird=0;
505                 midweird=0;
506                 proportionweird=0;
507                 vertexweird[0]=0;
508                 vertexweird[1]=0;
509                 vertexweird[2]=0;
510                 vertexweird[3]=0;
511                 vertexweird[4]=0;
512                 vertexweird[5]=0;
513
514                 if(!cellophane){
515                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
516                         glEnable(GL_CULL_FACE);
517                         glCullFace(GL_FRONT);
518                         glDepthMask(1);
519                         for(k=0;k<numplayers;k++){
520                                 if(k==0||tutoriallevel!=1){
521                                         glEnable(GL_BLEND);
522                                         glEnable(GL_LIGHTING);
523                                         terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
524                                         distance=findDistancefast(&viewer,&player[k].coords);
525                                         distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
526                                         glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
527                                         if(distance>=1)glDisable(GL_BLEND);
528                                         if(distance>=.5){
529                                                 checkpoint=DoRotation(player[k].skeleton.joints[abs(Random()%player[k].skeleton.num_joints)].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
530                                                 checkpoint.y+=1;
531                                                 if(!player[k].occluded==0)i=checkcollide(viewer,checkpoint,player[k].lastoccluded);
532                                                 if(i==-1||player[k].occluded==0)i=checkcollide(viewer,checkpoint);
533                                                 if(i!=-1){
534                                                         player[k].occluded+=1;
535                                                         player[k].lastoccluded=i;
536                                                 }
537                                                 else player[k].occluded=0;
538                                                 if(player[k].occluded<25)player[k].DrawSkeleton();
539                                         }
540                                 }
541                         }
542                 }
543
544                 if(!cameramode&&musictype==stream_music2)playerdist=findDistancefastflat(&player[0].coords,&viewer);
545                 else playerdist=-100;
546                 glPushMatrix();
547                 glCullFace(GL_BACK);
548                 glEnable(GL_TEXTURE_2D);
549                 objects.Draw();
550                 glPopMatrix();
551
552                 glPushMatrix();
553                 if(frustum.SphereInFrustum(realhawkcoords.x+hawk.boundingspherecenter.x,realhawkcoords.y+hawk.boundingspherecenter.y,realhawkcoords.z+hawk.boundingspherecenter.z,2)){   
554                         glAlphaFunc(GL_GREATER, 0.0001f);
555                         glDepthMask(1);
556                         glDisable(GL_CULL_FACE);
557                         glDisable(GL_LIGHTING);
558                         glEnable(GL_BLEND);
559                         glTranslatef(hawkcoords.x,hawkcoords.y,hawkcoords.z);
560                         glRotatef(hawkrotation,0,1,0);
561                         glTranslatef(25,0,0);
562                         distance=findDistancefast(&viewer,&realhawkcoords)*1.2;
563                         glColor4f(light.color[0],light.color[1],light.color[2],(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance);
564                         if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>1)glColor4f(light.color[0],light.color[1],light.color[2],1);
565                         if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>0)
566                                 hawk.drawdifftex(hawktexture);
567                 }
568                 glPopMatrix();
569
570                 //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                                         if(showdamagebar) {
1247                                                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1248                                                 glDisable(GL_CULL_FACE);
1249                                                 glDisable(GL_LIGHTING);
1250                                                 glDisable(GL_TEXTURE_2D);
1251                                                 glDepthMask(0);
1252                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1253                                                 glPushMatrix();                                                                         // Store The Projection Matrix
1254                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
1255                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);         // Set Up An Ortho Screen
1256                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1257                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
1258                                                 glLoadIdentity();                                                                       // Reset The Modelview Matrix
1259                                                 glTranslatef(15,screenheight*17.5/20,0);
1260                                                 glScalef(screenwidth/3+20,screenheight/20,1);
1261                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1262                                                 glEnable(GL_BLEND);
1263                                                 glColor4f(0.0,0.4,0.0,0.7);
1264                                                 float bar=((float)player[0].damage)/player[0].damagetolerance;
1265                                                 glBegin(GL_QUADS);
1266                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1267                                                 glVertex3f(1,0,0.0f);
1268                                                 glVertex3f(1,1,0.0f);
1269                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1270                                                 glEnd();
1271                                                 glColor4f(0.1,0.0,0.0,1);
1272                                                 bar = ((float)player[0].bloodloss)/player[0].damagetolerance;
1273                                                 glBegin(GL_QUADS);
1274                                                 glVertex3f(0,0,0.0f);
1275                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1276                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1277                                                 glVertex3f(0,1,0.0f);
1278                                                 glEnd();
1279                                                 glColor4f(0.4,0.0,0.0,0.7);
1280                                                 bar = ((float)player[0].damage)/player[0].damagetolerance;
1281                                                 glBegin(GL_QUADS);
1282                                                 glVertex3f(0,0,0.0f);
1283                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1284                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1285                                                 glVertex3f(0,1,0.0f);
1286                                                 glEnd();
1287                                                 glColor4f(0.4,0.0,0.0,0.7);
1288                                                 bar = ((float)player[0].permanentdamage)/player[0].damagetolerance;
1289                                                 glBegin(GL_QUADS);
1290                                                 glVertex3f(0,0,0.0f);
1291                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1292                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1293                                                 glVertex3f(0,1,0.0f);
1294                                                 glEnd();
1295                                                 glColor4f(0.4,0.0,0.0,0.7);
1296                                                 bar = ((float)player[0].superpermanentdamage)/player[0].damagetolerance;
1297                                                 glBegin(GL_QUADS);
1298                                                 glVertex3f(0,0,0.0f);
1299                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1300                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1301                                                 glVertex3f(0,1,0.0f);
1302                                                 glEnd();
1303                                                 glColor4f(0.0,0.0,0.0,0.7);
1304                                                 glLineWidth(2.0);
1305                                                 glBegin(GL_LINE_STRIP);
1306                                                 glVertex3f(0,0,0.0f);
1307                                                 glVertex3f(1,0,0.0f);
1308                                                 glVertex3f(1,1,0.0f);
1309                                                 glVertex3f(0,1,0.0f);
1310                                                 glVertex3f(0,0,0.0f);
1311                                                 glEnd();
1312                                                 
1313                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1314                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
1315                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1316                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
1317                                                 glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1318                                                 glEnable(GL_CULL_FACE);
1319                                                 glDisable(GL_BLEND);
1320                                                 glDepthMask(1);
1321                                                 glEnable(GL_TEXTURE_2D);
1322                                                 
1323                                                 // writing the numbers : 
1324                                                 sprintf (string, "Damages : %d/%d (%d)",(int)(player[0].damage),(int)(player[0].damagetolerance),(int)(player[0].bloodloss));
1325                                                 glColor4f(0,0,0,1);
1326                                                 text.glPrintOutline(1024/40-4,768/16-4+768*14/16-40,string,1,1.5*1.25,1024,768);
1327                                                 glColor4f(1,0,0,1);
1328                                                 text.glPrint(1024/40,768/16+768*14/16-40,string,1,1.5,1024,768);
1329                                         }
1330                                 }
1331
1332                                 glColor4f(.5,.5,.5,1);
1333
1334
1335                                 if((texttoggle||editorenabled)&&debugmode&&!mainmenu){
1336                                         sprintf (string, "The framespersecond is %d.",(int)(fps));
1337                                         text.glPrint(10,30,string,0,.8,1024,768);
1338
1339                                         sprintf (string, "Name: %s", registrationname);
1340                                         text.glPrint(10,260,string,0,.8,1024,768);
1341
1342
1343                                         if(editorenabled)sprintf (string, "Map editor enabled.");
1344                                         if(!editorenabled)sprintf (string, "Map editor Disabled.");
1345                                         text.glPrint(10,60,string,0,.8,1024,768);
1346                                         if(editorenabled){
1347                                                 sprintf (string, "Object size: %f",editorsize);
1348                                                 text.glPrint(10,75,string,0,.8,1024,768);
1349                                                 if(editorrotation>=0)sprintf (string, "Object rotation: %f",editorrotation);
1350                                                 else sprintf (string, "Object rotation: Random");
1351                                                 text.glPrint(10,90,string,0,.8,1024,768);
1352                                                 if(editorrotation2>=0)sprintf (string, "Object rotation2: %f",editorrotation2);
1353                                                 else sprintf (string, "Object rotation2: Random");
1354                                                 text.glPrint(10,105,string,0,.8,1024,768);
1355                                                 sprintf (string, "Object type: %d",editortype);
1356                                                 text.glPrint(10,120,string,0,.8,1024,768);
1357                                                 if(editortype==boxtype)sprintf (string, "(box)");
1358                                                 if(editortype==treetrunktype)sprintf (string, "(tree)");
1359                                                 if(editortype==walltype)sprintf (string, "(wall)");
1360                                                 if(editortype==weirdtype)sprintf (string, "(weird)");
1361                                                 if(editortype==spiketype)sprintf (string, "(spike)");
1362                                                 if(editortype==rocktype)sprintf (string, "(rock)");
1363                                                 if(editortype==bushtype)sprintf (string, "(bush)");
1364                                                 if(editortype==tunneltype)sprintf (string, "(tunnel)");
1365                                                 if(editortype==chimneytype)sprintf (string, "(chimney)");
1366                                                 if(editortype==platformtype)sprintf (string, "(platform)");
1367                                                 if(editortype==cooltype)sprintf (string, "(cool)");
1368                                                 if(editortype==firetype)sprintf (string, "(fire)");
1369                                                 text.glPrint(130,120,string,0,.8,1024,768);
1370
1371                                                 sprintf (string, "Numplayers: %d",numplayers);
1372                                                 text.glPrint(10,155,string,0,.8,1024,768);
1373                                                 sprintf (string, "Player %d: numwaypoints: %d",numplayers,player[numplayers-1].numwaypoints);
1374                                                 text.glPrint(10,140,string,0,.8,1024,768);
1375                                         }
1376                                         /*sprintf (string, "Coords are: %f %f %f",player[0].coords.x,player[0].coords.y,player[0].coords.z);
1377                                         text.glPrint(10,200,string,0,.8,1024,768);*/
1378                                         sprintf (string, "Difficulty: %d",difficulty);
1379                                         text.glPrint(10,240,string,0,.8,1024,768);
1380                                         /*
1381                                         sprintf (string, "lasthotspot: %d",hotspottype[numhotspots-1]);
1382                                         text.glPrint(10,240,string,0,.8,1024,768);
1383                                         sprintf (string, "killhotspot: %d",killhotspot);
1384                                         text.glPrint(10,220,string,0,.8,1024,768);
1385                                         sprintf (string, "winhotspot: %d",winhotspot);
1386                                         text.glPrint(10,200,string,0,.8,1024,768);*/
1387
1388                                 }
1389                 }
1390
1391                 if(drawmode==glowmode){
1392                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1393                         glDisable(GL_CULL_FACE);
1394                         glDisable(GL_LIGHTING);
1395                         glDisable(GL_TEXTURE_2D);
1396                         glDepthMask(0);
1397                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1398                         glPushMatrix();                                                                         // Store The Projection Matrix
1399                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1400                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1401                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1402                         glPushMatrix();                                                                         // Store The Modelview Matrix
1403                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1404                         glScalef(screenwidth,screenheight,1);
1405                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1406                         glEnable(GL_BLEND);
1407                         glColor4f(0,0,0,.5);
1408                         glBegin(GL_QUADS);
1409                         glVertex3f(0,           0,       0.0f);
1410                         glVertex3f(256, 0,       0.0f);
1411                         glVertex3f(256, 256, 0.0f);
1412                         glVertex3f(0,   256, 0.0f);
1413                         glEnd();
1414                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1415                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1416                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1417                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1418                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1419                         glEnable(GL_CULL_FACE);
1420                         glDisable(GL_BLEND);
1421                         glDepthMask(1);
1422                 }
1423
1424                 if((((blackout&&damageeffects)||(player[0].bloodloss>0&&damageeffects&&player[0].blooddimamount>0)||player[0].dead)&&!cameramode)||console){
1425                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1426                         glDisable(GL_CULL_FACE);
1427                         glDisable(GL_LIGHTING);
1428                         glDisable(GL_TEXTURE_2D);
1429                         glDepthMask(0);
1430                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1431                         glPushMatrix();                                                                         // Store The Projection Matrix
1432                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1433                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1434                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1435                         glPushMatrix();                                                                         // Store The Modelview Matrix
1436                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1437                         glScalef(screenwidth,screenheight,1);
1438                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1439                         glEnable(GL_BLEND);
1440                         if(player[0].dead)blackout+=multiplier*3;
1441                         if(player[0].dead==1)blackout=.4f;
1442                         if(player[0].dead==2&&blackout>.6)blackout=.6;
1443                         glColor4f(0,0,0,blackout);
1444                         if(!player[0].dead){
1445                                 if((player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5))*.3<.3){
1446                                         glColor4f(0,0,0,player[0].blooddimamount*player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5)*.3);
1447                                         blackout=player[0].blooddimamount*player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5)*.3;
1448                                 }
1449                                 else {
1450                                         glColor4f(0,0,0,player[0].blooddimamount*.3);
1451                                         blackout=player[0].blooddimamount*.3;
1452                                 }
1453                         }
1454                         if(console)glColor4f(.7,0,0,.2);
1455                         glBegin(GL_QUADS);
1456                         glVertex3f(0,           0,       0.0f);
1457                         glVertex3f(256, 0,       0.0f);
1458                         glVertex3f(256, 256, 0.0f);
1459                         glVertex3f(0,   256, 0.0f);
1460                         glEnd();
1461                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1462                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1463                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1464                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1465                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1466                         glEnable(GL_CULL_FACE);
1467                         glDisable(GL_BLEND);
1468                         glDepthMask(1);
1469                 }
1470
1471                 if(flashamount>0&&damageeffects){
1472                         if(flashamount>1)flashamount=1;
1473                         if(flashdelay<=0)flashamount-=multiplier;
1474                         flashdelay--;
1475                         if(flashamount<0)flashamount=0;
1476                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1477                         glDisable(GL_CULL_FACE);
1478                         glDisable(GL_LIGHTING);
1479                         glDepthMask(0);
1480                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1481                         glPushMatrix();                                                                         // Store The Projection Matrix
1482                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1483                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1484                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1485                         glPushMatrix();                                                                         // Store The Modelview Matrix
1486                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1487                         glScalef(screenwidth,screenheight,1);
1488                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1489                         glEnable(GL_BLEND);
1490                         glColor4f(flashr,flashg,flashb,flashamount);
1491                         glBegin(GL_QUADS);
1492                         glVertex3f(0,           0,       0.0f);
1493                         glVertex3f(256, 0,       0.0f);
1494                         glVertex3f(256, 256, 0.0f);
1495                         glVertex3f(0,   256, 0.0f);
1496                         glEnd();
1497                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1498                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1499                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1500                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1501                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1502                         glEnable(GL_CULL_FACE);
1503                         glDisable(GL_BLEND);
1504                         glDepthMask(1);
1505                 }       
1506
1507                 if(!console){
1508                         displaytime[0]=0;
1509                         glEnable(GL_TEXTURE_2D);
1510                         glColor4f(1,1,1,1);
1511                         if(chatting){
1512                                 sprintf (string, " ]");
1513                                 text.glPrint(10,30+screenheight-330,string,0,1,screenwidth,screenheight);
1514                                 if(displayblink){
1515                                         sprintf (string, "_");
1516                                         text.glPrint(30+(float)(displayselected)*10,30+(screenheight-330),string,0,1,screenwidth,screenheight);
1517                                 }
1518                         }
1519                         for(i=0;i<15;i++){
1520                                 if((i!=0||chatting)&&displaytime[i]<4)
1521                                         for(j=0;j<displaychars[i];j++){
1522                                                 glColor4f(1,1,1,4-displaytime[i]);
1523                                                 if(j<displaychars[i]){
1524                                                         sprintf (string, "%c",displaytext[i][j]);
1525                                                         text.glPrint(30+j*10,30+i*20+(screenheight-330),string,0,1,screenwidth,screenheight);
1526                                                 }
1527                                         }
1528                         }
1529                 }
1530
1531                 if(minimap&&indialogue==-1){
1532                         float mapviewdist;
1533                         mapviewdist=20000;
1534
1535                         glDisable(GL_DEPTH_TEST);
1536                         glColor3f (1.0, 1.0, 1.0); // no coloring
1537
1538                         glEnable(GL_TEXTURE_2D);
1539                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1540                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1541                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1542                         glDisable(GL_CULL_FACE);
1543                         glDisable(GL_LIGHTING);
1544                         glDepthMask(0);
1545                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1546                         glPushMatrix();                                                                         // Store The Projection Matrix
1547                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1548                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1549                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1550                         glPushMatrix();                                                                         // Store The Modelview Matrix
1551                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1552                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1553                         glTranslatef(1.75,.25,0);
1554                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1555                         glEnable(GL_BLEND);
1556                         glColor4f(1,1,1,1);
1557                         glPushMatrix();
1558                         float opac;
1559                         opac=.7;
1560                         XYZ center;
1561                         float radius;
1562                         float distcheck;
1563                         center=0;
1564                         int numliveplayers=0;
1565                         for(i=0;i<numplayers;i++){
1566                                 if(!player[i].dead)numliveplayers++;
1567                         }
1568
1569                         int numadd;
1570                         numadd=0;
1571
1572                         for(i=0;i<objects.numobjects;i++){
1573                                 if(objects.type[i]==treetrunktype||objects.type[i]==boxtype){
1574                                         center+=objects.position[i];    
1575                                         numadd++;
1576                                 }
1577                         }
1578                         for(i=0;i<numplayers;i++){
1579                                 if(!player[i].dead)center+=player[i].coords;    
1580                         }
1581                         center/=numadd+numliveplayers;
1582
1583                         center=player[0].coords;
1584
1585                         float maxdistance=0;
1586                         float tempdist;
1587                         int whichclosest;
1588                         for(i=0;i<objects.numobjects;i++){
1589                                 tempdist=findDistancefast(&center,&objects.position[i]);
1590                                 if(tempdist>maxdistance){
1591                                         whichclosest=i;
1592                                         maxdistance=tempdist;
1593                                 }
1594                         }
1595                         for(i=0;i<numplayers;i++){
1596                                 if(!player[i].dead){
1597                                         tempdist=findDistancefast(&center,&player[i].coords);
1598                                         if(tempdist>maxdistance){
1599                                                 whichclosest=i;
1600                                                 maxdistance=tempdist;
1601                                         }
1602                                 }
1603                         }
1604                         radius=fast_sqrt(maxdistance);
1605
1606                         radius=110;
1607
1608                         glScalef(.25/radius*256*terrain.scale*.4,.25/radius*256*terrain.scale*.4,1);
1609                         glPushMatrix();
1610                         glScalef(1/(1/radius*256*terrain.scale*.4),1/(1/radius*256*terrain.scale*.4),1);
1611                         /*float startx,starty,endx,endy;
1612                         glBegin(GL_QUADS);
1613                         glTexCoord2f(1-(center.x-radius)/terrain.scale/256,(center.z-radius)/terrain.scale/256);
1614                         glVertex3f(-1,          -1,      0.0f);
1615                         glTexCoord2f(1-(center.x+radius)/terrain.scale/256,(center.z-radius)/terrain.scale/256);
1616                         glVertex3f(1,   -1,      0.0f);
1617                         glTexCoord2f(1-(center.x+radius)/terrain.scale/256,(center.z+radius)/terrain.scale/256);
1618                         glVertex3f(1,   1, 0.0f);
1619                         glTexCoord2f(1-(center.x-radius)/terrain.scale/256,(center.z+radius)/terrain.scale/256);
1620                         glVertex3f(-1,  1, 0.0f);
1621                         glEnd();*/
1622                         glPopMatrix();
1623                         glRotatef(player[0].lookrotation*-1+180,0,0,1);
1624                         glTranslatef(-(center.x/terrain.scale/256*-2+1),(center.z/terrain.scale/256*-2+1),0);
1625                         for(i=0;i<objects.numobjects;i++){
1626                                 if(objects.type[i]==treetrunktype){
1627                                         distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
1628                                         if(distcheck<mapviewdist){
1629                                                 glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
1630                                                 glColor4f(0,.3,0,opac*(1-distcheck/mapviewdist));
1631                                                 glPushMatrix();
1632                                                 glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
1633                                                 glRotatef(objects.rotation[i],0,0,1);
1634                                                 glScalef(.003,.003,.003);
1635                                                 glBegin(GL_QUADS);
1636                                                 glTexCoord2f(0,0);
1637                                                 glVertex3f(-1,          -1,      0.0f);
1638                                                 glTexCoord2f(1,0);
1639                                                 glVertex3f(1,   -1,      0.0f);
1640                                                 glTexCoord2f(1,1);
1641                                                 glVertex3f(1,   1, 0.0f);
1642                                                 glTexCoord2f(0,1);
1643                                                 glVertex3f(-1,  1, 0.0f);
1644                                                 glEnd();
1645                                                 glPopMatrix();
1646                                         }
1647                                 }
1648                                 if(objects.type[i]==boxtype){
1649                                         distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
1650                                         if(distcheck<mapviewdist){
1651                                                 glBindTexture( GL_TEXTURE_2D, Mapboxtexture);
1652                                                 glColor4f(.4,.4,.4,opac*(1-distcheck/mapviewdist));
1653                                                 glPushMatrix();
1654                                                 glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
1655                                                 glRotatef(objects.rotation[i],0,0,1);
1656                                                 glScalef(.01*objects.scale[i],.01*objects.scale[i],.01*objects.scale[i]);
1657                                                 glBegin(GL_QUADS);
1658                                                 glTexCoord2f(0,0);
1659                                                 glVertex3f(-1,          -1,      0.0f);
1660                                                 glTexCoord2f(1,0);
1661                                                 glVertex3f(1,   -1,      0.0f);
1662                                                 glTexCoord2f(1,1);
1663                                                 glVertex3f(1,   1, 0.0f);
1664                                                 glTexCoord2f(0,1);
1665                                                 glVertex3f(-1,  1, 0.0f);
1666                                                 glEnd();
1667                                                 glPopMatrix();
1668                                         }
1669                                 }
1670                         }
1671                         if(editorenabled){
1672                                 glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
1673                                 for(i=0;i<numboundaries;i++){
1674                                         glColor4f(0,0,0,opac/3);
1675                                         glPushMatrix();
1676                                         glTranslatef(boundary[i].x/terrain.scale/256*-2+1,boundary[i].z/terrain.scale/256*2-1,0);
1677                                         glScalef(.002,.002,.002);
1678                                         glBegin(GL_QUADS);
1679                                         glTexCoord2f(0,0);
1680                                         glVertex3f(-1,          -1,      0.0f);
1681                                         glTexCoord2f(1,0);
1682                                         glVertex3f(1,   -1,      0.0f);
1683                                         glTexCoord2f(1,1);
1684                                         glVertex3f(1,   1, 0.0f);
1685                                         glTexCoord2f(0,1);
1686                                         glVertex3f(-1,  1, 0.0f);
1687                                         glEnd();
1688                                         glPopMatrix();
1689                                 }
1690                         }
1691                         for(i=0;i<numplayers;i++){
1692                                 distcheck=findDistancefast(&player[0].coords,&player[i].coords);
1693                                 if(distcheck<mapviewdist){
1694                                         glPushMatrix();
1695                                         glBindTexture( GL_TEXTURE_2D, Maparrowtexture);
1696                                         if(i==0)glColor4f(1,1,1,opac);
1697                                         else if(player[i].dead==2||player[i].howactive>typesleeping)glColor4f(0,0,0,opac*(1-distcheck/mapviewdist));
1698                                         else if(player[i].dead)glColor4f(.3,.3,.3,opac*(1-distcheck/mapviewdist));
1699                                         else if(player[i].aitype==attacktypecutoff)glColor4f(1,0,0,opac*(1-distcheck/mapviewdist));
1700                                         else if(player[i].aitype==passivetype)glColor4f(0,1,0,opac*(1-distcheck/mapviewdist));
1701                                         else glColor4f(1,1,0,1);
1702                                         glTranslatef(player[i].coords.x/terrain.scale/256*-2+1,player[i].coords.z/terrain.scale/256*2-1,0);
1703                                         glRotatef(player[i].rotation+180,0,0,1);
1704                                         glScalef(.005,.005,.005);
1705                                         glBegin(GL_QUADS);
1706                                         glTexCoord2f(0,0);
1707                                         glVertex3f(-1,          -1,      0.0f);
1708                                         glTexCoord2f(1,0);
1709                                         glVertex3f(1,   -1,      0.0f);
1710                                         glTexCoord2f(1,1);
1711                                         glVertex3f(1,   1, 0.0f);
1712                                         glTexCoord2f(0,1);
1713                                         glVertex3f(-1,  1, 0.0f);
1714                                         glEnd();
1715                                         /*glBegin(GL_TRIANGLES);
1716                                         glTexCoord2f(0,0);
1717                                         glVertex3f(-1,          -1,      0.0f);
1718                                         glTexCoord2f(1,0);
1719                                         glVertex3f(1,   -1,      0.0f);
1720                                         glTexCoord2f(1,1);
1721                                         glVertex3f(0,   1, 0.0f);
1722                                         glEnd();*/
1723                                         glPopMatrix();
1724                                 }
1725                         }
1726                         /*glBegin(GL_QUADS);
1727                         glTexCoord2f(0,0);
1728                         glVertex3f(-1,          -1,      0.0f);
1729                         glTexCoord2f(1,0);
1730                         glVertex3f(1,   -1,      0.0f);
1731                         glTexCoord2f(1,1);
1732                         glVertex3f(1,   1, 0.0f);
1733                         glTexCoord2f(0,1);
1734                         glVertex3f(-1,  1, 0.0f);
1735                         glEnd();*/
1736                         glPopMatrix();
1737                         glDisable(GL_TEXTURE_2D);
1738                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1739                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1740                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1741                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1742                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1743                         glEnable(GL_CULL_FACE);
1744                         glDisable(GL_BLEND);
1745                         glDepthMask(1);
1746                 }
1747
1748                 /*if(loading){
1749                 loading=2;
1750                 drawmode=normalmode;
1751                 }*/
1752
1753
1754                 if(loading&&!stealthloading&&(!campaign||player[0].dead)){
1755                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1756                         glDisable(GL_CULL_FACE);
1757                         glDisable(GL_LIGHTING);
1758                         glDisable(GL_TEXTURE_2D);
1759                         glDepthMask(0);
1760                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1761                         glPushMatrix();                                                                         // Store The Projection Matrix
1762                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1763                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1764                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1765                         glPushMatrix();                                                                         // Store The Modelview Matrix
1766                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1767                         glScalef(screenwidth,screenheight,1);
1768                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1769                         glEnable(GL_BLEND);
1770                         glColor4f(0,0,0,.7);
1771                         glBegin(GL_QUADS);
1772                         glVertex3f(0,           0,       0.0f);
1773                         glVertex3f(256, 0,       0.0f);
1774                         glVertex3f(256, 256, 0.0f);
1775                         glVertex3f(0,   256, 0.0f);
1776                         glEnd();
1777                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1778                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1779                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1780                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1781                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1782                         glEnable(GL_CULL_FACE);
1783                         glDisable(GL_BLEND);
1784                         glDepthMask(1);
1785
1786                         //logo
1787                         glDisable(GL_DEPTH_TEST);
1788                         glColor3f (1.0, 1.0, 1.0); // no coloring
1789
1790                         glEnable(GL_TEXTURE_2D);
1791                         /*glBindTexture( GL_TEXTURE_2D, logotexture);
1792                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1793                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1794                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1795                         glDisable(GL_CULL_FACE);
1796                         glDisable(GL_LIGHTING);
1797                         glDepthMask(0);
1798                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1799                         glPushMatrix();                                                                         // Store The Projection Matrix
1800                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1801                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1802                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1803                         glPushMatrix();                                                                         // Store The Modelview Matrix
1804                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1805                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1806                         glTranslatef(1.8,1.25,0);
1807                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1808                         glEnable(GL_BLEND);
1809                         glColor4f(1,1,1,1);
1810                         glPushMatrix();
1811                         glScalef(.25,.25,.25);
1812                         glBegin(GL_QUADS);
1813                         glTexCoord2f(0,0);
1814                         glVertex3f(-1,          -1,      0.0f);
1815                         glTexCoord2f(1,0);
1816                         glVertex3f(1,   -1,      0.0f);
1817                         glTexCoord2f(1,1);
1818                         glVertex3f(1,   1, 0.0f);
1819                         glTexCoord2f(0,1);
1820                         glVertex3f(-1,  1, 0.0f);
1821                         glEnd();
1822                         glPopMatrix();
1823                         glDisable(GL_TEXTURE_2D);
1824                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1825                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1826                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1827                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1828                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1829                         glEnable(GL_CULL_FACE);
1830                         glDisable(GL_BLEND);
1831                         glDepthMask(1);*/
1832
1833                         //Minimap
1834
1835                         if(loading!=4){                         
1836                                 glEnable(GL_TEXTURE_2D);
1837                                 glColor4f(1,1,1,1);
1838                                 sprintf (string, "Loading...");
1839                                 text.glPrint(1024/2-90,768/2,string,1,2,1024,768);
1840                         }
1841                         loading=2;
1842                         //if(ismotionblur)drawmode=motionblurmode;
1843                         drawmode=normalmode;
1844                 }
1845
1846                 if(winfreeze&&!campaign){
1847                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1848                         glDisable(GL_CULL_FACE);
1849                         glDisable(GL_LIGHTING);
1850                         glDisable(GL_TEXTURE_2D);
1851                         glDepthMask(0);
1852                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1853                         glPushMatrix();                                                                         // Store The Projection Matrix
1854                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1855                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1856                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1857                         glPushMatrix();                                                                         // Store The Modelview Matrix
1858                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1859                         glScalef(screenwidth,screenheight,1);
1860                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1861                         glEnable(GL_BLEND);
1862                         glColor4f(0,0,0,.4);
1863                         glBegin(GL_QUADS);
1864                         glVertex3f(0,           0,       0.0f);
1865                         glVertex3f(256, 0,       0.0f);
1866                         glVertex3f(256, 256, 0.0f);
1867                         glVertex3f(0,   256, 0.0f);
1868                         glEnd();
1869                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1870                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1871                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1872                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1873                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1874                         glEnable(GL_CULL_FACE);
1875                         glDisable(GL_BLEND);
1876                         glDepthMask(1);
1877
1878                         //logo
1879                         glDisable(GL_DEPTH_TEST);
1880                         glColor3f (1.0, 1.0, 1.0); // no coloring
1881
1882                         glEnable(GL_TEXTURE_2D);
1883                         /*glBindTexture( GL_TEXTURE_2D, logotexture);
1884                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1885                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1886                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1887                         glDisable(GL_CULL_FACE);
1888                         glDisable(GL_LIGHTING);
1889                         glDepthMask(0);
1890                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1891                         glPushMatrix();                                                                         // Store The Projection Matrix
1892                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1893                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1894                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1895                         glPushMatrix();                                                                         // Store The Modelview Matrix
1896                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1897                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1898                         glTranslatef(1.8,1.25,0);
1899                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1900                         glEnable(GL_BLEND);
1901                         glColor4f(1,1,1,1);
1902                         glPushMatrix();
1903                         glScalef(.25,.25,.25);
1904                         glBegin(GL_QUADS);
1905                         glTexCoord2f(0,0);
1906                         glVertex3f(-1,          -1,      0.0f);
1907                         glTexCoord2f(1,0);
1908                         glVertex3f(1,   -1,      0.0f);
1909                         glTexCoord2f(1,1);
1910                         glVertex3f(1,   1, 0.0f);
1911                         glTexCoord2f(0,1);
1912                         glVertex3f(-1,  1, 0.0f);
1913                         glEnd();
1914                         glPopMatrix();
1915                         glDisable(GL_TEXTURE_2D);
1916                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1917                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1918                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1919                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1920                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1921                         glEnable(GL_CULL_FACE);
1922                         glDisable(GL_BLEND);
1923                         glDepthMask(1);*/
1924
1925                         //Awards
1926                         int numawards;
1927                         int awards[30];
1928                         numawards=0;
1929
1930                         if(damagetaken==0&&player[0].bloodloss==0){
1931                                 awards[numawards]=awardflawless;
1932                                 numawards++;
1933                         }
1934                         bool alldead;
1935                         alldead=1;
1936                         if(numplayers>1)
1937                                 for(i=1;i<numplayers;i++){              
1938                                         if(player[i].dead!=2)alldead=0;
1939                                 }
1940                                 if(alldead){
1941                                         awards[numawards]=awardalldead;
1942                                         numawards++;
1943                                 }
1944                                 alldead=1;
1945                                 if(numplayers>1)
1946                                         for(i=1;i<numplayers;i++){              
1947                                                 if(player[i].dead!=1)alldead=0;
1948                                         }
1949                                         if(alldead){
1950                                                 awards[numawards]=awardnodead;
1951                                                 numawards++;
1952                                         }
1953                                         if(numresponded==0&&!numthrowkill){
1954                                                 awards[numawards]=awardstealth;
1955                                                 numawards++;
1956                                         }
1957                                         if(numattacks==numstaffattack&&numattacks>0){
1958                                                 awards[numawards]=awardbojutsu;
1959                                                 numawards++;
1960                                         }
1961                                         if(numattacks==numswordattack&&numattacks>0){
1962                                                 awards[numawards]=awardswordsman;
1963                                                 numawards++;
1964                                         }
1965                                         if(numattacks==numknifeattack&&numattacks>0){
1966                                                 awards[numawards]=awardknifefighter;
1967                                                 numawards++;
1968                                         }
1969                                         if(numattacks==numunarmedattack&&numthrowkill==0&&weapons.numweapons>0){
1970                                                 awards[numawards]=awardkungfu;
1971                                                 numawards++;
1972                                         }
1973                                         if(numescaped>0){
1974                                                 awards[numawards]=awardevasion;
1975                                                 numawards++;
1976                                         }
1977                                         if(numflipfail==0&&numflipped+numwallflipped*2>20){
1978                                                 awards[numawards]=awardacrobat;
1979                                                 numawards++;
1980                                         }
1981                                         if(numthrowkill==numplayers-1){
1982                                                 awards[numawards]=awardlongrange;
1983                                                 numawards++;
1984                                         }
1985                                         alldead=1;
1986                                         if(numplayers>1)
1987                                                 for(i=1;i<numplayers;i++){              
1988                                                         if(player[i].dead!=2)alldead=0;
1989                                                 }
1990                                                 if(numafterkill>0&&alldead){
1991                                                         awards[numawards]=awardbrutal;
1992                                                         numawards++;
1993                                                 }
1994                                                 if(numreversals>((float)numattacks)*.8&&numreversals>3){
1995                                                         awards[numawards]=awardaikido;
1996                                                         numawards++;
1997                                                 }
1998                                                 if(maxalarmed==1&&numplayers>2){
1999                                                         awards[numawards]=awardstrategy;
2000                                                         numawards++;
2001                                                 }
2002                                                 if(numflipfail>3){
2003                                                         awards[numawards]=awardklutz;
2004                                                         numawards++;
2005                                                 }
2006
2007
2008                                                 //Win Screen Won Victory
2009
2010                                                 glEnable(GL_TEXTURE_2D);
2011                                                 glColor4f(1,1,1,1);
2012                                                 sprintf (string, "Level Cleared!");
2013                                                 text.glPrintOutlined(1024/2-strlen(string)*10,768*7/8,string,1,2,1024,768);
2014
2015                                                 sprintf (string, "Score:     %d",(int)(bonustotal-startbonustotal));
2016                                                 text.glPrintOutlined(1024/30,768*6/8,string,1,2,1024,768);
2017
2018                                                 if(!campaign)sprintf (string, "Press Escape to return to menu or Space to continue");
2019                                                 if(campaign)sprintf (string, "Press Escape or Space to continue");
2020                                                 text.glPrintOutlined(640/2-strlen(string)*5,480*1/16,string,1,1,640,480);
2021
2022                                                 char temp[255];
2023
2024                                                 for(i=0;i<255;i++)string[i]='\0';
2025                                                 sprintf (temp, "Time:      %d:",(int)(((int)leveltime-(int)(leveltime)%60)/60));
2026                                                 strcat(string,temp);
2027                                                 if((int)(leveltime)%60<10)strcat(string,"0");
2028                                                 sprintf (temp, "%d",(int)(leveltime)%60);
2029                                                 strcat(string,temp);
2030                                                 text.glPrintOutlined(1024/30,768*6/8-40,string,1,2,1024,768);
2031
2032                                                 for(i=0;i<numawards;i++){
2033                                                         if(i<6){
2034                                                                 if(awards[i]==awardklutz)sprintf (string, "Suicidal");
2035                                                                 if(awards[i]==awardflawless)sprintf (string, "Flawless!");
2036                                                                 if(awards[i]==awardalldead)sprintf (string, "Take no prisoners");
2037                                                                 if(awards[i]==awardnodead)sprintf (string, "Merciful");
2038                                                                 if(awards[i]==awardstealth)sprintf (string, "One with the shadows!");
2039                                                                 if(awards[i]==awardswordsman)sprintf (string, "Swordsman");
2040                                                                 if(awards[i]==awardkungfu)sprintf (string, "Unarmed!");
2041                                                                 if(awards[i]==awardknifefighter)sprintf (string, "Knife fighter");
2042                                                                 if(awards[i]==awardcoward)sprintf (string, "Coward");
2043                                                                 if(awards[i]==awardevasion)sprintf (string, "Escape artist");
2044                                                                 if(awards[i]==awardacrobat)sprintf (string, "Gymnast");
2045                                                                 if(awards[i]==awardlongrange)sprintf (string, "Blade slinger");
2046                                                                 if(awards[i]==awardbrutal)sprintf (string, "Brutal");
2047                                                                 if(awards[i]==awardhyper)sprintf (string, "Hyper");
2048                                                                 if(awards[i]==awardaikido)sprintf (string, "Aikido master!");
2049                                                                 if(awards[i]==awardrambo)sprintf (string, "Rambo");
2050                                                                 if(awards[i]==awardfast)sprintf (string, "Fast");
2051                                                                 if(awards[i]==awardrealfast)sprintf (string, "Real fast");
2052                                                                 if(awards[i]==awarddamnfast)sprintf (string, "Damn fast");
2053                                                                 if(awards[i]==awardstrategy)sprintf (string, "Divide and conquer");
2054                                                                 if(awards[i]==awardbojutsu)sprintf (string, "Bojutsu");
2055                                                                 text.glPrintOutlined(1024/30,768*6/8-90-40*i,string,1,2,1024,768);
2056                                                         }
2057                                                 }
2058
2059                                                 //drawmode=normalmode;
2060                 }
2061
2062                 if(drawmode!=normalmode){
2063                         glEnable(GL_TEXTURE_2D);
2064                         glFinish();
2065                         if(!drawtoggle||drawmode!=realmotionblurmode||(drawtoggle==2||change==1)){
2066                                 if(screentexture){
2067
2068                                         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
2069                                         GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
2070                                         glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
2071                                         //glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_SUBTRACT);
2072                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
2073                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
2074                                         glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
2075
2076                                         glBindTexture( GL_TEXTURE_2D, screentexture);
2077                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
2078                                 }
2079                         }
2080                         if((drawtoggle||change==1)&&drawmode==realmotionblurmode){
2081                                 if(screentexture2){
2082                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
2083                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
2084                                 }
2085                                 if(!screentexture2){
2086                                         glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
2087
2088                                         glGenTextures( 1, &screentexture2 );
2089                                         glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2090
2091                                         glEnable(GL_TEXTURE_2D);
2092                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
2093                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
2094                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
2095
2096                                         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);                
2097                                 }
2098                         }
2099                         //glFlush();
2100                 }
2101
2102                 glClear(GL_DEPTH_BUFFER_BIT);
2103                 ReSizeGLScene(90,.1f);
2104                 glViewport(0,0,screenwidth,screenheight);       
2105
2106                 if(drawmode!=normalmode){
2107                         glDisable(GL_DEPTH_TEST);
2108                         if(drawmode==motionblurmode){
2109                                 glDrawBuffer(GL_FRONT);
2110                                 glReadBuffer(GL_BACK);
2111                                 //myassert(glGetError() == GL_NO_ERROR);
2112                                 //glFlush();
2113                         }
2114                         glColor3f (1.0, 1.0, 1.0); // no coloring
2115
2116                         glEnable(GL_TEXTURE_2D);
2117                         glBindTexture( GL_TEXTURE_2D, screentexture);
2118                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
2119                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
2120                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2121                         glDisable(GL_CULL_FACE);
2122                         glDisable(GL_LIGHTING);
2123                         glDepthMask(0);
2124                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2125                         glPushMatrix();                                                                         // Store The Projection Matrix
2126                         glLoadIdentity();                                                                       // Reset The Projection Matrix
2127                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2128                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2129                         glPushMatrix();                                                                         // Store The Modelview Matrix
2130                         glLoadIdentity();                                                               // Reset The Modelview Matrix
2131                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
2132                         glTranslatef(1,1,0);
2133                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2134                         glEnable(GL_BLEND);
2135                         if(drawmode==motionblurmode){
2136                                 if(motionbluramount<.2)motionbluramount=.2;
2137                                 //glColor4f(1,1,1,fast_sqrt(multiplier)*2.9*motionbluramount);
2138                                 glColor4f(1,1,1,motionbluramount);
2139                                 glPushMatrix();
2140                                 glBegin(GL_QUADS);
2141                                 glTexCoord2f(0,0);
2142                                 glVertex3f(-1,          -1,      0.0f);
2143                                 glTexCoord2f(texcoordwidth,0);
2144                                 glVertex3f(1,   -1,      0.0f);
2145                                 glTexCoord2f(texcoordwidth,texcoordheight);
2146                                 glVertex3f(1,   1, 0.0f);
2147                                 glTexCoord2f(0,texcoordheight);
2148                                 glVertex3f(-1,  1, 0.0f);
2149                                 glEnd();
2150                                 glPopMatrix();
2151                         }
2152                         if(drawmode==realmotionblurmode){
2153                                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2154                                 glClear(GL_COLOR_BUFFER_BIT);
2155                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2156                                 glBindTexture( GL_TEXTURE_2D, screentexture);
2157                                 glColor4f(1,1,1,.5);
2158                                 glPushMatrix();
2159                                 glBegin(GL_QUADS);
2160                                 glTexCoord2f(0,0);
2161                                 glVertex3f(-1,          -1,      0.0f);
2162                                 glTexCoord2f(texcoordwidth,0);
2163                                 glVertex3f(1,   -1,      0.0f);
2164                                 glTexCoord2f(texcoordwidth,texcoordheight);
2165                                 glVertex3f(1,   1, 0.0f);
2166                                 glTexCoord2f(0,texcoordheight);
2167                                 glVertex3f(-1,  1, 0.0f);
2168                                 glEnd();
2169                                 glPopMatrix();
2170                                 glBindTexture( GL_TEXTURE_2D, screentexture2);
2171                                 glColor4f(1,1,1,.5);
2172                                 glPushMatrix();
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                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2185                         }
2186                         if(drawmode==doublevisionmode){
2187                                 static float crosseyedness;
2188                                 crosseyedness=abs(player[0].damage-player[0].superpermanentdamage-(player[0].damagetolerance-player[0].superpermanentdamage)*1/2)/30;
2189                                 if(crosseyedness>1)crosseyedness=1;
2190                                 if(crosseyedness<0)crosseyedness=0;
2191                                 glColor4f(1,1,1,1);
2192                                 glDisable(GL_BLEND);
2193                                 glPushMatrix();
2194                                 glScalef(1,1,1);
2195                                 glBegin(GL_QUADS);
2196                                 glTexCoord2f(0,0);
2197                                 glVertex3f(-1,          -1,      0.0f);
2198                                 glTexCoord2f(texcoordwidth,0);
2199                                 glVertex3f(1,   -1,      0.0f);
2200                                 glTexCoord2f(texcoordwidth,texcoordheight);
2201                                 glVertex3f(1,   1, 0.0f);
2202                                 glTexCoord2f(0,texcoordheight);
2203                                 glVertex3f(-1,  1, 0.0f);
2204                                 glEnd();
2205                                 glPopMatrix();
2206                                 if(crosseyedness){
2207                                         glColor4f(1,1,1,.5);
2208                                         glEnable(GL_BLEND);
2209                                         glPushMatrix();
2210                                         glTranslatef(.015*crosseyedness,0,0);
2211                                         glScalef(1,1,1);
2212                                         glBegin(GL_QUADS);
2213                                         glTexCoord2f(0,0);
2214                                         glVertex3f(-1,          -1,      0.0f);
2215                                         glTexCoord2f(texcoordwidth,0);
2216                                         glVertex3f(1,   -1,      0.0f);
2217                                         glTexCoord2f(texcoordwidth,texcoordheight);
2218                                         glVertex3f(1,   1, 0.0f);
2219                                         glTexCoord2f(0,texcoordheight);
2220                                         glVertex3f(-1,  1, 0.0f);
2221                                         glEnd();
2222                                         glPopMatrix();
2223                                 }
2224                         }
2225                         if(drawmode==glowmode){
2226                                 glColor4f(.5,.5,.5,.5);
2227                                 glEnable(GL_BLEND);
2228                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2229                                 glPushMatrix();
2230                                 glTranslatef(.01,0,0);
2231                                 glBegin(GL_QUADS);
2232                                 glTexCoord2f(0,0);
2233                                 glVertex3f(-1,          -1,      0.0f);
2234                                 glTexCoord2f(texcoordwidth,0);
2235                                 glVertex3f(1,   -1,      0.0f);
2236                                 glTexCoord2f(texcoordwidth,texcoordheight);
2237                                 glVertex3f(1,   1, 0.0f);
2238                                 glTexCoord2f(0,texcoordheight);
2239                                 glVertex3f(-1,  1, 0.0f);
2240                                 glEnd();
2241                                 glPopMatrix();
2242                                 glPushMatrix();
2243                                 glTranslatef(-.01,0,0);
2244                                 glBegin(GL_QUADS);
2245                                 glTexCoord2f(0,0);
2246                                 glVertex3f(-1,          -1,      0.0f);
2247                                 glTexCoord2f(texcoordwidth,0);
2248                                 glVertex3f(1,   -1,      0.0f);
2249                                 glTexCoord2f(texcoordwidth,texcoordheight);
2250                                 glVertex3f(1,   1, 0.0f);
2251                                 glTexCoord2f(0,texcoordheight);
2252                                 glVertex3f(-1,  1, 0.0f);
2253                                 glEnd();
2254                                 glPopMatrix();
2255                                 glPushMatrix();
2256                                 glTranslatef(.0,.01,0);
2257                                 glBegin(GL_QUADS);
2258                                 glTexCoord2f(0,0);
2259                                 glVertex3f(-1,          -1,      0.0f);
2260                                 glTexCoord2f(texcoordwidth,0);
2261                                 glVertex3f(1,   -1,      0.0f);
2262                                 glTexCoord2f(texcoordwidth,texcoordheight);
2263                                 glVertex3f(1,   1, 0.0f);
2264                                 glTexCoord2f(0,texcoordheight);
2265                                 glVertex3f(-1,  1, 0.0f);
2266                                 glEnd();
2267                                 glPopMatrix();
2268                                 glPushMatrix();
2269                                 glTranslatef(0,-.01,0);
2270                                 glBegin(GL_QUADS);
2271                                 glTexCoord2f(0,0);
2272                                 glVertex3f(-1,          -1,      0.0f);
2273                                 glTexCoord2f(texcoordwidth,0);
2274                                 glVertex3f(1,   -1,      0.0f);
2275                                 glTexCoord2f(texcoordwidth,texcoordheight);
2276                                 glVertex3f(1,   1, 0.0f);
2277                                 glTexCoord2f(0,texcoordheight);
2278                                 glVertex3f(-1,  1, 0.0f);
2279                                 glEnd();
2280                                 glPopMatrix();
2281                         }
2282                         if(drawmode==radialzoommode){
2283                                 for(i=0;i<3;i++){
2284                                         //glRotatef((float)i*.1,0,0,1);
2285                                         glColor4f(1,1,1,1/((float)i+1));
2286                                         glPushMatrix();
2287                                         glScalef(1+(float)i*.01,1+(float)i*.01,1);
2288                                         glBegin(GL_QUADS);
2289                                         glTexCoord2f(0,0);
2290                                         glVertex3f(-1,          -1,      0.0f);
2291                                         glTexCoord2f(texcoordwidth,0);
2292                                         glVertex3f(1,   -1,      0.0f);
2293                                         glTexCoord2f(texcoordwidth,texcoordheight);
2294                                         glVertex3f(1,   1, 0.0f);
2295                                         glTexCoord2f(0,texcoordheight);
2296                                         glVertex3f(-1,  1, 0.0f);
2297                                         glEnd();
2298                                         glPopMatrix();
2299                                 }
2300                         }
2301                         glDisable(GL_TEXTURE_2D);
2302                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2303                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2304                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2305                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2306                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
2307                         glEnable(GL_CULL_FACE);
2308                         glDisable(GL_BLEND);
2309                         glDepthMask(1);
2310                 }
2311
2312                 if(console){
2313                         glEnable(GL_TEXTURE_2D);
2314                         glColor4f(1,1,1,1);
2315                         if(console){
2316                                 int offset;
2317                                 offset=0;
2318                                 if(consoleselected>=60)offset=consoleselected-60;
2319                                 sprintf (string, " ]");
2320                                 text.glPrint(10,30,string,0,1,1024,768);
2321                                 if(consoleblink){
2322                                         sprintf (string, "_");
2323                                         text.glPrint(30+(float)(consoleselected)*10-offset*10,30,string,0,1,1024,768);
2324                                 }
2325                                 for(i=0;i<15;i++){
2326                                         for(j=0;j<consolechars[i];j++){
2327                                                 glColor4f(1,1,1,1-(float)(i)/16);
2328                                                 if(j<consolechars[i]){
2329                                                         sprintf (string, "%c",consoletext[i][j]);
2330                                                         text.glPrint(30+j*10-offset*10,30+i*20,string,0,1,1024,768);
2331                                                 }
2332                                         }
2333                                 }
2334                         }
2335                 }
2336         }
2337
2338         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||(mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)){
2339                 multiplier=tempmult;
2340         }
2341
2342         if(mainmenu){
2343
2344         // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
2345         SDL_Delay(15);
2346
2347                 glDrawBuffer(GL_BACK);
2348                 glReadBuffer(GL_BACK);
2349                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2350                 ReSizeGLScene(90,.1f);
2351
2352                 int temptexdetail;
2353                 temptexdetail=texdetail;
2354                 if(texdetail>2)texdetail=2;
2355                 if(mainmenu!=oldmainmenu&&oldmainmenu!=0){
2356                         if(mainmenu==1){
2357                                 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
2358                                 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
2359                                 /*if(oldmainmenu==1||oldmainmenu==0){
2360                                 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
2361                                 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
2362                                 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
2363                                 loaddistrib=0;
2364                                 }*/
2365                         }
2366                         if(mainmenu==2){
2367                                 LoadTexture(":Data:Textures:Resume.png",&Mainmenuitems[1],0,0);
2368                                 LoadTexture(":Data:Textures:Endgame.png",&Mainmenuitems[3],0,0);
2369                                 /*if(oldmainmenu==2||oldmainmenu==0){
2370                                 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
2371                                 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
2372                                 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
2373                                 loaddistrib=0;
2374                                 }*/
2375                         }
2376                 }
2377                 if(lastcheck>.5||oldmainmenu!=mainmenu){
2378                         if(mainmenu==5){
2379                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
2380                                 //campaignnumlevels=0;
2381                                 //accountcampaignchoicesmade[accountactive]=0;
2382                                 ipstream.ignore(256,':');
2383                                 ipstream >> campaignnumlevels;
2384                                 for(i=0;i<campaignnumlevels;i++){
2385                                         ipstream.ignore(256,':');
2386                                         ipstream.ignore(256,':');
2387                                         ipstream.ignore(256,' ');
2388                                         ipstream >> campaignmapname[i];
2389                                         ipstream.ignore(256,':');
2390                                         ipstream >> campaigndescription[i];
2391                                         for(j=0;j<256;j++){
2392                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
2393                                         }
2394                                         ipstream.ignore(256,':');
2395                                         ipstream >> campaignchoosenext[i];
2396                                         ipstream.ignore(256,':');
2397                                         ipstream >> campaignnumnext[i];
2398                                         if(campaignnumnext[i])
2399                                                 for(j=0;j<campaignnumnext[i];j++){
2400                                                         ipstream.ignore(256,':');
2401                                                         ipstream >> campaignnextlevel[i][j];
2402                                                         campaignnextlevel[i][j]-=1;
2403                                                 }
2404                                                 ipstream.ignore(256,':');
2405                                                 ipstream >> campaignlocationx[i];
2406                                                 //campaignlocationx[i]-=30;
2407                                                 ipstream.ignore(256,':');
2408                                                 ipstream >> campaignlocationy[i];
2409                                                 //campaignlocationy[i]+=30;
2410                                 }
2411                                 ipstream.close();
2412
2413                                 for(i=0;i<campaignnumlevels;i++){
2414                                         levelvisible[i]=0;
2415                                         levelhighlight[i]=0;
2416                                 }
2417
2418                                 levelorder[0]=0;
2419                                 levelvisible[0]=1;
2420                                 if(accountcampaignchoicesmade[accountactive])
2421                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
2422                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
2423                                                 levelvisible[levelorder[i+1]]=1;
2424                                         }
2425                                         int whichlevelstart;
2426                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
2427                                         if(whichlevelstart<0){
2428                                                 accountcampaignscore[accountactive]=0;
2429                                                 accountcampaignfasttime[accountactive]=0;
2430                                                 campaignchoicenum=1;
2431                                                 campaignchoicewhich[0]=0;
2432                                         }
2433                                         else
2434                                         {
2435                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
2436                                                 if(campaignchoicenum==0){
2437                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
2438                                                         if(accountcampaignfasttime[accountactive]==0||accountcampaigntime[accountactive]<accountcampaignfasttime[accountactive])accountcampaignfasttime[accountactive]=accountcampaigntime[accountactive];              
2439                                                 }
2440                                                 if(campaignchoicenum)
2441                                                         for(i=0;i<campaignchoicenum;i++){
2442                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
2443                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2444                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2445                                                         }
2446                                         }
2447                                         /*levelorder[0]=0;
2448                                         levelorder[1]=1;
2449                                         levelorder[2]=2;
2450                                         levelorder[3]=3;*/
2451                         }
2452                 }
2453                 if(mainmenu==5){
2454                         lastcheck=0;
2455                 }
2456
2457                 texdetail=temptexdetail;
2458
2459                 /*if(mainmenu!=0)*/oldmainmenu=mainmenu;
2460
2461                 if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==119||mainmenu==13||mainmenu==17||mainmenu==18){
2462                         glClear(GL_DEPTH_BUFFER_BIT);
2463                         glEnable(GL_ALPHA_TEST);
2464                         glAlphaFunc(GL_GREATER, 0.001f);
2465                         glEnable(GL_TEXTURE_2D);
2466                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2467                         glDisable(GL_CULL_FACE);
2468                         glDisable(GL_LIGHTING);
2469                         glDepthMask(0);
2470                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2471                         glPushMatrix();                                                                         // Store The Projection Matrix
2472                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
2473                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2474                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2475                                         glPushMatrix();                                                                         // Store The Modelview Matrix
2476                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
2477                                         glTranslatef(screenwidth/2,screenheight/2,0);
2478                                         glPushMatrix();
2479                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
2480                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2481                                                 glDisable(GL_BLEND);
2482                                                 glColor4f(0,0,0,1.0);
2483                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2484                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2485                                                 glDisable(GL_TEXTURE_2D);
2486                                                 glPushMatrix();
2487                                                         //glScalef(.25,.25,.25);
2488                                                         glBegin(GL_QUADS);
2489                                                         glTexCoord2f(0,0);
2490                                                         glVertex3f(-1,          -1,      0.0f);
2491                                                         glTexCoord2f(1,0);
2492                                                         glVertex3f(1,   -1,      0.0f);
2493                                                         glTexCoord2f(1,1);
2494                                                         glVertex3f(1,   1, 0.0f);
2495                                                         glTexCoord2f(0,1);
2496                                                         glVertex3f(-1,  1, 0.0f);
2497                                                         glEnd();
2498                                                 glPopMatrix();
2499                                                 glEnable(GL_BLEND);
2500                                                 glColor4f(0.4,0.4,0.4,1.0);
2501                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2502                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2503                                                 glEnable(GL_TEXTURE_2D);
2504                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
2505                                                 glPushMatrix();
2506                                                         //glScalef(.25,.25,.25);
2507                                                         glBegin(GL_QUADS);
2508                                                         glTexCoord2f(0,0);
2509                                                         glVertex3f(-1,          -1,      0.0f);
2510                                                         glTexCoord2f(1,0);
2511                                                         glVertex3f(1,   -1,      0.0f);
2512                                                         glTexCoord2f(1,1);
2513                                                         glVertex3f(1,   1, 0.0f);
2514                                                         glTexCoord2f(0,1);
2515                                                         glVertex3f(-1,  1, 0.0f);
2516                                                         glEnd();
2517                                                 glPopMatrix();
2518                                         glPopMatrix();
2519                                 glPopMatrix();
2520                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2521                         glPopMatrix();
2522                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2523
2524                         if(mainmenu==3){                        
2525                                 nummenuitems=14;
2526                                 if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)sprintf (menustring[0], "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
2527                                 else sprintf (menustring[0], "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
2528                                 startx[0]=10+20;
2529                                 starty[0]=440;
2530                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2531                                 endy[0]=starty[0]+20;
2532                                 movex[0]=0;
2533                                 movey[0]=0;
2534
2535                                 if(newdetail==2)sprintf (menustring[1], "Detail: High");
2536                                 else if(newdetail==1)sprintf (menustring[1], "Detail: Medium");
2537                                 else sprintf (menustring[1], "Detail: Low");
2538                                 startx[1]=10+60;
2539                                 starty[1]=405;
2540                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2541                                 endy[1]=starty[1]+20;
2542                                 movex[1]=0;
2543                                 movey[1]=0;
2544
2545                                 if(bloodtoggle==2)sprintf (menustring[2], "Blood: On, high detail (slower)");
2546                                 if(bloodtoggle==1)sprintf (menustring[2], "Blood: On, low detail");
2547                                 if(bloodtoggle==0)sprintf (menustring[2], "Blood: Off");
2548                                 startx[2]=10+70;
2549                                 starty[2]=370;
2550                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2551                                 endy[2]=starty[2]+20;
2552                                 movex[2]=0;
2553                                 movey[2]=0;
2554
2555                                 if(difficulty==2)sprintf (menustring[3], "Difficulty: Insane");
2556                                 if(difficulty==1)sprintf (menustring[3], "Difficulty: Difficult");
2557                                 if(difficulty==0)sprintf (menustring[3], "Difficulty: Easier");
2558                                 startx[3]=10+20-1000;
2559                                 starty[3]=335-1000;
2560                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2561                                 endy[3]=starty[3]+20;
2562                                 movex[3]=0;
2563                                 movey[3]=0;
2564
2565                                 if(ismotionblur==1)sprintf (menustring[4], "Blur Effects: Enabled (less compatible)");
2566                                 if(ismotionblur==0)sprintf (menustring[4], "Blur Effects: Disabled (more compatible)");
2567                                 startx[4]=10;
2568                                 starty[4]=335;
2569                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2570                                 endy[4]=starty[4]+20;
2571                                 movex[4]=0;
2572                                 movey[4]=0;
2573
2574                                 if(decals==1)sprintf (menustring[5], "Decals: Enabled (slower)");
2575                                 if(decals==0)sprintf (menustring[5], "Decals: Disabled");
2576                                 startx[5]=10+60;
2577                                 starty[5]=300;
2578                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2579                                 endy[5]=starty[5]+20;
2580                                 movex[5]=0;
2581                                 movey[5]=0;
2582
2583                                 if(musictoggle==1)sprintf (menustring[6], "Music: Enabled");
2584                                 if(musictoggle==0)sprintf (menustring[6], "Music: Disabled");
2585                                 startx[6]=10+70;
2586                                 starty[6]=265;
2587                                 endx[6]=startx[6]+strlen(menustring[6])*10;
2588                                 endy[6]=starty[6]+20;
2589                                 movex[6]=0;
2590                                 movey[6]=0;
2591
2592                                 if(invertmouse==1)sprintf (menustring[9], "Invert mouse: Yes");
2593                                 if(invertmouse==0)sprintf (menustring[9], "Invert mouse: No");
2594                                 startx[9]=10;
2595                                 starty[9]=230;
2596                                 endx[9]=startx[9]+strlen(menustring[9])*10;
2597                                 endy[9]=starty[9]+20;
2598                                 movex[9]=0;
2599                                 movey[9]=0;
2600
2601                                 sprintf (menustring[10], "Mouse Speed: %d", (int)(usermousesensitivity*5));
2602                                 startx[10]=20;
2603                                 starty[10]=195;
2604                                 endx[10]=startx[10]+strlen(menustring[10])*10;
2605                                 endy[10]=starty[10]+20;
2606                                 movex[10]=0;
2607                                 movey[10]=0;
2608                                 
2609                                 sprintf (menustring[11], "Volume: %d%%", (int)(volume*100));
2610                                 startx[11]=10+60;
2611                                 starty[11]=160;
2612                                 endx[11]=startx[11]+strlen(menustring[11])*10;
2613                                 endy[11]=starty[11]+20;
2614                                 movex[11]=0;
2615                                 movey[11]=0;
2616                                 
2617                                 sprintf (menustring[13], "Damage Bar: %s",(showdamagebar?"on":"off"));
2618                                 startx[13]=30;
2619                                 starty[13]=125;
2620                                 endx[13]=startx[13]+strlen(menustring[13])*10;
2621                                 endy[13]=starty[13]+20;
2622                                 movex[13]=0;
2623                                 movey[13]=0;
2624                                 
2625                                 sprintf (menustring[7], "-Configure Controls-");
2626                                 startx[7]=10+15;
2627                                 starty[7]=90;
2628                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2629                                 endy[7]=starty[7]+20;
2630                                 movex[7]=0;
2631                                 movey[7]=0;
2632
2633                                 sprintf (menustring[12], "-Configure Stereo -");
2634                                 startx[12]=10+15;
2635                                 starty[12]=55;
2636                                 endx[12]=startx[12]+strlen(menustring[7])*10;
2637                                 endy[12]=starty[12]+20;
2638                                 movex[12]=0;
2639                                 movey[12]=0;
2640                                 
2641                                 if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)sprintf (menustring[8], "Back");
2642                                 else sprintf (menustring[8], "Back (some changes take effect next time Lugaru is opened)");
2643                                 startx[8]=10;
2644                                 endx[8]=startx[8]+strlen(menustring[8])*10;
2645                                 starty[8]=10;
2646                                 endy[8]=starty[8]+20;
2647                                 movex[8]=0;
2648                                 movey[8]=0;
2649                         }
2650
2651                         if(mainmenu==4){                        
2652                                 nummenuitems=10;
2653                                 if(keyselect!=0)sprintf (menustring[0], "Forwards: %s",KeyToChar(forwardkey));
2654                                 else sprintf (menustring[0], "Forwards: _");
2655                                 startx[0]=10;
2656                                 starty[0]=400;
2657                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2658                                 endy[0]=starty[0]+20;
2659                                 movex[0]=0;
2660                                 movey[0]=0;
2661
2662                                 if(keyselect!=1)sprintf (menustring[1], "Back: %s",KeyToChar(backkey));
2663                                 else sprintf (menustring[1], "Back: _");
2664                                 startx[1]=10+40;
2665                                 starty[1]=360;
2666                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2667                                 endy[1]=starty[1]+20;
2668                                 movex[1]=0;
2669                                 movey[1]=0;
2670
2671                                 if(keyselect!=2)sprintf (menustring[2], "Left: %s",KeyToChar(leftkey));
2672                                 else sprintf (menustring[2], "Left: _");
2673                                 startx[2]=10+40;
2674                                 starty[2]=320;
2675                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2676                                 endy[2]=starty[2]+20;
2677                                 movex[2]=0;
2678                                 movey[2]=0;
2679
2680                                 if(keyselect!=3)sprintf (menustring[3], "Right: %s",KeyToChar(rightkey));
2681                                 else sprintf (menustring[3], "Right: _");
2682                                 startx[3]=10+30;
2683                                 starty[3]=280;
2684                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2685                                 endy[3]=starty[3]+20;
2686                                 movex[3]=0;
2687                                 movey[3]=0;
2688
2689                                 if(keyselect!=4)sprintf (menustring[4], "Crouch: %s",KeyToChar(crouchkey));
2690                                 else sprintf (menustring[4], "Crouch: _");
2691                                 startx[4]=10+20;
2692                                 starty[4]=240;
2693                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2694                                 endy[4]=starty[4]+20;
2695                                 movex[4]=0;
2696                                 movey[4]=0;
2697
2698                                 if(keyselect!=5)sprintf (menustring[5], "Jump: %s",KeyToChar(jumpkey));
2699                                 else sprintf (menustring[5], "Jump: _");
2700                                 startx[5]=10+40;
2701                                 starty[5]=200;
2702                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2703                                 endy[5]=starty[5]+20;
2704                                 movex[5]=0;
2705                                 movey[5]=0;
2706
2707                                 if(keyselect!=6)sprintf (menustring[6], "Draw: %s",KeyToChar(drawkey));
2708                                 else sprintf (menustring[6], "Draw: _");
2709                                 startx[6]=10+40;
2710                                 starty[6]=160;
2711                                 endx[6]=startx[6]+strlen(menustring[6])*10;
2712                                 endy[6]=starty[6]+20;
2713                                 movex[6]=0;
2714                                 movey[6]=0;
2715
2716                                 if(keyselect!=7)sprintf (menustring[7], "Throw: %s",KeyToChar(throwkey));
2717                                 else sprintf (menustring[7], "Throw: _");
2718                                 startx[7]=10+30;
2719                                 starty[7]=120;
2720                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2721                                 endy[7]=starty[7]+20;
2722                                 movex[7]=0;
2723                                 movey[7]=0;
2724
2725                                 if(keyselect!=8)sprintf (menustring[8], "Attack: %s",KeyToChar(attackkey));
2726                                 else sprintf (menustring[8], "Attack: _");
2727                                 startx[8]=10+20;
2728                                 starty[8]=80;
2729                                 endx[8]=startx[8]+strlen(menustring[8])*10;
2730                                 endy[8]=starty[8]+20;
2731                                 movex[8]=0;
2732                                 movey[8]=0;
2733
2734
2735
2736                                 sprintf (menustring[9], "Back");
2737                                 startx[9]=10;
2738                                 endx[9]=startx[9]+strlen(menustring[9])*10;
2739                                 starty[9]=10;
2740                                 endy[9]=starty[9]+20;
2741                                 movex[9]=0;
2742                                 movey[9]=0;
2743                         }
2744                         if(mainmenu==5){                        
2745                                 nummenuitems=7+accountcampaignchoicesmade[accountactive]+campaignchoicenum;
2746
2747                                 sprintf (menustring[0], "%s",accountname[accountactive]);
2748                                 startx[0]=5;
2749                                 starty[0]=400;
2750                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2751                                 endy[0]=starty[0]+20;
2752                                 movex[0]=0;
2753                                 movey[0]=0;
2754
2755                                 sprintf (menustring[1], "Tutorial");
2756                                 startx[1]=5;
2757                                 starty[1]=300;
2758                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2759                                 endy[1]=starty[1]+20;
2760                                 movex[1]=0;
2761                                 movey[1]=0;
2762
2763                                 sprintf (menustring[2], "Challenge");
2764                                 startx[2]=5;
2765                                 starty[2]=240;
2766                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2767                                 endy[2]=starty[2]+20;
2768                                 movex[2]=0;
2769                                 movey[2]=0;
2770
2771                                 sprintf (menustring[3], "Delete User");
2772                                 startx[3]=400;
2773                                 starty[3]=10;
2774                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2775                                 endy[3]=starty[3]+20;
2776                                 movex[3]=0;
2777                                 movey[3]=0;
2778
2779                                 sprintf (menustring[4], "Main Menu");
2780                                 startx[4]=5;
2781                                 starty[4]=10;
2782                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2783                                 endy[4]=starty[4]+20;
2784                                 movex[4]=0;
2785                                 movey[4]=0;
2786
2787                                 sprintf (menustring[5], "Change User");
2788                                 startx[5]=5;
2789                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2790                                 starty[5]=180;
2791                                 endy[5]=starty[5]+20;
2792                                 movex[5]=0;
2793                                 movey[5]=0;
2794
2795                                 //World
2796
2797                                 sprintf (menustring[6], "World");
2798                                 startx[6]=30+120;
2799                                 starty[6]=30+480-400-50;
2800                                 endx[6]=startx[6]+400;
2801                                 endy[6]=30+480-50;
2802                                 movex[6]=0;
2803                                 movey[6]=0;
2804
2805                                 if(accountcampaignchoicesmade[accountactive])
2806                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
2807                                                 sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
2808                                                 startx[7+i]=30+120+campaignlocationx[levelorder[i]]*400/512;
2809                                                 starty[7+i]=30+30+(512-campaignlocationy[levelorder[i]])*400/512;
2810                                                 endx[7+i]=startx[7+i]+10;
2811                                                 endy[7+i]=starty[7+i]+10;
2812                                                 movex[7+i]=0;
2813                                                 movey[7+i]=0;
2814                                         }
2815
2816                                         if(campaignchoicenum>0)
2817                                                 for(i=accountcampaignchoicesmade[accountactive];i<accountcampaignchoicesmade[accountactive]+campaignchoicenum;i++){
2818                                                         sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
2819                                                         startx[7+i]=30+120+campaignlocationx[campaignchoicewhich[i-(accountcampaignchoicesmade[accountactive])]]*400/512;
2820                                                         starty[7+i]=30+30+(512-campaignlocationy[campaignchoicewhich[i-(accountcampaignchoicesmade[accountactive])]])*400/512;
2821                                                         endx[7+i]=startx[7+i]+10;
2822                                                         endy[7+i]=starty[7+i]+10;
2823                                                         movex[7+i]=0;
2824                                                         movey[7+i]=0;
2825                                                 }
2826
2827                                                 /*sprintf (menustring[7], "Dot");
2828                                                 startx[7]=120+260*400/512;
2829                                                 starty[7]=30+(512-184)*400/512;
2830                                                 endx[7]=startx[7]+10;
2831                                                 endy[7]=starty[7]+10;
2832                                                 movex[7]=0;
2833                                                 movey[7]=0;
2834
2835                                                 sprintf (menustring[8], "Dot");
2836                                                 startx[8]=120+129*400/512;
2837                                                 starty[8]=30+(512-284)*400/512;
2838                                                 endx[8]=startx[8]+10;
2839                                                 endy[8]=starty[8]+10;
2840                                                 movex[8]=0;
2841                                                 movey[8]=0;
2842
2843                                                 sprintf (menustring[9], "Dot");
2844                                                 startx[9]=120+358*400/512;
2845                                                 starty[9]=30+(512-235)*400/512;
2846                                                 endx[9]=startx[9]+10;
2847                                                 endy[9]=starty[9]+10;
2848                                                 movex[9]=0;
2849                                                 movey[9]=0;
2850
2851                                                 sprintf (menustring[10], "Dot");
2852                                                 startx[10]=120+359*400/512;
2853                                                 starty[10]=30+(512-308)*400/512;
2854                                                 endx[10]=startx[10]+10;
2855                                                 endy[10]=starty[10]+10;
2856                                                 movex[10]=0;
2857                                                 movey[10]=0;
2858
2859                                                 sprintf (menustring[11], "Dot");
2860                                                 startx[11]=120+288*400/512;
2861                                                 starty[11]=30+(512-277)*400/512;
2862                                                 endx[11]=startx[11]+10;
2863                                                 endy[11]=starty[11]+10;
2864                                                 movex[11]=0;
2865                                                 movey[11]=0;*/
2866                         }
2867
2868                         if(mainmenu==6){                        
2869                                 nummenuitems=3;
2870
2871                                 sprintf (menustring[0], "Are you sure you want to delete this user?");
2872                                 startx[0]=10;
2873                                 starty[0]=400;
2874                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2875                                 endy[0]=starty[0]+20;
2876                                 movex[0]=0;
2877                                 movey[0]=0;
2878
2879                                 sprintf (menustring[1], "Yes");
2880                                 startx[1]=10;
2881                                 starty[1]=360;
2882                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2883                                 endy[1]=starty[1]+20;
2884                                 movex[1]=0;
2885                                 movey[1]=0;
2886
2887                                 sprintf (menustring[2], "No");
2888                                 startx[2]=10;
2889                                 starty[2]=320;
2890                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2891                                 endy[2]=starty[2]+20;
2892                                 movex[2]=0;
2893                                 movey[2]=0;
2894
2895                                 sprintf (menustring[3], "Extra 4");
2896                                 startx[3]=10;
2897                                 starty[3]=280;
2898                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2899                                 endy[3]=starty[3]+20;
2900                                 movex[3]=0;
2901                                 movey[3]=0;
2902
2903                                 sprintf (menustring[4], "Extra 5");
2904                                 startx[4]=10;
2905                                 starty[4]=240;
2906                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2907                                 endy[4]=starty[4]+20;
2908                                 movex[4]=0;
2909                                 movey[4]=0;
2910
2911                                 sprintf (menustring[5], "Back");
2912                                 startx[5]=10;
2913                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2914                                 starty[5]=10;
2915                                 endy[5]=starty[5]+20;
2916                                 movex[5]=0;
2917                                 movey[5]=0;
2918                         }
2919
2920                         if(mainmenu==7){                        
2921                                 nummenuitems=numaccounts+2;
2922
2923                                 int num;
2924
2925                                 if(numaccounts<8)
2926                                         sprintf (menustring[0], "New User");
2927                                 else
2928                                         sprintf (menustring[0], "No More Users");
2929                                 startx[0]=10;
2930                                 starty[0]=400;
2931                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2932                                 endy[0]=starty[0]+20;
2933                                 movex[0]=0;
2934                                 movey[0]=0;
2935
2936                                 if(entername)startx[0]+=10;
2937
2938
2939                                 num=1;
2940                                 if(numaccounts)
2941                                         for(i=0;i<numaccounts;i++){
2942                                                 sprintf (menustring[num], "%s",accountname[i]);
2943                                                 startx[num]=10;
2944                                                 starty[num]=360-20-20*num;
2945                                                 endx[num]=startx[num]+strlen(menustring[num])*10;
2946                                                 endy[num]=starty[num]+20;
2947                                                 movex[num]=0;
2948                                                 movey[num]=0;
2949
2950                                                 num++;
2951                                         }
2952
2953                                         sprintf (menustring[num], "Back");
2954                                         startx[num]=10;
2955                                         endx[num]=startx[num]+strlen(menustring[num])*10;
2956                                         starty[num]=10;
2957                                         endy[num]=starty[num]+20;
2958                                         movex[num]=0;
2959                                         movey[num]=0;
2960                         }
2961                         if(mainmenu==8){                        
2962                                 nummenuitems=3;
2963
2964                                 sprintf (menustring[0], "Easier");
2965                                 startx[0]=10;
2966                                 starty[0]=400;
2967                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2968                                 endy[0]=starty[0]+20;
2969                                 movex[0]=0;
2970                                 movey[0]=0;
2971
2972                                 sprintf (menustring[1], "Difficult");
2973                                 startx[1]=10;
2974                                 starty[1]=360;
2975                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2976                                 endy[1]=starty[1]+20;
2977                                 movex[1]=0;
2978                                 movey[1]=0;
2979
2980                                 sprintf (menustring[2], "Insane");
2981                                 startx[2]=10;
2982                                 starty[2]=320;
2983                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2984                                 endy[2]=starty[2]+20;
2985                                 movex[2]=0;
2986                                 movey[2]=0;
2987                         }
2988                         if(mainmenu==9){                        
2989                                 int tempncl;
2990                                 //tempncl=numchallengelevels;
2991                                 //numchallengelevels=9;
2992                                 nummenuitems=2+numchallengelevels;
2993                                 char temp[255];
2994
2995                                 for(j=0;j<numchallengelevels;j++){
2996                                         for(i=0;i<255;i++)menustring[j][i]='\0';
2997                                         sprintf (temp, "Level %d",j+1);
2998                                         strcpy(menustring[j],temp);
2999                                         for(i=0;i<17;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
3000                                         menustring[j][17]='\0';
3001                                         sprintf (temp, "%d",(int)accounthighscore[accountactive][j]);
3002                                         strcat(menustring[j],temp);
3003                                         for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
3004                                         menustring[j][32]='\0';
3005                                         sprintf (temp, "%d:",(int)(((int)accountfasttime[accountactive][j]-(int)(accountfasttime[accountactive][j])%60)/60));
3006                                         strcat(menustring[j],temp);
3007                                         if((int)(accountfasttime[accountactive][j])%60<10)strcat(menustring[j],"0");
3008                                         sprintf (temp, "%d",(int)(accountfasttime[accountactive][j])%60);
3009                                         strcat(menustring[j],temp);
3010
3011                                         startx[j]=10;
3012                                         starty[j]=400-j*25;
3013                                         endx[j]=startx[j]+strlen(menustring[j])*10;
3014                                         endy[j]=starty[j]+20;
3015                                         movex[j]=0;
3016                                         movey[j]=0;
3017                                 }
3018
3019                                 sprintf (menustring[numchallengelevels], "Back");
3020                                 startx[numchallengelevels]=10;
3021                                 endx[numchallengelevels]=startx[numchallengelevels]+strlen(menustring[numchallengelevels])*10;
3022                                 starty[numchallengelevels]=10;
3023                                 endy[numchallengelevels]=starty[numchallengelevels]+20;
3024                                 movex[numchallengelevels]=0;
3025                                 movey[numchallengelevels]=0;
3026
3027                                 sprintf (menustring[numchallengelevels+1], "             High Score      Best Time");
3028                                 startx[numchallengelevels+1]=10;
3029                                 starty[numchallengelevels+1]=440;
3030                                 endx[numchallengelevels+1]=startx[numchallengelevels+1]+strlen(menustring[numchallengelevels+1])*10;
3031                                 endy[numchallengelevels+1]=starty[numchallengelevels+1]+20;
3032                                 movex[numchallengelevels+1]=0;
3033                                 movey[numchallengelevels+1]=0;
3034
3035                                 //numchallengelevels=tempncl;
3036
3037                         }
3038                         if(mainmenu==11){                       
3039                                 nummenuitems=2+numchallengelevels;
3040                                 char temp[255];
3041
3042                                 for(j=0;j<numchallengelevels;j++){
3043                                         for(i=0;i<255;i++)menustring[j][i]='\0';
3044                                         sprintf (temp, "Level %d",j+1);
3045                                         strcpy(menustring[j],temp);
3046                                         for(i=0;i<17;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
3047                                         menustring[j][17]='\0';
3048                                         sprintf (temp, "%d",(int)accounthighscore[accountactive][j]);
3049                                         strcat(menustring[j],temp);
3050                                         for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
3051                                         menustring[j][32]='\0';
3052                                         sprintf (temp, "%d:",(int)(((int)accountfasttime[accountactive][j]-(int)(accountfasttime[accountactive][j])%60)/60));
3053                                         strcat(menustring[j],temp);
3054                                         if((int)(accountfasttime[accountactive][j])%60<10)strcat(menustring[j],"0");
3055                                         sprintf (temp, "%d",(int)(accountfasttime[accountactive][j])%60);
3056                                         strcat(menustring[j],temp);
3057
3058                                         startx[j]=10;
3059                                         starty[j]=360-j*40;
3060                                         endx[j]=startx[j]+strlen(menustring[j])*10;
3061                                         endy[j]=starty[j]+20;
3062                                         movex[j]=0;
3063                                         movey[j]=0;
3064                                 }
3065
3066                                 sprintf (menustring[numchallengelevels], "Back");
3067                                 startx[numchallengelevels]=10;
3068                                 endx[numchallengelevels]=startx[numchallengelevels]+strlen(menustring[numchallengelevels])*10;
3069                                 starty[numchallengelevels]=10;
3070                                 endy[numchallengelevels]=starty[numchallengelevels]+20;
3071                                 movex[numchallengelevels]=0;
3072                                 movey[numchallengelevels]=0;
3073
3074                                 sprintf (menustring[numchallengelevels+1], "             High Score      Best Time");
3075                                 startx[numchallengelevels+1]=10;
3076                                 starty[numchallengelevels+1]=400;
3077                                 endx[numchallengelevels+1]=startx[numchallengelevels+1]+strlen(menustring[numchallengelevels+1])*10;
3078                                 endy[numchallengelevels+1]=starty[numchallengelevels+1]+20;
3079                                 movex[numchallengelevels+1]=0;
3080                                 movey[numchallengelevels+1]=0;
3081
3082                         }
3083                         if(mainmenu==10){                       
3084                                 nummenuitems=6;
3085                                 char temp[255];
3086
3087                                 sprintf (menustring[0], "Congratulations!");
3088                                 startx[0]=220;
3089                                 starty[0]=330;
3090                                 endx[0]=startx[0]+strlen(menustring[0])*10;
3091                                 endy[0]=starty[0]+20;
3092                                 movex[0]=0;
3093                                 movey[0]=0;
3094
3095                                 sprintf (menustring[1], "You have avenged your family and");
3096                                 startx[1]=140;
3097                                 starty[1]=300;
3098                                 endx[1]=startx[1]+strlen(menustring[1])*10;
3099                                 endy[1]=starty[1]+20;
3100                                 movex[1]=0;
3101                                 movey[1]=0;
3102
3103                                 sprintf (menustring[2], "restored peace to the island of Lugaru.");
3104                                 startx[2]=110;
3105                                 starty[2]=270;
3106                                 endx[2]=startx[2]+strlen(menustring[2])*10;
3107                                 endy[2]=starty[2]+20;
3108                                 movex[2]=0;
3109                                 movey[2]=0;
3110
3111                                 sprintf (menustring[3], "Back");
3112                                 startx[3]=10;
3113                                 endx[3]=startx[3]+strlen(menustring[3])*10;
3114                                 starty[3]=10;
3115                                 endy[3]=starty[3]+20;
3116                                 movex[3]=0;
3117                                 movey[3]=0;
3118
3119                                 for(i=0;i<255;i++)menustring[4][i]='\0';
3120                                 sprintf (temp, "Your score:");
3121                                 strcpy(menustring[4],temp);
3122                                 for(i=0;i<20;i++)if(menustring[4][i]=='\0')menustring[4][i]=' ';
3123                                 menustring[4][20]='\0';
3124                                 sprintf (temp, "%d",(int)accountcampaignscore[accountactive]);
3125                                 strcat(menustring[4],temp);
3126                                 startx[4]=190;
3127                                 endx[4]=startx[4]+strlen(menustring[4])*10;
3128                                 starty[4]=200;
3129                                 endy[4]=starty[4]+20;
3130                                 movex[4]=0;
3131                                 movey[4]=0;
3132                                 /*
3133                                 for(i=0;i<255;i++)menustring[5][i]='\0';
3134                                 sprintf (temp, "Your time:");
3135                                 strcpy(menustring[5],temp);
3136                                 for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
3137                                 menustring[5][20]='\0';
3138                                 sprintf (temp, "%d",(int)accountcampaigntime[accountactive]);
3139                                 strcat(menustring[5],temp);
3140                                 startx[5]=200;
3141                                 endx[5]=startx[5]+strlen(menustring[5])*10;
3142                                 starty[5]=180;
3143                                 endy[5]=starty[5]+20;
3144                                 movex[5]=0;
3145                                 movey[5]=0;
3146                                 */
3147                                 for(i=0;i<255;i++)menustring[5][i]='\0';
3148                                 sprintf (temp, "Highest score:");
3149                                 strcpy(menustring[5],temp);
3150                                 for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
3151                                 menustring[5][20]='\0';
3152                                 sprintf (temp, "%d",(int)accountcampaignhighscore[accountactive]);
3153                                 strcat(menustring[5],temp);
3154                                 startx[5]=190;
3155                                 endx[5]=startx[5]+strlen(menustring[5])*10;
3156                                 starty[5]=180;
3157                                 endy[5]=starty[5]+20;
3158                                 movex[5]=0;
3159                                 movey[5]=0;
3160                                 /*
3161                                 for(i=0;i<255;i++)menustring[7][i]='\0';
3162                                 sprintf (temp, "Lowest time:");
3163                                 strcpy(menustring[7],temp);
3164                                 for(i=0;i<20;i++)if(menustring[7][i]=='\0')menustring[7][i]=' ';
3165                                 menustring[7][20]='\0';
3166                                 sprintf (temp, "%d",(int)accountcampaignfasttime[accountactive]);
3167                                 strcat(menustring[7],temp);
3168                                 startx[7]=200;
3169                                 endx[7]=startx[7]+strlen(menustring[7])*10;
3170                                 starty[7]=130;
3171                                 endy[7]=starty[7]+20;
3172                                 movex[7]=0;
3173                                 movey[7]=0;*/
3174                         }
3175                         if (mainmenu==18) {
3176                                 nummenuitems=4;
3177                                 sprintf (menustring[0], "Stereo mode: %s", StereoModeName(newstereomode));
3178                                 startx[0]=70;
3179                                 starty[0]=400;
3180                                 endx[0]=startx[0]+strlen(menustring[0])*10;
3181                                 endy[0]=starty[0]+20;
3182                                 movex[0]=0;
3183                                 movey[0]=0;
3184                                 
3185                                 sprintf (menustring[1], "Stereo separation: %.3f", stereoseparation);
3186                                 startx[1]=10;
3187                                 starty[1]=360;
3188                                 endx[1]=startx[1]+strlen(menustring[1])*10;
3189                                 endy[1]=starty[1]+20;
3190                                 movex[1]=0;
3191                                 movey[1]=0;
3192
3193                                 sprintf (menustring[2], "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
3194                                 startx[2]=40;
3195                                 starty[2]=320;
3196                                 endx[2]=startx[2]+strlen(menustring[2])*10;
3197                                 endy[2]=starty[2]+20;
3198                                 movex[2]=0;
3199                                 movey[2]=0;
3200                                 
3201                                 sprintf (menustring[3], "Back");
3202                                 startx[3]=10;
3203                                 endx[3]=startx[3]+strlen(menustring[3])*10;
3204                                 starty[3]=10;
3205                                 endy[3]=starty[3]+20;
3206                                 movex[3]=0;
3207                                 movey[3]=0;                             
3208                         }
3209                 }
3210
3211                 if(mainmenu==13){       
3212                         nummenuitems=2;
3213                         char temp[255];
3214
3215                         sprintf (menustring[0], "Please enter your name:");
3216                         startx[0]=50;
3217                         starty[0]=250;
3218                         endx[0]=startx[0]+strlen(menustring[0])*10;
3219                         endy[0]=starty[0]+20;
3220                         movex[0]=0;
3221                         movey[0]=0;
3222
3223                         sprintf (menustring[1], "Please enter your name:");
3224                         startx[1]=290;
3225                         starty[1]=250;
3226                         endx[1]=startx[1]+strlen(menustring[1])*10;
3227                         endy[1]=starty[1]+20;
3228                         movex[1]=0;
3229                         movey[1]=0;
3230                 }
3231                 if(mainmenu==1||mainmenu==2){
3232                         nummenuitems=7;
3233                         startx[0]=150;
3234                         starty[0]=480-128;
3235                         endx[0]=150+256;
3236                         endy[0]=480;
3237                         movex[0]=0;
3238                         movey[0]=0;
3239
3240                         startx[1]=18;
3241                         starty[1]=480-152-32;
3242                         endx[1]=18+128;
3243                         endy[1]=480-152;
3244                         movex[1]=0;
3245                         movey[1]=0;
3246
3247                         startx[2]=18;
3248                         starty[2]=480-228-32;
3249                         endx[2]=2+128;
3250                         endy[2]=480-228;
3251                         movex[2]=0;
3252                         movey[2]=0;
3253
3254                         if(mainmenu==1){
3255                                 startx[3]=18;
3256                                 starty[3]=480-306-32;
3257                                 endx[3]=22+64;
3258                                 endy[3]=480-306;
3259                                 movex[3]=0;
3260                                 movey[3]=0;
3261                         }
3262
3263                         if(mainmenu==2){
3264                                 startx[3]=18;
3265                                 starty[3]=480-306-32;
3266                                 endx[3]=22+128;
3267                                 endy[3]=480-306;
3268                                 movex[3]=0;
3269                                 movey[3]=0;
3270                         }
3271
3272                         /*startx[4]=150;
3273                         starty[4]=480-256;
3274                         endx[4]=150+256;
3275                         endy[4]=480;
3276                         */
3277                         if(anim==0){
3278                                 startx[4]=380;
3279                                 starty[4]=480-140-256;
3280                                 endx[4]=380+256;
3281                                 endy[4]=480-140;
3282                                 movex[4]=80;
3283                                 movey[4]=0;
3284
3285                                 startx[5]=145;
3286                                 starty[5]=480-138-256;
3287                                 endx[5]=145+256;
3288                                 endy[5]=480-138;
3289                                 movex[5]=40;
3290                                 movey[5]=0;
3291
3292                                 startx[6]=254;
3293                                 starty[6]=480-144-256;
3294                                 endx[6]=254+256;
3295                                 endy[6]=480-144;
3296                                 movex[6]=20;
3297                                 movey[6]=0;
3298                         }
3299                         if(anim==1){
3300                                 startx[4]=180;
3301                                 starty[4]=480-140-256;
3302                                 endx[4]=180+256;
3303                                 endy[4]=480-140;
3304                                 movex[4]=80;
3305                                 movey[4]=0;
3306
3307                                 startx[5]=500;
3308                                 starty[5]=480-138-256;
3309                                 endx[5]=500+256;
3310                                 endy[5]=480-138;
3311                                 movex[5]=40;
3312                                 movey[5]=0;
3313
3314                                 startx[6]=340;
3315                                 starty[6]=480-144-256;
3316                                 endx[6]=340+256;
3317                                 endy[6]=480-144;
3318                                 movex[6]=20;
3319                                 movey[6]=0;
3320                         }
3321                         if(anim==2){
3322                                 startx[4]=460;
3323                                 starty[4]=480-140-256;
3324                                 endx[4]=460+256;
3325                                 endy[4]=480-140;
3326                                 movex[4]=50;
3327                                 movey[4]=0;
3328
3329                                 startx[5]=295;
3330                                 starty[5]=480-150-256;
3331                                 endx[5]=295+256;
3332                                 endy[5]=480-138;
3333                                 movex[5]=-10;
3334                                 movey[5]=0;
3335
3336                                 startx[6]=204;
3337                                 starty[6]=480-144-256;
3338                                 endx[6]=204+256;
3339                                 endy[6]=480-144;
3340                                 movex[6]=-30;
3341                                 movey[6]=0;
3342                         }
3343                         if(anim==3){
3344                                 startx[4]=150;
3345                                 starty[4]=480-140-256;
3346                                 endx[4]=200+256;
3347                                 endy[4]=480-140;
3348                                 movex[4]=80;
3349                                 movey[4]=0;
3350
3351                                 startx[5]=350;
3352                                 starty[5]=480-150-256;
3353                                 endx[5]=350+256;
3354                                 endy[5]=480-138;
3355                                 movex[5]=5;
3356                                 movey[5]=0;
3357
3358                                 startx[6]=500;
3359                                 starty[6]=480-144-256;
3360                                 endx[6]=500+256;
3361                                 endy[6]=480-144;
3362                                 movex[6]=-10;
3363                                 movey[6]=0;
3364                         }
3365                         if(anim==4){
3366                                 startx[4]=190;
3367                                 starty[4]=480-100-256;
3368                                 endx[4]=190+256;
3369                                 endy[4]=480-100;
3370                                 movex[4]=-30;
3371                                 movey[4]=0;
3372
3373                                 startx[5]=185;
3374                                 starty[5]=480-120-256;
3375                                 endx[5]=185+256;
3376                                 endy[5]=480-120;
3377                                 movex[5]=-5;
3378                                 movey[5]=0;
3379
3380                                 startx[6]=400;
3381                                 starty[6]=480-144-256;
3382                                 endx[6]=400+256;
3383                                 endy[6]=480-144;
3384                                 movex[6]=20;
3385                                 movey[6]=0;
3386                         }
3387                 }
3388
3389                 selected=-1;
3390
3391                 if(mainmenu==1||mainmenu==2)
3392                         for(i=1;i<4;i++){
3393                                 if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
3394                                         selected=i;
3395                                 }
3396                         }
3397
3398                         if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==18)
3399                                 for(i=0;i<nummenuitems;i++){
3400                                         if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
3401                                                 if(mainmenu!=5)selected=i;
3402                                                 if(mainmenu==5&&(i!=0&&i!=6))selected=i;
3403                                                 if(mainmenu==9&&(i!=numchallengelevels+1))selected=i;
3404                                                 if(mainmenu==11&&(i!=numchallengelevels+1))selected=i;
3405                                         }
3406                                 }
3407
3408                                 if(nummenuitems>0)
3409                                         for(i=0;i<nummenuitems;i++){
3410                                                 if(selected==i)selectedlong[i]+=multiplier*5;
3411                                                 if(selectedlong[i]>1)selectedlong[i]=1;
3412                                                 if(selected!=i)selectedlong[i]-=multiplier*5;
3413                                                 if(selectedlong[i]<0)selectedlong[i]=0; 
3414                                                 //if(i>=4)selectedlong[i]=.3;           
3415                                                 if(i>=4&&(mainmenu==1||mainmenu==2))selectedlong[i]=0;  
3416                                         }
3417
3418                                         if(nummenuitems>0)
3419                                                 for(i=0;i<nummenuitems;i++){
3420                                                         offsetx[i]=(startx[i]+endx[i])/2-(mousecoordh/screenwidth*640);
3421                                                         offsety[i]=(starty[i]+endy[i])/2-(480-(mousecoordv/screenheight*480));
3422                                                         offsetx[i]*=.06f;
3423                                                         offsety[i]*=.06f;
3424                                                         offsetx[i]=0;
3425                                                         offsety[i]=0;
3426                                                         if(i>=4&&(mainmenu==1||mainmenu==2)){
3427                                                                 offsetx[i]=(startx[i]+endx[i]+movex[i]*transition)/2-(640+190)/2;
3428                                                                 offsety[i]=(starty[i]+endy[i]+movey[i]*transition)/2-(336+150)/2;
3429                                                                 offsetx[i]*=.06f;
3430                                                                 offsety[i]*=.06f;
3431                                                         }
3432                                                 }
3433
3434                                                 if(mainmenu==1||mainmenu==2){
3435                                                         glClear(GL_DEPTH_BUFFER_BIT);
3436                                                         glEnable(GL_ALPHA_TEST);
3437                                                         glAlphaFunc(GL_GREATER, 0.001f);
3438                                                         glEnable(GL_TEXTURE_2D);
3439                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3440                                                         glDisable(GL_CULL_FACE);
3441                                                         glDisable(GL_LIGHTING);
3442                                                         glDepthMask(0);
3443                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3444                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3445                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3446                                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3447                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3448                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3449                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3450                                                                         glTranslatef(screenwidth/2,screenheight/2,0);
3451                                                                         glPushMatrix();
3452                                                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
3453                                                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3454                                                                                 glDisable(GL_BLEND);
3455                                                                                 glColor4f(0,0,0,1.0);
3456                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3457                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3458                                                                                 glDisable(GL_TEXTURE_2D);
3459                                                                                 glPushMatrix();
3460                                                                                         //glScalef(.25,.25,.25);
3461                                                                                         glBegin(GL_QUADS);
3462                                                                                         glTexCoord2f(0,0);
3463                                                                                         glVertex3f(-1,          -1,      0.0f);
3464                                                                                         glTexCoord2f(1,0);
3465                                                                                         glVertex3f(1,   -1,      0.0f);
3466                                                                                         glTexCoord2f(1,1);
3467                                                                                         glVertex3f(1,   1, 0.0f);
3468                                                                                         glTexCoord2f(0,1);
3469                                                                                         glVertex3f(-1,  1, 0.0f);
3470                                                                                         glEnd();
3471                                                                                 glPopMatrix();
3472                                                                                 glEnable(GL_BLEND);
3473                                                                                 glColor4f(0.4,0.4,0.4,1.0);
3474                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3475                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3476                                                                                 glEnable(GL_TEXTURE_2D);
3477                                                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
3478                                                                                 glPushMatrix();
3479                                                                                         //glScalef(.25,.25,.25);
3480                                                                                         glBegin(GL_QUADS);
3481                                                                                         glTexCoord2f(0,0);
3482                                                                                         glVertex3f(-1,          -1,      0.0f);
3483                                                                                         glTexCoord2f(1,0);
3484                                                                                         glVertex3f(1,   -1,      0.0f);
3485                                                                                         glTexCoord2f(1,1);
3486                                                                                         glVertex3f(1,   1, 0.0f);
3487                                                                                         glTexCoord2f(0,1);
3488                                                                                         glVertex3f(-1,  1, 0.0f);
3489                                                                                         glEnd();
3490                                                                                 glPopMatrix();
3491                                                                         glPopMatrix();
3492                                                                 glPopMatrix();
3493                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3494                                                         glPopMatrix();
3495
3496                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3497                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3498                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3499                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3500                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3501                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3502                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3503                                                                         glPushMatrix();
3504                                                                                 glDisable(GL_TEXTURE_2D);
3505                                                                                 glColor4f(1,0,0,1);
3506                                                                                 /*glPushMatrix();
3507                                                                                 glBegin(GL_QUADS);
3508                                                                                 glTexCoord2f(0,0);
3509                                                                                 if(anim!=1)glVertex3f(190,      150,     0.0f);
3510                                                                                 if(anim==1)glVertex3f(190+movex[4]*transition,  150,     0.0f);
3511                                                                                 glTexCoord2f(1,0);
3512                                                                                 glVertex3f(640, 150,     0.0f);
3513                                                                                 glTexCoord2f(1,1);
3514                                                                                 glVertex3f(640, 336, 0.0f);
3515                                                                                 glTexCoord2f(0,1);
3516                                                                                 if(anim!=1)glVertex3f(190, 336, 0.0f);
3517                                                                                 if(anim==1)glVertex3f(190+movex[4]*transition, 336,      0.0f);
3518                                                                                 glEnd();
3519                                                                                 glPopMatrix();*/
3520                                                                         glPopMatrix();
3521                                                                 glPopMatrix();
3522                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3523                                                         glPopMatrix();
3524                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3525
3526                                                 }
3527
3528                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3529                                                 glPushMatrix();                                                                         // Store The Projection Matrix
3530                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3531                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3532                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3533                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3534                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3535                                                 glEnable(GL_TEXTURE_2D);
3536                                                 if(nummenuitems>0)
3537                                                 {
3538                                                         for(j=0;j<nummenuitems;j++)
3539                                                         {
3540                                                                 if(j<=3||(mainmenu!=1&&mainmenu!=2))
3541                                                                 {
3542                                                                         //glDisable(GL_BLEND);
3543                                                                         glEnable(GL_ALPHA_TEST);
3544                                                                         glEnable(GL_BLEND);
3545                                                                         //glDisable(GL_ALPHA_TEST);
3546                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3547                                                                         if(mainmenu==1||mainmenu==2)
3548                                                                         {
3549                                                                                 glColor4f(1,1,1,1);
3550                                                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3551                                                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[j]);
3552                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
3553                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
3554                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3555                                                                                 glPushMatrix();
3556                                                                                         glBegin(GL_QUADS);
3557                                                                                         glTexCoord2f(0,0);
3558                                                                                         glVertex3f(startx[j]+movex[j]*transition,       starty[j]+movey[j]*transition,   0.0f);
3559                                                                                         glTexCoord2f(1,0);
3560                                                                                         glVertex3f(endx[j]+movex[j]*transition,         starty[j]+movey[j]*transition,   0.0f);
3561                                                                                         glTexCoord2f(1,1);
3562                                                                                         glVertex3f(endx[j]+movex[j]*transition,         endy[j]+movey[j]*transition, 0.0f);
3563                                                                                         glTexCoord2f(0,1);
3564                                                                                         glVertex3f(startx[j]+movex[j]*transition,       endy[j]+movey[j]*transition, 0.0f);
3565                                                                                         glEnd();
3566                                                                                 glPopMatrix();
3567                                                                                 glEnable(GL_BLEND);
3568                                                                                 //glDisable(GL_ALPHA_TEST);
3569                                                                                 if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3570                                                                                 for(i=0;i<10;i++)
3571                                                                                 {
3572                                                                                         if(1-((float)i)/10-(1-selectedlong[j])>0)
3573                                                                                         {
3574                                                                                                 glColor4f(1,1,1,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3575                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3576                                                                                                 glPushMatrix();
3577                                                                                                         glBegin(GL_QUADS);
3578                                                                                                         glTexCoord2f(0,0);
3579                                                                                                         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);
3580                                                                                                         glTexCoord2f(1,0);
3581                                                                                                         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);
3582                                                                                                         glTexCoord2f(1,1);
3583                                                                                                         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);
3584                                                                                                         glTexCoord2f(0,1);
3585                                                                                                         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);
3586                                                                                                         glEnd();
3587                                                                                                 glPopMatrix();
3588                                                                                         }
3589                                                                                 }
3590                                                                         }
3591                                                                         if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==18)
3592                                                                         {
3593                                                                                 if(mainmenu!=5||j<6)
3594                                                                                 {
3595                                                                                         glColor4f(1,0,0,1);
3596                                                                                         if(mainmenu==9&&j>accountprogress[accountactive]&&j<numchallengelevels)glColor4f(0.5,0,0,1);
3597                                                                                         if(mainmenu==11&&j>accountprogress[accountactive]&&j<numchallengelevels)glColor4f(0.5,0,0,1);
3598                                                                                         //if(1-((float)i)/10-(1-selectedlong[j])>0){
3599                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3600                                                                                         glPushMatrix();
3601                                                                                                 if(mainmenu!=7||j!=0||!entername)text.glPrint(startx[j],starty[j],menustring[j],0,1,640,480);
3602                                                                                                 else
3603                                                                                                 {
3604                                                                                                         if(displayblink){
3605                                                                                                                 sprintf (string, "_");
3606                                                                                                                 text.glPrint(startx[j]+(float)(displayselected)*10,starty[j],string,0,1,640,480);
3607                                                                                                         }
3608                                                                                                         k=0;
3609                                                                                                         for(l=0;l<displaychars[k];l++){
3610                                                                                                                 if(l<displaychars[k]){
3611                                                                                                                         sprintf (string, "%c",displaytext[k][l]);
3612                                                                                                                         text.glPrint(startx[j]+l*10,starty[j],string,0,1,640,480);
3613                                                                                                                 }
3614                                                                                                         }
3615                                                                                                 }
3616                                                                                         glPopMatrix();
3617                                                                                         /*}
3618                                                                                         else{
3619                                                                                         glPushMatrix();
3620                                                                                         sprintf (string, "Hooo!");
3621                                                                                         text.glPrint(startx[0],starty[0],string,0,1,640,480);
3622                                                                                         glPopMatrix();
3623                                                                                         }*/
3624                                                                                         glEnable(GL_BLEND);
3625                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3626                                                                                         for(i=0;i<15;i++)
3627                                                                                         {
3628                                                                                                 if(1-((float)i)/15-(1-selectedlong[j])>0)
3629                                                                                                 {
3630                                                                                                         glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3631                                                                                                         if(mainmenu==9&&j>accountprogress[accountactive]&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3632                                                                                                         if(mainmenu==11&&j>accountprogress[accountactive]&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3633                                                                                                         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);
3634                                                                                                         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);
3635                                                                                                         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);
3636                                                                                                         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);
3637                                                                                                         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);
3638                                                                                                         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);
3639                                                                                                         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);
3640                                                                                                         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);
3641                                                                                                         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);
3642                                                                                                         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);
3643                                                                                                         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);
3644                                                                                                         if(mainmenu==18)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3645                                                                                                         /*else{
3646                                                                                                         if(displayblink){
3647                                                                                                         sprintf (string, "_");
3648                                                                                                         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);
3649                                                                                                         }
3650                                                                                                         k=0;
3651                                                                                                         for(l=0;l<displaychars[k];l++){
3652                                                                                                         if(l<displaychars[k]){
3653                                                                                                         sprintf (string, "%c",displaytext[k][l]);
3654                                                                                                         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);
3655                                                                                                         }
3656                                                                                                         }
3657                                                                                                         }*/
3658                                                                                                 }
3659                                                                                         }
3660                                                                                 }
3661                                                                                 else
3662                                                                                 {
3663                                                                                         glClear(GL_DEPTH_BUFFER_BIT);
3664                                                                                         glEnable(GL_ALPHA_TEST);
3665                                                                                         glAlphaFunc(GL_GREATER, 0.001f);
3666                                                                                         glEnable(GL_TEXTURE_2D);
3667                                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3668                                                                                         glDisable(GL_CULL_FACE);
3669                                                                                         glDisable(GL_LIGHTING);
3670                                                                                         if(j==6)glColor4f(1,1,1,1);
3671                                                                                         else glColor4f(1,0,0,1);
3672
3673                                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3674                                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3675                                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3676                                                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3677                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3678                                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3679                                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3680                                                                                                         glPushMatrix();
3681
3682                                                                                                                 //Draw world, draw map
3683                                                                                                                 glTranslatef(2,-5,0);
3684
3685                                                                                                                 if(j>6&&j<nummenuitems-1)
3686                                                                                                                 {
3687                                                                                                                         XYZ linestart,lineend,offset;
3688                                                                                                                         XYZ fac;
3689                                                                                                                         float startsize;
3690                                                                                                                         float endsize;
3691                                                                                                                         linestart=0;
3692                                                                                                                         lineend=0;
3693                                                                                                                         offset=0;
3694                                                                                                                         //float linestartx,lineendx,linestarty,lineendy,offsetx,offsety;
3695                                                                                                                         linestart.x=(startx[j]+endx[j])/2;
3696                                                                                                                         linestart.y=(starty[j]+endy[j])/2;
3697                                                                                                                         if(j>=6+accountcampaignchoicesmade[accountactive]){
3698                                                                                                                                 linestart.x=(startx[6+accountcampaignchoicesmade[accountactive]]+endx[6+accountcampaignchoicesmade[accountactive]])/2;
3699                                                                                                                                 linestart.y=(starty[6+accountcampaignchoicesmade[accountactive]]+endy[6+accountcampaignchoicesmade[accountactive]])/2;
3700                                                                                                                         }
3701                                                                                                                         lineend.x=(startx[j+1]+endx[j+1])/2;
3702                                                                                                                         lineend.y=(starty[j+1]+endy[j+1])/2;
3703                                                                                                                         offset=lineend-linestart;
3704                                                                                                                         fac=offset;
3705                                                                                                                         Normalise(&fac);
3706                                                                                                                         offset=DoRotation(offset,0,0,90);
3707                                                                                                                         Normalise(&offset);
3708                                                                                                                         glDisable(GL_TEXTURE_2D);                                                       
3709
3710                                                                                                                         if(j<6+accountcampaignchoicesmade[accountactive]){
3711                                                                                                                                 glColor4f(0.5,0,0,1);
3712                                                                                                                                 startsize=.5;
3713                                                                                                                                 endsize=.5;
3714                                                                                                                         }
3715                                                                                                                         if(j>=6+accountcampaignchoicesmade[accountactive]){
3716                                                                                                                                 glColor4f(1,0,0,1);
3717                                                                                                                                 endsize=1;
3718                                                                                                                                 startsize=.5;
3719                                                                                                                         }
3720
3721                                                                                                                         linestart+=fac*4*startsize;
3722                                                                                                                         lineend-=fac*4*endsize;
3723
3724                                                                                                                         if(!(j>7+accountcampaignchoicesmade[accountactive]+campaignchoicenum)){
3725                                                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3726                                                                                                                                 glPushMatrix();
3727                                                                                                                                         glBegin(GL_QUADS);
3728                                                                                                                                         glTexCoord2f(0,0);
3729                                                                                                                                         glVertex3f(linestart.x-offset.x*startsize,      linestart.y-offset.y*startsize,          0.0f);
3730                                                                                                                                         glTexCoord2f(1,0);
3731                                                                                                                                         glVertex3f(linestart.x+offset.x*startsize,      linestart.y+offset.y*startsize,          0.0f);
3732                                                                                                                                         glTexCoord2f(1,1);
3733                                                                                                                                         glVertex3f(lineend.x+offset.x*endsize,          lineend.y+offset.y*endsize, 0.0f);
3734                                                                                                                                         glTexCoord2f(0,1);
3735                                                                                                                                         glVertex3f(lineend.x-offset.x*endsize,          lineend.y-offset.y*endsize, 0.0f);
3736                                                                                                                                         glEnd();
3737                                                                                                                                 glPopMatrix();
3738                                                                                                                         }
3739                                                                                                                         glEnable(GL_TEXTURE_2D);
3740                                                                                                                 }
3741
3742
3743                                                                                                                 if(j==6)glBindTexture( GL_TEXTURE_2D, Mainmenuitems[7]);
3744                                                                                                                 else glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
3745                                                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
3746                                                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
3747                                                                                                                 if(j-7<accountcampaignchoicesmade[accountactive])glColor4f(0.5,0,0,1);
3748                                                                                                                 if(j-7>=accountcampaignchoicesmade[accountactive])glColor4f(1,0,0,1);
3749                                                                                                                 if(j==6)glColor4f(1,1,1,1);
3750                                                                                                                 XYZ midpoint;
3751                                                                                                                 float itemsize;
3752                                                                                                                 itemsize=abs(startx[j]-endx[j])/2;
3753                                                                                                                 midpoint=0;
3754                                                                                                                 midpoint.x=(startx[j]+endx[j])/2;
3755                                                                                                                 midpoint.y=(starty[j]+endy[j])/2;
3756                                                                                                                 if(j>6&&(j-7<accountcampaignchoicesmade[accountactive]))itemsize*=.5;
3757                                                                                                                 if(!(j-7>accountcampaignchoicesmade[accountactive]+campaignchoicenum))
3758                                                                                                                 {
3759                                                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3760                                                                                                                         glPushMatrix();
3761                                                                                                                                 glBegin(GL_QUADS);
3762                                                                                                                                 glTexCoord2f(0,0);
3763                                                                                                                                 glVertex3f(midpoint.x-itemsize+movex[j]*transition,     midpoint.y-itemsize+movey[j]*transition,         0.0f);
3764                                                                                                                                 glTexCoord2f(1,0);
3765                                                                                                                                 glVertex3f(midpoint.x+itemsize+movex[j]*transition,             midpoint.y-itemsize+movey[j]*transition,         0.0f);
3766                                                                                                                                 glTexCoord2f(1,1);
3767                                                                                                                                 glVertex3f(midpoint.x+itemsize+movex[j]*transition,             midpoint.y+itemsize+movey[j]*transition, 0.0f);
3768                                                                                                                                 glTexCoord2f(0,1);
3769                                                                                                                                 glVertex3f(midpoint.x-itemsize+movex[j]*transition,     midpoint.y+itemsize+movey[j]*transition, 0.0f);
3770                                                                                                                                 glEnd();
3771                                                                                                                         glPopMatrix();
3772                                                                                                                         glEnable(GL_BLEND);
3773                                                                                                                         //glDisable(GL_ALPHA_TEST);
3774                                                                                                                         if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3775                                                                                                                         for(i=0;i<10;i++)
3776                                                                                                                         {
3777                                                                                                                                 if(1-((float)i)/10-(1-selectedlong[j])>0)
3778                                                                                                                                 {
3779                                                                                                                                         glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3780                                                                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3781                                                                                                                                         glPushMatrix();
3782                                                                                                                                                 glBegin(GL_QUADS);
3783                                                                                                                                                 glTexCoord2f(0,0);
3784                                                                                                                                                 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);
3785                                                                                                                                                 glTexCoord2f(1,0);
3786                                                                                                                                                 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);
3787                                                                                                                                                 glTexCoord2f(1,1);
3788                                                                                                                                                 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);
3789                                                                                                                                                 glTexCoord2f(0,1);
3790                                                                                                                                                 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);
3791                                                                                                                                                 glEnd();
3792                                                                                                                                         glPopMatrix();
3793                                                                                                                                 }
3794                                                                                                                         }
3795                                                                                                                 }
3796                                                                                                         glPopMatrix();
3797                                                                                                 glPopMatrix();
3798                                                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3799                                                                                         glPopMatrix();
3800                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3801
3802                                                                                         if(j-7>=accountcampaignchoicesmade[accountactive]){
3803                                                                                                 //glColor4f(0,0,0,1);
3804                                                                                                 //text.glPrintOutline(startx[j]+10-1.5,starty[j]-4-1.5,menustring[j],0,0.6*1.25,640,480);
3805                                                                                                 //glColor4f(1,0,0,1);
3806                                                                                                 //text.glPrint(startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
3807                                                                                                 text.glPrintOutlined(0.9,0,0,startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
3808                                                                                                 glDisable(GL_DEPTH_TEST);
3809                                                                                         }
3810                                                                                 }
3811                                                                         }
3812                                                                 }
3813                                                         }
3814                                                 }
3815                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3816                                                 glPopMatrix();
3817                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3818                                                 glPopMatrix();
3819
3820                                                         if(mainmenu==1||mainmenu==2)
3821                                                                 if(transition<.1||transition>.9){
3822                                                                         glClear(GL_DEPTH_BUFFER_BIT);
3823                                                                         glEnable(GL_ALPHA_TEST);
3824                                                                         glAlphaFunc(GL_GREATER, 0.001f);
3825                                                                         glEnable(GL_TEXTURE_2D);
3826                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3827                                                                         glDisable(GL_CULL_FACE);
3828                                                                         glDisable(GL_LIGHTING);
3829                                                                         glDepthMask(0);
3830                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3831                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3832                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3833                                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3834                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3835                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3836                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3837                                                                                         glPushMatrix();
3838                                                                                                 glDisable(GL_TEXTURE_2D);
3839                                                                                                 if(transition<.1)glColor4f(1,0,0,1-(transition*10));
3840                                                                                                 if(transition>.9)glColor4f(1,0,0,1-((1-transition)*10));
3841                                                                                                 /*glPushMatrix();
3842                                                                                                 glBegin(GL_QUADS);
3843                                                                                                 glTexCoord2f(0,0);
3844                                                                                                 glVertex3f(190, 150,     0.0f);
3845                                                                                                 glTexCoord2f(1,0);
3846                                                                                                 glVertex3f(640, 150,     0.0f);
3847                                                                                                 glTexCoord2f(1,1);
3848                                                                                                 glVertex3f(640, 336, 0.0f);
3849                                                                                                 glTexCoord2f(0,1);
3850                                                                                                 glVertex3f(190, 336, 0.0f);
3851                                                                                                 glEnd();
3852                                                                                                 glPopMatrix();*/
3853                                                                                         glPopMatrix();
3854                                                                                 glPopMatrix();
3855                                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3856                                                                         glPopMatrix();
3857                                                                 }
3858
3859                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3860                                                                 glPushMatrix();                                                                         // Store The Projection Matrix
3861                                                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
3862                                                                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3863                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3864                                                                         glPushMatrix();                                                                         // Store The Modelview Matrix
3865                                                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3866                                                                                 glTranslatef(screenwidth/2,screenheight/2,0);
3867                                                                                 glPushMatrix();
3868                                                                                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
3869                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3870                                                                                         glEnable(GL_BLEND);
3871                                                                                         glEnable(GL_TEXTURE_2D);
3872                                                                                         glColor4f(1,1,1,1);
3873                                                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3874                                                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3875                                                                                 glPopMatrix();
3876                                                                                 glPushMatrix();
3877                                                                                         glTranslatef(mousecoordh-screenwidth/2,mousecoordv*-1+screenheight/2,0);
3878                                                                                         glScalef((float)screenwidth/64,(float)screenwidth/64,1);
3879                                                                                         glTranslatef(1,-1,0);
3880                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3881                                                                                         glColor4f(1,1,1,1);
3882                                                                                         glBindTexture( GL_TEXTURE_2D, cursortexture);
3883                                                                                         glPushMatrix();
3884                                                                                                 //glScalef(.25,.25,.25);
3885                                                                                                 glBegin(GL_QUADS);
3886                                                                                                 glTexCoord2f(0,0);
3887                                                                                                 glVertex3f(-1,          -1,      0.0f);
3888                                                                                                 glTexCoord2f(1,0);
3889                                                                                                 glVertex3f(1,   -1,      0.0f);
3890                                                                                                 glTexCoord2f(1,1);
3891                                                                                                 glVertex3f(1,   1, 0.0f);
3892                                                                                                 glTexCoord2f(0,1);
3893                                                                                                 glVertex3f(-1,  1, 0.0f);
3894                                                                                                 glEnd();
3895                                                                                         glPopMatrix();
3896                                                                                 glPopMatrix();
3897                                                                         glPopMatrix();
3898                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3899                                                                 glPopMatrix();
3900
3901
3902                                                                 if(flashamount>0)
3903                                                                 {
3904                                                                         //printf("Flash amount: %f, delay %i\n", flashamount, flashdelay);
3905                                                                         if(flashamount>1)flashamount=1;
3906                                                                         if(flashdelay<=0)flashamount-=multiplier;
3907                                                                         flashdelay--;
3908                                                                         if(flashamount<0)flashamount=0;
3909                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3910                                                                         glDisable(GL_CULL_FACE);
3911                                                                         glDisable(GL_LIGHTING);
3912                                                                         glDisable(GL_TEXTURE_2D);
3913                                                                         glDepthMask(0);
3914                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3915                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3916                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3917                                                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3918                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3919                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3920                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3921                                                                                         glScalef(screenwidth,screenheight,1);
3922                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3923                                                                                         glEnable(GL_BLEND);
3924                                                                                         glColor4f(flashr,flashg,flashb,flashamount);
3925                                                                                         glBegin(GL_QUADS);
3926                                                                                         glVertex3f(0,           0,       0.0f);
3927                                                                                         glVertex3f(256, 0,       0.0f);
3928                                                                                         glVertex3f(256, 256, 0.0f);
3929                                                                                         glVertex3f(0,   256, 0.0f);
3930                                                                                         glEnd();
3931                                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3932                                                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
3933                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3934                                                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
3935                                                                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
3936                                                                         glEnable(GL_CULL_FACE);
3937                                                                         glDisable(GL_BLEND);
3938                                                                         glDepthMask(1);
3939                                                                 }       
3940         }
3941
3942         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)){
3943                 tempmult=multiplier;
3944                 multiplier=0;
3945         }
3946
3947
3948         //glFlush();
3949         if ( side == stereoRight || side == stereoCenter ) {
3950                 if(drawmode!=motionblurmode||mainmenu){
3951                         swap_gl_buffers();
3952                 }
3953         }
3954
3955         //myassert(glGetError() == GL_NO_ERROR);
3956         glDrawBuffer(GL_BACK);
3957         glReadBuffer(GL_BACK);
3958         //glFlush();
3959
3960         weapons.DoStuff();
3961
3962         if(drawtoggle==2)drawtoggle=0;
3963
3964         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
3965                 multiplier=tempmult;
3966         }
3967         //Jordan fixed your warning!
3968         return 0;
3969 }
3970