]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
6ff358a13adb6bca67711d17c0eb71e2bb765e8d
[lugaru.git] / Source / GameTick.cpp
1 #if PLATFORM_UNIX
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #else
6 #include <direct.h>
7 #endif
8
9 #include <ctime>
10 #include "Game.h"
11
12 using namespace std;
13
14 extern float multiplier;
15 extern XYZ viewer;
16 extern int environment;
17 extern float texscale;
18 extern Terrain terrain;
19 extern FSOUND_SAMPLE    *samp[100];
20 extern int channels[100];
21 extern Sprites sprites;
22 extern int kTextureSize;
23 extern float screenwidth,screenheight;
24 extern float gravity;
25 extern int detail;
26 extern float texdetail;
27 extern Objects objects;
28 extern int slomo;
29 extern float slomodelay;
30 extern bool floatjump;
31 extern float volume;
32 extern Animation animation[animation_count];
33 extern Light light;
34 extern float texdetail;
35 extern GLubyte bloodText[512*512*3];
36 extern GLubyte wolfbloodText[512*512*3];
37 extern float terraindetail;
38 extern float camerashake;
39 extern float woozy;
40 extern float blackout;
41 extern bool cellophane;
42 extern bool musictoggle;
43 extern int difficulty;
44 extern Weapons weapons;
45 extern Person player[maxplayers];
46 extern int numplayers;
47 extern int bloodtoggle;
48 extern bool invertmouse;
49 extern float windvar;
50 extern float precipdelay;
51 extern XYZ viewerfacing;
52 extern bool ambientsound;
53 extern bool mousejump;
54 extern float viewdistance;
55 extern bool freeze;
56 extern bool autoslomo;
57 extern int newnetmessages;
58 extern char netmessages[256];
59 extern bool keyboardfrozen;
60 extern int netdatanew;
61 extern bool loadingstuff;
62 extern char mapname[256];
63 extern XYZ windvector;
64 extern bool buttons[3];
65 extern bool debugmode;
66 static int music1;
67 extern int mainmenu;
68 extern int oldmainmenu;
69 extern bool visibleloading;
70 extern int loadscreencolor;
71 extern float flashamount,flashr,flashg,flashb;
72 extern int flashdelay;
73 extern XYZ envsound[30];
74 extern float envsoundvol[30];
75 extern int numenvsounds;
76 extern float envsoundlife[30];
77 extern float usermousesensitivity;
78 extern bool ismotionblur;
79 extern bool foliage;
80 extern bool trilinear;
81 extern bool damageeffects;
82 extern bool showpoints;
83 extern bool texttoggle;
84 extern bool alwaysblur;
85 extern float gamespeed;
86 extern bool decals;
87 extern bool vblsync;
88 extern bool immediate;
89 extern bool velocityblur;
90 extern int bonus;
91 extern int oldbonus;
92 extern float bonusvalue;
93 extern float bonustotal;
94 extern float bonustime;
95 extern float startbonustotal;
96 extern float tintr,tintg,tintb;
97 extern float bonusnum[100];
98 extern bool skyboxtexture;
99 extern float skyboxr;
100 extern float skyboxg;
101 extern float skyboxb;
102 extern float skyboxlightr;
103 extern float skyboxlightg;
104 extern float skyboxlightb;
105 extern float fadestart;
106 extern float slomospeed;
107 extern float slomofreq;
108 extern int tutoriallevel;
109 extern float smoketex;
110 extern float tutorialstagetime;
111 extern int tutorialstage;
112 extern float tutorialmaxtime;
113 extern float tutorialsuccess;
114 extern bool againbonus;
115 extern bool reversaltrain;
116 extern bool canattack;
117 extern bool cananger;
118 extern float damagedealt;
119 extern float damagetaken;
120 extern int maptype;
121 extern int editoractive;
122 extern int editorpathtype;
123 extern bool oldbuttons[3];
124
125 extern float hostiletime;
126
127 extern bool gamestarted;
128
129 extern int numhotspots;
130 extern int winhotspot;
131 extern int windialogue;
132 extern int killhotspot;
133 extern XYZ hotspot[40];
134 extern int hotspottype[40];
135 extern float hotspotsize[40];
136 extern char hotspottext[40][256];
137 extern int currenthotspot;
138
139 extern int kBitsPerPixel;
140 extern int hostile;
141
142 extern int numaccounts;
143 extern int accountactive;
144 extern int accountdifficulty[10];
145 extern int accountprogress[10];
146 extern float accountpoints[10];
147 extern float accounthighscore[10][50];
148 extern float accountfasttime[10][50];
149 extern bool accountunlocked[10][60];
150 extern char accountname[10][256];
151
152 extern bool stillloading;
153 extern bool winfreeze;
154
155 extern int numfalls;
156 extern int numflipfail;
157 extern int numseen;
158 extern int numstaffattack;
159 extern int numswordattack;
160 extern int numknifeattack;
161 extern int numunarmedattack;
162 extern int numescaped;
163 extern int numflipped;
164 extern int numwallflipped;
165 extern int numthrowkill;
166 extern int numafterkill;
167 extern int numreversals;
168 extern int numattacks;
169 extern int maxalarmed;
170 extern int numresponded;
171
172 extern int numdialogues;
173 extern int numdialogueboxes[max_dialogues];
174 extern int dialoguetype[max_dialogues];
175 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
176 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
177 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
178 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
179 extern char dialoguename[max_dialogues][max_dialoguelength][64];
180 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
181 extern XYZ participantlocation[max_dialogues][10];
182 extern int participantfocus[max_dialogues][max_dialoguelength];
183 extern int participantaction[max_dialogues][max_dialoguelength];
184 extern float participantrotation[max_dialogues][10];
185 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
186 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
187 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
188 extern int indialogue;
189 extern int whichdialogue;
190 extern int directing;
191 extern float dialoguetime;
192 extern int dialoguegonethrough[20];
193
194 extern bool campaign;
195
196 extern float oldgamespeed;
197
198 extern float accountcampaignhighscore[10];
199 extern float accountcampaignfasttime[10];
200 extern float accountcampaignscore[10];
201 extern float accountcampaigntime[10];
202
203 extern int accountcampaignchoicesmade[10];
204 extern int accountcampaignchoices[10][5000];
205 /********************> Tick() <*****/
206 extern FSOUND_STREAM * strm[20];
207 extern "C"      void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
208 extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
209
210 extern void ScreenShot(const char * fname);
211 void Screenshot (void)
212 {
213         char temp[1024];
214         time_t  t = time(NULL);
215         struct  tm *tme = localtime(&t);
216         sprintf(temp, "Screenshots\\Screenshot_%04d_%02d_%02d--%02d_%02d_%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
217
218         mkdir("Screenshots", S_IRWXU);
219         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
220
221         /*FSSpec                                MAC_file;
222         GraphicsExportComponent         QT_exporter;
223         OSErr                           MAC_error_code;
224         CGrafPtr                        MAC_currentPort;
225         GDHandle                        MAC_currentDevice;
226         unsigned char*          MAC_pixels;
227         Rect                            MAC_picture_rectangle;
228         GWorldPtr                       MAC_offscreen_graphics_port;
229
230         static int numscreenshots=0;
231
232         // Make an FSSpec
233         static char buf[256];
234         if(numscreenshots==0){
235         buf[0]=26;
236         buf[1]=':';
237         buf[2]='S';
238         buf[3]='c';
239         buf[4]='r';
240         buf[5]='e';
241         buf[6]='e';
242         buf[7]='n';
243         buf[8]='s';
244         buf[9]='h';
245         buf[10]='o';
246         buf[11]='t';
247         buf[12]='s';
248         buf[13]=':';
249         buf[14]='S';
250         buf[15]='c';
251         buf[16]='r';
252         buf[17]='e';
253         buf[18]='e';
254         buf[19]='n';
255         buf[20]='s';
256         buf[21]='h';
257         buf[22]='o';
258         buf[23]='t';
259         buf[24]='0';
260         buf[25]='0';
261         buf[26]='0';
262         }
263
264         FInfo *fndrInfo;
265         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
266         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
267         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
268         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
269         numscreenshots++;
270         buf[26]++;
271         if(buf[26]==':'){
272         buf[26]='0';
273         buf[25]++;
274         if(buf[25]==':'){
275         buf[25]='0';
276         buf[24]++;
277         if(buf[24]==':'){
278         buf[24]='9';
279         buf[25]='9';
280         buf[26]='9';
281         }
282         }
283         }
284         }
285         }
286
287
288         // Get the GWorld
289         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
290         //assert(MAC_gWorld != NULL);
291
292         // Allocate memory for loading image
293         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
294         if (MAC_pixels == NULL) {
295         //UTIL_Error("Could not create Texture data.");
296         return;
297         }
298
299         // Get GWorld
300         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);      
301
302         // Make a picture Rectangle
303         MAC_picture_rectangle.left = 0;
304         MAC_picture_rectangle.right = screenwidth;
305         MAC_picture_rectangle.top = 0;
306         MAC_picture_rectangle.bottom = screenheight;    
307
308         // Create new offscreen GWorld
309         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
310         if (MAC_error_code)     {
311         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
312         delete MAC_pixels;
313         //UTIL_Error("Could not create offscreen GWorld. ");
314         return;
315
316         }
317
318         // Copy OpenGL Context to new GWorld
319         glReadBuffer(GL_FRONT); 
320         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
321
322         // Swizzle texture
323         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
324         unsigned char temp = MAC_pixels[byte+0];
325         MAC_pixels[byte+0] = MAC_pixels[byte+3];
326         MAC_pixels[byte+3] = MAC_pixels[byte+2];
327         MAC_pixels[byte+2] = MAC_pixels[byte+1];
328         MAC_pixels[byte+1] = temp;
329         }
330
331         // Flip the image  :(   This could probably be optimized
332         int vert;
333         int src_index;
334         int dst_index;
335         unsigned char temp;
336         for (int horz = 0; horz < screenwidth; ++horz)
337         for (vert = 0; vert < screenheight / 2; ++vert) {               
338         src_index = (screenwidth * vert + horz) * 4;
339         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
340
341         temp=MAC_pixels[src_index+0];
342         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
343         MAC_pixels[dst_index+0]=temp;
344
345         temp=MAC_pixels[src_index+1];
346         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
347         MAC_pixels[dst_index+1]=temp;
348
349         temp=MAC_pixels[src_index+2];
350         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
351         MAC_pixels[dst_index+2]=temp;
352
353         temp=MAC_pixels[src_index+3];
354         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
355         MAC_pixels[dst_index+3]=temp;
356         }
357
358
359
360         // Export the Gworld
361         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
362         if (MAC_error_code) {
363         //UTIL_Warning("Unable to export screenshot."); 
364         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
365         ::DisposeGWorld(MAC_offscreen_graphics_port);
366         delete MAC_pixels;
367         return;
368         }                                                                                               
369
370         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
371         if (MAC_error_code) {
372         ::CloseComponent(QT_exporter);
373         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
374         ::DisposeGWorld(MAC_offscreen_graphics_port);
375         delete MAC_pixels;
376         //UTIL_Warning("Unable to export screenshot.");
377         return;
378         }                                                               
379
380         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
381         if (MAC_error_code) {
382         ::CloseComponent(QT_exporter);
383         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
384         ::DisposeGWorld(MAC_offscreen_graphics_port);
385         delete MAC_pixels;
386         //UTIL_Warning("Unable to export screenshot.");
387         return;
388         }                                                       
389
390         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
391         if (MAC_error_code) {
392         ::CloseComponent(QT_exporter);
393         ::SetGWorld(MAC_currentPort, MAC_currentDevice);                        
394         ::DisposeGWorld(MAC_offscreen_graphics_port);
395         delete MAC_pixels;
396         //UTIL_Warning("Unable to export screenshot.");
397         return;
398         }                                               
399
400         ::CloseComponent(QT_exporter);
401         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
402         ::DisposeGWorld(MAC_offscreen_graphics_port);
403
404         delete MAC_pixels;*/
405 }
406
407
408
409 void    Game::SetUpLighting(){
410         if(environment==snowyenvironment){
411                 light.color[0]=.65;
412                 light.color[1]=.65;
413                 light.color[2]=.7;
414                 light.ambient[0]=.4;
415                 light.ambient[1]=.4;
416                 light.ambient[2]=.44;           
417         }
418         if(environment==desertenvironment){
419                 light.color[0]=.95;
420                 light.color[1]=.95;
421                 light.color[2]=.95;
422                 light.ambient[0]=.4;
423                 light.ambient[1]=.35;
424                 light.ambient[2]=.3;            
425         }
426
427         if(environment==grassyenvironment){
428                 light.color[0]=.95;
429                 light.color[1]=.95;
430                 light.color[2]=1;
431                 light.ambient[0]=.4;
432                 light.ambient[1]=.4;
433                 light.ambient[2]=.44;           
434         }
435         if(!skyboxtexture){
436                 light.color[0]=1;
437                 light.color[1]=1;
438                 light.color[2]=1;
439                 light.ambient[0]=.4;
440                 light.ambient[1]=.4;
441                 light.ambient[2]=.4;    
442         }
443         float average;
444         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
445         light.color[0]*=(skyboxlightr+average)/2;
446         light.color[1]*=(skyboxlightg+average)/2;
447         light.color[2]*=(skyboxlightb+average)/2;
448         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
449         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
450         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;   
451         /*
452         light.ambient[0]=0;
453         light.ambient[1]=0;
454         light.ambient[2]=0;     */
455 }
456
457 int Game::findPathDist(int start,int end){
458         int i,j,k,smallestcount,count,connected;
459         int last,last2,last3,last4;
460         int closest;
461
462         smallestcount=1000;
463         for(i=0;i<50;i++){
464                 count=0;
465                 last=start;
466                 last2=-1;
467                 last3=-1;
468                 last4=-1;
469                 while(last!=end&&count<30){
470                         closest=-1;
471                         for(j=0;j<numpathpoints;j++){
472                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
473                                 {
474                                         connected=0;
475                                         if(numpathpointconnect[j])
476                                                 for(k=0;k<numpathpointconnect[j];k++){
477                                                         if(pathpointconnect[j][k]==last)connected=1;
478                                                 }
479                                                 if(!connected)
480                                                         if(numpathpointconnect[last])
481                                                                 for(k=0;k<numpathpointconnect[last];k++){
482                                                                         if(pathpointconnect[last][k]==j)connected=1;
483                                                                 }
484                                                                 if(connected)
485                                                                         if(closest==-1||Random()%2==0){
486                                                                                 closest=j;
487                                                                         }
488                                 }
489                         }
490                         last4=last3;
491                         last3=last2;
492                         last2=last;
493                         last=closest;
494                         count++;
495                 }
496                 if(count<smallestcount)smallestcount=count;
497         }
498         return smallestcount;
499 }
500
501 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
502         static XYZ colpoint,colviewer,coltarget;
503         static float minx,minz,maxx,maxz,miny,maxy;
504         static int i;
505
506         //startpoint.y+=.7;
507         //endpoint.y+=.7;
508         //startpoint.y-=.1;
509         //endpoint.y-=.1;
510
511         minx=startpoint.x;
512         if(minx>endpoint.x)minx=endpoint.x;
513         miny=startpoint.y;
514         if(miny>endpoint.y)miny=endpoint.y;
515         minz=startpoint.z;
516         if(minz>endpoint.z)minz=endpoint.z;
517
518         maxx=startpoint.x;
519         if(maxx<endpoint.x)maxx=endpoint.x;
520         maxy=startpoint.y;
521         if(maxy<endpoint.y)maxy=endpoint.y;
522         maxz=startpoint.z;
523         if(maxz<endpoint.z)maxz=endpoint.z;
524
525         minx-=1;
526         miny-=1;
527         minz-=1;
528         maxx+=1;
529         maxy+=1;
530         maxz+=1;
531
532         for(i=0;i<objects.numobjects;i++){
533                 if(objects.position[i].x>minx-objects.model[i].boundingsphereradius&&objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&objects.position[i].y>miny-objects.model[i].boundingsphereradius&&objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&objects.position[i].z>minz-objects.model[i].boundingsphereradius&&objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
534                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
535                                 colviewer=startpoint;
536                                 coltarget=endpoint;
537                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;  
538                         }
539                 }
540         }
541
542         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
543
544         return -1;
545 }
546
547 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
548         static XYZ colpoint,colviewer,coltarget;
549         static float minx,minz,maxx,maxz,miny,maxy;
550         static int i;
551
552         //startpoint.y+=.7;
553         //endpoint.y+=.7;
554         //startpoint.y-=.1;
555         //endpoint.y-=.1;
556
557         minx=startpoint.x;
558         if(minx>endpoint.x)minx=endpoint.x;
559         miny=startpoint.y;
560         if(miny>endpoint.y)miny=endpoint.y;
561         minz=startpoint.z;
562         if(minz>endpoint.z)minz=endpoint.z;
563
564         maxx=startpoint.x;
565         if(maxx<endpoint.x)maxx=endpoint.x;
566         maxy=startpoint.y;
567         if(maxy<endpoint.y)maxy=endpoint.y;
568         maxz=startpoint.z;
569         if(maxz<endpoint.z)maxz=endpoint.z;
570
571         minx-=1;
572         miny-=1;
573         minz-=1;
574         maxx+=1;
575         maxy+=1;
576         maxz+=1;
577
578         if(what!=1000){
579                 if(objects.position[what].x>minx-objects.model[what].boundingsphereradius&&objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&objects.position[what].y>miny-objects.model[what].boundingsphereradius&&objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&objects.position[what].z>minz-objects.model[what].boundingsphereradius&&objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
580                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
581                                 colviewer=startpoint;
582                                 coltarget=endpoint;
583                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i; 
584                         }
585                 }
586         }
587
588         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
589
590         return -1;
591 }
592
593 void    Game::Setenvironment(int which)
594 {
595         LOGFUNC;
596
597         LOG(" Setting environment...");
598
599         float temptexdetail;
600         environment=which;
601 /*
602         FSOUND_SetPaused(channels[music1snow], TRUE);
603         FSOUND_SetPaused(channels[music1grass], TRUE);
604         FSOUND_SetPaused(channels[music1desert], TRUE);
605         FSOUND_SetPaused(channels[wind], TRUE);
606         FSOUND_SetPaused(channels[desertambient], TRUE);
607 */
608         FSOUND_SetPaused(channels[stream_music1snow], TRUE);
609         FSOUND_SetPaused(channels[stream_music1grass], TRUE);
610         FSOUND_SetPaused(channels[stream_music1desert], TRUE);
611         FSOUND_SetPaused(channels[stream_wind], TRUE);
612         FSOUND_SetPaused(channels[stream_desertambient], TRUE);
613
614
615         if(environment==snowyenvironment){
616                 windvector=0;
617                 windvector.z=3;
618                 if(ambientsound){
619                         //PlaySoundEx( wind, samp[wind], NULL, TRUE);
620                         PlayStreamEx(stream_wind, strm[stream_wind], 0, TRUE);
621                         FSOUND_SetPaused(channels[stream_wind], FALSE);
622                         FSOUND_SetVolume(channels[stream_wind], 256);
623                 }
624
625                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
626                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
627                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
628                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
629
630                 FSOUND_Sample_Free(samp[footstepsound]);
631                 FSOUND_Sample_Free(samp[footstepsound2]);
632                 FSOUND_Sample_Free(samp[footstepsound3]);
633                 FSOUND_Sample_Free(samp[footstepsound4]);
634                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
635                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
636                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
637                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
638                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
639                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
640                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
641                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
642
643                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
644
645                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
646
647                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
648
649
650
651
652                 temptexdetail=texdetail;
653                 if(texdetail>1)texdetail=4;
654                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
655                         ":Data:Textures:Skybox(snow):Left.jpg",
656                         ":Data:Textures:Skybox(snow):Back.jpg",
657                         ":Data:Textures:Skybox(snow):Right.jpg",
658                         ":Data:Textures:Skybox(snow):Up.jpg",
659                         ":Data:Textures:Skybox(snow):Down.jpg",
660                         ":Data:Textures:Skybox(snow):Cloud.jpg",
661                         ":Data:Textures:Skybox(snow):Reflect.jpg");
662
663
664
665
666                 texdetail=temptexdetail;
667         }
668         if(environment==desertenvironment){
669                 windvector=0;
670                 windvector.z=2;
671                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
672                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
673                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
674                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
675
676
677                 if(ambientsound){
678                         //PlaySoundEx( desertambient, samp[desertambient], NULL, TRUE);
679                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, TRUE);
680                         FSOUND_SetPaused(channels[stream_desertambient], FALSE);
681                         FSOUND_SetVolume(channels[stream_desertambient], 256);
682                 }
683
684                 FSOUND_Sample_Free(samp[footstepsound]);
685                 FSOUND_Sample_Free(samp[footstepsound2]);
686                 FSOUND_Sample_Free(samp[footstepsound3]);
687                 FSOUND_Sample_Free(samp[footstepsound4]);
688                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
689                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
690                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0, 0);
691                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0, 0);
692                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
693                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
694                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
695                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
696
697                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
698
699                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
700
701                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
702
703
704
705                 temptexdetail=texdetail;
706                 if(texdetail>1)texdetail=4;
707                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
708                         ":Data:Textures:Skybox(sand):Left.jpg",
709                         ":Data:Textures:Skybox(sand):Back.jpg",
710                         ":Data:Textures:Skybox(sand):Right.jpg",
711                         ":Data:Textures:Skybox(sand):Up.jpg",
712                         ":Data:Textures:Skybox(sand):Down.jpg",
713                         ":Data:Textures:Skybox(sand):Cloud.jpg",
714                         ":Data:Textures:Skybox(sand):Reflect.jpg");
715
716
717
718
719                 texdetail=temptexdetail;
720         }
721         if(environment==grassyenvironment){
722                 windvector=0;
723                 windvector.z=2;
724                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
725                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
726                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
727                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
728
729                 if(ambientsound){
730                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, TRUE);
731                         FSOUND_SetPaused(channels[stream_wind], FALSE);
732                         FSOUND_SetVolume(channels[stream_wind], 100);
733                 }
734
735                 FSOUND_Sample_Free(samp[footstepsound]);
736                 FSOUND_Sample_Free(samp[footstepsound2]);
737                 FSOUND_Sample_Free(samp[footstepsound3]);
738                 FSOUND_Sample_Free(samp[footstepsound4]);
739                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass1.ogg", FSOUND_HW3D, 0, 0);
740                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass2.ogg", FSOUND_HW3D, 0, 0);
741                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0, 0);
742                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0, 0);
743                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
744                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
745                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
746                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
747
748                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
749
750                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
751
752                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
753
754
755
756                 temptexdetail=texdetail;
757                 if(texdetail>1)texdetail=4;
758                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
759                         ":Data:Textures:Skybox(grass):Left.jpg",
760                         ":Data:Textures:Skybox(grass):Back.jpg",
761                         ":Data:Textures:Skybox(grass):Right.jpg",
762                         ":Data:Textures:Skybox(grass):Up.jpg",
763                         ":Data:Textures:Skybox(grass):Down.jpg",
764                         ":Data:Textures:Skybox(grass):Cloud.jpg",
765                         ":Data:Textures:Skybox(grass):Reflect.jpg");
766
767
768
769                 texdetail=temptexdetail;
770         }
771         temptexdetail=texdetail;
772         texdetail=1;
773         terrain.load(":Data:Textures:heightmap.png");
774
775         texdetail=temptexdetail;
776 }
777
778
779 void    Game::Loadlevel(int which){
780         stealthloading=0;
781
782         if(which==0)Loadlevel((char *)":Data:Maps:map1");
783         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
784         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
785         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
786         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
787         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
788         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
789         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
790         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
791         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
792         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
793         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
794         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
795         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
796         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
797         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
798         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
799         else Loadlevel((char *)":Data:Maps:mapsave");
800
801         whichlevel=which;
802 }
803
804 /*char * Game::MD5_string (unsigned char *string){
805 char temp[50];
806 char temp2[100];
807
808 strcpy(temp2,(const char *)string);
809 strcat((char *)temp2,(const char *)"Lugaru");                                   
810 sprintf (temp, "%d",strlen((char *)temp2));
811 strcat((char *)temp2,temp);                                     
812
813 MD5 context;
814 unsigned int len = strlen ( (char *)temp2);
815
816 context.update   ((unsigned char *)temp2, len);
817 context.finalize ();
818
819 return context.hex_digest();
820 }*/
821
822
823
824 void    Game::Loadlevel(char *name){
825         int i,j,k,l,m;
826         static int oldlevel;
827         int templength;
828         float lamefloat;
829         int lameint;
830
831         float headprop,legprop,armprop,bodyprop;
832
833         LOGFUNC;
834
835         LOG(std::string("Loading level...") + name);
836
837         if(!gameon)visibleloading=1;
838
839         if(stealthloading)visibleloading=0;
840
841         if(!stillloading)loadtime=0;
842         gamestarted=1;
843
844         numenvsounds=0;
845         //visibleloading=1;
846         if(tutoriallevel!=-1)tutoriallevel=0;
847         else tutoriallevel=1;
848
849         if(tutoriallevel==1)tutorialstage=0;
850         if(tutorialstage==0){
851                 tutorialstagetime=0;
852                 tutorialmaxtime=1;
853         }
854         loadingstuff=1;
855         if(!firstload){
856                 oldlevel=50;
857         }
858         FSOUND_SetPaused(channels[whooshsound], TRUE);
859         FSOUND_SetPaused(channels[stream_firesound], TRUE);
860
861         int mapvers;
862         FILE                    *tfile;
863         tfile=fopen( name, "rb" );
864         if(tfile)
865         {
866                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
867
868
869                 scoreadded=0;
870                 windialogue=0;
871
872                 hostiletime=0;
873
874                 won=0;
875
876                 //campaign=0;
877                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
878
879                 numdialogues=0;
880
881                 for(i=0;i<20;i++)
882                 {
883                         dialoguegonethrough[i]=0;
884                 }
885
886                 indialogue=-1;
887                 cameramode=0;
888
889                 damagedealt=0;
890                 damagetaken=0;
891
892                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
893
894                 if(difficulty!=2)minimap=1;
895                 else minimap=0;
896
897                 numhotspots=0;
898                 currenthotspot=-1;
899                 bonustime=1;
900
901                 skyboxtexture=1;
902                 skyboxr=1;
903                 skyboxg=1;
904                 skyboxb=1;
905
906                 freeze=0;
907                 winfreeze=0;
908
909                 for(i=0;i<100;i++)
910                 {
911                         bonusnum[i]=0;
912                 }
913
914                 numfalls=0;
915                 numflipfail=0;
916                 numseen=0;
917                 numstaffattack=0;
918                 numswordattack=0;
919                 numknifeattack=0;
920                 numunarmedattack=0;
921                 numescaped=0;
922                 numflipped=0;
923                 numwallflipped=0;
924                 numthrowkill=0;
925                 numafterkill=0;
926                 numreversals=0;
927                 numattacks=0;
928                 maxalarmed=0;
929                 numresponded=0;
930
931                 bonustotal=startbonustotal;
932                 bonus=0;
933                 gameon=1;
934                 changedelay=0;
935                 if(console)
936                 {
937                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
938                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
939                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
940                         freeze=0;
941                         console=0;
942                 }
943
944                 if(!stealthloading)
945                 {
946                         terrain.numdecals=0;
947                         sprites.numsprites=0;
948                         for(i=0;i<objects.numobjects;i++)
949                         {
950                                 objects.model[i].numdecals=0;
951                         }
952
953                         j=objects.numobjects;
954                         for(i=0;i<j;i++)
955                         {
956                                 objects.DeleteObject(0);
957                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
958                         }
959
960                         for(i=0;i<subdivision;i++)
961                         {
962                                 for(j=0;j<subdivision;j++)
963                                 {
964                                         terrain.patchobjectnum[i][j]=0;
965                                 }
966                         }
967                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
968                 }
969
970                 weapons.numweapons=0;
971
972                 funpackf(tfile, "Bi", &mapvers);
973                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
974                 else indemo=0;
975                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
976                 else maptype=mapkilleveryone;
977                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
978                 else hostile=1;
979                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
980                 else
981                 {
982                         viewdistance=100;
983                         fadestart=.6;
984                 }
985                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
986                 else
987                 {
988                         skyboxtexture=1;
989                         skyboxr=1;
990                         skyboxg=1;
991                         skyboxb=1;
992                 }
993                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
994                 else
995                 {
996                         skyboxlightr=skyboxr;
997                         skyboxlightg=skyboxg;
998                         skyboxlightb=skyboxb;
999                 }
1000                 if(!stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons);
1001                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1002                 player[0].originalcoords=player[0].coords;
1003                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1004                 {
1005                         for(j=0;j<player[0].num_weapons;j++)
1006                         {
1007                                 player[0].weaponids[j]=weapons.numweapons;
1008                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1009                                 weapons.owner[weapons.numweapons]=0;
1010                                 weapons.numweapons++;
1011                         }
1012                 }
1013
1014                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1015
1016                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1017                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1018                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1019                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1020
1021                 funpackf(tfile, "Bi", &player[0].numclothes);
1022
1023                 if(mapvers>=9)
1024                 {
1025                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1026                 }
1027                 else
1028                 {
1029                         player[0].whichskin=0;
1030                         player[0].creature=rabbittype;
1031                 }
1032
1033                 for(i=0;i<max_dialogues;i++)
1034                 {
1035                         for(j=0;j<max_dialoguelength;j++)
1036                         {
1037                                 for(k=0;k<128;k++)
1038                                 {
1039                                         dialoguetext[i][j][k]='\0';
1040                                 }
1041                                 for(k=0;k<64;k++)
1042                                 {
1043                                         dialoguename[i][j][k]='\0';
1044                                 }
1045                         }
1046                 }
1047
1048                 player[0].lastattack=-1;
1049                 player[0].lastattack2=-1;
1050                 player[0].lastattack3=-1;
1051
1052                 if(mapvers>=8)
1053                 {
1054                         funpackf(tfile, "Bi", &numdialogues);
1055                         if(numdialogues)
1056                         {
1057                                 for(k=0;k<numdialogues;k++)
1058                                 {
1059                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1060                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1061                                         for(l=0;l<10;l++)
1062                                         {
1063                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1064                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1065                                         }
1066                                         if(numdialogueboxes)
1067                                         {
1068                                                 for(l=0;l<numdialogueboxes[k];l++)
1069                                                 {
1070                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1071                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1072                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1073                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1074                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1075
1076                                                         bool doneread;
1077
1078                                                         funpackf(tfile, "Bi",&templength);
1079                                                         if(templength>128||templength<=0)templength=128;
1080                                                         for(m=0;m<templength;m++){
1081                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1082                                                                 if(dialoguetext[k][l][m]=='\0')break;
1083                                                         }
1084
1085                                                         funpackf(tfile, "Bi",&templength);
1086                                                         if(templength>64||templength<=0)templength=64;
1087                                                         for(m=0;m<templength;m++){
1088                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1089                                                                 if(dialoguename[k][l][m]=='\0'){
1090                                                                         break;  
1091                                                                 }
1092                                                         }
1093                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1094                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1095                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1096
1097                                                         for(m=0;m<10;m++)
1098                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1099
1100                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1101                                                 }
1102                                         }
1103                                 }
1104                         }
1105                 }
1106                 else numdialogues=0;
1107
1108                 if(player[0].numclothes)
1109                 {
1110                         for(k=0;k<player[0].numclothes;k++)
1111                         {
1112                                 funpackf(tfile, "Bi", &templength);
1113                                 for(l=0;l<templength;l++)
1114                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1115                                 player[0].clothes[k][templength]='\0';
1116                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);                                                                        
1117                         }
1118                 }
1119
1120                 funpackf(tfile, "Bi", &environment);
1121
1122                 funpackf(tfile, "Bi", &objects.numobjects);
1123                 if(objects.numobjects)
1124                 {
1125                         for(i=0;i<objects.numobjects;i++)
1126                         {
1127                                 funpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", &objects.type[i],&objects.rotation[i],&objects.rotation2[i], &objects.position[i].x, &objects.position[i].y, &objects.position[i].z,&objects.scale[i]);
1128                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1129                         }
1130                 }
1131
1132                 if(mapvers>=7)
1133                 {
1134                         funpackf(tfile, "Bi", &numhotspots);
1135                         if(numhotspots)
1136                         {
1137                                 for(i=0;i<numhotspots;i++)
1138                                 {
1139                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1140                                         funpackf(tfile, "Bi", &templength);
1141                                         if(templength)
1142                                                 for(l=0;l<templength;l++)
1143                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1144                                         hotspottext[i][templength]='\0';
1145                                         if(hotspottype[i]==-111)indemo=1;
1146                                 }
1147                         }
1148                 }
1149                 else numhotspots=0;
1150
1151                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1152
1153                 if(!stealthloading)
1154                 {
1155                         objects.center=0;
1156                         for(i=0;i<objects.numobjects;i++)
1157                         {
1158                                 objects.center+=objects.position[i];    
1159                         }
1160                         objects.center/=objects.numobjects;
1161
1162
1163                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1164
1165                         float maxdistance=0;
1166                         float tempdist;
1167                         int whichclosest;
1168                         for(i=0;i<objects.numobjects;i++)
1169                         {
1170                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1171                                 if(tempdist>maxdistance)
1172                                 {
1173                                         whichclosest=i;
1174                                         maxdistance=tempdist;
1175                                 }
1176                         }
1177                         objects.radius=fast_sqrt(maxdistance);
1178                 }                               
1179
1180                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1181                 //mapcenter=objects.center;
1182                 //mapradius=objects.radius;
1183
1184                 funpackf(tfile, "Bi", &numplayers);
1185                 int howmanyremoved=0;
1186                 bool removeanother=0;
1187                 if(numplayers>1&&numplayers<maxplayers)
1188                 {
1189                         for(i=1;i<numplayers;i++)
1190                         {
1191                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1192                                 removeanother=0;
1193
1194                                 funpackf(tfile, "Bi Bi Bf Bf Bf Bi",&player[i-howmanyremoved].whichskin,&player[i-howmanyremoved].creature, &player[i-howmanyremoved].coords.x,&player[i-howmanyremoved].coords.y,&player[i-howmanyremoved].coords.z,&player[i-howmanyremoved].num_weapons);
1195                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1196                                 else player[i-howmanyremoved].howactive=typeactive;
1197                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1198                                 else player[i-howmanyremoved].scale=-1;
1199                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1200                                 else player[i-howmanyremoved].immobile=0;
1201                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1202                                 else player[i-howmanyremoved].rotation=0;
1203                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1204                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1205                                         removeanother=1;
1206                                         howmanyremoved++;
1207                                 }
1208                                 if(!removeanother)
1209                                 {
1210                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1211                                         {
1212                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1213                                                 {
1214                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1215                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1216                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1217                                                         weapons.numweapons++;
1218                                                 }
1219                                         }
1220                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1221                                         //player[i-howmanyremoved].numwaypoints=10;
1222                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1223                                         {
1224                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1225                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1226                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1227                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1228                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1229                                         }
1230
1231                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1232                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1233
1234                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1235                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1236                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1237                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1238
1239                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1240                                         else
1241                                         {
1242                                                 headprop=1;
1243                                                 bodyprop=1;
1244                                                 armprop=1;
1245                                                 legprop=1;
1246                                         }
1247                                         if(player[i-howmanyremoved].creature==wolftype)
1248                                         {
1249                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1250                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1251                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1252                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1253                                         }
1254
1255                                         if(player[i-howmanyremoved].creature==rabbittype)
1256                                         {
1257                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1258                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1259                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1260                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1261                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1262                                         }
1263
1264                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1265                                         if(player[i-howmanyremoved].numclothes)
1266                                         {
1267                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1268                                                 {
1269                                                         int templength;
1270                                                         funpackf(tfile, "Bi", &templength);
1271                                                         for(l=0;l<templength;l++)
1272                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1273                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1274                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);                                                                   
1275                                                 }
1276                                         }
1277                                 }
1278                         }
1279                 }
1280                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1281
1282                 numplayers-=howmanyremoved;
1283                 funpackf(tfile, "Bi", &numpathpoints);
1284                 if(numpathpoints>30||numpathpoints<0)
1285                         numpathpoints=0;
1286                 if(numpathpoints)
1287                 {
1288                         for(j=0;j<numpathpoints;j++)
1289                         {
1290                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1291                                 for(k=0;k<numpathpointconnect[j];k++){
1292                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1293                                 }
1294                         }
1295                 }
1296                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1297
1298                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1299
1300                 SetUpLighting();
1301                 if(environment!=oldenvironment)Setenvironment(environment);
1302                 oldenvironment=environment;
1303
1304                 if(!stealthloading)
1305                 {
1306                         j=objects.numobjects;
1307                         objects.numobjects=0;
1308                         for(i=0;i<j;i++)
1309                         {
1310                                 //if(objects.type[i]!=spiketype)
1311                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1312                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1313                         }
1314
1315                         //if(skyboxtexture){
1316                         terrain.DoShadows();
1317                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1318                         objects.DoShadows();
1319                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1320                         /*}
1321                         else terrain.DoLighting();
1322                         */
1323                 }
1324
1325                 fclose(tfile);
1326
1327                 oldlevel=whichlevel;
1328
1329
1330                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1331                 for(i=0;i<numplayers;i++)
1332                 {
1333                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1334                         player[i].burnt=0;
1335                         player[i].bled=0;
1336                         player[i].onfire=0;
1337                         if(i==0||player[i].scale<0)player[i].scale=.2;
1338                         player[i].skeleton.free=0;
1339                         player[i].skeleton.id=i;
1340                         //if(Random()%2==0)player[i].creature=wolftype;
1341                         //else player[i].creature=rabbittype;
1342                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1343                         if(player[i].creature!=wolftype)player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",0);
1344                         else
1345                         {
1346                                 if(player[i].creature!=wolftype){
1347                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
1348                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1349                                 }
1350                                 if(player[i].creature==wolftype){
1351                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
1352                                 }
1353                         }
1354
1355
1356                         int texsize;
1357                         texsize=512*512*3/texdetail/texdetail;
1358                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1359                         //player[i].skeleton.skinText.resize(texsize);
1360
1361                         if(player[i].creature==rabbittype)
1362                         {
1363                                 if(player[i].whichskin==0){
1364                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1365                                 }
1366                                 else if(player[i].whichskin==1){
1367                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1368                                 }
1369                                 else if(player[i].whichskin==2){
1370                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1371                                 }
1372                                 else if(player[i].whichskin==3){
1373                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1374                                 }
1375                                 else if(player[i].whichskin==4){
1376                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1377                                 }
1378                                 else if(player[i].whichskin==5){
1379                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1380                                 }
1381                                 else if(player[i].whichskin==6){
1382                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1383                                 }
1384                                 else if(player[i].whichskin==7){
1385                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1386                                 }
1387                                 else if(player[i].whichskin==8){
1388                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1389                                 }
1390                                 else if(player[i].whichskin==9){
1391                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1392                                 }
1393                         }
1394                         if(player[i].creature==wolftype)
1395                         {
1396                                 //k=abs(Random()%3);
1397                                 if(player[i].whichskin==0){
1398                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1399                                 }
1400                                 else if(player[i].whichskin==1){
1401                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1402                                 }
1403                                 else if(player[i].whichskin==2){
1404                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1405                                 }
1406                         }
1407
1408                         if(player[i].numclothes)
1409                         {
1410                                 for(j=0;j<player[i].numclothes;j++)
1411                                 {
1412                                         tintr=player[i].clothestintr[j];
1413                                         tintg=player[i].clothestintg[j];
1414                                         tintb=player[i].clothestintb[j];
1415                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1416                                 }
1417                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1418                         }
1419
1420                         player[i].currentanimation=bounceidleanim;
1421                         player[i].targetanimation=bounceidleanim;
1422                         player[i].currentframe=0;
1423                         player[i].targetframe=1;
1424                         player[i].target=0;
1425                         player[i].speed=1+(float)(Random()%100)/1000;
1426                         if(difficulty==0)player[i].speed-=.2;
1427                         if(difficulty==1)player[i].speed-=.1;
1428
1429                         player[i].velocity=0;
1430                         player[i].oldcoords=player[i].coords;
1431                         player[i].realoldcoords=player[i].coords;
1432
1433                         player[i].id=i;
1434                         player[i].skeleton.id=i;
1435                         player[i].updatedelay=0;
1436                         player[i].normalsupdatedelay=0;
1437
1438                         player[i].aitype=passivetype;
1439                         player[i].aitarget=0;
1440                         player[i].madskills=0;
1441
1442                         if(i==0)
1443                         {
1444                                 player[i].proportionhead=1.2;
1445                                 player[i].proportionbody=1.05;
1446                                 player[i].proportionarms=1.00;
1447                                 player[i].proportionlegs=1.1;
1448                                 player[i].proportionlegs.y=1.05;
1449                         }
1450                         player[i].headless=0;
1451                         player[i].currentoffset=0;
1452                         player[i].targetoffset=0;
1453                         /*player[i].armorhead=1;
1454                         player[i].armorhigh=1;
1455                         player[i].armorlow=1;
1456                         player[i].protectionhead=1;
1457                         player[i].protectionhigh=1;
1458                         player[i].protectionlow=1;
1459                         player[i].metalhead=1;
1460                         player[i].metalhigh=1;
1461                         player[i].metallow=1;
1462                         player[i].power=1;
1463                         player[i].speedmult=1;*/
1464
1465                         player[i].damagetolerance=200;
1466
1467                         if(player[i].creature==wolftype)
1468                         {
1469                                 /*player[i].proportionhead=1.1;
1470                                 player[i].proportionbody=1.1;
1471                                 player[i].proportionarms=1.1;
1472                                 player[i].proportionlegs=1.1;
1473                                 player[i].proportionlegs.y=1.1;*/
1474                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1475
1476                                 player[i].damagetolerance=300;
1477                         }                               
1478
1479                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1480                         if(cellophane)
1481                         {
1482                                 player[i].proportionhead.z=0;
1483                                 player[i].proportionbody.z=0;
1484                                 player[i].proportionarms.z=0;
1485                                 player[i].proportionlegs.z=0;
1486                         }
1487
1488                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1489
1490                         player[i].headmorphness=0;
1491                         player[i].targetheadmorphness=1;
1492                         player[i].headmorphstart=0;
1493                         player[i].headmorphend=0;
1494
1495                         player[i].pausetime=0;
1496
1497                         player[i].dead=0;
1498                         player[i].jumppower=5;
1499                         player[i].damage=0;
1500                         player[i].permanentdamage=0;
1501                         player[i].superpermanentdamage=0;
1502
1503                         player[i].forwardkeydown=0;
1504                         player[i].leftkeydown=0;
1505                         player[i].backkeydown=0;
1506                         player[i].rightkeydown=0;
1507                         player[i].jumpkeydown=0;
1508                         player[i].crouchkeydown=0;
1509                         player[i].throwkeydown=0;
1510
1511                         player[i].collided=-10;
1512                         player[i].loaded=1;
1513                         player[i].bloodloss=0;
1514                         player[i].weaponactive=-1;
1515                         player[i].weaponstuck=-1;
1516                         player[i].bleeding=0;
1517                         player[i].deathbleeding=0;
1518                         player[i].stunned=0;
1519                         player[i].hasvictim=0;
1520                         player[i].wentforweapon=0;
1521                 }
1522
1523                 player[0].aitype=playercontrolled;
1524                 player[0].weaponactive=-1;
1525
1526                 if(difficulty==1)
1527                 {
1528                         //player[0].speedmult=1/.9;
1529                         player[0].power=1/.9;
1530                 }
1531
1532                 if(difficulty==0)
1533                 {
1534                         //player[0].speedmult=1/.8;
1535                         player[0].power=1/.8;
1536                 }
1537
1538                 //player[0].weaponstuck=1;
1539
1540                 if(difficulty==1)player[0].damagetolerance=250;
1541                 if(difficulty==0)player[0].damagetolerance=300;
1542                 if(difficulty==0)player[0].armorhead*=1.5;
1543                 if(difficulty==0)player[0].armorhigh*=1.5;
1544                 if(difficulty==0)player[0].armorlow*=1.5;
1545                 cameraloc=player[0].coords;
1546                 cameraloc.y+=5;
1547                 rotation=player[0].rotation;
1548
1549                 hawkcoords=player[0].coords;
1550                 hawkcoords.y+=30;
1551
1552                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1553                 //weapons.numweapons=numplayers;
1554                 for(i=0;i<weapons.numweapons;i++)
1555                 {
1556                         weapons.bloody[i]=0;
1557                         weapons.blooddrip[i]=0;
1558                         weapons.blooddripdelay[i]=0;
1559                         weapons.onfire[i]=0;
1560                         weapons.flamedelay[i]=0;
1561                         weapons.damage[i]=0;
1562                         //weapons.type[i]=sword;
1563                         if(weapons.type[i]==sword){
1564                                 weapons.mass[i]=1.5;
1565                                 weapons.tipmass[i]=1;
1566                                 weapons.length[i]=.8;
1567                         }
1568                         if(weapons.type[i]==staff){
1569                                 weapons.mass[i]=2;
1570                                 weapons.tipmass[i]=1;
1571                                 weapons.length[i]=1.5;
1572                         }
1573                         if(weapons.type[i]==knife){
1574                                 weapons.mass[i]=1;
1575                                 weapons.tipmass[i]=1.2;
1576                                 weapons.length[i]=.25;
1577                         }
1578                         weapons.position[i]=-1000;
1579                         weapons.tippoint[i]=-1000;
1580                 }
1581
1582 /*              for(i=0;i<32;i++){
1583                         //if(i<16||i>20)                                
1584                         FSOUND_StopSound(i);
1585                 }
1586 */
1587                 LOG("Starting background music...");
1588
1589                 FSOUND_StopSound(FSOUND_ALL);
1590                 if(environment==snowyenvironment)
1591                 {
1592                         if(ambientsound)
1593                         {
1594                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
1595                                 FSOUND_SetPaused(channels[stream_wind], FALSE);
1596                                 FSOUND_SetVolume(channels[stream_wind], 256);
1597                         }
1598                 }
1599                 else if(environment==desertenvironment)
1600                 {
1601                         if(ambientsound)
1602                         {
1603                                 //PlaySoundEx(desertambient,
1604                                 //      samp[desertambient], NULL, TRUE);
1605                                 PlayStreamEx(stream_desertambient,
1606                                         strm[stream_desertambient], NULL, TRUE);
1607                                 FSOUND_SetPaused(channels[stream_desertambient], FALSE);
1608                                 FSOUND_SetVolume(channels[stream_desertambient], 256);
1609                         }
1610                 }
1611                 else if(environment==grassyenvironment)
1612                 {
1613                         if(ambientsound)
1614                         {
1615                                 //PlaySoundEx(wind, samp[wind], NULL, TRUE);
1616                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
1617                                 FSOUND_SetPaused(channels[stream_wind], FALSE);
1618                                 FSOUND_SetVolume(channels[stream_wind], 100);
1619                         }
1620                 }
1621                 oldmusicvolume[0]=0;
1622                 oldmusicvolume[1]=0;
1623                 oldmusicvolume[2]=0;
1624                 oldmusicvolume[3]=0;
1625
1626
1627                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1628                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1629                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1630                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1631                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1632                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1633                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1634                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1635                 */
1636
1637                 if(!firstload)
1638                 {
1639                         firstload=1;
1640                 }
1641         }
1642         leveltime=0;
1643         loadingstuff=0;
1644         visibleloading=0;
1645 }
1646
1647 void    Game::Tick()
1648 {
1649         static int i,k,j,l,m;
1650         static XYZ facing,flatfacing,absflatfacing;
1651         static XYZ rotatetarget;
1652         static bool oldkey;
1653         static float oldtargetrotation;
1654         static int target, numgood;
1655         static XYZ tempcoords1,tempcoords2;
1656         static XYZ test;
1657         static XYZ test2;
1658         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1659         static int whichhit;
1660         static bool donesomething;
1661         static bool oldjumpkeydown;
1662
1663         int templength;
1664
1665         float headprop,bodyprop,armprop,legprop;
1666
1667         if(newnetmessages){
1668                 newnetmessages=0;
1669                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
1670                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
1671                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
1672
1673                 for(k=14;k>=2;k--){
1674                         for(j=0;j<255;j++){
1675                                 consoletext[k][j]=consoletext[k-1][j];
1676                         }
1677                         consolechars[k]=consolechars[k-1];
1678                 }
1679                 for(k=14;k>=2;k--){
1680                         for(j=0;j<255;j++){
1681                                 displaytext[k][j]=displaytext[k-1][j];
1682                         }
1683                         displaychars[k]=displaychars[k-1];
1684                         displaytime[k]=displaytime[k-1];
1685                 }
1686                 for(j=0;j<255;j++){
1687                         consoletext[1][j]=' ';
1688                         displaytext[1][j]=' ';
1689                 }
1690                 sprintf (consoletext[1], netmessages);
1691                 sprintf (displaytext[1], netmessages);
1692                 consolechars[1]=255;
1693                 displaychars[1]=255;
1694                 displaytime[1]=0;
1695         }
1696
1697         for(i=0;i<15;i++){
1698                 displaytime[i]+=multiplier;
1699         }
1700
1701         static unsigned char    theKeyMap[16];
1702         GetKeys( theKeyMap );
1703
1704         keyboardfrozen=0;
1705
1706
1707         static bool mainmenutogglekeydown;
1708         if(!console){
1709                 if(mainmenu&&endgame==1)mainmenu=10;
1710                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1711                         for(j=0;j<255;j++){
1712                                 displaytext[0][j]=' ';
1713                         }
1714                         displaychars[0]=0;
1715                         displayselected=0;
1716                         entername=0;
1717                         mainmenutogglekeydown=1;
1718                 }
1719                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||(mainmenu==12&&!tryquit)||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17||mainmenu==10)){
1720                         selected=-1;
1721                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1722                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1723                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1724                                 else if(mainmenu==0&&winfreeze){
1725                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1726                                         stealthloading=1;
1727                                         else stealthloading=0;
1728
1729                                         if(!stealthloading){
1730                                         float gLoc[3]={0,0,0};
1731                                         float vel[3]={0,0,0};
1732                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
1733                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
1734                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1735                                         FSOUND_SetVolume(channels[firestartsound], 256);
1736                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
1737                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1738
1739                                         flashr=1;
1740                                         flashg=0;
1741                                         flashb=0;
1742                                         flashamount=1;
1743                                         flashdelay=1;
1744                                         }
1745
1746                                         startbonustotal=0;
1747
1748                                         for(i=0;i<campaignnumlevels;i++){
1749                                         levelvisible[i]=0;
1750                                         levelhighlight[i]=0;
1751                                         }
1752
1753                                         levelorder[0]=0;
1754                                         levelvisible[0]=1;
1755                                         if(accountcampaignchoicesmade[accountactive])
1756                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1757                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1758                                         levelvisible[levelorder[i+1]]=1;
1759                                         }
1760                                         int whichlevelstart;
1761                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1762                                         if(whichlevelstart<0){
1763                                         campaignchoicenum=1;
1764                                         campaignchoicewhich[0]=0;
1765                                         }
1766                                         else
1767                                         {
1768                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1769                                         if(campaignchoicenum)
1770                                         for(i=0;i<campaignchoicenum;i++){
1771                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1772                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1773                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1774                                         }
1775                                         }
1776
1777                                         loading=2;
1778                                         loadtime=0;
1779                                         targetlevel=7;
1780                                         if(firstload)TickOnceAfter();
1781                                         if(!firstload)LoadStuff();
1782                                         //else {
1783                                         for(i=0;i<255;i++){
1784                                         mapname[i]='\0';
1785                                         }
1786                                         mapname[0]=':';
1787                                         mapname[1]='D';
1788                                         mapname[2]='a';
1789                                         mapname[3]='t';
1790                                         mapname[4]='a';
1791                                         mapname[5]=':';
1792                                         mapname[6]='M';
1793                                         mapname[7]='a';
1794                                         mapname[8]='p';
1795                                         mapname[9]='s';
1796                                         mapname[10]=':';
1797
1798                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1799                                         //accountcampaignchoicesmade[accountactive]++;
1800
1801
1802                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1803                                         whichchoice=0;
1804                                         visibleloading=1;
1805                                         stillloading=1;
1806                                         Loadlevel(mapname);
1807                                         campaign=1;
1808                                         mainmenu=0;
1809                                         gameon=1;
1810                                         FSOUND_SetPaused(channels[music3], TRUE);
1811
1812                                         stealthloading=0;*/
1813                                 }
1814                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1815                                 if(mainmenu&&musictoggle){
1816                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1817                                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
1818                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
1819                                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
1820                                                 FSOUND_SetVolume(channels[stream_music3], 256);
1821                                                 FSOUND_SetPaused(channels[music1], TRUE);
1822                                         }
1823                                 }
1824                                 if(!mainmenu){
1825                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
1826                                         FSOUND_SetPaused(channels[music1], FALSE);
1827                                 }
1828                         }
1829                         if(mainmenu==3){
1830                                 float gLoc[3]={0,0,0};
1831                                 float vel[3]={0,0,0};
1832                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1833                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1834                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1835                                 FSOUND_SetVolume(channels[fireendsound], 256);
1836                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1837                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1838
1839                                 flashr=1;
1840                                 flashg=0;
1841                                 flashb=0;
1842                                 flashamount=1;
1843                                 flashdelay=1;
1844
1845                                 if(newdetail>2)newdetail=detail;
1846                                 if(newdetail<0)newdetail=detail;
1847 #if !USE_SDL  // we'll take anything that works.
1848                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
1849                                 if(newscreenheight>3000)newscreenheight=screenheight;
1850 #endif
1851                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1852                                 if(newscreenheight<0)newscreenheight=screenheight;
1853
1854                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
1855                                 opstream << "Screenwidth:\n";
1856                                 opstream << newscreenwidth;
1857                                 opstream << "\nScreenheight:\n";
1858                                 opstream << newscreenheight;
1859                                 opstream << "\nMouse sensitivity:\n";
1860                                 opstream << usermousesensitivity;
1861                                 opstream << "\nBlur(0,1):\n";
1862                                 opstream << ismotionblur;
1863                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1864                                 opstream << newdetail;
1865                                 opstream << "\nFloating jump:\n";
1866                                 opstream << floatjump;
1867                                 opstream << "\nMouse jump:\n";
1868                                 opstream << mousejump;
1869                                 opstream << "\nAmbient sound:\n";
1870                                 opstream << ambientsound;
1871                                 opstream << "\nBlood (0,1,2):\n";
1872                                 opstream << bloodtoggle;
1873                                 opstream << "\nAuto slomo:\n";
1874                                 opstream << autoslomo;
1875                                 opstream << "\nFoliage:\n";
1876                                 opstream << foliage;
1877                                 opstream << "\nMusic:\n";
1878                                 opstream << musictoggle;
1879                                 opstream << "\nTrilinear:\n";
1880                                 opstream << trilinear;
1881                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1882                                 opstream << decals;
1883                                 opstream << "\nInvert mouse:\n";
1884                                 opstream << invertmouse;
1885                                 opstream << "\nGamespeed:\n";
1886                                 if(oldgamespeed==0)oldgamespeed=1;
1887                                 opstream << oldgamespeed;
1888                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1889                                 opstream << difficulty;
1890                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1891                                 opstream << damageeffects;
1892                                 opstream << "\nText:\n";
1893                                 opstream << texttoggle;
1894                                 opstream << "\nDebug:\n";
1895                                 opstream << debugmode;
1896                                 opstream << "\nVBL Sync:\n";
1897                                 opstream << vblsync;
1898                                 opstream << "\nShow Points:\n";
1899                                 opstream << showpoints;
1900                                 opstream << "\nAlways Blur:\n";
1901                                 opstream << alwaysblur;
1902                                 opstream << "\nImmediate mode (turn on on G5):\n";
1903                                 opstream << immediate;
1904                                 opstream << "\nVelocity blur:\n";
1905                                 opstream << velocityblur;
1906                             opstream << "\nVolume:\n";
1907                         opstream << volume;
1908                                 opstream << "\nForward key:\n";
1909                                 opstream << KeyToChar(forwardkey);
1910                                 opstream << "\nBack key:\n";
1911                                 opstream << KeyToChar(backkey);
1912                                 opstream << "\nLeft key:\n";
1913                                 opstream << KeyToChar(leftkey);
1914                                 opstream << "\nRight key:\n";
1915                                 opstream << KeyToChar(rightkey);
1916                                 opstream << "\nJump key:\n";
1917                                 opstream << KeyToChar(jumpkey);
1918                                 opstream << "\nCrouch key:\n";
1919                                 opstream << KeyToChar(crouchkey);
1920                                 opstream << "\nDraw key:\n";
1921                                 opstream << KeyToChar(drawkey);
1922                                 opstream << "\nThrow key:\n";
1923                                 opstream << KeyToChar(throwkey);
1924                                 opstream << "\nAttack key:\n";
1925                                 opstream << KeyToChar(attackkey);
1926                                 opstream << "\nChat key:\n";
1927                                 opstream << KeyToChar(chatkey);
1928                                 opstream.close();
1929                         }       
1930                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==10||mainmenu==11||mainmenu==100){
1931                                 float gLoc[3]={0,0,0};
1932                                 float vel[3]={0,0,0};
1933                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1934                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1935                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1936                                 FSOUND_SetVolume(channels[fireendsound], 256);
1937                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1938                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1939
1940                                 flashr=1;
1941                                 flashg=0;
1942                                 flashb=0;
1943                                 flashamount=1;
1944                                 flashdelay=1;
1945                         }       
1946                         if(mainmenu==3&&gameon)mainmenu=2;
1947                         if(mainmenu==3&&!gameon)mainmenu=1;
1948                         if(mainmenu==5&&gameon)mainmenu=2;
1949                         if(mainmenu==5&&!gameon)mainmenu=1;
1950                         if(mainmenu==4)mainmenu=3;
1951                         if(mainmenu==6)mainmenu=5;
1952                         if(mainmenu==7)mainmenu=1;
1953                         if(mainmenu==9)mainmenu=5;
1954                         if(mainmenu==11)mainmenu=5;
1955                         if(mainmenu==12)mainmenu=5;
1956                         if(mainmenu==13)mainmenu=12;
1957                         if(mainmenu==14)mainmenu=13;
1958                         if(mainmenu==10)mainmenu=5;
1959                         if(mainmenu==100){
1960                                 mainmenu=5;
1961                                 gameon=0;
1962                                 winfreeze=0;
1963                         }
1964                         mainmenutogglekeydown=1;
1965                 }
1966                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1967                         mainmenutogglekeydown=0;
1968                 }
1969         }
1970
1971         /*static bool minimaptogglekeydown;
1972         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1973         minimap=1-minimap;
1974         minimaptogglekeydown=1;
1975         }
1976         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1977         minimaptogglekeydown=0;
1978         }
1979         */
1980
1981         static bool minimaptogglekeydown;
1982         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
1983                 if(tutorialstage!=51)
1984                         tutorialstagetime=tutorialmaxtime;
1985                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
1986                 FSOUND_SetVolume(channels[consolefailsound], 128);
1987                 FSOUND_SetPaused(channels[consolefailsound], FALSE);
1988                 minimaptogglekeydown=1;
1989         }
1990         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1991                 minimaptogglekeydown=0;
1992         }
1993
1994         if(mainmenu){
1995                 //menu buttons
1996                 if(mainmenu==1||mainmenu==2){
1997                         if(Button()&&!oldbutton&&selected==1){
1998                                 if(!gameon){
1999                                         float gLoc[3]={0,0,0};
2000                                         float vel[3]={0,0,0};
2001                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2002                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2003                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2004                                         FSOUND_SetVolume(channels[firestartsound], 256);
2005                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
2006                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2007
2008                                         flashr=1;
2009                                         flashg=0;
2010                                         flashb=0;
2011                                         flashamount=1;
2012                                         flashdelay=1;
2013
2014                                         //new game
2015                                         if(accountactive!=-1)mainmenu=5;
2016                                         else mainmenu=7;
2017                                         /*
2018                                         startbonustotal=0;
2019
2020                                         loading=2;
2021                                         loadtime=0;
2022                                         if(firstload)TickOnceAfter();
2023                                         if(!firstload)LoadStuff();
2024                                         else {
2025                                         Loadlevel(0);
2026                                         }
2027                                         mainmenu=0;
2028                                         gameon=1;
2029                                         FSOUND_SetPaused(channels[music3], TRUE);       */                      
2030                                 }
2031                                 else
2032                                 {
2033                                         //resume
2034                                         mainmenu=0;
2035                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
2036                                         FSOUND_SetPaused(channels[music1], FALSE);
2037                                 }
2038                         }
2039
2040                         if(Button()&&!oldbutton&&selected==2){
2041                                 float gLoc[3]={0,0,0};
2042                                 float vel[3]={0,0,0};
2043                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2044                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2045                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2046                                 FSOUND_SetVolume(channels[firestartsound], 256);
2047                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2048                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2049
2050                                 flashr=1;
2051                                 flashg=0;
2052                                 flashb=0;
2053                                 flashamount=1;
2054                                 flashdelay=1;
2055
2056                                 //options
2057
2058                                 mainmenu=3;                     
2059
2060                                 if(newdetail>2)newdetail=detail;
2061                                 if(newdetail<0)newdetail=detail;
2062                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2063                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2064                                 if(newscreenheight>3000)newscreenheight=screenheight;
2065                                 if(newscreenheight<0)newscreenheight=screenheight;      
2066                         }
2067
2068                         if(Button()&&!oldbutton&&selected==3){
2069                                 float gLoc[3]={0,0,0};
2070                                 float vel[3]={0,0,0};
2071                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2072                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2073                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2074                                 FSOUND_SetVolume(channels[fireendsound], 256);
2075                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2076                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2077
2078                                 flashr=1;
2079                                 flashg=0;
2080                                 flashb=0;
2081                                 flashamount=1;
2082                                 flashdelay=1;
2083
2084                                 if(!gameon){
2085                                         //quit
2086                                         tryquit=1;
2087                                         if(registered)FSOUND_SetPaused(channels[stream_music3], TRUE);
2088                                 }
2089                                 else{
2090                                         //end game
2091                                         gameon=0;
2092                                         mainmenu=1;
2093                                 }
2094                         }
2095                         if(Button())oldbutton=1;
2096                         else oldbutton=0;
2097                 }
2098
2099                 if(mainmenu==3){
2100                         if(Button()&&!oldbutton&&selected!=-1){
2101                                 float gLoc[3]={0,0,0};
2102                                 float vel[3]={0,0,0};
2103                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2104                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2105                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2106                                 FSOUND_SetVolume(channels[firestartsound], 256);
2107                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2108                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2109                         }
2110                         if(Button()&&!oldbutton&&selected==0){
2111                                 #if USE_SDL
2112                                 extern SDL_Rect **resolutions;
2113                                 bool isCustomResolution = true;
2114                                 bool found = false;
2115                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2116                                 {
2117                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2118                                                 isCustomResolution = false;
2119
2120                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2121                                         {
2122                                                 i++;
2123                                                 if (resolutions[i] != NULL)
2124                                                 {
2125                                                         newscreenwidth = (int) resolutions[i]->w;
2126                                                         newscreenheight = (int) resolutions[i]->h;
2127                                                 }
2128                                                 else if (isCustomResolution)
2129                                                 {
2130                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2131                                                         {
2132                                                                 newscreenwidth = (int) resolutions[0]->w;
2133                                                                 newscreenheight = (int) resolutions[0]->h;
2134                                                         }
2135                                                         else
2136                                                         {
2137                                                                 newscreenwidth = screenwidth;
2138                                                                 newscreenheight = screenheight;
2139                                                         }
2140                                                 }
2141                                                 else
2142                                                 {
2143                                                         newscreenwidth = (int) resolutions[0]->w;
2144                                                         newscreenheight = (int) resolutions[0]->h;
2145                                                 }
2146                                                 found = true;
2147                                         }
2148                                 }
2149
2150                                 if (!found)
2151                                 {
2152                                         newscreenwidth = (int) resolutions[0]->w;
2153                                         newscreenheight = (int) resolutions[0]->h;
2154                                 }
2155
2156                                 #else
2157                                 int whichres;
2158                                 whichres=-1;
2159                                 if(newscreenwidth==640&&newscreenheight==480)whichres=0;
2160                                 if(newscreenwidth==800&&newscreenheight==600)whichres=1;
2161                                 if(newscreenwidth==1024&&newscreenheight==768)whichres=2;
2162                                 if(newscreenwidth==1280&&newscreenheight==1024)whichres=3;
2163                                 if(newscreenwidth==1600&&newscreenheight==1200)whichres=4;
2164                                 if(newscreenwidth==840&&newscreenheight==524)whichres=5;
2165                                 if(newscreenwidth==1024&&newscreenheight==640)whichres=6;
2166                                 if(newscreenwidth==1344&&newscreenheight==840)whichres=7;
2167                                 if(newscreenwidth==1920&&newscreenheight==1200)whichres=8;
2168
2169                                 if(whichres==-1||whichres==8){
2170                                         newscreenwidth=640;
2171                                         newscreenheight=480;
2172                                 }
2173                                 if(whichres==0){
2174                                         newscreenwidth=800;
2175                                         newscreenheight=600;
2176                                 }
2177                                 if(whichres==1){
2178                                         newscreenwidth=1024;
2179                                         newscreenheight=768;
2180                                 }
2181                                 if(whichres==2){
2182                                         newscreenwidth=1280;
2183                                         newscreenheight=1024;
2184                                 }
2185                                 if(whichres==3){
2186                                         newscreenwidth=1600;
2187                                         newscreenheight=1200;
2188                                 }
2189                                 if(whichres==4){
2190                                         newscreenwidth=840;
2191                                         newscreenheight=524;
2192                                 }
2193                                 if(whichres==5){
2194                                         newscreenwidth=1024;
2195                                         newscreenheight=640;
2196                                 }
2197                                 if(whichres==6){
2198                                         newscreenwidth=1344;
2199                                         newscreenheight=840;
2200                                 }
2201                                 if(whichres==7){
2202                                         newscreenwidth=1920;
2203                                         newscreenheight=1200;
2204                                 }
2205                                 #endif
2206                         }
2207                         if(Button()&&!oldbutton&&selected==1){
2208                                 newdetail++;
2209                                 if(newdetail>2)newdetail=0;
2210                         }
2211                         if(Button()&&!oldbutton&&selected==2){
2212                                 bloodtoggle++;
2213                                 if(bloodtoggle>2)bloodtoggle=0;
2214                         }
2215                         if(Button()&&!oldbutton&&selected==3){
2216                                 difficulty++;
2217                                 if(difficulty>2)difficulty=0;
2218                         }
2219                         if(Button()&&!oldbutton&&selected==4){
2220                                 ismotionblur=1-ismotionblur;
2221                         }
2222                         if(Button()&&!oldbutton&&selected==5){
2223                                 decals=1-decals;
2224                         }
2225                         if(Button()&&!oldbutton&&selected==6){
2226                                 musictoggle=1-musictoggle;
2227
2228                                 if(!musictoggle){
2229                                         FSOUND_SetPaused(channels[music1], TRUE);
2230                                         FSOUND_SetPaused(channels[stream_music2], TRUE);
2231                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
2232
2233                                         for(i=0;i<4;i++){
2234                                                 oldmusicvolume[i]=0;
2235                                                 musicvolume[i]=0;
2236                                         }
2237                                 }
2238
2239                                 if(musictoggle){
2240                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
2241                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
2242                                         FSOUND_SetVolume(channels[stream_music3], 256);                         
2243                                 }
2244                         }
2245                         if(Button()&&!oldbutton&&selected==9){
2246                                 invertmouse=1-invertmouse;
2247                         }
2248                         if(Button()&&!oldbutton&&selected==10){
2249                                 usermousesensitivity+=.2;
2250                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2251                         }
2252                         if(Button()&&!oldbutton&&selected==11){
2253                                 volume+=.1f;
2254                                 if(volume>1.0001f)volume=0;
2255                                 FSOUND_SetSFXMasterVolume((int)(volume*255));
2256                         }
2257                         if(Button()&&!oldbutton&&selected==7){
2258                                 /*float gLoc[3]={0,0,0};
2259                                 float vel[3]={0,0,0};
2260                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2261                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2262                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2263                                 FSOUND_SetVolume(channels[firestartsound], 256);
2264                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2265                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2266                                 */
2267                                 flashr=1;
2268                                 flashg=0;
2269                                 flashb=0;
2270                                 flashamount=1;
2271                                 flashdelay=1;
2272
2273                                 //options
2274
2275                                 mainmenu=4;             
2276                                 keyselect=-1;
2277                         }
2278                         if(Button()&&!oldbutton&&selected==8){
2279                                 float gLoc[3]={0,0,0};
2280                                 float vel[3]={0,0,0};
2281                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2282                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2283                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2284                                 FSOUND_SetVolume(channels[fireendsound], 256);
2285                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2286                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2287
2288                                 flashr=1;
2289                                 flashg=0;
2290                                 flashb=0;
2291                                 flashamount=1;
2292                                 flashdelay=1;
2293
2294                                 if(newdetail>2)newdetail=detail;
2295                                 if(newdetail<0)newdetail=detail;
2296 #if !USE_SDL  // we'll take anything that works.
2297                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2298                                 if(newscreenheight>3000)newscreenheight=screenheight;
2299 #endif
2300                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2301                                 if(newscreenheight<0)newscreenheight=screenheight;
2302
2303
2304                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2305                                 opstream << "Screenwidth:\n";
2306                                 opstream << newscreenwidth;
2307                                 opstream << "\nScreenheight:\n";
2308                                 opstream << newscreenheight;
2309                                 opstream << "\nMouse sensitivity:\n";
2310                                 opstream << usermousesensitivity;
2311                                 opstream << "\nBlur(0,1):\n";
2312                                 opstream << ismotionblur;
2313                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2314                                 opstream << newdetail;
2315                                 opstream << "\nFloating jump:\n";
2316                                 opstream << floatjump;
2317                                 opstream << "\nMouse jump:\n";
2318                                 opstream << mousejump;
2319                                 opstream << "\nAmbient sound:\n";
2320                                 opstream << ambientsound;
2321                                 opstream << "\nBlood (0,1,2):\n";
2322                                 opstream << bloodtoggle;
2323                                 opstream << "\nAuto slomo:\n";
2324                                 opstream << autoslomo;
2325                                 opstream << "\nFoliage:\n";
2326                                 opstream << foliage;
2327                                 opstream << "\nMusic:\n";
2328                                 opstream << musictoggle;
2329                                 opstream << "\nTrilinear:\n";
2330                                 opstream << trilinear;
2331                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2332                                 opstream << decals;
2333                                 opstream << "\nInvert mouse:\n";
2334                                 opstream << invertmouse;
2335                                 opstream << "\nGamespeed:\n";
2336                                 if(oldgamespeed==0)oldgamespeed=1;
2337                                 opstream << oldgamespeed;
2338                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2339                                 opstream << difficulty;
2340                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2341                                 opstream << damageeffects;
2342                                 opstream << "\nText:\n";
2343                                 opstream << texttoggle;
2344                                 opstream << "\nDebug:\n";
2345                                 opstream << debugmode;
2346                                 opstream << "\nVBL Sync:\n";
2347                                 opstream << vblsync;
2348                                 opstream << "\nShow Points:\n";
2349                                 opstream << showpoints;
2350                                 opstream << "\nAlways Blur:\n";
2351                                 opstream << alwaysblur;
2352                                 opstream << "\nImmediate mode (turn on on G5):\n";
2353                                 opstream << immediate;
2354                                 opstream << "\nVelocity blur:\n";
2355                                 opstream << velocityblur;
2356                             opstream << "\nVolume:\n";
2357                         opstream << volume;
2358                                 opstream << "\nForward key:\n";
2359                                 opstream << KeyToChar(forwardkey);
2360                                 opstream << "\nBack key:\n";
2361                                 opstream << KeyToChar(backkey);
2362                                 opstream << "\nLeft key:\n";
2363                                 opstream << KeyToChar(leftkey);
2364                                 opstream << "\nRight key:\n";
2365                                 opstream << KeyToChar(rightkey);
2366                                 opstream << "\nJump key:\n";
2367                                 opstream << KeyToChar(jumpkey);
2368                                 opstream << "\nCrouch key:\n";
2369                                 opstream << KeyToChar(crouchkey);
2370                                 opstream << "\nDraw key:\n";
2371                                 opstream << KeyToChar(drawkey);
2372                                 opstream << "\nThrow key:\n";
2373                                 opstream << KeyToChar(throwkey);
2374                                 opstream << "\nAttack key:\n";
2375                                 opstream << KeyToChar(attackkey);
2376                                 opstream << "\nChat key:\n";
2377                                 opstream << KeyToChar(chatkey);
2378                                 opstream.close();
2379
2380                                 if(mainmenu==3&&gameon)mainmenu=2;
2381                                 if(mainmenu==3&&!gameon)mainmenu=1;
2382                         }
2383                         if(Button())oldbutton=1;
2384                         else oldbutton=0;
2385                 }
2386                 if(mainmenu==4){
2387                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2388                                 float gLoc[3]={0,0,0};
2389                                 float vel[3]={0,0,0};
2390                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2391                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2392                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2393                                 FSOUND_SetVolume(channels[firestartsound], 256);
2394                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2395                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2396                         }
2397                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2398                                 keyselect=selected;
2399                                 oldbuttons[0]=1;
2400                                 oldbuttons[1]=1;
2401                                 oldbuttons[2]=1;
2402                         }
2403                         if(keyselect!=-1){
2404                                 for(i=0;i<3;i++)
2405                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2406                                 for(i=0;i<140;i++){
2407                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2408                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2409                                                         float gLoc[3]={0,0,0};
2410                                                         float vel[3]={0,0,0};
2411                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2412                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2413                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2414                                                         FSOUND_SetVolume(channels[fireendsound], 256);
2415                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
2416                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2417
2418                                                         int keynum;
2419                                                         keynum=i;
2420                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2421                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2422
2423
2424
2425                                                         if(keyselect==0)forwardkey=keynum;
2426                                                         if(keyselect==1)backkey=keynum;
2427                                                         if(keyselect==2)leftkey=keynum;
2428                                                         if(keyselect==3)rightkey=keynum;
2429                                                         if(keyselect==4)crouchkey=keynum;
2430                                                         if(keyselect==5)jumpkey=keynum;
2431                                                         if(keyselect==6)drawkey=keynum;
2432                                                         if(keyselect==7)throwkey=keynum;
2433                                                         if(keyselect==8)attackkey=keynum;
2434                                                         keyselect=-1;
2435                                                 }
2436                                         }
2437                                 }}
2438                         if(Button()&&!oldbutton&&selected==9){
2439                                 float gLoc[3]={0,0,0};
2440                                 float vel[3]={0,0,0};
2441                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2442                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2443                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2444                                 FSOUND_SetVolume(channels[fireendsound], 256);
2445                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2446                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2447
2448                                 flashr=1;
2449                                 flashg=0;
2450                                 flashb=0;
2451                                 flashamount=1;
2452                                 flashdelay=1;
2453
2454                                 mainmenu=3;
2455
2456                                 if(newdetail>2)newdetail=detail;
2457                                 if(newdetail<0)newdetail=detail;
2458                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2459                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2460                                 if(newscreenheight>3000)newscreenheight=screenheight;
2461                                 if(newscreenheight<0)newscreenheight=screenheight;
2462                         }
2463                 }
2464
2465                 if(mainmenu==5){
2466                         if(accountcampaignchoicesmade[accountactive]>8&&!registered){
2467                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
2468                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
2469                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
2470                                 FSOUND_SetVolume(channels[stream_music3], 256);
2471
2472                                 gameon=0;
2473                                 mainmenu=12;
2474                                 accountcampaignchoicesmade[accountactive]=0;
2475                                 accountcampaignscore[accountactive]=0;
2476                                 accountcampaigntime[accountactive]=0;
2477
2478                                 float gLoc[3]={0,0,0};
2479                                 float vel[3]={0,0,0};
2480                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2481                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2482                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2483                                 FSOUND_SetVolume(channels[fireendsound], 256);
2484                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2485                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2486
2487                                 flashr=1;
2488                                 flashg=0;
2489                                 flashb=0;
2490                                 flashamount=1;
2491                                 flashdelay=1;
2492                         }
2493
2494                         if(endgame==2){
2495                                 accountcampaignchoicesmade[accountactive]=0;
2496                                 accountcampaignscore[accountactive]=0;
2497                                 accountcampaigntime[accountactive]=0;
2498                                 endgame=0;
2499                         }
2500
2501                         if(Button()&&!oldbutton&&selected==1){                  
2502                                 float gLoc[3]={0,0,0};
2503                                 float vel[3]={0,0,0};
2504                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2505                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2506                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2507                                 FSOUND_SetVolume(channels[firestartsound], 256);
2508                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2509                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2510
2511                                 flashr=1;
2512                                 flashg=0;
2513                                 flashb=0;
2514                                 flashamount=1;
2515                                 flashdelay=1;
2516
2517                                 startbonustotal=0;
2518
2519                                 loading=2;
2520                                 loadtime=0;
2521                                 targetlevel=-1;
2522                                 if(firstload)TickOnceAfter();
2523                                 if(!firstload)LoadStuff();
2524                                 else {
2525                                         Loadlevel(-1);
2526                                 }
2527
2528                                 mainmenu=0;
2529                                 gameon=1;
2530                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2531                         }
2532                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){                       
2533                                 float gLoc[3]={0,0,0};
2534                                 float vel[3]={0,0,0};
2535                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2536                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2537                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2538                                 FSOUND_SetVolume(channels[firestartsound], 256);
2539                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2540                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2541
2542                                 flashr=1;
2543                                 flashg=0;
2544                                 flashb=0;
2545                                 flashamount=1;
2546                                 flashdelay=1;
2547
2548                                 startbonustotal=0;
2549
2550                                 loading=2;
2551                                 loadtime=0;
2552                                 targetlevel=7;
2553                                 if(firstload)TickOnceAfter();
2554                                 if(!firstload)LoadStuff();
2555                                 //else {
2556                                 for(i=0;i<255;i++){
2557                                         mapname[i]='\0';
2558                                 }
2559                                 mapname[0]=':';
2560                                 mapname[1]='D';
2561                                 mapname[2]='a';
2562                                 mapname[3]='t';
2563                                 mapname[4]='a';
2564                                 mapname[5]=':';
2565                                 mapname[6]='M';
2566                                 mapname[7]='a';
2567                                 mapname[8]='p';
2568                                 mapname[9]='s';
2569                                 mapname[10]=':';
2570                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2571                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2572                                 visibleloading=1;
2573                                 stillloading=1;
2574                                 Loadlevel(mapname);
2575                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2576                                 //}
2577                                 campaign=1;
2578                                 mainmenu=0;
2579                                 gameon=1;
2580                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2581                         }
2582                         if(Button()&&!oldbutton&&selected==4){
2583                                 float gLoc[3]={0,0,0};
2584                                 float vel[3]={0,0,0};
2585                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2586                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2587                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2588                                 FSOUND_SetVolume(channels[fireendsound], 256);
2589                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2590                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2591
2592                                 flashr=1;
2593                                 flashg=0;
2594                                 flashb=0;
2595                                 flashamount=1;
2596                                 flashdelay=1;
2597
2598                                 if(mainmenu==5&&gameon)mainmenu=2;
2599                                 if(mainmenu==5&&!gameon)mainmenu=1;
2600                         }
2601                         if(Button()&&!oldbutton&&selected==5){
2602                                 float gLoc[3]={0,0,0};
2603                                 float vel[3]={0,0,0};
2604                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2605                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2606                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2607                                 FSOUND_SetVolume(channels[fireendsound], 256);
2608                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2609                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2610
2611                                 flashr=1;
2612                                 flashg=0;
2613                                 flashb=0;
2614                                 flashamount=1;
2615                                 flashdelay=1;
2616
2617                                 mainmenu=7;
2618                         }
2619                         if(Button()&&!oldbutton&&selected==3){
2620                                 float gLoc[3]={0,0,0};
2621                                 float vel[3]={0,0,0};
2622                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2623                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2624                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2625                                 FSOUND_SetVolume(channels[firestartsound], 256);
2626                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2627                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2628
2629                                 flashr=1;
2630                                 flashg=0;
2631                                 flashb=0;
2632                                 flashamount=1;
2633                                 flashdelay=1;
2634
2635                                 mainmenu=6;
2636                         }
2637                         if(Button()&&!oldbutton&&selected==2){
2638                                 float gLoc[3]={0,0,0};
2639                                 float vel[3]={0,0,0};
2640                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2641                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2642                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2643                                 FSOUND_SetVolume(channels[firestartsound], 256);
2644                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2645                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2646
2647                                 flashr=1;
2648                                 flashg=0;
2649                                 flashb=0;
2650                                 flashamount=1;
2651                                 flashdelay=1;
2652
2653                                 mainmenu=9;
2654                         }
2655                         if(Button())oldbutton=1;
2656                         else oldbutton=0;
2657                 }
2658                 if(mainmenu==9){
2659                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){                   
2660                                 float gLoc[3]={0,0,0};
2661                                 float vel[3]={0,0,0};
2662                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2663                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2664                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2665                                 FSOUND_SetVolume(channels[firestartsound], 256);
2666                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2667                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2668
2669                                 flashr=1;
2670                                 flashg=0;
2671                                 flashb=0;
2672                                 flashamount=1;
2673                                 flashdelay=1;
2674
2675                                 startbonustotal=0;
2676
2677                                 loading=2;
2678                                 loadtime=0;
2679                                 targetlevel=selected;
2680                                 if(firstload)TickOnceAfter();
2681                                 if(!firstload)LoadStuff();
2682                                 else {
2683                                         Loadlevel(selected);
2684                                 }
2685                                 campaign=0;
2686
2687                                 mainmenu=0;
2688                                 gameon=1;
2689                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2690                         }
2691                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2692                                 float gLoc[3]={0,0,0};
2693                                 float vel[3]={0,0,0};
2694                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2695                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2696                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2697                                 FSOUND_SetVolume(channels[fireendsound], 256);
2698                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2699                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2700
2701                                 flashr=1;
2702                                 flashg=0;
2703                                 flashb=0;
2704                                 flashamount=1;
2705                                 flashdelay=1;
2706
2707                                 mainmenu=5;
2708                         }
2709                         if(Button())oldbutton=1;
2710                         else oldbutton=0;
2711                 }
2712                 if(mainmenu==11){
2713                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){                   
2714                                 float gLoc[3]={0,0,0};
2715                                 float vel[3]={0,0,0};
2716                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2717                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2718                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2719                                 FSOUND_SetVolume(channels[firestartsound], 256);
2720                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2721                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2722
2723                                 flashr=1;
2724                                 flashg=0;
2725                                 flashb=0;
2726                                 flashamount=1;
2727                                 flashdelay=1;
2728
2729                                 startbonustotal=0;
2730
2731                                 loading=2;
2732                                 loadtime=0;
2733                                 targetlevel=selected;
2734                                 if(firstload)TickOnceAfter();
2735                                 if(!firstload)LoadStuff();
2736                                 else {
2737                                         Loadlevel(selected);
2738                                 }
2739                                 campaign=0;
2740
2741                                 mainmenu=0;
2742                                 gameon=1;
2743                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2744                         }
2745                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2746                                 float gLoc[3]={0,0,0};
2747                                 float vel[3]={0,0,0};
2748                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2749                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2750                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2751                                 FSOUND_SetVolume(channels[fireendsound], 256);
2752                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2753                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2754
2755                                 flashr=1;
2756                                 flashg=0;
2757                                 flashb=0;
2758                                 flashamount=1;
2759                                 flashdelay=1;
2760
2761                                 mainmenu=5;
2762                         }
2763                         if(Button())oldbutton=1;
2764                         else oldbutton=0;
2765                 }
2766                 if(mainmenu==10){
2767                         endgame=2;
2768                         if(Button()&&!oldbutton&&selected==3){
2769                                 float gLoc[3]={0,0,0};
2770                                 float vel[3]={0,0,0};
2771                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2772                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2773                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2774                                 FSOUND_SetVolume(channels[fireendsound], 256);
2775                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2776                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2777
2778                                 flashr=1;
2779                                 flashg=0;
2780                                 flashb=0;
2781                                 flashamount=1;
2782                                 flashdelay=1;
2783
2784                                 mainmenu=5;
2785                         }
2786                         if(Button())oldbutton=1;
2787                         else oldbutton=0;
2788                 }
2789
2790                 if(mainmenu==15||mainmenu==16){
2791                         if(Button()&&!oldbutton&&selected==1){
2792                                 float gLoc[3]={0,0,0};
2793                                 float vel[3]={0,0,0};
2794                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2795                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2796                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2797                                 FSOUND_SetVolume(channels[fireendsound], 256);
2798                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2799                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2800
2801                                 flashr=1;
2802                                 flashg=0;
2803                                 flashb=0;
2804                                 flashamount=1;
2805                                 flashdelay=1;
2806
2807                                 if(mainmenu==15)mainmenu=5;
2808                                 else mainmenu=12;
2809                         }
2810                         if(Button())oldbutton=1;
2811                         else oldbutton=0;
2812                 }
2813
2814                 if(mainmenu==12){
2815                         endgame=2;
2816                         if(Button()&&!oldbutton&&selected==3){
2817                                 if(tryquit)quit=1;
2818                                 float gLoc[3]={0,0,0};
2819                                 float vel[3]={0,0,0};
2820                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2821                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2822                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2823                                 FSOUND_SetVolume(channels[fireendsound], 256);
2824                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2825                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2826
2827                                 flashr=1;
2828                                 flashg=0;
2829                                 flashb=0;
2830                                 flashamount=1;
2831                                 flashdelay=1;
2832
2833                                 mainmenu=5;
2834                         }
2835
2836                         if(Button()&&!oldbutton&&selected==4){
2837                                 registernow=1;
2838                                 quit=1;
2839                                 float gLoc[3]={0,0,0};
2840                                 float vel[3]={0,0,0};
2841                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2842                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2843                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2844                                 FSOUND_SetVolume(channels[fireendsound], 256);
2845                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2846                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2847
2848                                 flashr=1;
2849                                 flashg=0;
2850                                 flashb=0;
2851                                 flashamount=1;
2852                                 flashdelay=1;
2853                         }
2854
2855
2856                         if(Button()&&!oldbutton&&selected==5){
2857                                 tryquit=0;
2858                                 float gLoc[3]={0,0,0};
2859                                 float vel[3]={0,0,0};
2860                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2861                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2862                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2863                                 FSOUND_SetVolume(channels[fireendsound], 256);
2864                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2865                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2866
2867                                 flashr=1;
2868                                 flashg=0;
2869                                 flashb=0;
2870                                 flashamount=1;
2871                                 flashdelay=1;
2872
2873                                 mainmenu=13;
2874                         }
2875                         if(Button())oldbutton=1;
2876                         else oldbutton=0;
2877                 }
2878                 if(mainmenu==6){
2879                         if(Button()&&!oldbutton&&selected!=-1){
2880                                 float gLoc[3]={0,0,0};
2881                                 float vel[3]={0,0,0};
2882                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2883                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2884                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2885                                 FSOUND_SetVolume(channels[firestartsound], 256);
2886                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2887                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2888                         }
2889                         if(Button()&&!oldbutton&&selected==1){
2890                                 float gLoc[3]={0,0,0};
2891                                 float vel[3]={0,0,0};
2892                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2893                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2894                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2895                                 FSOUND_SetVolume(channels[fireendsound], 256);
2896                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2897                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2898
2899                                 flashr=1;
2900                                 flashg=0;
2901                                 flashb=0;
2902                                 flashamount=1;
2903                                 flashdelay=1;
2904
2905                                 for(i=accountactive;i<numaccounts-1;i++){
2906                                         accountdifficulty[i]=accountdifficulty[i+1];
2907                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2908                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2909                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2910                                         }
2911                                         accountpoints[i]=accountpoints[i+1];
2912                                         for(j=0;j<50;j++){
2913                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2914                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2915                                         }
2916                                         for(j=0;j<60;j++){
2917                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2918                                         }
2919                                         for(j=0;j<256;j++){
2920                                                 accountname[i][j]=accountname[i+1][j];
2921                                         }
2922                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2923                                         accountprogress[i]=accountprogress[i+1];
2924                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2925                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2926                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2927                                 }
2928
2929                                 numaccounts--;
2930                                 accountactive=-1;
2931
2932
2933                                 mainmenu=7;
2934                         }
2935                         if(Button()&&!oldbutton&&selected==2){
2936                                 float gLoc[3]={0,0,0};
2937                                 float vel[3]={0,0,0};
2938                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2939                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2940                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2941                                 FSOUND_SetVolume(channels[fireendsound], 256);
2942                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2943                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2944
2945                                 flashr=1;
2946                                 flashg=0;
2947                                 flashb=0;
2948                                 flashamount=1;
2949                                 flashdelay=1;
2950
2951                                 mainmenu=5;
2952                         }
2953                         if(Button())oldbutton=1;
2954                         else oldbutton=0;
2955                 }
2956                 if(mainmenu==7){
2957                         if(Button()&&!oldbutton&&selected!=-1){
2958                                 float gLoc[3]={0,0,0};
2959                                 float vel[3]={0,0,0};
2960                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2961                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2962                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2963                                 FSOUND_SetVolume(channels[firestartsound], 256);
2964                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2965                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2966                         }
2967                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2968                                 entername=1;
2969                         }
2970                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2971                                 accountactive=selected-1;
2972                                 mainmenu=5;
2973                                 flashr=1;
2974                                 flashg=0;
2975                                 flashb=0;
2976                                 flashamount=1;
2977                                 flashdelay=1;
2978                         }
2979                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2980                                 float gLoc[3]={0,0,0};
2981                                 float vel[3]={0,0,0};
2982                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2983                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2984                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2985                                 FSOUND_SetVolume(channels[fireendsound], 256);
2986                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2987                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2988
2989                                 flashr=1;
2990                                 flashg=0;
2991                                 flashb=0;
2992                                 flashamount=1;
2993                                 flashdelay=1;
2994
2995                                 mainmenu=1;
2996
2997                                 for(j=0;j<255;j++){
2998                                         displaytext[0][j]=' ';
2999                                 }
3000                                 displaychars[0]=0;
3001                                 displayselected=0;
3002                                 entername=0;
3003                         }
3004                         if(Button())oldbutton=1;
3005                         else oldbutton=0;
3006                 }
3007                 if(mainmenu==8){
3008                         if(Button()&&!oldbutton&&selected!=-1){
3009                                 float gLoc[3]={0,0,0};
3010                                 float vel[3]={0,0,0};
3011                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3012                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3013                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3014                                 FSOUND_SetVolume(channels[firestartsound], 256);
3015                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3016                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3017
3018                                 if(selected==0)accountdifficulty[accountactive]=0;
3019                                 if(selected==1)accountdifficulty[accountactive]=1;
3020                                 if(selected==2)accountdifficulty[accountactive]=2;
3021
3022                                 mainmenu=5;     
3023
3024                                 flashr=1;
3025                                 flashg=0;
3026                                 flashb=0;
3027                                 flashamount=1;
3028                                 flashdelay=1;
3029
3030                         }
3031                         if(Button())oldbutton=1;
3032                         else oldbutton=0;
3033                 }
3034
3035
3036                 if(Button())oldbutton=1;
3037                 else oldbutton=0;
3038
3039                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
3040                         tryquit=1;
3041                         if(mainmenu==3){
3042                                 if(newdetail>2)newdetail=detail;
3043                                 if(newdetail<0)newdetail=detail;
3044 #if !USE_SDL  // we'll take anything that works.
3045                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
3046                                 if(newscreenheight>3000)newscreenheight=screenheight;
3047 #endif
3048                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
3049                                 if(newscreenheight<0)newscreenheight=screenheight;
3050
3051                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
3052                                 opstream << "Screenwidth:\n";
3053                                 opstream << newscreenwidth;
3054                                 opstream << "\nScreenheight:\n";
3055                                 opstream << newscreenheight;
3056                                 opstream << "\nMouse sensitivity:\n";
3057                                 opstream << usermousesensitivity;
3058                                 opstream << "\nBlur(0,1):\n";
3059                                 opstream << ismotionblur;
3060                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
3061                                 opstream << newdetail;
3062                                 opstream << "\nFloating jump:\n";
3063                                 opstream << floatjump;
3064                                 opstream << "\nMouse jump:\n";
3065                                 opstream << mousejump;
3066                                 opstream << "\nAmbient sound:\n";
3067                                 opstream << ambientsound;
3068                                 opstream << "\nBlood (0,1,2):\n";
3069                                 opstream << bloodtoggle;
3070                                 opstream << "\nAuto slomo:\n";
3071                                 opstream << autoslomo;
3072                                 opstream << "\nFoliage:\n";
3073                                 opstream << foliage;
3074                                 opstream << "\nMusic:\n";
3075                                 opstream << musictoggle;
3076                                 opstream << "\nTrilinear:\n";
3077                                 opstream << trilinear;
3078                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
3079                                 opstream << decals;
3080                                 opstream << "\nInvert mouse:\n";
3081                                 opstream << invertmouse;
3082                                 opstream << "\nGamespeed:\n";
3083                                 if(oldgamespeed==0)oldgamespeed=1;
3084                                 opstream << oldgamespeed;
3085                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
3086                                 opstream << difficulty;
3087                                 opstream << "\nDamage effects(blackout, doublevision):\n";
3088                                 opstream << damageeffects;
3089                                 opstream << "\nText:\n";
3090                                 opstream << texttoggle;
3091                                 opstream << "\nDebug:\n";
3092                                 opstream << debugmode;
3093                                 opstream << "\nVBL Sync:\n";
3094                                 opstream << vblsync;
3095                                 opstream << "\nShow Points:\n";
3096                                 opstream << showpoints;
3097                                 opstream << "\nAlways Blur:\n";
3098                                 opstream << alwaysblur;
3099                                 opstream << "\nImmediate mode (turn on on G5):\n";
3100                                 opstream << immediate;
3101                                 opstream << "\nVelocity blur:\n";
3102                                 opstream << velocityblur;
3103                             opstream << "\nVolume:\n";
3104                         opstream << volume;
3105                                 opstream << "\nForward key:\n";
3106                                 opstream << KeyToChar(forwardkey);
3107                                 opstream << "\nBack key:\n";
3108                                 opstream << KeyToChar(backkey);
3109                                 opstream << "\nLeft key:\n";
3110                                 opstream << KeyToChar(leftkey);
3111                                 opstream << "\nRight key:\n";
3112                                 opstream << KeyToChar(rightkey);
3113                                 opstream << "\nJump key:\n";
3114                                 opstream << KeyToChar(jumpkey);
3115                                 opstream << "\nCrouch key:\n";
3116                                 opstream << KeyToChar(crouchkey);
3117                                 opstream << "\nDraw key:\n";
3118                                 opstream << KeyToChar(drawkey);
3119                                 opstream << "\nThrow key:\n";
3120                                 opstream << KeyToChar(throwkey);
3121                                 opstream << "\nAttack key:\n";
3122                                 opstream << KeyToChar(attackkey);
3123                                 opstream << "\nChat key:\n";
3124                                 opstream << KeyToChar(chatkey);
3125                                 opstream.close();
3126                         }
3127                 }
3128
3129                 if(mainmenu==1||mainmenu==2){
3130                         if(loaddistrib>4)transition+=multiplier/8;
3131                         if(transition>1){
3132                                 transition=0;
3133                                 anim++;
3134                                 if(anim>4)anim=0;
3135                                 loaddistrib=0;
3136                         }
3137                 }
3138                 FSOUND_SetFrequency(channels[stream_music3], 22050);            
3139
3140                 if(entername||mainmenu==13||mainmenu==14){
3141                         for(i=0;i<140;i++){
3142                                 if(IsKeyDown(theKeyMap, i)){
3143                                         togglekeydelay[i]+=multiplier;
3144                                         if(togglekeydelay[i]>.4){
3145                                                 togglekey[i]=0;
3146                                                 togglekeydelay[i]=.36;
3147                                         }
3148                                         if(!togglekey[i]){
3149                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3150                                                         for(j=255;j>=displayselected+1;j--){
3151                                                                 displaytext[0][j]=displaytext[0][j-1];
3152                                                         }
3153                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3154                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3155                                                         displayselected++;
3156                                                         displaychars[0]++;
3157                                                 }
3158                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3159                                                         for(j=displayselected-1;j<255;j++){
3160                                                                 displaytext[0][j]=displaytext[0][j+1];
3161                                                         }
3162                                                         displaytext[0][255]=' ';
3163                                                         displayselected--;
3164                                                         displaychars[0]--;
3165                                                 }
3166                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3167                                                         displayselected--;
3168                                                 }
3169                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3170                                                         displayselected++;
3171                                                 }
3172                                                 if(i==MAC_RETURN_KEY&&entername){
3173                                                         if(displaychars[0]){
3174                                                                 numaccounts++;
3175                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
3176                                                                 accountactive=numaccounts-1;
3177                                                                 accountdifficulty[accountactive]=1;
3178                                                                 accountprogress[accountactive]=0;
3179                                                                 accountpoints[accountactive]=0;
3180                                                                 accountcampaigntime[accountactive]=0;
3181                                                                 accountcampaignscore[accountactive]=0;
3182                                                                 accountcampaignfasttime[accountactive]=0;
3183                                                                 accountcampaignhighscore[accountactive]=0;
3184                                                                 for(j=0;j<50;j++){
3185                                                                         accounthighscore[accountactive][j]=0;
3186                                                                         accountfasttime[accountactive][j]=0;
3187                                                                 }
3188                                                                 for(j=0;j<60;j++){
3189                                                                         accountunlocked[accountactive][j]=0;
3190                                                                 }
3191                                                                 accountcampaignchoicesmade[accountactive]=0;
3192
3193                                                                 for(j=0;j<255;j++){
3194                                                                         displaytext[0][j]=' ';
3195                                                                 }
3196                                                                 displaychars[0]=0;
3197                                                                 displayselected=0;
3198                                                                 entername=0;
3199
3200                                                                 mainmenu=8;
3201
3202                                                                 flashr=1;
3203                                                                 flashg=0;
3204                                                                 flashb=0;
3205                                                                 flashamount=1;
3206                                                                 flashdelay=1;
3207
3208                                                                 float gLoc[3]={0,0,0};
3209                                                                 float vel[3]={0,0,0};
3210                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3211                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3212                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3213                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3214                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3215                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3216
3217                                                                 for(j=0;j<255;j++){
3218                                                                         displaytext[0][j]=' ';
3219                                                                 }
3220                                                                 displaychars[0]=0;
3221
3222
3223                                                                 displayselected=0;
3224                                                         }}
3225
3226                                                 if(i==MAC_RETURN_KEY&&mainmenu==14){
3227                                                         if(displaychars[0]){
3228                                                                 char serialstring[256];
3229                                                                 char tempstring[256];
3230                                                                 #if defined(__APPLE__)
3231                                                                 sprintf (tempstring, "%s", registrationname);
3232                                                                 #elif defined(_MSC_VER) || defined(__linux__)
3233                                                                 sprintf (tempstring, "%s-windows", registrationname);
3234                                                                 #else
3235                                                                 #error Please make sure you have the right registration key stuff here!
3236                                                                 #endif
3237                                                                 long num1;
3238                                                                 long num2;
3239                                                                 long num3;
3240                                                                 long num4;
3241                                                                 long long longnum;
3242                                                                 longnum = MD5_string ( tempstring);
3243                                                                 //longnum = 1111111111111111;
3244                                                                 num1 = longnum/100000000;
3245                                                                 num2 = longnum%100000000;
3246                                                                 sprintf (tempstring, "%d-%d-%d-%d\0\0\0\0\0", num1/10000, num1%10000, num2/10000, num2%10000);
3247
3248                                                                 int goodcode=3;
3249                                                                 int numchars=3;
3250                                                                 if(num1/10000>999)numchars+=4;
3251                                                                 else if(num1/10000>99)numchars+=3;
3252                                                                 else if(num1/10000>9)numchars+=2;
3253                                                                 else numchars+=1;
3254                                                                 if(num1%10000>999)numchars+=4;
3255                                                                 else if(num1%10000>99)numchars+=3;
3256                                                                 else if(num1%10000>9)numchars+=2;
3257                                                                 else numchars+=1;
3258                                                                 if(num2/10000>999)numchars+=4;
3259                                                                 else if(num2/10000>99)numchars+=3;
3260                                                                 else if(num2/10000>9)numchars+=2;
3261                                                                 else numchars+=1;
3262                                                                 if(num2%10000>999)numchars+=4;
3263                                                                 else if(num2%10000>99)numchars+=3;
3264                                                                 else if(num2%10000>9)numchars+=2;
3265                                                                 else numchars+=1;
3266
3267                                                                 //numchars=12;
3268
3269                                                                 for(j=0;j<numchars;j++){
3270                                                                         if(displaytext[0][j]!=tempstring[j]&&tempstring[j]!=' '&&tempstring[j]!='\0')goodcode--;
3271                                                                 }
3272
3273                                                                 if(longnum==LONGLONGCONST(5077041556214789))goodcode=-1;
3274
3275                                                                 if(goodcode<0)goodcode=0;
3276
3277                                                                 if(goodcode){
3278                                                                         registered=1;
3279                                                                         mainmenu=15;
3280
3281                                                                         FILE                    *tfile;
3282                                                                         tfile=fopen( ":Data:Sounds:flame.ogg", "wb" );
3283                                                                         if (tfile)
3284                                                                         {
3285                                                                                 int numchars;
3286                                                                                 numchars=strlen(registrationname);
3287                                                                                 fpackf(tfile, "Bb", registered);
3288                                                                                 fpackf(tfile, "Bi", numchars);
3289                                                                                 if(numchars>0)
3290                                                                                 {
3291                                                                                         for(j=0;j<numchars;j++)
3292                                                                                         {
3293                                                                                                 fpackf(tfile, "Bb",  registrationname[j]);
3294                                                                                         }
3295                                                                                 }
3296                                                                                 fpackf(tfile, "Bi", num1);
3297                                                                                 fpackf(tfile, "Bi", num2);
3298                                                                                 fclose(tfile);
3299                                                                         }
3300                                                                 }
3301                                                                 else
3302                                                                 {
3303                                                                         mainmenu=16;
3304                                                                 }
3305                                                                 flashr=1;
3306                                                                 flashg=0;
3307                                                                 flashb=0;
3308                                                                 flashamount=1;
3309                                                                 flashdelay=1;
3310
3311                                                                 float gLoc[3]={0,0,0};
3312                                                                 float vel[3]={0,0,0};
3313                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3314                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3315                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3316                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3317                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3318                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3319
3320                                                                 for(j=0;j<255;j++){
3321                                                                         displaytext[0][j]=' ';
3322                                                                 }
3323                                                                 displaychars[0]=0;
3324                                                                 displayselected=0;
3325                                                         }}
3326
3327                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3328                                                         if(displaychars[0]){
3329                                                                 sprintf (registrationname, "%s", displaytext[0]);
3330                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3331
3332                                                                 mainmenu=14;
3333
3334                                                                 flashr=1;
3335                                                                 flashg=0;
3336                                                                 flashb=0;
3337                                                                 flashamount=1;
3338                                                                 flashdelay=1;
3339
3340                                                                 float gLoc[3]={0,0,0};
3341                                                                 float vel[3]={0,0,0};
3342                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3343                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3344                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3345                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3346                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3347                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3348
3349                                                                 for(j=0;j<255;j++){
3350                                                                         displaytext[0][j]=' ';
3351                                                                 }
3352                                                                 displaychars[0]=0;
3353
3354                                                                 /*char tempstring[50];
3355                                                                 sprintf (tempstring, registrationname);
3356                                                                 long num1;
3357                                                                 long num2;
3358                                                                 long num3;
3359                                                                 long num4;
3360                                                                 long long longnum;
3361                                                                 longnum = MD5_string ( tempstring);
3362                                                                 num1 = longnum/100000000;
3363                                                                 num2 = longnum%100000000;
3364                                                                 sprintf (displaytext[0], "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
3365
3366                                                                 displaychars[0]=strlen(displaytext[0]);
3367                                                                 */
3368                                                                 displayselected=0;
3369                                                         }}
3370                                         }
3371                                         togglekey[i]=1;
3372                                 }
3373                                 else {
3374                                         togglekey[i]=0;
3375                                         togglekeydelay[i]=0;
3376                                 }
3377                         }
3378
3379                         displayblinkdelay-=multiplier;
3380                         if(displayblinkdelay<=0){
3381                                 displayblinkdelay=.3;
3382                                 displayblink=1-displayblink;
3383                         }
3384                 }
3385         }
3386
3387         if(!mainmenu){  
3388                 if(hostile==1)hostiletime+=multiplier;
3389                 else hostiletime=0;
3390                 if(!winfreeze)leveltime+=multiplier;
3391                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3392                         chatting=0;
3393                         console=0;
3394                         freeze=0;
3395                         displaychars[0]=0;
3396                 }
3397
3398                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3399                         chatting=1;
3400                         chattogglekeydown=1;
3401                         togglekey[chatkey]=1;
3402                         togglekeydelay[chatkey]=-20;
3403                 }
3404
3405                 if(!IsKeyDown(theKeyMap, chatkey)){
3406                         chattogglekeydown=0;
3407                 }
3408
3409                 if(chatting){
3410                         for(i=0;i<140;i++){
3411                                 if(IsKeyDown(theKeyMap, i)){
3412                                         togglekeydelay[i]+=multiplier;
3413                                         if(togglekeydelay[i]>.4){
3414                                                 togglekey[i]=0;
3415                                                 togglekeydelay[i]=.36;
3416                                         }
3417                                         if(!togglekey[i]){
3418                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3419                                                         for(j=255;j>=displayselected+1;j--){
3420                                                                 displaytext[0][j]=displaytext[0][j-1];
3421                                                         }
3422                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3423                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3424                                                         displayselected++;
3425                                                         displaychars[0]++;
3426                                                 }
3427                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3428                                                         for(j=displayselected-1;j<255;j++){
3429                                                                 displaytext[0][j]=displaytext[0][j+1];
3430                                                         }
3431                                                         displaytext[0][255]=' ';
3432                                                         displayselected--;
3433                                                         displaychars[0]--;
3434                                                 }
3435                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3436                                                         displayselected--;
3437                                                 }
3438                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3439                                                         displayselected++;
3440                                                 }
3441                                                 if(i==MAC_RETURN_KEY){
3442                                                         if(displaychars[0]){
3443                                                                 /*for(j=0;j<displaychars[0];j++){
3444                                                                 talkname[j]=displaytext[0][j];
3445                                                                 }
3446                                                                 talkname[displaychars[0]]='\0';
3447                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3448                                                                 //NetworkSendInformation(chatname);
3449                                                                 */
3450                                                                 for(j=0;j<255;j++){
3451                                                                         displaytext[0][j]=' ';
3452                                                                 }
3453                                                                 displaychars[0]=0;
3454                                                                 displayselected=0;
3455                                                                 chatting=0;
3456                                                         }
3457                                                 }
3458                                         }
3459                                         togglekey[i]=1;
3460                                 }
3461                                 else {
3462                                         togglekey[i]=0;
3463                                         togglekeydelay[i]=0;
3464                                 }
3465                         }
3466
3467                         displayblinkdelay-=multiplier;
3468                         if(displayblinkdelay<=0){
3469                                 displayblinkdelay=.3;
3470                                 displayblink=1-displayblink;
3471                         }
3472                 }
3473
3474                 if(chatting)keyboardfrozen=1;
3475
3476                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3477                         freeze=1-freeze;
3478                         if(freeze){
3479                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3480                         }
3481                         freezetogglekeydown=1;
3482                 }
3483
3484                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3485                         freezetogglekeydown=0;
3486                 }
3487
3488                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3489                         console=1-console;
3490                         if(!console)freeze=0;
3491                         if(console){
3492                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3493                         }
3494                         consoletogglekeydown=1;
3495                 }
3496
3497                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3498                         consoletogglekeydown=0;
3499                 }
3500
3501                 if(console)freeze=1;
3502
3503                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3504                         for(i=0;i<140;i++){
3505                                 if(IsKeyDown(theKeyMap, i)){
3506                                         togglekeydelay[i]+=multiplier;
3507                                         if(togglekeydelay[i]>.4){
3508                                                 togglekey[i]=0;
3509                                                 togglekeydelay[i]=.36;
3510                                         }
3511                                         if(!togglekey[i]){
3512                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3513                                                         for(j=255;j>=consoleselected+1;j--){
3514                                                                 consoletext[0][j]=consoletext[0][j-1];
3515                                                         }
3516                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3517                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3518                                                         consoleselected++;
3519                                                         consolechars[0]++;
3520                                                 }
3521                                                 else if(i==MAC_ENTER_KEY){
3522                                                         for(j=255;j>=consoleselected+1;j--){
3523                                                                 consoletext[0][j]=consoletext[0][j-1];
3524                                                         }
3525                                                         consoletext[0][consoleselected]='\n';
3526                                                         consoleselected++;
3527                                                         consolechars[0]++;
3528                                                 }
3529                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3530                                                         for(j=consoleselected-1;j<255;j++){
3531                                                                 consoletext[0][j]=consoletext[0][j+1];
3532                                                         }
3533                                                         consoletext[0][255]=' ';
3534                                                         consoleselected--;
3535                                                         consolechars[0]--;
3536                                                 }
3537                                                 if(i==MAC_ARROW_UP_KEY){
3538                                                         if(archiveselected<14)archiveselected++;
3539                                                         for(j=0;j<255;j++){
3540                                                                 consolechars[0]=consolechars[archiveselected];
3541                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3542                                                                 consoleselected=consolechars[0];
3543                                                         }
3544                                                 }
3545                                                 if(i==MAC_ARROW_DOWN_KEY){
3546                                                         if(archiveselected>0)archiveselected--;
3547                                                         for(j=0;j<255;j++){
3548                                                                 consolechars[0]=consolechars[archiveselected];
3549                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3550                                                                 consoleselected=consolechars[0];
3551                                                         }
3552                                                 }
3553                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3554                                                         consoleselected--;
3555                                                 }
3556                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3557                                                         consoleselected++;
3558                                                 }
3559                                                 if(i==MAC_RETURN_KEY){
3560                                                         archiveselected=0;
3561                                                         donesomething=0;
3562                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3563                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3564                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3565                                                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3566                                                                 donesomething=1;
3567                                                                 tryquit=1;
3568                                                         }
3569                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3570                                                         for(j=5;j<consolechars[0];j++){
3571                                                         talkname[j-5]=consoletext[0][j];
3572                                                         }
3573                                                         talkname[consolechars[0]-5]='\0';
3574                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3575                                                         //NetworkSendInformation(chatname);
3576                                                         donesomething=1;
3577                                                         }
3578                                                         if(Compare(consoletext[0],"name ",0,4)){
3579                                                         int numchars;
3580                                                         numchars=consolechars[0]-5;
3581                                                         if(numchars>32)numchars=32;
3582                                                         for(j=5;j<numchars+5;j++){
3583                                                         talkname[j-5]=consoletext[0][j];
3584                                                         }
3585                                                         talkname[numchars]='\0';
3586                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3587                                                         //NetworkSendInformation(chatname);
3588                                                         sprintf (playerName, "%s",talkname);
3589                                                         //NetworkSendName(playerName);
3590                                                         donesomething=1;
3591                                                         }*/
3592                                                         if(Compare(consoletext[0],"map ",0,3)){
3593                                                                 mapname[0]=':';
3594                                                                 mapname[1]='D';
3595                                                                 mapname[2]='a';
3596                                                                 mapname[3]='t';
3597                                                                 mapname[4]='a';
3598                                                                 mapname[5]=':';
3599                                                                 mapname[6]='M';
3600                                                                 mapname[7]='a';
3601                                                                 mapname[8]='p';
3602                                                                 mapname[9]='s';
3603                                                                 mapname[10]=':';
3604                                                                 for(j=4;j<consolechars[0];j++){
3605                                                                         mapname[j-4+11]=consoletext[0][j];
3606                                                                 }
3607                                                                 mapname[consolechars[0]-4+11]='\0';
3608                                                                 Loadlevel(mapname);
3609                                                                 whichlevel=-2;
3610                                                                 campaign=0;
3611                                                                 donesomething=1;
3612                                                         }
3613                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3614                                                         int v;
3615                                                         unsigned char playerNameStr[32];
3616                                                         char theIPAddress[256];
3617                                                         char thePort[32];
3618                                                         NMUInt32 port = 25710;
3619
3620                                                         strcpy(playerName, "Client");
3621                                                         GameC2PStr( playerName, playerNameStr );
3622
3623                                                         for(j=0;j<consolechars[0]-8;j++){
3624                                                         theIPAddress[j]=consoletext[0][j+8];
3625                                                         }
3626                                                         theIPAddress[consolechars[0]-8]='\0';
3627
3628                                                         sprintf( thePort, "%li", port );
3629                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3630                                                         if(v)
3631                                                         {
3632                                                         if(consolechars[0]>0){
3633                                                         for(k=14;k>=1;k--){
3634                                                         for(j=0;j<255;j++){
3635                                                         consoletext[k][j]=consoletext[k-1][j];
3636                                                         }
3637                                                         consolechars[k]=consolechars[k-1];
3638                                                         }
3639                                                         for(j=0;j<255;j++){
3640                                                         consoletext[0][j]=' ';
3641                                                         }
3642                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3643                                                         else sprintf (consoletext[0], "Could not open connection");
3644
3645                                                         consolechars[0]=255;
3646                                                         consoleselected=0;
3647                                                         }
3648                                                         }
3649                                                         else 
3650                                                         {
3651                                                         donesomething=1;
3652                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3653                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3654                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3655
3656                                                         if(consolechars[0]>0){
3657                                                         for(k=14;k>=1;k--){
3658                                                         for(j=0;j<255;j++){
3659                                                         consoletext[k][j]=consoletext[k-1][j];
3660                                                         }
3661                                                         consolechars[k]=consolechars[k-1];
3662                                                         }
3663                                                         for(j=0;j<255;j++){
3664                                                         consoletext[0][j]=' ';
3665                                                         }
3666                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3667
3668                                                         consolechars[0]=255;
3669                                                         consoleselected=0;
3670                                                         }
3671                                                         }
3672                                                         }
3673
3674                                                         if(Compare(consoletext[0],"host ",0,4)){
3675                                                         unsigned char gameNameStr[32], playerNameStr[32];
3676                                                         char gameName[32];//, playerName[32];
3677                                                         NMUInt32 port;
3678                                                         int players;
3679                                                         int v;
3680
3681                                                         port = 25710;
3682                                                         players =4;
3683
3684                                                         strcpy(gameName, "Host's game");
3685                                                         strcpy(playerName, "Host");
3686                                                         GameC2PStr( gameName, gameNameStr );
3687                                                         GameC2PStr( playerName, playerNameStr );
3688
3689                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3690                                                         if(v)
3691                                                         {
3692                                                         if(consolechars[0]>0){
3693                                                         for(k=14;k>=1;k--){
3694                                                         for(j=0;j<255;j++){
3695                                                         consoletext[k][j]=consoletext[k-1][j];
3696                                                         }
3697                                                         consolechars[k]=consolechars[k-1];
3698                                                         }
3699                                                         for(j=0;j<255;j++){
3700                                                         consoletext[0][j]=' ';
3701                                                         }
3702                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3703
3704                                                         consolechars[0]=255;
3705                                                         consoleselected=0;
3706                                                         }
3707                                                         }
3708                                                         else
3709                                                         {
3710                                                         donesomething=1;
3711                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3712                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3713                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3714
3715                                                         if(consolechars[0]>0){
3716                                                         for(k=14;k>=1;k--){
3717                                                         for(j=0;j<255;j++){
3718                                                         consoletext[k][j]=consoletext[k-1][j];
3719                                                         }
3720                                                         consolechars[k]=consolechars[k-1];
3721                                                         }
3722                                                         for(j=0;j<255;j++){
3723                                                         consoletext[0][j]=' ';
3724                                                         }
3725                                                         sprintf (consoletext[0], "Game hosted");
3726
3727                                                         consolechars[0]=255;
3728                                                         consoleselected=0;
3729                                                         }
3730                                                         }
3731                                                         }
3732                                                         */
3733                                                         if(Compare(consoletext[0],"save ",0,4)){
3734                                                                 mapname[0]=':';
3735                                                                 mapname[1]='D';
3736                                                                 mapname[2]='a';
3737                                                                 mapname[3]='t';
3738                                                                 mapname[4]='a';
3739                                                                 mapname[5]=':';
3740                                                                 mapname[6]='M';
3741                                                                 mapname[7]='a';
3742                                                                 mapname[8]='p';
3743                                                                 mapname[9]='s';
3744                                                                 mapname[10]=':';
3745                                                                 for(j=5;j<consolechars[0];j++){
3746                                                                         mapname[j-5+11]=consoletext[0][j];
3747                                                                 }
3748                                                                 mapname[consolechars[0]-5+11]='\0';
3749
3750                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3751                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3752                                                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3753
3754                                                                 int mapvers;
3755                                                                 mapvers=12;
3756
3757
3758                                                                 FILE                    *tfile;
3759                                                                 tfile=fopen( mapname, "wb" );
3760                                                                 fpackf(tfile, "Bi", mapvers);
3761                                                                 //fpackf(tfile, "Bi", indemo);
3762                                                                 fpackf(tfile, "Bi", maptype);
3763                                                                 fpackf(tfile, "Bi", hostile);
3764                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3765                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3766                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3767                                                                 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z, player[0].rotation, player[0].targetrotation, player[0].num_weapons);
3768                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3769                                                                         for(j=0;j<player[0].num_weapons;j++){
3770                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3771                                                                         }
3772
3773                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3774                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3775                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3776                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3777
3778                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3779
3780                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3781
3782                                                                         fpackf(tfile, "Bi", numdialogues);
3783                                                                         if(numdialogues)
3784                                                                                 for(k=0;k<numdialogues;k++){
3785                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3786                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3787                                                                                         for(l=0;l<10;l++){
3788                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3789                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3790                                                                                         }
3791                                                                                         if(numdialogueboxes)
3792                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3793                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3794                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3795                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3796                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3797                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3798
3799                                                                                                         templength=strlen(dialoguetext[k][l]);
3800                                                                                                         fpackf(tfile, "Bi",(templength));
3801                                                                                                         for(m=0;m<templength;m++){
3802                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3803                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3804                                                                                                         }
3805
3806                                                                                                         templength=strlen(dialoguename[k][l]);
3807                                                                                                         fpackf(tfile, "Bi",templength);
3808                                                                                                         for(m=0;m<templength;m++){
3809                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3810                                                                                                                 if(dialoguename[k][l][m]=='\0')break;   
3811                                                                                                         }
3812
3813                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3814                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3815                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3816
3817                                                                                                         for(m=0;m<10;m++)
3818                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3819
3820                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3821                                                                                                 }
3822                                                                                 }
3823
3824                                                                                 if(player[0].numclothes)
3825                                                                                         for(k=0;k<player[0].numclothes;k++){
3826                                                                                                 templength=strlen(player[0].clothes[k]);
3827                                                                                                 fpackf(tfile, "Bi", templength);
3828                                                                                                 for(l=0;l<templength;l++)
3829                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3830                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);                                                                                                                                             
3831                                                                                         }
3832
3833                                                                                         fpackf(tfile, "Bi", environment);
3834
3835                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3836
3837                                                                                         if(objects.numobjects)
3838                                                                                                 for(k=0;k<objects.numobjects;k++){
3839                                                                                                         fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k], objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
3840                                                                                                 }
3841
3842                                                                                                 fpackf(tfile, "Bi", numhotspots);
3843                                                                                                 if(numhotspots)
3844                                                                                                         for(i=0;i<numhotspots;i++){
3845                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3846                                                                                                                 templength=strlen(hotspottext[i]);
3847                                                                                                                 fpackf(tfile, "Bi",templength);
3848                                                                                                                 for(l=0;l<templength;l++)
3849                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3850                                                                                                         }
3851
3852                                                                                                         fpackf(tfile, "Bi", numplayers);
3853                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3854                                                                                                                 for(j=1;j<numplayers;j++){
3855                                                                                                                         fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature, player[j].coords.x, player[j].coords.y, player[j].coords.z, player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
3856                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3857                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3858                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3859                                                                                                                                 }
3860                                                                                                                                 if(player[j].numwaypoints<30){
3861                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3862                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3863                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3864                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3865                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3866                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3867                                                                                                                                         }
3868                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3869                                                                                                                                 }
3870                                                                                                                                 else{
3871                                                                                                                                         player[j].numwaypoints=0;
3872                                                                                                                                         player[j].waypoint=0;
3873                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3874                                                                                                                                 }
3875
3876                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3877                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3878                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3879                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3880
3881                                                                                                                                 if(player[j].creature==wolftype){
3882                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3883                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3884                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3885                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3886                                                                                                                                 }
3887
3888                                                                                                                                 if(player[j].creature==rabbittype){
3889                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3890                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3891                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3892                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3893                                                                                                                                 }
3894
3895                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3896
3897
3898
3899                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3900                                                                                                                                 if(player[j].numclothes)
3901                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3902                                                                                                                                                 int templength;
3903                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3904                                                                                                                                                 fpackf(tfile, "Bi", templength);
3905                                                                                                                                                 for(l=0;l<templength;l++)
3906                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3907                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);                                                                                                                             
3908                                                                                                                                         }
3909                                                                                                                 }
3910
3911                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3912                                                                                                                 if(numpathpoints)
3913                                                                                                                         for(j=0;j<numpathpoints;j++){
3914                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3915                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3916                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3917                                                                                                                                 }
3918                                                                                                                         }
3919
3920                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3921
3922
3923                                                                                                                         fclose(tfile);
3924                                                                                                                         donesomething=1;
3925
3926                                                                                                                         /*
3927                                                                                                                         FILE                    *tfile;
3928                                                                                                                         tfile=fopen( mapname, "wb" );
3929                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3930                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3931                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3932                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3933                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3934                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3935                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3936                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3937                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3938                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3939                                                                                                                         }
3940
3941                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3942                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3943                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3944                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3945                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3946                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3947                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3948                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3949                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3950                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3951                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3952
3953                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3954                                                                                                                         if(player[0].numclothes)
3955                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3956                                                                                                                         int templength;
3957                                                                                                                         templength=strlen(player[0].clothes[k]);
3958                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);       
3959                                                                                                                         for(l=0;l<templength;l++)
3960                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3961                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);      
3962                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);      
3963                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);                                                                              
3964                                                                                                                         }
3965
3966                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3967
3968                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3969
3970                                                                                                                         for(k=0;k<objects.numobjects;k++){
3971                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3972                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3973                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3974                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3975                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3976                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3977                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3978                                                                                                                         }
3979
3980                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3981                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3982                                                                                                                         for(j=1;j<numplayers;j++){
3983                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3984                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3985                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3986                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3987                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3988                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3989                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3990                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3991                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3992                                                                                                                         }
3993                                                                                                                         if(player[j].numwaypoints<30){
3994                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3995                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3996                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3997                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3998                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3999                                                                                                                         }
4000                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4001                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4002                                                                                                                         }
4003                                                                                                                         else{
4004                                                                                                                         player[j].numwaypoints=0;
4005                                                                                                                         player[j].waypoint=0;
4006                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4007                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4008                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4009                                                                                                                         }
4010                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
4011                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
4012                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
4013                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
4014                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
4015                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
4016                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
4017                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
4018                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
4019                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
4020                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
4021
4022                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
4023                                                                                                                         if(player[j].numclothes)
4024                                                                                                                         for(k=0;k<player[j].numclothes;k++){
4025                                                                                                                         int templength;
4026                                                                                                                         templength=strlen(player[j].clothes[k]);
4027                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);       
4028                                                                                                                         for(l=0;l<templength;l++)
4029                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
4030                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);      
4031                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);      
4032                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);                                                                              
4033                                                                                                                         }
4034                                                                                                                         }
4035                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4036                                                                                                                         if(numpathpoints)
4037                                                                                                                         for(j=0;j<numpathpoints;j++){
4038                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
4039                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
4040                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
4041                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4042                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
4043                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4044                                                                                                                         }
4045                                                                                                                         }
4046
4047                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
4048                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
4049                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
4050
4051                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
4052
4053                                                                                                                         fclose(tfile);
4054                                                                                                                         donesomething=1;*/
4055                                                         }
4056                                                         /*
4057                                                         if(Compare(consoletext[0],"save ",0,4)){
4058                                                         mapname[0]=':';
4059                                                         mapname[1]='D';
4060                                                         mapname[2]='a';
4061                                                         mapname[3]='t';
4062                                                         mapname[4]='a';
4063                                                         mapname[5]=':';
4064                                                         mapname[6]='M';
4065                                                         mapname[7]='a';
4066                                                         mapname[8]='p';
4067                                                         mapname[9]='s';
4068                                                         mapname[10]=':';
4069                                                         for(j=5;j<consolechars[0];j++){
4070                                                         mapname[j-5+11]=consoletext[0][j];
4071                                                         }
4072                                                         mapname[consolechars[0]-5+11]='\0';
4073
4074                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
4075                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
4076                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
4077
4078                                                         FILE                    *tfile;
4079                                                         tfile=fopen( mapname, "wb" );
4080                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
4081                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
4082                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
4083                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
4084                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
4085                                                         for(j=0;j<player[0].num_weapons;j++){
4086                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
4087                                                         }
4088                                                         fwrite( &environment, 1, sizeof(int), tfile );
4089
4090                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
4091                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
4092                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
4093                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
4094                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
4095
4096                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4097                                                         if(numplayers>1&&numplayers<maxplayers)
4098                                                         for(j=1;j<numplayers;j++){
4099                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
4100                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4101                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4102                                                         for(k=0;k<player[j].num_weapons;k++){
4103                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4104                                                         }
4105                                                         if(player[j].numwaypoints<30){
4106                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4107                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
4108                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4109                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4110                                                         }
4111                                                         else{
4112                                                         player[j].numwaypoints=0;
4113                                                         player[j].waypoint=0;
4114                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4115                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4116                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4117                                                         }
4118                                                         }
4119                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4120                                                         if(numpathpoints)
4121                                                         for(j=0;j<numpathpoints;j++){
4122                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
4123                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4124                                                         for(k=0;k<numpathpointconnect[j];k++){
4125                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4126                                                         }
4127                                                         }
4128                                                         fclose(tfile);
4129                                                         donesomething=1;
4130                                                         }*/
4131                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
4132                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4133                                                                 donesomething=1;
4134                                                         }
4135                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
4136                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
4137                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
4138                                                         donesomething=1;
4139                                                         }*/
4140
4141                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
4142                                                                 for(j=6;j<consolechars[0];j++){
4143                                                                         mapname[j-6]=consoletext[0][j];
4144                                                                 }
4145
4146                                                                 tintr=atof(mapname);
4147
4148                                                                 donesomething=1;
4149                                                         }
4150
4151                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
4152                                                                 for(j=6;j<consolechars[0];j++){
4153                                                                         mapname[j-6]=consoletext[0][j];
4154                                                                 }
4155
4156                                                                 player[0].speedmult=atof(mapname);
4157
4158                                                                 donesomething=1;
4159                                                         }
4160
4161                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
4162                                                                 for(j=9;j<consolechars[0];j++){
4163                                                                         mapname[j-9]=consoletext[0][j];
4164                                                                 }
4165
4166                                                                 player[0].power=atof(mapname);
4167
4168                                                                 donesomething=1;
4169                                                         }
4170
4171                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
4172                                                                 for(j=13;j<consolechars[0];j++){
4173                                                                         mapname[j-13]=consoletext[0][j];
4174                                                                 }
4175
4176                                                                 viewdistance=atof(mapname)*100;
4177
4178                                                                 donesomething=1;
4179                                                         }
4180
4181                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
4182                                                                 for(j=10;j<consolechars[0];j++){
4183                                                                         mapname[j-10]=consoletext[0][j];
4184                                                                 }
4185
4186                                                                 fadestart=atof(mapname);
4187
4188                                                                 donesomething=1;
4189                                                         }
4190
4191                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
4192                                                                 for(j=6;j<consolechars[0];j++){
4193                                                                         mapname[j-6]=consoletext[0][j];
4194                                                                 }
4195
4196                                                                 player[0].power=atof(mapname);
4197
4198                                                                 donesomething=1;
4199                                                         }
4200
4201                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
4202                                                                 for(j=6;j<consolechars[0];j++){
4203                                                                         mapname[j-6]=consoletext[0][j];
4204                                                                 }
4205
4206                                                                 slomospeed=atof(mapname);
4207                                                                 slomo=1-slomo;
4208                                                                 slomodelay=1000;
4209
4210                                                                 donesomething=1;
4211                                                         }
4212
4213                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
4214                                                                 for(j=8;j<consolechars[0];j++){
4215                                                                         mapname[j-8]=consoletext[0][j];
4216                                                                 }
4217
4218                                                                 slomofreq=atoi(mapname);
4219
4220                                                                 donesomething=1;
4221                                                         }
4222
4223                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
4224                                                                 for(j=5;j<consolechars[0];j++){
4225                                                                         mapname[j-5]=consoletext[0][j];
4226                                                                 }
4227
4228                                                                 player[0].scale=atof(mapname)*.2;
4229
4230                                                                 donesomething=1;
4231                                                         }
4232
4233                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
4234                                                                 int closest=-1;
4235                                                                 float closestdist=-1;
4236                                                                 float distance;
4237                                                                 if(numplayers>1)
4238                                                                         for(i=1;i<numplayers;i++){
4239                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4240                                                                                 if(closestdist==-1||distance<closestdist){
4241                                                                                         closestdist=distance;
4242                                                                                         closest=i;
4243                                                                                 }
4244                                                                         }
4245
4246                                                                         for(j=9;j<consolechars[0];j++){
4247                                                                                 mapname[j-9]=consoletext[0][j];
4248                                                                         }
4249
4250                                                                         player[closest].scale=atof(mapname)*.2;
4251
4252                                                                         donesomething=1;
4253                                                         }
4254
4255                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
4256                                                                 int startpoint;
4257                                                                 int alldone;
4258
4259                                                                 int closest=-1;
4260                                                                 float closestdist=-1;
4261                                                                 float distance;
4262                                                                 if(numplayers>1)
4263                                                                         for(i=1;i<numplayers;i++){
4264                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4265                                                                                 if(closestdist==-1||distance<closestdist){
4266                                                                                         closestdist=distance;
4267                                                                                         closest=i;
4268                                                                                 }
4269                                                                         }
4270
4271                                                                         alldone=0;
4272                                                                         startpoint=15;
4273                                                                         j=startpoint;
4274                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4275                                                                                 mapname[j-startpoint]=consoletext[0][j];
4276                                                                                 j++;
4277                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4278                                                                         }
4279                                                                         mapname[j-startpoint]='\0';
4280
4281                                                                         headprop=atof(mapname);
4282
4283                                                                         j++;
4284                                                                         startpoint=j;
4285                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4286                                                                                 mapname[j-startpoint]=consoletext[0][j];
4287                                                                                 j++;
4288                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4289                                                                         }
4290                                                                         mapname[j-startpoint]='\0';
4291
4292                                                                         bodyprop=atof(mapname);
4293
4294                                                                         j++;
4295                                                                         startpoint=j;
4296                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4297                                                                                 mapname[j-startpoint]=consoletext[0][j];
4298                                                                                 j++;
4299                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4300                                                                         }
4301                                                                         mapname[j-startpoint]='\0';
4302
4303                                                                         armprop=atof(mapname);
4304
4305                                                                         j++;
4306                                                                         startpoint=j;
4307                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4308                                                                                 mapname[j-startpoint]=consoletext[0][j];
4309                                                                                 j++;
4310                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4311                                                                         }
4312                                                                         mapname[j-startpoint]='\0';
4313
4314                                                                         legprop=atof(mapname);
4315
4316                                                                         if(player[closest].creature==wolftype){
4317                                                                                 player[closest].proportionhead=1.1*headprop;
4318                                                                                 player[closest].proportionbody=1.1*bodyprop;
4319                                                                                 player[closest].proportionarms=1.1*armprop;
4320                                                                                 player[closest].proportionlegs=1.1*legprop;
4321                                                                         }
4322
4323                                                                         if(player[closest].creature==rabbittype){
4324                                                                                 player[closest].proportionhead=1.2*headprop;
4325                                                                                 player[closest].proportionbody=1.05*bodyprop;
4326                                                                                 player[closest].proportionarms=1.00*armprop;
4327                                                                                 player[closest].proportionlegs=1.1*legprop;
4328                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4329                                                                         }
4330
4331                                                                         donesomething=1;
4332                                                         }
4333
4334
4335                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4336                                                                 for(i=1;i<numplayers;i++){
4337                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4338                                                                 }
4339
4340                                                                 donesomething=1;
4341                                                         }
4342
4343                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4344                                                                 for(j=9;j<consolechars[0];j++){
4345                                                                         mapname[j-9]=consoletext[0][j];
4346                                                                 }
4347
4348                                                                 tutoriallevel=atoi(mapname);
4349
4350                                                                 donesomething=1;
4351                                                         }
4352
4353
4354                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4355                                                                 for(j=6;j<consolechars[0];j++){
4356                                                                         mapname[j-6]=consoletext[0][j];
4357                                                                 }
4358
4359                                                                 tintg=atof(mapname);
4360
4361                                                                 donesomething=1;
4362                                                         }
4363
4364                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4365                                                                 for(j=6;j<consolechars[0];j++){
4366                                                                         mapname[j-6]=consoletext[0][j];
4367                                                                 }
4368
4369                                                                 tintb=atof(mapname);
4370
4371                                                                 donesomething=1;
4372                                                         }
4373
4374                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4375                                                                 for(j=8;j<consolechars[0];j++){
4376                                                                         mapname[j-8]=consoletext[0][j];
4377                                                                 }
4378
4379                                                                 hostile=atoi(mapname);
4380
4381                                                                 donesomething=1;
4382                                                         }
4383
4384
4385                                                         if(Compare(consoletext[0],"type active ",0,11)){
4386                                                                 editoractive=typeactive;
4387
4388                                                                 donesomething=1;
4389                                                         }
4390
4391                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4392                                                                 indemo=1;
4393                                                                 hotspot[numhotspots]=player[0].coords;
4394                                                                 hotspotsize[numhotspots]=0;
4395                                                                 hotspottype[numhotspots]=-111;
4396                                                                 mapname[0]='\0';
4397                                                                 strcpy(hotspottext[numhotspots],"mapname");
4398                                                                 numhotspots++;
4399
4400                                                                 donesomething=1;
4401                                                         }
4402
4403                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4404                                                                 indemo=0;
4405                                                                 numhotspots--;
4406
4407                                                                 donesomething=1;
4408                                                         }
4409
4410                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4411                                                                 editoractive=typesitting;
4412
4413                                                                 donesomething=1;
4414                                                         }
4415
4416                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4417                                                                 editoractive=typesittingwall;
4418
4419                                                                 donesomething=1;
4420                                                         }
4421
4422                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4423                                                                 editoractive=typesleeping;
4424
4425                                                                 donesomething=1;
4426                                                         }
4427                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4428                                                                 editoractive=typedead1;
4429
4430                                                                 donesomething=1;
4431                                                         }
4432                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4433                                                                 editoractive=typedead2;
4434
4435                                                                 donesomething=1;
4436                                                         }
4437                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4438                                                                 editoractive=typedead3;
4439                                                                 donesomething=1;
4440                                                         }
4441                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4442                                                                 editoractive=typedead4;
4443
4444                                                                 donesomething=1;
4445                                                         }
4446
4447                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4448                                                                 editorpathtype=wpkeepwalking;
4449
4450                                                                 donesomething=1;
4451                                                         }
4452
4453                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4454                                                                 editorpathtype=wppause;
4455
4456                                                                 donesomething=1;
4457                                                         }
4458
4459                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4460                                                                 maptype=mapkilleveryone;
4461
4462                                                                 donesomething=1;
4463                                                         }
4464
4465                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4466                                                                 maptype=mapgosomewhere;
4467
4468                                                                 donesomething=1;
4469                                                         }
4470
4471                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4472                                                                 maptype=mapkillsomeone;
4473
4474                                                                 donesomething=1;
4475
4476                                                         }
4477
4478                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4479                                                                 maptype=mapkillmost;
4480
4481                                                                 donesomething=1;
4482
4483                                                         }
4484
4485                                                         if(Compare(consoletext[0],"hs ",0,2)){
4486                                                                 int startpoint;
4487                                                                 int alldone;
4488
4489                                                                 hotspot[numhotspots]=player[0].coords;
4490
4491                                                                 alldone=0;
4492                                                                 startpoint=3;
4493                                                                 j=startpoint;
4494                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4495                                                                         mapname[j-startpoint]=consoletext[0][j];
4496                                                                         j++;
4497                                                                         if(consoletext[0][j]=='\0')alldone=1;
4498                                                                 }
4499                                                                 mapname[j-startpoint]='\0';
4500
4501                                                                 hotspotsize[numhotspots]=atof(mapname);
4502
4503                                                                 j++;
4504                                                                 startpoint=j;
4505                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4506                                                                         mapname[j-startpoint]=consoletext[0][j];
4507                                                                         j++;
4508                                                                         if(consoletext[0][j]=='\0')alldone=1;
4509                                                                 }
4510                                                                 mapname[j-startpoint]='\0';
4511
4512                                                                 hotspottype[numhotspots]=atoi(mapname);
4513
4514                                                                 j++;
4515                                                                 startpoint=j;
4516                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4517                                                                         mapname[j-startpoint]=consoletext[0][j];
4518                                                                         j++;
4519                                                                         if(consoletext[0][j]=='\0')alldone=1;
4520                                                                 }
4521                                                                 mapname[j-startpoint]='\n';
4522                                                                 mapname[j-startpoint+1]='\0';
4523
4524                                                                 strcpy(hotspottext[numhotspots],mapname);
4525
4526                                                                 numhotspots++;
4527
4528                                                                 donesomething=1;
4529                                                         }
4530
4531                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4532                                                                 int startpoint;
4533                                                                 int alldone;
4534
4535                                                                 alldone=0;
4536                                                                 startpoint=9;
4537                                                                 j=startpoint;
4538                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4539                                                                         mapname[j-startpoint]=consoletext[0][j];
4540                                                                         j++;
4541                                                                         if(consoletext[0][j]=='\0')alldone=1;
4542                                                                 }
4543                                                                 mapname[j-startpoint]='\0';
4544                                                                 startpoint=j+1;
4545
4546                                                                 dialoguetype[numdialogues]=atoi(mapname);
4547
4548                                                                 mapname[0]=':';
4549                                                                 mapname[1]='D';
4550                                                                 mapname[2]='a';
4551                                                                 mapname[3]='t';
4552                                                                 mapname[4]='a';
4553                                                                 mapname[5]=':';
4554                                                                 mapname[6]='D';
4555                                                                 mapname[7]='i';
4556                                                                 mapname[8]='a';
4557                                                                 mapname[9]='l';
4558                                                                 mapname[10]='o';
4559                                                                 mapname[11]='g';
4560                                                                 mapname[12]='u';
4561                                                                 mapname[13]='e';
4562                                                                 mapname[14]='s';
4563                                                                 mapname[15]=':';
4564                                                                 for(j=startpoint;j<consolechars[0];j++){
4565                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4566                                                                 }
4567                                                                 mapname[consolechars[0]-startpoint+16]='.';
4568                                                                 mapname[consolechars[0]-startpoint+17]='t';
4569                                                                 mapname[consolechars[0]-startpoint+18]='x';
4570                                                                 mapname[consolechars[0]-startpoint+19]='t';
4571                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4572
4573                                                                 for(j=0;j<max_dialoguelength;j++){
4574                                                                         for(k=0;k<128;k++){
4575                                                                                 dialoguetext[numdialogues][j][k]='\0';
4576                                                                         }
4577                                                                         for(k=0;k<64;k++){
4578                                                                                 dialoguename[numdialogues][j][k]='\0';
4579                                                                         }
4580                                                                 }
4581
4582                                                                 ifstream ipstream(ConvertFileName(mapname));
4583                                                                 ipstream.ignore(256,':');
4584                                                                 ipstream >> numdialogueboxes[numdialogues];
4585                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4586                                                                         ipstream.ignore(256,':');
4587                                                                         ipstream.ignore(256,':');
4588                                                                         ipstream.ignore(256,' ');
4589                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4590                                                                         ipstream.ignore(256,':');
4591                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4592                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4593                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4594                                                                         ipstream.ignore(256,':');
4595                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4596                                                                         ipstream.ignore(256,':');
4597                                                                         ipstream.ignore(256,' ');
4598                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4599                                                                         for(j=0;j<128;j++){
4600                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4601                                                                         }
4602                                                                         ipstream.ignore(256,':');
4603                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4604                                                                 }
4605
4606                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4607                                                                         for(j=0;j<numplayers;j++){
4608                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4609                                                                         }
4610                                                                 }
4611                                                                 ipstream.close();
4612
4613                                                                 directing=1;
4614                                                                 indialogue=0;
4615                                                                 whichdialogue=numdialogues;
4616
4617
4618                                                                 numdialogues++;
4619
4620                                                                 donesomething=1;
4621                                                         }
4622
4623                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4624                                                                 int startpoint;
4625                                                                 int alldone;
4626                                                                 int whichdi;
4627
4628                                                                 alldone=0;
4629                                                                 startpoint=12;
4630                                                                 j=startpoint;
4631                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4632                                                                         mapname[j-startpoint]=consoletext[0][j];
4633                                                                         j++;
4634                                                                         if(consoletext[0][j]=='\0')alldone=1;
4635                                                                 }
4636                                                                 mapname[j-startpoint]='\0';
4637                                                                 startpoint=j+1;
4638
4639                                                                 whichdi=atoi(mapname);
4640
4641                                                                 mapname[0]=':';
4642                                                                 mapname[1]='D';
4643                                                                 mapname[2]='a';
4644                                                                 mapname[3]='t';
4645                                                                 mapname[4]='a';
4646                                                                 mapname[5]=':';
4647                                                                 mapname[6]='D';
4648                                                                 mapname[7]='i';
4649                                                                 mapname[8]='a';
4650                                                                 mapname[9]='l';
4651                                                                 mapname[10]='o';
4652                                                                 mapname[11]='g';
4653                                                                 mapname[12]='u';
4654                                                                 mapname[13]='e';
4655                                                                 mapname[14]='s';
4656                                                                 mapname[15]=':';
4657                                                                 for(j=startpoint;j<consolechars[0];j++){
4658                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4659                                                                 }
4660                                                                 mapname[consolechars[0]-startpoint+16]='.';
4661                                                                 mapname[consolechars[0]-startpoint+17]='t';
4662                                                                 mapname[consolechars[0]-startpoint+18]='x';
4663                                                                 mapname[consolechars[0]-startpoint+19]='t';
4664                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4665
4666                                                                 for(j=0;j<max_dialoguelength;j++){
4667                                                                         for(k=0;k<128;k++){
4668                                                                                 dialoguetext[whichdi][j][k]='\0';
4669                                                                         }
4670                                                                         for(k=0;k<64;k++){
4671                                                                                 dialoguename[whichdi][j][k]='\0';
4672                                                                         }
4673                                                                 }
4674
4675                                                                 ifstream ipstream(ConvertFileName(mapname));
4676                                                                 ipstream.ignore(256,':');
4677                                                                 ipstream >> numdialogueboxes[whichdi];
4678                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4679                                                                         ipstream.ignore(256,':');
4680                                                                         ipstream.ignore(256,':');
4681                                                                         ipstream.ignore(256,' ');
4682                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4683                                                                         ipstream.ignore(256,':');
4684                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4685                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4686                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4687                                                                         ipstream.ignore(256,':');
4688                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4689                                                                         ipstream.ignore(256,':');
4690                                                                         ipstream.ignore(256,' ');
4691                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4692                                                                         for(j=0;j<128;j++){
4693                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4694                                                                         }
4695                                                                         ipstream.ignore(256,':');
4696                                                                         ipstream >> dialogueboxsound[whichdi][i];
4697                                                                 }
4698
4699                                                                 ipstream.close();
4700
4701                                                                 donesomething=1;
4702                                                         }
4703
4704                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4705                                                                 int startpoint;
4706                                                                 int alldone;
4707                                                                 int whichdi;
4708
4709                                                                 alldone=0;
4710                                                                 startpoint=8;
4711                                                                 j=startpoint;
4712                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4713                                                                         mapname[j-startpoint]=consoletext[0][j];
4714                                                                         j++;
4715                                                                         if(consoletext[0][j]=='\0')alldone=1;
4716                                                                 }
4717                                                                 mapname[j-startpoint]='\0';
4718                                                                 dialoguetype[0]=atoi(mapname);
4719
4720                                                                 startpoint=j+1;
4721
4722                                                                 donesomething=1;
4723                                                         }
4724
4725
4726                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4727                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4728
4729                                                                 donesomething=1;
4730                                                         }
4731
4732                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4733                                                                 numdialogues--;
4734                                                                 if(numdialogues<0)numdialogues=0;
4735
4736                                                                 donesomething=1;
4737                                                         }
4738
4739                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4740                                                                 player[0].immobile=1;
4741                                                                 donesomething=1;
4742                                                         }
4743
4744                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4745                                                                 player[0].immobile=0;
4746                                                                 donesomething=1;
4747                                                         }
4748
4749                                                         if(Compare(consoletext[0],"play ",0,4)){
4750                                                                 int startpoint;
4751                                                                 int alldone;
4752
4753                                                                 alldone=0;
4754                                                                 startpoint=5;
4755                                                                 j=startpoint;
4756                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4757                                                                         mapname[j-startpoint]=consoletext[0][j];
4758                                                                         j++;
4759                                                                         if(consoletext[0][j]=='\0')alldone=1;
4760                                                                 }
4761                                                                 mapname[j-startpoint]='\0';
4762                                                                 startpoint=j+1;
4763
4764                                                                 whichdialogue=atoi(mapname);
4765
4766                                                                 if(numdialogues>whichdialogue){
4767                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4768                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4769                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4770                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4771                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4772                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4773                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4774                                                                         }
4775
4776                                                                         directing=0;
4777                                                                         indialogue=0;
4778
4779                                                                         donesomething=1;
4780
4781                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4782                                                                         float gLoc[3];
4783                                                                         float vel[3];
4784                                                                         XYZ temppos;
4785                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4786                                                                         temppos=temppos-viewer;
4787                                                                         Normalise(&temppos);
4788                                                                         temppos+=viewer;
4789
4790                                                                         gLoc[0]=temppos.x;
4791                                                                         gLoc[1]=temppos.y;
4792                                                                         gLoc[2]=temppos.z;
4793                                                                         vel[0]=0;
4794                                                                         vel[1]=0;
4795                                                                         vel[2]=0;
4796                                                                         int whichsoundplay;
4797                                                                         whichsoundplay=rabbitchitter;
4798                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4799                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4800                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4801                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4802                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4803                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4804                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4805                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4806                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4807                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4808                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4809                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4810                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4811                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4812                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4813                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4814                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4815                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4816                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4817                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
4818                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4819                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
4820                                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
4821                                                                         //}
4822                                                                 }
4823                                                         }
4824
4825
4826
4827
4828                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4829                                                                 numhotspots--;
4830                                                                 if(numhotspots<0)numhotspots=0;
4831                                                                 donesomething=1;
4832                                                         }
4833
4834
4835                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4836                                                                 int startpoint;
4837                                                                 int alldone;
4838
4839                                                                 alldone=0;
4840                                                                 startpoint=11;
4841                                                                 j=startpoint;
4842                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4843                                                                         mapname[j-startpoint]=consoletext[0][j];
4844                                                                         j++;
4845                                                                         if(consoletext[0][j]=='\0')alldone=1;
4846                                                                 }
4847                                                                 mapname[j-startpoint]='\0';
4848
4849                                                                 headprop=atof(mapname);
4850
4851                                                                 j++;
4852                                                                 startpoint=j;
4853                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4854                                                                         mapname[j-startpoint]=consoletext[0][j];
4855                                                                         j++;
4856                                                                         if(consoletext[0][j]=='\0')alldone=1;
4857                                                                 }
4858                                                                 mapname[j-startpoint]='\0';
4859
4860                                                                 bodyprop=atof(mapname);
4861
4862                                                                 j++;
4863                                                                 startpoint=j;
4864                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4865                                                                         mapname[j-startpoint]=consoletext[0][j];
4866                                                                         j++;
4867                                                                         if(consoletext[0][j]=='\0')alldone=1;
4868                                                                 }
4869                                                                 mapname[j-startpoint]='\0';
4870
4871                                                                 armprop=atof(mapname);
4872
4873                                                                 j++;
4874                                                                 startpoint=j;
4875                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4876                                                                         mapname[j-startpoint]=consoletext[0][j];
4877                                                                         j++;
4878                                                                         if(consoletext[0][j]=='\0')alldone=1;
4879                                                                 }
4880                                                                 mapname[j-startpoint]='\0';
4881
4882                                                                 legprop=atof(mapname);
4883
4884                                                                 if(player[0].creature==wolftype){
4885                                                                         player[0].proportionhead=1.1*headprop;
4886                                                                         player[0].proportionbody=1.1*bodyprop;
4887                                                                         player[0].proportionarms=1.1*armprop;
4888                                                                         player[0].proportionlegs=1.1*legprop;
4889                                                                 }
4890
4891                                                                 if(player[0].creature==rabbittype){
4892                                                                         player[0].proportionhead=1.2*headprop;
4893                                                                         player[0].proportionbody=1.05*bodyprop;
4894                                                                         player[0].proportionarms=1.00*armprop;
4895                                                                         player[0].proportionlegs=1.1*legprop;
4896                                                                         player[0].proportionlegs.y=1.05*legprop;
4897                                                                 }
4898
4899                                                                 donesomething=1;
4900                                                         }
4901
4902                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4903                                                                 for(i=0;i<numplayers;i++){
4904                                                                         if(i>0)player[i].immobile=1;
4905                                                                 }
4906                                                                 donesomething=1;
4907                                                         }
4908
4909
4910                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4911                                                                 player[0].armorhead=1;
4912                                                                 player[0].armorhigh=1;
4913                                                                 player[0].armorlow=1;
4914                                                                 player[0].protectionhead=1;
4915                                                                 player[0].protectionhigh=1;
4916                                                                 player[0].protectionlow=1;
4917                                                                 player[0].metalhead=1;
4918                                                                 player[0].metalhigh=1;
4919                                                                 player[0].metallow=1;
4920                                                                 player[0].power=1;
4921                                                                 player[0].speedmult=1;
4922                                                                 player[0].scale=1;
4923
4924                                                                 if(player[0].creature==wolftype){
4925                                                                         player[0].proportionhead=1.1;
4926                                                                         player[0].proportionbody=1.1;
4927                                                                         player[0].proportionarms=1.1;
4928                                                                         player[0].proportionlegs=1.1;
4929                                                                 }
4930
4931                                                                 if(player[0].creature==rabbittype){
4932                                                                         player[0].proportionhead=1.2;
4933                                                                         player[0].proportionbody=1.05;
4934                                                                         player[0].proportionarms=1.00;
4935                                                                         player[0].proportionlegs=1.1;
4936                                                                         player[0].proportionlegs.y=1.05;
4937                                                                 }
4938
4939                                                                 player[0].numclothes=0;
4940                                                                 if(player[0].whichskin==0){
4941                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4942                                                                 }
4943                                                                 else if(player[0].whichskin==1){
4944                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4945                                                                 }
4946                                                                 else if(player[0].whichskin==2){
4947                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4948                                                                 }
4949                                                                 else if(player[0].whichskin==3){
4950                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4951                                                                 }
4952                                                                 else if(player[0].whichskin==4){
4953                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4954                                                                 }
4955                                                                 else if(player[0].whichskin==5){
4956                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4957                                                                 }
4958                                                                 else if(player[0].whichskin==6){
4959                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4960                                                                 }
4961                                                                 else if(player[0].whichskin==7){
4962                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4963                                                                 }
4964                                                                 else if(player[0].whichskin==8){
4965                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4966                                                                 }
4967                                                                 else if(player[0].whichskin==9){
4968                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4969                                                                 }
4970
4971                                                                 editoractive=typeactive;
4972                                                                 player[0].immobile=0;
4973
4974
4975
4976                                                                 donesomething=1;
4977                                                         }
4978
4979                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4980                                                                 int startpoint;
4981                                                                 int alldone;
4982                                                                 alldone=0;
4983                                                                 startpoint=5;
4984                                                                 j=startpoint;
4985                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4986                                                                         mapname[j-startpoint]=consoletext[0][j];
4987                                                                         j++;
4988                                                                         if(consoletext[0][j]=='\0')alldone=1;
4989                                                                 }
4990                                                                 mapname[j-startpoint]='\0';
4991
4992                                                                 tintr=atof(mapname);
4993
4994                                                                 j++;
4995                                                                 startpoint=j;
4996                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4997                                                                         mapname[j-startpoint]=consoletext[0][j];
4998                                                                         j++;
4999                                                                         if(consoletext[0][j]=='\0')alldone=1;
5000                                                                 }
5001                                                                 mapname[j-startpoint]='\0';
5002
5003                                                                 tintg=atof(mapname);
5004
5005                                                                 j++;
5006                                                                 startpoint=j;
5007                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5008                                                                         mapname[j-startpoint]=consoletext[0][j];
5009                                                                         j++;
5010                                                                         if(consoletext[0][j]=='\0')alldone=1;
5011                                                                 }
5012                                                                 mapname[j-startpoint]='\0';
5013
5014                                                                 tintb=atof(mapname);
5015
5016                                                                 donesomething=1;
5017                                                         }
5018
5019                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
5020                                                                 int startpoint;
5021                                                                 int alldone;
5022                                                                 alldone=0;
5023                                                                 startpoint=9;
5024                                                                 j=startpoint;
5025                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5026                                                                         mapname[j-startpoint]=consoletext[0][j];
5027                                                                         j++;
5028                                                                         if(consoletext[0][j]=='\0')alldone=1;
5029                                                                 }
5030                                                                 mapname[j-startpoint]='\0';
5031
5032                                                                 skyboxr=atof(mapname);
5033
5034                                                                 j++;
5035                                                                 startpoint=j;
5036                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5037                                                                         mapname[j-startpoint]=consoletext[0][j];
5038                                                                         j++;
5039                                                                         if(consoletext[0][j]=='\0')alldone=1;
5040                                                                 }
5041                                                                 mapname[j-startpoint]='\0';
5042
5043                                                                 skyboxg=atof(mapname);
5044
5045                                                                 j++;
5046                                                                 startpoint=j;
5047                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5048                                                                         mapname[j-startpoint]=consoletext[0][j];
5049                                                                         j++;
5050                                                                         if(consoletext[0][j]=='\0')alldone=1;
5051                                                                 }
5052                                                                 mapname[j-startpoint]='\0';
5053
5054                                                                 skyboxb=atof(mapname);
5055
5056                                                                 skyboxlightr=skyboxr;
5057                                                                 skyboxlightg=skyboxg;
5058                                                                 skyboxlightb=skyboxb;
5059
5060                                                                 SetUpLighting();
5061
5062                                                                 //if(skyboxtexture){
5063                                                                 terrain.DoShadows();
5064                                                                 objects.DoShadows();
5065                                                                 /*}
5066                                                                 else terrain.DoLighting();
5067                                                                 */
5068                                                                 donesomething=1;
5069                                                         } 
5070
5071                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
5072                                                                 int startpoint;
5073                                                                 int alldone;
5074                                                                 alldone=0;
5075                                                                 startpoint=10;
5076                                                                 j=startpoint;
5077                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5078                                                                         mapname[j-startpoint]=consoletext[0][j];
5079                                                                         j++;
5080                                                                         if(consoletext[0][j]=='\0')alldone=1;
5081                                                                 }
5082                                                                 mapname[j-startpoint]='\0';
5083
5084                                                                 skyboxlightr=atof(mapname);
5085
5086                                                                 j++;
5087                                                                 startpoint=j;
5088                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5089                                                                         mapname[j-startpoint]=consoletext[0][j];
5090                                                                         j++;
5091                                                                         if(consoletext[0][j]=='\0')alldone=1;
5092                                                                 }
5093                                                                 mapname[j-startpoint]='\0';
5094
5095                                                                 skyboxlightg=atof(mapname);
5096
5097                                                                 j++;
5098                                                                 startpoint=j;
5099                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5100                                                                         mapname[j-startpoint]=consoletext[0][j];
5101                                                                         j++;
5102                                                                         if(consoletext[0][j]=='\0')alldone=1;
5103                                                                 }
5104                                                                 mapname[j-startpoint]='\0';
5105
5106                                                                 skyboxlightb=atof(mapname);
5107
5108                                                                 SetUpLighting();
5109
5110                                                                 //if(skyboxtexture){
5111                                                                 terrain.DoShadows();
5112                                                                 objects.DoShadows();
5113                                                                 /*}
5114                                                                 else terrain.DoLighting();
5115                                                                 */
5116                                                                 donesomething=1;
5117                                                         } 
5118
5119                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
5120                                                                 skyboxtexture=1-skyboxtexture;
5121
5122                                                                 SetUpLighting();
5123                                                                 //if(skyboxtexture){
5124                                                                 terrain.DoShadows();
5125                                                                 objects.DoShadows();
5126                                                                 /*}
5127                                                                 else terrain.DoLighting();
5128                                                                 */
5129                                                                 donesomething=1;
5130                                                         }
5131
5132                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
5133                                                                 int startpoint;
5134                                                                 int alldone;
5135                                                                 alldone=0;
5136                                                                 startpoint=11;
5137                                                                 j=startpoint;
5138                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5139                                                                         mapname[j-startpoint]=consoletext[0][j];
5140                                                                         j++;
5141                                                                         if(consoletext[0][j]=='\0')alldone=1;
5142                                                                 }
5143                                                                 mapname[j-startpoint]='\0';
5144
5145                                                                 player[0].protectionhead=atof(mapname);
5146
5147                                                                 j++;
5148                                                                 startpoint=j;
5149                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5150                                                                         mapname[j-startpoint]=consoletext[0][j];
5151                                                                         j++;
5152                                                                         if(consoletext[0][j]=='\0')alldone=1;
5153                                                                 }
5154                                                                 mapname[j-startpoint]='\0';
5155
5156                                                                 player[0].protectionhigh=atof(mapname);
5157
5158                                                                 j++;
5159                                                                 startpoint=j;
5160                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5161                                                                         mapname[j-startpoint]=consoletext[0][j];
5162                                                                         j++;
5163                                                                         if(consoletext[0][j]=='\0')alldone=1;
5164                                                                 }
5165                                                                 mapname[j-startpoint]='\0';
5166
5167                                                                 player[0].protectionlow=atof(mapname);
5168
5169                                                                 donesomething=1;
5170                                                         }
5171
5172                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
5173                                                                 int startpoint;
5174                                                                 int alldone;
5175                                                                 alldone=0;
5176                                                                 startpoint=6;
5177                                                                 j=startpoint;
5178                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5179                                                                         mapname[j-startpoint]=consoletext[0][j];
5180                                                                         j++;
5181                                                                         if(consoletext[0][j]=='\0')alldone=1;
5182                                                                 }
5183                                                                 mapname[j-startpoint]='\0';
5184
5185                                                                 player[0].armorhead=atof(mapname);
5186
5187                                                                 j++;
5188                                                                 startpoint=j;
5189                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5190                                                                         mapname[j-startpoint]=consoletext[0][j];
5191                                                                         j++;
5192                                                                         if(consoletext[0][j]=='\0')alldone=1;
5193                                                                 }
5194                                                                 mapname[j-startpoint]='\0';
5195
5196                                                                 player[0].armorhigh=atof(mapname);
5197
5198                                                                 j++;
5199                                                                 startpoint=j;
5200                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5201                                                                         mapname[j-startpoint]=consoletext[0][j];
5202                                                                         j++;
5203                                                                         if(consoletext[0][j]=='\0')alldone=1;
5204                                                                 }
5205                                                                 mapname[j-startpoint]='\0';
5206
5207                                                                 player[0].armorlow=atof(mapname);
5208
5209                                                                 donesomething=1;
5210                                                         }
5211
5212                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
5213                                                                 for(i=0;i<numplayers;i++){
5214                                                                         player[i].protectionhead=1.0;
5215                                                                         player[i].protectionhigh=1.0;
5216                                                                         player[i].protectionlow=1.0;
5217                                                                         player[i].armorhead=1.0;
5218                                                                         player[i].armorhigh=1.0;
5219                                                                         player[i].armorlow=1.0;
5220                                                                 }
5221
5222                                                                 donesomething=1;
5223                                                         }
5224
5225                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
5226                                                                 int closest=-1;
5227                                                                 float closestdist=-1;
5228                                                                 float distance;
5229                                                                 if(numplayers>1)
5230                                                                         for(i=1;i<numplayers;i++){
5231                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5232                                                                                 if(closestdist==-1||distance<closestdist){
5233                                                                                         closestdist=distance;
5234                                                                                         closest=i;
5235                                                                                 }
5236                                                                         }
5237
5238                                                                         int startpoint;
5239                                                                         int alldone;
5240                                                                         alldone=0;
5241                                                                         startpoint=15;
5242                                                                         j=startpoint;
5243                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5244                                                                                 mapname[j-startpoint]=consoletext[0][j];
5245                                                                                 j++;
5246                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5247                                                                         }
5248                                                                         mapname[j-startpoint]='\0';
5249
5250                                                                         player[closest].protectionhead=atof(mapname);
5251
5252                                                                         j++;
5253                                                                         startpoint=j;
5254                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5255                                                                                 mapname[j-startpoint]=consoletext[0][j];
5256                                                                                 j++;
5257                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5258                                                                         }
5259                                                                         mapname[j-startpoint]='\0';
5260
5261                                                                         player[closest].protectionhigh=atof(mapname);
5262
5263                                                                         j++;
5264                                                                         startpoint=j;
5265                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5266                                                                                 mapname[j-startpoint]=consoletext[0][j];
5267                                                                                 j++;
5268                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5269                                                                         }
5270                                                                         mapname[j-startpoint]='\0';
5271
5272                                                                         player[closest].protectionlow=atof(mapname);
5273
5274                                                                         donesomething=1;
5275                                                         }
5276
5277                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
5278                                                                 int closest=-1;
5279                                                                 float closestdist=-1;
5280                                                                 float distance;
5281                                                                 if(numplayers>1)
5282                                                                         for(i=1;i<numplayers;i++){
5283                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5284                                                                                 if(closestdist==-1||distance<closestdist){
5285                                                                                         closestdist=distance;
5286                                                                                         closest=i;
5287                                                                                 }
5288                                                                         }
5289                                                                         int startpoint;
5290                                                                         int alldone;
5291                                                                         alldone=0;
5292                                                                         startpoint=10;
5293                                                                         j=startpoint;
5294                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5295                                                                                 mapname[j-startpoint]=consoletext[0][j];
5296                                                                                 j++;
5297                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5298                                                                         }
5299                                                                         mapname[j-startpoint]='\0';
5300
5301                                                                         player[closest].armorhead=atof(mapname);
5302
5303                                                                         j++;
5304                                                                         startpoint=j;
5305                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5306                                                                                 mapname[j-startpoint]=consoletext[0][j];
5307                                                                                 j++;
5308                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5309                                                                         }
5310                                                                         mapname[j-startpoint]='\0';
5311
5312                                                                         player[closest].armorhigh=atof(mapname);
5313
5314                                                                         j++;
5315                                                                         startpoint=j;
5316                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5317                                                                                 mapname[j-startpoint]=consoletext[0][j];
5318                                                                                 j++;
5319                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5320                                                                         }
5321                                                                         mapname[j-startpoint]='\0';
5322
5323                                                                         player[closest].armorlow=atof(mapname);
5324
5325                                                                         donesomething=1;
5326                                                         }
5327
5328
5329                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5330                                                                 int startpoint;
5331                                                                 int alldone;
5332                                                                 alldone=0;
5333                                                                 startpoint=6;
5334                                                                 j=startpoint;
5335                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5336                                                                         mapname[j-startpoint]=consoletext[0][j];
5337                                                                         j++;
5338                                                                         if(consoletext[0][j]=='\0')alldone=1;
5339                                                                 }
5340                                                                 mapname[j-startpoint]='\0';
5341
5342                                                                 player[0].metalhead=atof(mapname);
5343
5344                                                                 j++;
5345                                                                 startpoint=j;
5346                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5347                                                                         mapname[j-startpoint]=consoletext[0][j];
5348                                                                         j++;
5349                                                                         if(consoletext[0][j]=='\0')alldone=1;
5350                                                                 }
5351                                                                 mapname[j-startpoint]='\0';
5352
5353                                                                 player[0].metalhigh=atof(mapname);
5354
5355                                                                 j++;
5356                                                                 startpoint=j;
5357                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5358                                                                         mapname[j-startpoint]=consoletext[0][j];
5359                                                                         j++;
5360                                                                         if(consoletext[0][j]=='\0')alldone=1;
5361                                                                 }
5362
5363                                                                 mapname[j-startpoint]='\0';
5364
5365                                                                 player[0].metallow=atof(mapname);
5366
5367                                                                 donesomething=1;
5368                                                         }
5369
5370                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5371                                                                 int closest=-1;
5372                                                                 float closestdist=-1;
5373                                                                 float distance;
5374                                                                 if(numplayers>1)
5375                                                                         for(i=1;i<numplayers;i++){
5376                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5377                                                                                 if(closestdist==-1||distance<closestdist){
5378                                                                                         closestdist=distance;
5379                                                                                         closest=i;
5380                                                                                 }
5381                                                                         }
5382                                                                         player[closest].numclothes=0;
5383                                                                         if(player[closest].whichskin==0){
5384                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5385                                                                         }
5386                                                                         else if(player[closest].whichskin==1){
5387                                                                                 LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5388                                                                         }
5389                                                                         else if(player[closest].whichskin==2){
5390                                                                                 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5391                                                                         }
5392                                                                         else if(player[closest].whichskin==3){
5393                                                                                 LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5394                                                                         }
5395                                                                         else if(player[closest].whichskin==4){
5396                                                                                 LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5397                                                                         }
5398                                                                         else if(player[closest].whichskin==5){
5399                                                                                 LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5400                                                                         }
5401                                                                         else if(player[closest].whichskin==6){
5402                                                                                 LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5403                                                                         }
5404                                                                         else if(player[closest].whichskin==7){
5405                                                                                 LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5406                                                                         }
5407                                                                         else if(player[closest].whichskin==8){
5408                                                                                 LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5409                                                                         }
5410                                                                         else if(player[closest].whichskin==9){
5411                                                                                 LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5412                                                                         }
5413
5414                                                                         donesomething=1;
5415                                                         }
5416
5417                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5418                                                                 int closest=0;
5419
5420                                                                 player[closest].numclothes=0;
5421                                                                 if(player[closest].whichskin==0){
5422                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5423                                                                 }
5424                                                                 else if(player[closest].whichskin==1){
5425                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5426                                                                 }
5427                                                                 else if(player[closest].whichskin==2){
5428                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5429                                                                 }
5430                                                                 else if(player[closest].whichskin==3){
5431                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5432                                                                 }
5433                                                                 else if(player[closest].whichskin==4){
5434                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5435                                                                 }
5436                                                                 else if(player[closest].whichskin==5){
5437                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5438                                                                 }
5439                                                                 else if(player[closest].whichskin==6){
5440                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5441                                                                 }
5442                                                                 else if(player[closest].whichskin==7){
5443                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5444                                                                 }
5445                                                                 else if(player[closest].whichskin==8){
5446                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5447                                                                 }
5448                                                                 else if(player[closest].whichskin==9){
5449                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5450                                                                 }
5451
5452                                                                 donesomething=1;
5453                                                         }
5454
5455                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5456                                                                 mapname[0]=':';
5457                                                                 mapname[1]='D';
5458                                                                 mapname[2]='a';
5459                                                                 mapname[3]='t';
5460                                                                 mapname[4]='a';
5461                                                                 mapname[5]=':';
5462                                                                 mapname[6]='T';
5463                                                                 mapname[7]='e';
5464                                                                 mapname[8]='x';
5465                                                                 mapname[9]='t';
5466                                                                 mapname[10]='u';
5467                                                                 mapname[11]='r';
5468                                                                 mapname[12]='e';
5469                                                                 mapname[13]='s';
5470                                                                 mapname[14]=':';
5471                                                                 for(j=8;j<consolechars[0];j++){
5472                                                                         mapname[j-8+15]=consoletext[0][j];
5473                                                                 }
5474                                                                 mapname[consolechars[0]-8+15]='.';
5475                                                                 mapname[consolechars[0]-8+16]='p';
5476                                                                 mapname[consolechars[0]-8+17]='n';
5477                                                                 mapname[consolechars[0]-8+18]='g';
5478                                                                 mapname[consolechars[0]-8+19]='\0';
5479
5480                                                                 //:Data:Textures:Pants.png
5481
5482                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5483                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5484                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5485                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5486                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5487                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5488                                                                         player[0].numclothes++;
5489                                                                 }
5490
5491                                                                 donesomething=1;
5492                                                         }
5493
5494                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5495                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5496
5497                                                                 donesomething=1;
5498                                                         }
5499
5500                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5501                                                                 cellophane=1-cellophane;
5502
5503                                                                 if(cellophane){
5504                                                                         for(i=0;i<numplayers;i++){
5505                                                                                 player[i].proportionhead.z=0;
5506                                                                                 player[i].proportionbody.z=0;
5507                                                                                 player[i].proportionarms.z=0;
5508                                                                                 player[i].proportionlegs.z=0;
5509                                                                         }
5510                                                                 }
5511
5512                                                                 if(!cellophane){
5513                                                                         for(i=0;i<numplayers;i++){
5514                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5515                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5516                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5517                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5518                                                                         }
5519                                                                 }
5520
5521                                                                 donesomething=1;
5522                                                         }
5523
5524                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5525                                                                 mapname[0]=':';
5526                                                                 mapname[1]='D';
5527                                                                 mapname[2]='a';
5528                                                                 mapname[3]='t';
5529                                                                 mapname[4]='a';
5530                                                                 mapname[5]=':';
5531                                                                 mapname[6]='T';
5532                                                                 mapname[7]='e';
5533                                                                 mapname[8]='x';
5534                                                                 mapname[9]='t';
5535                                                                 mapname[10]='u';
5536                                                                 mapname[11]='r';
5537                                                                 mapname[12]='e';
5538                                                                 mapname[13]='s';
5539                                                                 mapname[14]=':';
5540                                                                 for(j=12;j<consolechars[0];j++){
5541                                                                         mapname[j-12+15]=consoletext[0][j];
5542                                                                 }
5543                                                                 mapname[consolechars[0]-12+15]='.';
5544                                                                 mapname[consolechars[0]-12+16]='p';
5545                                                                 mapname[consolechars[0]-12+17]='n';
5546                                                                 mapname[consolechars[0]-12+18]='g';
5547                                                                 mapname[consolechars[0]-12+19]='\0';
5548
5549                                                                 //:Data:Textures:Pants.png
5550                                                                 int closest=-1;
5551                                                                 float closestdist=-1;
5552                                                                 float distance;
5553                                                                 if(numplayers>1)
5554                                                                         for(i=1;i<numplayers;i++){
5555                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5556                                                                                 if(closestdist==-1||distance<closestdist){
5557                                                                                         closestdist=distance;
5558                                                                                         closest=i;
5559                                                                                 }
5560                                                                         }
5561
5562                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5563                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5564                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5565                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5566                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5567                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5568                                                                                 player[closest].numclothes++;
5569                                                                         }
5570
5571                                                                         donesomething=1;
5572                                                         }
5573
5574                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5575                                                                 player[0].skeleton.id=0;
5576                                                                 player[0].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
5577                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5578                                                                 player[0].creature=rabbittype;
5579                                                                 player[0].scale=.2;
5580
5581                                                                 player[0].proportionhead=1.2;
5582                                                                 player[0].proportionbody=1.05;
5583                                                                 player[0].proportionarms=1.00;
5584                                                                 player[0].proportionlegs=1.1;
5585                                                                 player[0].proportionlegs.y=1.05;
5586                                                                 player[0].headless=0;
5587
5588                                                                 player[0].damagetolerance=200;
5589
5590                                                                 donesomething=1;
5591                                                         }
5592                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5593                                                                 player[0].skeleton.id=0;
5594                                                                 player[0].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
5595                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5596                                                                 player[0].creature=wolftype;
5597
5598                                                                 player[0].proportionhead=1.1;
5599                                                                 player[0].proportionbody=1.1;
5600                                                                 player[0].proportionarms=1.1;
5601                                                                 player[0].proportionlegs=1.1;
5602                                                                 player[0].proportionlegs.y=1.1;
5603                                                                 player[0].scale=.23;
5604
5605                                                                 player[0].damagetolerance=300;
5606
5607                                                                 donesomething=1;
5608                                                         }
5609                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5610                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5611                                                         donesomething=1;
5612                                                         }
5613                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5614                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5615                                                         donesomething=1;
5616                                                         }
5617                                                         if(Compare(consoletext[0],"david ",0,5)){
5618                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5619                                                         donesomething=1;
5620                                                         }*/
5621                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5622                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5623                                                                 donesomething=1;
5624                                                         }
5625                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5626                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5627                                                                 donesomething=1;
5628                                                         }
5629                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5630                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5631                                                                 donesomething=1;
5632                                                         }/*
5633                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5634                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5635                                                          donesomething=1;
5636                                                          }*/
5637                                                         if(Compare(consoletext[0],"white ",0,5)){
5638                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5639                                                                 donesomething=1;
5640                                                         }
5641                                                         if(Compare(consoletext[0],"brown ",0,5)){
5642                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5643                                                                 donesomething=1;
5644                                                         }
5645                                                         if(Compare(consoletext[0],"black ",0,5)){
5646                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5647                                                                 donesomething=1;
5648                                                         }
5649                                                         if(consolechars[0]>0){
5650                                                                 for(k=14;k>=1;k--){
5651                                                                         for(j=0;j<255;j++){
5652                                                                                 consoletext[k][j]=consoletext[k-1][j];
5653                                                                         }
5654                                                                         consolechars[k]=consolechars[k-1];
5655                                                                 }
5656                                                                 for(j=0;j<255;j++){
5657                                                                         consoletext[0][j]=' ';
5658                                                                 }
5659                                                                 consolechars[0]=0;
5660                                                                 consoleselected=0;
5661
5662                                                                 if(!donesomething){
5663                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
5664                                                                         FSOUND_SetVolume(channels[consolefailsound], 256);
5665                                                                         FSOUND_SetPaused(channels[consolefailsound], FALSE);
5666                                                                 }
5667                                                         }
5668                                                 }
5669                                         }
5670                                         togglekey[i]=1;
5671                                 }
5672                                 else {
5673                                         togglekey[i]=0;
5674                                         togglekeydelay[i]=0;
5675                                 }
5676                         }
5677
5678                         consoleblinkdelay-=multiplier;
5679                         if(consoleblinkdelay<=0){
5680                                 consoleblinkdelay=.3;
5681                                 consoleblink=1-consoleblink;
5682                         }
5683                 }
5684
5685                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5686                         tryquit=1;
5687                         if(mainmenu==3){
5688                                 if(newdetail>2)newdetail=detail;
5689                                 if(newdetail<0)newdetail=detail;
5690 #if !USE_SDL  // we'll take anything that works.
5691                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
5692                                 if(newscreenheight>3000)newscreenheight=screenheight;
5693 #endif
5694                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5695                                 if(newscreenheight<0)newscreenheight=screenheight;
5696
5697                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5698                                 opstream << "Screenwidth:\n";
5699                                 opstream << newscreenwidth;
5700                                 opstream << "\nScreenheight:\n";
5701                                 opstream << newscreenheight;
5702                                 opstream << "\nMouse sensitivity:\n";
5703                                 opstream << usermousesensitivity;
5704                                 opstream << "\nBlur(0,1):\n";
5705                                 opstream << ismotionblur;
5706                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5707                                 opstream << newdetail;
5708                                 opstream << "\nFloating jump:\n";
5709                                 opstream << floatjump;
5710                                 opstream << "\nMouse jump:\n";
5711                                 opstream << mousejump;
5712                                 opstream << "\nAmbient sound:\n";
5713                                 opstream << ambientsound;
5714                                 opstream << "\nBlood (0,1,2):\n";
5715                                 opstream << bloodtoggle;
5716                                 opstream << "\nAuto slomo:\n";
5717                                 opstream << autoslomo;
5718                                 opstream << "\nFoliage:\n";
5719                                 opstream << foliage;
5720                                 opstream << "\nMusic:\n";
5721                                 opstream << musictoggle;
5722                                 opstream << "\nTrilinear:\n";
5723                                 opstream << trilinear;
5724                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5725                                 opstream << decals;
5726                                 opstream << "\nInvert mouse:\n";
5727                                 opstream << invertmouse;
5728                                 opstream << "\nGamespeed:\n";
5729                                 if(oldgamespeed==0)oldgamespeed=1;
5730                                 opstream << oldgamespeed;
5731                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5732                                 opstream << difficulty;
5733                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5734                                 opstream << damageeffects;
5735                                 opstream << "\nText:\n";
5736                                 opstream << texttoggle;
5737                                 opstream << "\nDebug:\n";
5738                                 opstream << debugmode;
5739                                 opstream << "\nVBL Sync:\n";
5740                                 opstream << vblsync;
5741                                 opstream << "\nShow Points:\n";
5742                                 opstream << showpoints;
5743                                 opstream << "\nAlways Blur:\n";
5744                                 opstream << alwaysblur;
5745                                 opstream << "\nImmediate mode (turn on on G5):\n";
5746                                 opstream << immediate;
5747                                 opstream << "\nVelocity blur:\n";
5748                                 opstream << velocityblur;
5749                             opstream << "\nVolume:\n";
5750                         opstream << volume;
5751                                 opstream << "\nForward key:\n";
5752                                 opstream << KeyToChar(forwardkey);
5753                                 opstream << "\nBack key:\n";
5754                                 opstream << KeyToChar(backkey);
5755                                 opstream << "\nLeft key:\n";
5756                                 opstream << KeyToChar(leftkey);
5757                                 opstream << "\nRight key:\n";
5758                                 opstream << KeyToChar(rightkey);
5759                                 opstream << "\nJump key:\n";
5760                                 opstream << KeyToChar(jumpkey);
5761                                 opstream << "\nCrouch key:\n";
5762                                 opstream << KeyToChar(crouchkey);
5763                                 opstream << "\nDraw key:\n";
5764                                 opstream << KeyToChar(drawkey);
5765                                 opstream << "\nThrow key:\n";
5766                                 opstream << KeyToChar(throwkey);
5767                                 opstream << "\nAttack key:\n";
5768                                 opstream << KeyToChar(attackkey);
5769                                 opstream << "\nChat key:\n";
5770                                 opstream << KeyToChar(chatkey);
5771                                 opstream.close();
5772                         }
5773                 }
5774
5775                 static int oldwinfreeze;
5776                 if(winfreeze&&!oldwinfreeze){
5777                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
5778                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
5779                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
5780                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
5781                 }
5782                 if(winfreeze==0)oldwinfreeze=winfreeze;
5783                 else oldwinfreeze++;
5784
5785                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5786                         if(winfreeze)winfreeze=0;
5787                         oldjumpkeydown=1;
5788                 }
5789                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5790                         if(winfreeze){
5791                                 mainmenu=9;
5792                                 gameon=0;
5793                         }
5794                 }
5795                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5796                         oldjumpkeydown=1;
5797                 }
5798                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5799
5800                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5801
5802                         static bool oldbuttondialogue;
5803
5804                         if(indialogue!=-1)talkdelay=1;
5805                         talkdelay-=multiplier;
5806
5807                         if(talkdelay<=0)
5808                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5809                                         for(i=0;i<numdialogues;i++){
5810                                                 int realdialoguetype;
5811                                                 bool special;
5812                                                 if(dialoguetype[i]>49){
5813                                                         realdialoguetype=dialoguetype[i]-50; 
5814                                                         special=1;
5815                                                 }
5816                                                 else if(dialoguetype[i]>39){
5817                                                         realdialoguetype=dialoguetype[i]-40; 
5818                                                         special=1;
5819                                                 }
5820                                                 else if(dialoguetype[i]>29){
5821                                                         realdialoguetype=dialoguetype[i]-30; 
5822                                                         special=1;
5823                                                 }
5824                                                 else if(dialoguetype[i]>19){
5825                                                         realdialoguetype=dialoguetype[i]-20; 
5826                                                         special=1;
5827                                                 }
5828                                                 else if(dialoguetype[i]>9){
5829                                                         realdialoguetype=dialoguetype[i]-10; 
5830                                                         special=1;
5831                                                 }
5832                                                 else {
5833                                                         realdialoguetype=dialoguetype[i];
5834                                                         special=0;
5835                                                 }
5836                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5837                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5838                                                                 whichdialogue=i;
5839                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5840                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5841                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5842                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5843                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5844                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5845                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5846                                                                 }
5847                                                                 directing=0;
5848                                                                 indialogue=0;
5849                                                                 dialoguetime=0;
5850                                                                 dialoguegonethrough[i]++;
5851                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5852                                                                         static float gLoc[3];
5853                                                                         static float vel[3];
5854                                                                         XYZ temppos;
5855                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5856                                                                         temppos=temppos-viewer;
5857                                                                         Normalise(&temppos);
5858                                                                         temppos+=viewer;
5859
5860                                                                         gLoc[0]=temppos.x;
5861                                                                         gLoc[1]=temppos.y;
5862                                                                         gLoc[2]=temppos.z;vel[0]=0;
5863                                                                         vel[1]=0;
5864                                                                         vel[2]=0;
5865                                                                         int whichsoundplay;
5866                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5867                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5868                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5869                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5870                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5871                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5872                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5873                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5874                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5875                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5876                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5877                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5878                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5879                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5880                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5881                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5882                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5883                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5884                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5885                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5886                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
5887                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5888                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
5889                                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
5890                                                                 }
5891                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5892                                                         }
5893                                                 }
5894                                         }
5895
5896                                         windvar+=multiplier;
5897                                         smoketex+=multiplier;
5898                                         tutorialstagetime+=multiplier;
5899
5900                                         static float hotspotvisual[40];
5901                                         if(numhotspots){
5902                                                 XYZ hotspotsprite;
5903                                                 if(editorenabled)
5904                                                         for(i=0;i<numhotspots;i++)
5905                                                                 hotspotvisual[i]-=multiplier/320;
5906
5907                                                 for(i=0;i<numhotspots;i++){
5908                                                         //if(hotspottype[i]<=10)
5909                                                         while(hotspotvisual[i]<0){
5910                                                                 hotspotsprite=0;
5911                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5912                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5913                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5914                                                                 hotspotsprite+=hotspot[i];
5915                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5916                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5917                                                         }                               
5918                                                 }
5919
5920                                                 for(i=0;i<numhotspots;i++){
5921                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5922                                                                 hotspot[i]=player[hotspottype[i]].coords;
5923                                                         }
5924                                                 }
5925                                         }
5926
5927                                         //Tutorial
5928                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5929                                                 tutorialstage++;
5930                                                 tutorialsuccess=0;
5931                                                 if(tutorialstage<=1){
5932                                                         canattack=0;
5933                                                         cananger=0;
5934                                                         reversaltrain=0;
5935                                                 }
5936                                                 if(tutorialstage==1){
5937                                                         tutorialmaxtime=5;
5938                                                 }
5939                                                 if(tutorialstage==2){
5940                                                         tutorialmaxtime=2;
5941                                                 }
5942                                                 if(tutorialstage==3){
5943                                                         tutorialmaxtime=600;
5944                                                 }
5945                                                 if(tutorialstage==4){
5946                                                         tutorialmaxtime=1000;
5947                                                 }
5948                                                 if(tutorialstage==5){
5949                                                         tutorialmaxtime=600;
5950                                                 }
5951                                                 if(tutorialstage==6){
5952                                                         tutorialmaxtime=600;
5953                                                 }
5954                                                 if(tutorialstage==7){
5955                                                         tutorialmaxtime=600;
5956                                                 }
5957                                                 if(tutorialstage==8){
5958                                                         tutorialmaxtime=600;
5959                                                 }
5960                                                 if(tutorialstage==9){
5961                                                         tutorialmaxtime=600;
5962                                                 }
5963                                                 if(tutorialstage==10){
5964                                                         tutorialmaxtime=2;
5965                                                 }
5966                                                 if(tutorialstage==11){
5967                                                         tutorialmaxtime=1000;
5968                                                 }
5969                                                 if(tutorialstage==12){
5970                                                         tutorialmaxtime=1000;
5971                                                 }
5972                                                 if(tutorialstage==13){
5973                                                         tutorialmaxtime=2;
5974                                                 }
5975                                                 if(tutorialstage==14){
5976                                                         tutorialmaxtime=3;
5977
5978                                                         XYZ temp,temp2;
5979
5980                                                         temp.x=1011;
5981                                                         temp.y=84;
5982                                                         temp.z=491;
5983                                                         temp2.x=1025;
5984                                                         temp2.y=75;
5985                                                         temp2.z=447;
5986
5987                                                         player[1].coords=(temp+temp2)/2;
5988
5989                                                         float gLoc[3];
5990                                                         float vel[3];
5991                                                         gLoc[0]=player[1].coords.x;
5992                                                         gLoc[1]=player[1].coords.y;
5993                                                         gLoc[2]=player[1].coords.z;
5994                                                         vel[0]=0;
5995                                                         vel[1]=0;
5996                                                         vel[2]=0;
5997                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
5998                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5999                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6000                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6001
6002                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6003                                                                 if(Random()%2==0){
6004                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6005                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6006                                                                         if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
6007                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6008                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6009                                                                 }
6010                                                         }
6011
6012                                                 }
6013                                                 if(tutorialstage==15){
6014                                                         tutorialmaxtime=500;
6015                                                 }
6016                                                 if(tutorialstage==16){
6017                                                         tutorialmaxtime=500;
6018                                                 }
6019                                                 if(tutorialstage==17){
6020                                                         tutorialmaxtime=500;
6021                                                 }
6022                                                 if(tutorialstage==18){
6023                                                         tutorialmaxtime=500;
6024                                                 }
6025                                                 if(tutorialstage==19){
6026                                                         tutorialstage=20;
6027                                                         //tutorialmaxtime=500;
6028                                                 }
6029                                                 if(tutorialstage==20){
6030                                                         tutorialmaxtime=500;
6031                                                 }
6032                                                 if(tutorialstage==21){
6033                                                         tutorialmaxtime=500;
6034                                                         if(bonus==cannon){
6035                                                                 bonus=Slicebonus;
6036                                                                 againbonus=1;
6037                                                         }
6038                                                         else againbonus=0;
6039                                                 }
6040                                                 if(tutorialstage==22){
6041                                                         tutorialmaxtime=500;
6042                                                 }
6043                                                 if(tutorialstage==23){
6044                                                         tutorialmaxtime=500;
6045                                                 }
6046                                                 if(tutorialstage==24){
6047                                                         tutorialmaxtime=500;
6048                                                 }
6049                                                 if(tutorialstage==25){
6050                                                         tutorialmaxtime=500;
6051                                                 }
6052                                                 if(tutorialstage==26){
6053                                                         tutorialmaxtime=2;
6054                                                 }
6055                                                 if(tutorialstage==27){
6056                                                         tutorialmaxtime=4;
6057                                                         reversaltrain=1;
6058                                                         cananger=1;
6059                                                         player[1].aitype=attacktypecutoff;
6060                                                 }
6061                                                 if(tutorialstage==28){
6062                                                         tutorialmaxtime=400;
6063                                                 }
6064                                                 if(tutorialstage==29){
6065                                                         tutorialmaxtime=400;
6066                                                         player[0].escapednum=0;
6067                                                 }
6068                                                 if(tutorialstage==30){
6069                                                         tutorialmaxtime=4;
6070                                                         reversaltrain=0;
6071                                                         cananger=0;
6072                                                         player[1].aitype=passivetype;
6073                                                 }
6074                                                 if(tutorialstage==31){
6075                                                         tutorialmaxtime=13;
6076                                                 }
6077                                                 if(tutorialstage==32){
6078                                                         tutorialmaxtime=8;
6079                                                 }
6080                                                 if(tutorialstage==33){
6081                                                         tutorialmaxtime=400;
6082                                                         cananger=1;
6083                                                         canattack=1;
6084                                                         player[1].aitype=attacktypecutoff;
6085                                                 }
6086                                                 if(tutorialstage==34){
6087                                                         tutorialmaxtime=400;
6088                                                 }
6089                                                 if(tutorialstage==35){
6090                                                         tutorialmaxtime=400;
6091                                                 }
6092                                                 if(tutorialstage==36){
6093                                                         tutorialmaxtime=2;
6094                                                         reversaltrain=0;
6095                                                         cananger=0;
6096                                                         player[1].aitype=passivetype;
6097                                                 }
6098                                                 if(tutorialstage==37){
6099                                                         damagedealt=0;
6100                                                         damagetaken=0;
6101                                                         tutorialmaxtime=50;
6102                                                         cananger=1;
6103                                                         canattack=1;
6104                                                         player[1].aitype=attacktypecutoff;
6105                                                 }
6106                                                 if(tutorialstage==38){
6107                                                         tutorialmaxtime=4;
6108                                                         canattack=0;
6109                                                         cananger=0;
6110                                                         player[1].aitype=passivetype;
6111                                                 }
6112                                                 if(tutorialstage==39){
6113                                                         XYZ temp,temp2;
6114
6115                                                         temp.x=1011;
6116                                                         temp.y=84;
6117                                                         temp.z=491;
6118                                                         temp2.x=1025;
6119                                                         temp2.y=75;
6120                                                         temp2.z=447;
6121
6122
6123                                                         weapons.owner[weapons.numweapons]=-1;
6124                                                         weapons.type[weapons.numweapons]=knife;
6125                                                         weapons.damage[weapons.numweapons]=0;
6126                                                         weapons.mass[weapons.numweapons]=1;
6127                                                         weapons.tipmass[weapons.numweapons]=1.2;
6128                                                         weapons.length[weapons.numweapons]=.25;
6129                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6130                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6131
6132                                                         weapons.velocity[weapons.numweapons]=0.1;
6133                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6134                                                         weapons.missed[weapons.numweapons]=1;
6135                                                         weapons.hitsomething[weapons.numweapons]=0;
6136                                                         weapons.freetime[weapons.numweapons]=0;
6137                                                         weapons.firstfree[weapons.numweapons]=1;
6138                                                         weapons.physics[weapons.numweapons]=1;
6139
6140                                                         weapons.numweapons++;
6141                                                 }
6142                                                 if(tutorialstage==40){
6143                                                         tutorialmaxtime=300;
6144                                                 }
6145                                                 if(tutorialstage==41){
6146                                                         tutorialmaxtime=300;
6147                                                 }
6148                                                 if(tutorialstage==42){
6149                                                         tutorialmaxtime=8;
6150                                                 }
6151                                                 if(tutorialstage==43){
6152                                                         tutorialmaxtime=300;
6153                                                 }
6154                                                 if(tutorialstage==44){
6155                                                         weapons.owner[0]=1;
6156                                                         player[0].weaponactive=-1;
6157                                                         player[0].num_weapons=0;
6158                                                         player[1].weaponactive=0;
6159                                                         player[1].num_weapons=1;
6160                                                         player[1].weaponids[0]=0;
6161
6162                                                         cananger=1;
6163                                                         canattack=1;
6164                                                         player[1].aitype=attacktypecutoff;
6165
6166                                                         tutorialmaxtime=300;
6167                                                 }
6168                                                 if(tutorialstage==45){
6169                                                         weapons.owner[0]=1;
6170                                                         player[0].weaponactive=-1;
6171                                                         player[0].num_weapons=0;
6172                                                         player[1].weaponactive=0;
6173                                                         player[1].num_weapons=1;
6174                                                         player[1].weaponids[0]=0;
6175
6176                                                         tutorialmaxtime=300;
6177                                                 }
6178                                                 if(tutorialstage==46){
6179                                                         weapons.owner[0]=1;
6180                                                         player[0].weaponactive=-1;
6181                                                         player[0].num_weapons=0;
6182                                                         player[1].weaponactive=0;
6183                                                         player[1].num_weapons=1;
6184                                                         player[1].weaponids[0]=0;
6185
6186                                                         weapons.type[0]=sword;
6187
6188                                                         tutorialmaxtime=300;
6189                                                 }
6190
6191                                                 if(tutorialstage==47){
6192                                                         tutorialmaxtime=10;
6193
6194                                                         XYZ temp,temp2;
6195
6196                                                         temp.x=1011;
6197                                                         temp.y=84;
6198                                                         temp.z=491;
6199                                                         temp2.x=1025;
6200                                                         temp2.y=75;
6201                                                         temp2.z=447;
6202
6203                                                         weapons.owner[weapons.numweapons]=-1;
6204                                                         weapons.type[weapons.numweapons]=sword;
6205                                                         weapons.damage[weapons.numweapons]=0;
6206                                                         weapons.mass[weapons.numweapons]=1;
6207                                                         weapons.tipmass[weapons.numweapons]=1.2;
6208                                                         weapons.length[weapons.numweapons]=.25;
6209                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6210                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6211
6212                                                         weapons.velocity[weapons.numweapons]=0.1;
6213                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6214                                                         weapons.missed[weapons.numweapons]=1;
6215                                                         weapons.hitsomething[weapons.numweapons]=0;
6216                                                         weapons.freetime[weapons.numweapons]=0;
6217                                                         weapons.firstfree[weapons.numweapons]=1;
6218                                                         weapons.physics[weapons.numweapons]=1;
6219
6220                                                         weapons.owner[0]=1;
6221                                                         weapons.owner[1]=0;
6222                                                         player[0].weaponactive=0;
6223                                                         player[0].num_weapons=1;
6224                                                         player[0].weaponids[0]=1;       
6225                                                         player[1].weaponactive=0;
6226                                                         player[1].num_weapons=1;
6227                                                         player[1].weaponids[0]=0;       
6228
6229                                                         weapons.numweapons++;
6230                                                 }
6231                                                 if(tutorialstage==48){
6232                                                         canattack=0;
6233                                                         cananger=0;
6234                                                         player[1].aitype=passivetype;
6235
6236                                                         tutorialmaxtime=15;
6237
6238                                                         weapons.owner[0]=1;
6239                                                         weapons.owner[1]=0;
6240                                                         player[0].weaponactive=0;
6241                                                         player[0].num_weapons=1;
6242                                                         player[0].weaponids[0]=1;       
6243                                                         player[1].weaponactive=0;
6244                                                         player[1].num_weapons=1;
6245                                                         player[1].weaponids[0]=0;
6246
6247                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
6248                                                         else weapons.type[0]=staff;
6249
6250                                                         weapons.numweapons++;
6251                                                 }
6252                                                 if(tutorialstage==49){
6253                                                         canattack=0;
6254                                                         cananger=0;
6255                                                         player[1].aitype=passivetype;
6256
6257                                                         tutorialmaxtime=200;
6258
6259                                                         weapons.position[1]=1000;
6260                                                         weapons.tippoint[1]=1000;
6261
6262                                                         weapons.numweapons=1;
6263                                                         weapons.owner[0]=0;
6264                                                         player[1].weaponactive=-1;
6265                                                         player[1].num_weapons=0;
6266                                                         player[0].weaponactive=0;
6267                                                         player[0].num_weapons=1;
6268                                                         player[0].weaponids[0]=0;       
6269
6270                                                         weapons.type[0]=knife;
6271
6272                                                         weapons.numweapons++;
6273                                                 }
6274                                                 if(tutorialstage==50){
6275                                                         tutorialmaxtime=8;
6276
6277                                                         XYZ temp,temp2;
6278                                                         float gLoc[3];
6279                                                         float vel[3];
6280                                                         gLoc[0]=player[1].coords.x;
6281                                                         gLoc[1]=player[1].coords.y;
6282                                                         gLoc[2]=player[1].coords.z;
6283                                                         vel[0]=0;
6284                                                         vel[1]=0;
6285                                                         vel[2]=0;
6286                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
6287                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6288                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6289                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6290
6291                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6292                                                                 if(Random()%2==0){
6293                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6294                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6295                                                                         if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
6296                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6297                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6298                                                                 }
6299                                                         }
6300
6301                                                         player[1].num_weapons=0;
6302                                                         player[1].weaponstuck=-1;
6303                                                         player[1].weaponactive=-1;
6304
6305                                                         weapons.numweapons=0;
6306
6307                                                         weapons.owner[0]=-1;
6308                                                         weapons.velocity[0]=0.1;
6309                                                         weapons.tipvelocity[0]=-0.1;
6310                                                         weapons.missed[0]=1;
6311                                                         weapons.hitsomething[0]=0;
6312                                                         weapons.freetime[0]=0;
6313                                                         weapons.firstfree[0]=1;
6314                                                         weapons.physics[0]=1;
6315                                                 }
6316                                                 if(tutorialstage==51){
6317                                                         tutorialmaxtime=80000;
6318                                                 }
6319                                                 if(tutorialstage<=51)tutorialstagetime=0;
6320                                         }
6321
6322                                         //Tutorial success
6323                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6324                                                 if(tutorialstage==3){
6325                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6326                                                 }
6327                                                 if(tutorialstage==4){
6328                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6329                                                 }
6330                                                 if(tutorialstage==5){
6331                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6332                                                 }
6333                                                 if(tutorialstage==6){
6334                                                         if(player[0].isCrouch())tutorialsuccess=1;
6335                                                 }
6336                                                 if(tutorialstage==7){
6337                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6338                                                 }
6339                                                 if(tutorialstage==8){
6340                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6341                                                 }
6342                                                 if(tutorialstage==9){
6343                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6344                                                 }
6345                                                 if(tutorialstage==11){
6346                                                         if(player[0].isWallJump())tutorialsuccess=1;
6347                                                 }
6348                                                 if(tutorialstage==12){
6349                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6350                                                 }
6351                                                 if(tutorialstage==15){
6352                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6353                                                 }
6354                                                 if(tutorialstage==16){
6355                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6356                                                 }
6357                                                 if(tutorialstage==17){
6358                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6359                                                 }
6360                                                 if(tutorialstage==18){
6361                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6362                                                 }
6363                                                 if(tutorialstage==19){
6364                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6365                                                 }
6366                                                 if(tutorialstage==20){
6367                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6368                                                 }
6369                                                 if(tutorialstage==21){
6370                                                         if(bonus==cannon)tutorialsuccess=1;
6371                                                 }
6372                                                 if(tutorialstage==22){
6373                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6374                                                 }
6375                                                 if(tutorialstage==23){
6376                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6377                                                 }
6378                                                 if(tutorialstage==24){
6379                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6380                                                 }
6381                                                 if(tutorialstage==25){
6382                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6383                                                 }
6384                                                 if(tutorialstage==28){
6385                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6386                                                 }
6387                                                 if(tutorialstage==29){
6388                                                         if(player[0].escapednum==2){
6389                                                                 tutorialsuccess=1;
6390                                                                 reversaltrain=0;
6391                                                                 cananger=0;
6392                                                                 player[1].aitype=passivetype;
6393                                                         }
6394                                                 }
6395                                                 if(tutorialstage==33){
6396                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6397                                                 }
6398                                                 if(tutorialstage==34){
6399                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6400                                                 }
6401                                                 if(tutorialstage==35){
6402                                                         if(animation[player[0].targetanimation].attack==reversal){
6403                                                                 tutorialsuccess=1;
6404                                                                 reversaltrain=0;
6405                                                                 cananger=0;
6406                                                                 player[1].aitype=passivetype;
6407                                                         }
6408                                                 }
6409                                                 if(tutorialstage==40){
6410                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6411                                                 }
6412                                                 if(tutorialstage==41){
6413                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6414                                                 }
6415                                                 if(tutorialstage==43){
6416                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6417                                                 }
6418                                                 if(tutorialstage==44){
6419                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6420                                                 }
6421                                                 if(tutorialstage==45){
6422                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6423                                                 }
6424                                                 if(tutorialstage==46){
6425                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6426                                                 }
6427                                                 if(tutorialstage==49){
6428                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6429                                                 }
6430                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6431
6432
6433                                                 if(tutorialstagetime==tutorialmaxtime-3){
6434                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
6435                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6436                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
6437                                                 }
6438
6439                                                 if(tutorialsuccess>=1){
6440                                                         if(tutorialstage==34||tutorialstage==35)
6441                                                                 tutorialstagetime=tutorialmaxtime-1;
6442                                                 }
6443                                         }
6444
6445                                         if(tutoriallevel){
6446                                                 if(tutorialstage<14||tutorialstage>=50){
6447                                                         player[1].coords.y=300;
6448                                                         player[1].velocity=0;
6449                                                 }
6450                                         }
6451
6452                                         if(tutoriallevel!=1){
6453                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6454                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
6455                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6456                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
6457                                                 }
6458                                         }
6459                                         else
6460                                                 if(bonustime==0){
6461                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
6462                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6463                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6464                                                 }
6465                                                 if(bonustime==0){
6466                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6467                                                         else bonusnum[bonus]+=0.15;
6468                                                         if(tutoriallevel)bonusvalue=0;
6469                                                         bonusvalue/=bonusnum[bonus];
6470                                                         bonustotal+=bonusvalue;
6471                                                 }
6472                                                 bonustime+=multiplier;
6473
6474                                                 if(environment==snowyenvironment){
6475                                                         precipdelay-=multiplier;
6476                                                         while(precipdelay<0){
6477                                                                 precipdelay+=.04;
6478                                                                 if(!detail)precipdelay+=.04;
6479                                                                 XYZ footvel,footpoint;
6480
6481                                                                 footvel=0;
6482                                                                 footpoint=viewer+viewerfacing*6;
6483                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6484                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6485                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6486                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6487                                                         }
6488                                                 }
6489                                                 for(k=0;k<numplayers;k++){
6490                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6491                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6492
6493                                                         if((player[k].isRun()&&((player[k].targetrotation!=rabbitrunninganim&&player[k].targetrotation!=wolfrunninganim)||player[k].targetframe==4))||player[k].targetanimation==removeknifeanim||player[k].targetanimation==crouchremoveknifeanim||player[k].targetanimation==flipanim||player[k].targetanimation==fightsidestep||player[k].targetanimation==walkanim){
6494                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6495                                                                 else if(player[k].rotation>player[k].targetrotation){
6496                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6497                                                                 }
6498                                                                 else if(player[k].rotation<player[k].targetrotation){
6499                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6500                                                                 }
6501                                                         }
6502
6503
6504                                                         if(player[k].isStop()||player[k].isLanding()||player[k].targetanimation==staggerbackhighanim||(player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||player[k].targetanimation==staggerbackhardanim||player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim||player[k].targetanimation==rollanim||(animation[player[k].targetanimation].attack&&player[k].targetanimation!=rabbitkickanim&&(player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&(player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
6505                                                                 player[k].turnspeed*=2;
6506                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6507                                                                 else if(player[k].rotation>player[k].targetrotation){
6508                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6509                                                                 }
6510                                                                 else if(player[k].rotation<player[k].targetrotation){
6511                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6512                                                                 }
6513                                                                 player[k].turnspeed/=2;
6514                                                         }
6515
6516                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6517                                                                 player[k].turnspeed*=4;
6518                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6519                                                                 else if(player[k].rotation>player[k].targetrotation){
6520                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6521                                                                 }
6522                                                                 else if(player[k].rotation<player[k].targetrotation){
6523                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6524                                                                 }
6525                                                                 player[k].turnspeed/=4;
6526                                                         }
6527
6528                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6529                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6530
6531                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6532                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6533                                                                         bool tempcollide=0;
6534
6535                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6536                                                                         if(player[k].collide>1)player[k].collide=1;
6537                                                                         player[k].collide-=multiplier*30;
6538
6539                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6540                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6541                                                                         }
6542                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6543                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6544                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6545                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6546                                                                                                 lowpoint=player[k].coords;
6547                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6548                                                                                                 else lowpoint.y+=1.3;
6549                                                                                                 if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1){
6550                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6551                                                                                                 }
6552                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6553                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6554                                                                                                 */
6555                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6556                                                                                                         flatfacing=lowpoint-player[k].coords;
6557                                                                                                         player[k].coords=lowpoint;
6558                                                                                                         player[k].coords.y-=1.3;
6559                                                                                                         player[k].collide=1;
6560                                                                                                         tempcollide=1;
6561                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6562                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6563                                                                                                                 tempcoords1=lowpoint;
6564                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6565                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6566                                                                                                                         player[k].target=0;
6567                                                                                                                         player[k].targetanimation=walljumpleftanim;
6568                                                                                                                         player[k].targetframe=0;
6569                                                                                                                         float gLoc[3];
6570                                                                                                                         float vel[3];
6571                                                                                                                         gLoc[0]=player[k].coords.x;
6572                                                                                                                         gLoc[1]=player[k].coords.y;
6573                                                                                                                         gLoc[2]=player[k].coords.z;
6574                                                                                                                         vel[0]=0;
6575                                                                                                                         vel[1]=0;
6576                                                                                                                         vel[2]=0;
6577                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6578                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6579                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6580                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6581                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6582
6583                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6584                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6585                                                                                                                         player[k].rotation*=360/6.28;
6586                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6587                                                                                                                         player[k].targetrotation=player[k].rotation;
6588                                                                                                                         player[k].lowrotation=player[k].rotation;
6589                                                                                                                         if(k==0)numwallflipped++;
6590                                                                                                                 }
6591                                                                                                                 else
6592                                                                                                                 {
6593                                                                                                                         lowpoint=tempcoords1;
6594                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6595                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6596                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6597                                                                                                                                 player[k].target=0;
6598                                                                                                                                 player[k].targetanimation=walljumprightanim;
6599                                                                                                                                 player[k].targetframe=0;
6600                                                                                                                                 float gLoc[3];
6601                                                                                                                                 float vel[3];
6602                                                                                                                                 gLoc[0]=player[k].coords.x;
6603                                                                                                                                 gLoc[1]=player[k].coords.y;
6604                                                                                                                                 gLoc[2]=player[k].coords.z;
6605                                                                                                                                 vel[0]=0;
6606                                                                                                                                 vel[1]=0;
6607                                                                                                                                 vel[2]=0;
6608                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6609                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6610                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6611                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6612                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6613
6614                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6615                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6616                                                                                                                                 player[k].rotation*=360/6.28;
6617                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6618                                                                                                                                 player[k].targetrotation=player[k].rotation;
6619                                                                                                                                 player[k].lowrotation=player[k].rotation;
6620                                                                                                                                 if(k==0)numwallflipped++;
6621                                                                                                                         }
6622                                                                                                                         else
6623                                                                                                                         {
6624                                                                                                                                 lowpoint=tempcoords1;
6625                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6626                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6627                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6628                                                                                                                                         player[k].target=0;
6629                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6630                                                                                                                                         player[k].targetframe=0;
6631                                                                                                                                         float gLoc[3];
6632                                                                                                                                         float vel[3];
6633                                                                                                                                         gLoc[0]=player[k].coords.x;
6634                                                                                                                                         gLoc[1]=player[k].coords.y;
6635                                                                                                                                         gLoc[2]=player[k].coords.z;
6636                                                                                                                                         vel[0]=0;
6637                                                                                                                                         vel[1]=0;
6638                                                                                                                                         vel[2]=0;
6639                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6640                                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6641                                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6642                                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6643                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6644
6645                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6646                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6647                                                                                                                                         player[k].rotation*=360/6.28;
6648                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6649                                                                                                                                         player[k].targetrotation=player[k].rotation;
6650                                                                                                                                         player[k].lowrotation=player[k].rotation;
6651                                                                                                                                         if(k==0)numwallflipped++;
6652                                                                                                                                 }
6653                                                                                                                                 else
6654                                                                                                                                 {
6655                                                                                                                                         lowpoint=tempcoords1;
6656                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6657                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6658                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6659                                                                                                                                                 player[k].target=0;
6660                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6661                                                                                                                                                 player[k].targetframe=0;
6662                                                                                                                                                 float gLoc[3];
6663                                                                                                                                                 float vel[3];
6664                                                                                                                                                 gLoc[0]=player[k].coords.x;
6665                                                                                                                                                 gLoc[1]=player[k].coords.y;
6666                                                                                                                                                 gLoc[2]=player[k].coords.z;
6667                                                                                                                                                 vel[0]=0;
6668                                                                                                                                                 vel[1]=0;
6669                                                                                                                                                 vel[2]=0;
6670                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6671                                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6672                                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6673                                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6674                                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6675
6676                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6677                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6678                                                                                                                                                 player[k].rotation*=360/6.28;
6679                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6680                                                                                                                                                 player[k].rotation+=180;
6681                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6682                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6683                                                                                                                                                 if(k==0)numwallflipped++;
6684                                                                                                                                         }
6685                                                                                                                                 }
6686                                                                                                                         }
6687                                                                                                                 }
6688                                                                                                         }
6689                                                                                                 }
6690                                                                                         }
6691                                                                                         else if(objects.type[i]==rocktype){
6692                                                                                                 lowpoint2=player[k].coords;
6693                                                                                                 lowpoint=player[k].coords;
6694                                                                                                 lowpoint.y+=2;
6695                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6696                                                                                                         player[k].coords=colpoint;
6697                                                                                                         player[k].collide=1;
6698                                                                                                         tempcollide=1;
6699
6700                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6701                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6702
6703                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6704                                                                                                                 player[k].target=0;
6705                                                                                                                 player[k].targetframe=0;        
6706                                                                                                                 player[k].onterrain=1;
6707
6708                                                                                                                 if(player[k].id==0){
6709                                                                                                                         FSOUND_SetPaused(channels[whooshsound], TRUE);
6710                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 0);
6711                                                                                                                 }
6712
6713                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6714                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6715                                                                                                                         player[k].targetanimation=player[k].getLanding();
6716                                                                                                                         float gLoc[3];
6717                                                                                                                         float vel[3];
6718                                                                                                                         gLoc[0]=player[k].coords.x;
6719                                                                                                                         gLoc[1]=player[k].coords.y;
6720                                                                                                                         gLoc[2]=player[k].coords.z;
6721                                                                                                                         vel[0]=player[k].velocity.x;
6722                                                                                                                         vel[1]=player[k].velocity.y;
6723                                                                                                                         vel[2]=player[k].velocity.z;
6724                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, TRUE);
6725                                                                                                                         FSOUND_3D_SetAttributes(channels[landsound], gLoc, vel);
6726                                                                                                                         FSOUND_SetVolume(channels[landsound], 128);
6727                                                                                                                         FSOUND_SetPaused(channels[landsound], FALSE);
6728                                                                                                                         if(k==0){
6729                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6730                                                                                                                                 envsoundvol[numenvsounds]=16;
6731                                                                                                                                 envsoundlife[numenvsounds]=.4;
6732                                                                                                                                 numenvsounds++;
6733                                                                                                                         }
6734
6735                                                                                                                 }
6736                                                                                                         }
6737                                                                                                 }                               
6738                                                                                         }
6739                                                                                 }
6740                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6741                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6742                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6743                                                                                                 lowpoint=player[k].coords;
6744                                                                                                 lowpoint.y+=1.35;
6745                                                                                                 if(objects.type[i]!=rocktype)
6746                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6747                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;               
6748                                                                                                                 player[k].coords=lowpoint;
6749                                                                                                                 player[k].coords.y-=1.35;
6750                                                                                                                 player[k].collide=1;    
6751
6752                                                                                                                 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&((/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)&&*/player[k].currentanimation!=climbanim&&player[k].currentanimation!=hanganim&&!player[k].isWallJump())||player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6753                                                                                                                         lowpoint=player[k].coords;
6754                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6755                                                                                                                         lowpoint=player[k].coords;
6756                                                                                                                         lowpoint.y+=.05;
6757                                                                                                                         facing=0;
6758                                                                                                                         facing.z=-1;
6759                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6760                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6761                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6762                                                                                                                         if(whichhit!=-1){
6763                                                                                                                                 lowpoint=player[k].coords;
6764                                                                                                                                 lowpoint.y+=.1;
6765                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6766                                                                                                                                 lowpoint2=lowpoint;
6767                                                                                                                                 lowpointtarget2=lowpointtarget;
6768                                                                                                                                 lowpoint3=lowpoint;
6769                                                                                                                                 lowpointtarget3=lowpointtarget;
6770                                                                                                                                 lowpoint4=lowpoint;
6771                                                                                                                                 lowpointtarget4=lowpointtarget;
6772                                                                                                                                 lowpoint5=lowpoint;
6773                                                                                                                                 lowpointtarget5=lowpointtarget;
6774                                                                                                                                 lowpoint6=lowpoint;
6775                                                                                                                                 lowpointtarget6=lowpointtarget;
6776                                                                                                                                 lowpoint7=lowpoint;
6777                                                                                                                                 lowpointtarget7=lowpoint;
6778                                                                                                                                 lowpoint2.x+=.1;
6779                                                                                                                                 lowpointtarget2.x+=.1;
6780                                                                                                                                 lowpoint3.z+=.1;
6781                                                                                                                                 lowpointtarget3.z+=.1;
6782                                                                                                                                 lowpoint4.x-=.1;
6783                                                                                                                                 lowpointtarget4.x-=.1;
6784                                                                                                                                 lowpoint5.z-=.1;
6785                                                                                                                                 lowpointtarget5.z-=.1;
6786                                                                                                                                 lowpoint6.y+=45/13;
6787                                                                                                                                 lowpointtarget6.y+=45/13;
6788                                                                                                                                 lowpointtarget6+=facing*.6;
6789                                                                                                                                 lowpointtarget7.y+=90/13;
6790                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6791                                                                                                                                 if(objects.friction[i]>.5)
6792                                                                                                                                         if(whichhit!=-1){
6793                                                                                                                                                 //if(k==0){
6794                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6795                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6796                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6797                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)
6798                                                                                                                                                                         for(j=0;j<45;j++){
6799                                                                                                                                                                                 lowpoint=player[k].coords;
6800                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6801                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6802                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6803                                                                                                                                                                                         if(j<=6){
6804                                                                                                                                                                                                 j=100;
6805                                                                                                                                                                                         }
6806                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6807                                                                                                                                                                                         j=100;
6808                                                                                                                                                                                         }*/
6809                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6810                                                                                                                                                                                                 j=100;
6811                                                                                                                                                                                         }
6812                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6813                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6814                                                                                                                                                                                                 if(1==1/*dotproduct(&player[k].velocity,&lowpoint)>0||player[k].aitype!=playercontrolled||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim||player[k].targetanimation==jumpupanim)*/){
6815                                                                                                                                                                                                         lowpoint=player[k].coords;
6816                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6817                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6818                                                                                                                                                                                                         flatfacing=player[k].coords;
6819                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6820                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6821                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6822
6823                                                                                                                                                                                                         if(j>10||!player[k].isRun()){                                                                                                   
6824                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6825                                                                                                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6826                                                                                                                                                                                                                 }
6827                                                                                                                                                                                                                 float gLoc[3];
6828                                                                                                                                                                                                                 float vel[3];
6829                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6830                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6831                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6832                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6833                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6834                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6835                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
6836                                                                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6837                                                                                                                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
6838                                                                                                                                                                                                                 FSOUND_SetPaused(channels[jumpsound], FALSE);
6839
6840                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6841                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6842                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6843                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6844                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6845                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6846
6847                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6848                                                                                                                                                                                                                 player[k].velocity=0;
6849
6850                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6851                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6852                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6853                                                                                                                                                                                                                         player[k].jumppower=0;
6854                                                                                                                                                                                                                         player[k].jumpclimb=1;
6855                                                                                                                                                                                                                 }
6856                                                                                                                                                                                                                 player[k].transspeed=6;
6857                                                                                                                                                                                                                 player[k].target=0;
6858
6859                                                                                                                                                                                                                 //player[k].currentframe=1;
6860                                                                                                                                                                                                                 player[k].targetframe=1;
6861                                                                                                                                                                                                                 if(j>25){
6862                                                                                                                                                                                                                         //player[k].currentframe=0;
6863                                                                                                                                                                                                                         player[k].targetframe=0;
6864                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6865                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6866                                                                                                                                                                                                                         player[k].jumppower=0;
6867                                                                                                                                                                                                                 }       
6868                                                                                                                                                                                                         }
6869                                                                                                                                                                                                         j=100;
6870                                                                                                                                                                                                 }
6871                                                                                                                                                                                         }
6872                                                                                                                                                                                 }
6873                                                                                                                                                                         }
6874                                                                                                                                                                         //}
6875                                                                                                                                         }
6876                                                                                                                         }
6877                                                                                                                 }
6878                                                                                                         }
6879                                                                                         }
6880                                                                                         if(player[k].collide<=0){
6881                                                                                                 if(!player[k].onterrain&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim&&!player[k].isWallJump()&&!player[k].isFlip()){
6882                                                                                                         if(player[k].currentanimation!=climbanim&&player[k].currentanimation!=tempanim&&player[k].targetanimation!=backhandspringanim&&(player[k].targetanimation!=rollanim||player[k].targetframe<2||player[k].targetframe>6)){
6883                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6884                                                                                                                 player[k].targetanimation=jumpdownanim;
6885                                                                                                                 player[k].targetframe=0;
6886                                                                                                                 player[k].target=0;
6887
6888                                                                                                                 float gLoc[3];
6889                                                                                                                 float vel[3];
6890                                                                                                                 gLoc[0]=player[k].coords.x;
6891                                                                                                                 gLoc[1]=player[k].coords.y;
6892                                                                                                                 gLoc[2]=player[k].coords.z;
6893                                                                                                                 vel[0]=player[k].velocity.x;
6894                                                                                                                 vel[1]=player[k].velocity.y;
6895                                                                                                                 vel[2]=player[k].velocity.z;
6896                                                                                                                 if(k==0){
6897                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
6898                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6899                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
6900                                                                                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
6901                                                                                                                 }
6902                                                                                                         }
6903                                                                                                         player[k].velocity.y+=gravity;
6904                                                                                                 }
6905                                                                                         }
6906                                                                 }
6907                                                         }
6908                                                         player[k].realoldcoords=player[k].coords;
6909                                                 }
6910
6911                                                 static XYZ oldviewer;
6912
6913                                                 if(indialogue==-1){
6914                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6915                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6916                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6917                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6918                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6919                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6920                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6921                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6922                                                 }
6923                                                 else
6924                                                 {
6925                                                         player[0].forwardkeydown=0;
6926                                                         player[0].leftkeydown=0;
6927                                                         player[0].backkeydown=0;
6928                                                         player[0].rightkeydown=0;
6929                                                         player[0].jumpkeydown=0;
6930                                                         player[0].crouchkeydown=0;
6931                                                         player[0].drawkeydown=0;
6932                                                         player[0].throwkeydown=0;
6933                                                 }
6934
6935                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6936
6937
6938                                                 static bool endkeydown;
6939                                                 if(indialogue!=-1){
6940                                                         cameramode=1;
6941                                                         if(directing){  
6942                                                                 facing=0;
6943                                                                 facing.z=-1;
6944
6945                                                                 facing=DoRotation(facing,-rotation2,0,0);
6946                                                                 facing=DoRotation(facing,0,0-rotation,0);
6947
6948                                                                 flatfacing=0;
6949                                                                 flatfacing.z=-1;
6950
6951                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6952
6953                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6954                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6955                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6956                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6957                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6958                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6959                                                                 if(!endkeydown&&(IsKeyDown(theKeyMap, MAC_1_KEY)||IsKeyDown(theKeyMap, MAC_2_KEY)||IsKeyDown(theKeyMap, MAC_3_KEY)||IsKeyDown(theKeyMap, MAC_4_KEY)||IsKeyDown(theKeyMap, MAC_5_KEY)
6960                                                                         ||IsKeyDown(theKeyMap, MAC_6_KEY)||IsKeyDown(theKeyMap, MAC_7_KEY)||IsKeyDown(theKeyMap, MAC_8_KEY)||IsKeyDown(theKeyMap, MAC_9_KEY)||IsKeyDown(theKeyMap, MAC_0_KEY)
6961                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6962                                                                                 int whichend;
6963                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6964                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6965                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6966                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6967                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6968                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6969                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6970                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6971                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6972                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6973                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6974                                                                                 if(whichend!=-1){
6975                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6976                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6977                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6978                                                                                 }
6979                                                                                 if(whichend==-1){
6980                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6981                                                                                 }
6982                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6983                                                                                         indialogue=-1;
6984                                                                                         directing=0;
6985                                                                                         cameramode=0;
6986                                                                                 }
6987                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6988                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6989                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6990                                                                                 indialogue++;
6991                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6992                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6993                                                                                                 static float gLoc[3];
6994                                                                                                 static float vel[3];
6995                                                                                                 XYZ temppos;
6996                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6997                                                                                                 temppos=temppos-viewer;
6998                                                                                                 Normalise(&temppos);
6999                                                                                                 temppos+=viewer;
7000
7001                                                                                                 gLoc[0]=temppos.x;
7002                                                                                                 gLoc[1]=temppos.y;
7003                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
7004                                                                                                 vel[1]=0;
7005                                                                                                 vel[2]=0;
7006                                                                                                 int whichsoundplay;
7007                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7008                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7009                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7010                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7011                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7012                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7013                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7014                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7015                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7016                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7017                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7018                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7019                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7020                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7021                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7022                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7023                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7024                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7025                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7026                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7027                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
7028                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7029                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
7030                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
7031                                                                                         }
7032                                                                                 }
7033
7034                                                                                 for(j=0;j<numplayers;j++){
7035                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
7036                                                                                 }
7037
7038                                                                                 endkeydown=1;
7039                                                                         }
7040                                                                         if((IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY)
7041                                                                                 ||IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY)
7042                                                                                 )){
7043                                                                                         int whichend;
7044                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
7045                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
7046                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
7047                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
7048                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
7049                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
7050                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
7051                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
7052                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
7053                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
7054                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
7055                                                                                 }
7056                                                                                 if(!IsKeyDown(theKeyMap, MAC_1_KEY)&&!IsKeyDown(theKeyMap, MAC_2_KEY)&&!IsKeyDown(theKeyMap, MAC_3_KEY)&&!IsKeyDown(theKeyMap, MAC_4_KEY)&&!IsKeyDown(theKeyMap, MAC_5_KEY)
7057                                                                                         &&!IsKeyDown(theKeyMap, MAC_6_KEY)&&!IsKeyDown(theKeyMap, MAC_7_KEY)&&!IsKeyDown(theKeyMap, MAC_8_KEY)&&!IsKeyDown(theKeyMap, MAC_9_KEY)&&!IsKeyDown(theKeyMap, MAC_0_KEY)
7058                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7059                                                                                                 endkeydown=0;
7060                                                                                         }
7061                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7062                                                                                                 indialogue=-1;
7063                                                                                                 directing=0;
7064                                                                                                 cameramode=0;
7065                                                                                         }
7066                                                         }
7067                                                         if(!directing){ 
7068                                                                 FSOUND_SetPaused(channels[whooshsound], TRUE);
7069                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
7070                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
7071                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
7072                                                                 }                               
7073                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
7074                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
7075                                                                 if(dialoguetime>0.5)
7076                                                                         if((!endkeydown&&(IsKeyDown(theKeyMap, MAC_1_KEY)||IsKeyDown(theKeyMap, MAC_2_KEY)||IsKeyDown(theKeyMap, MAC_3_KEY)||IsKeyDown(theKeyMap, MAC_4_KEY)||IsKeyDown(theKeyMap, MAC_5_KEY)
7077                                                                                 ||IsKeyDown(theKeyMap, MAC_6_KEY)||IsKeyDown(theKeyMap, MAC_7_KEY)||IsKeyDown(theKeyMap, MAC_8_KEY)||IsKeyDown(theKeyMap, MAC_9_KEY)||IsKeyDown(theKeyMap, MAC_0_KEY)
7078                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
7079                                                                                         indialogue++;
7080                                                                                         endkeydown=1;
7081                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
7082                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
7083                                                                                                         static float gLoc[3];
7084                                                                                                         static float vel[3];
7085                                                                                                         XYZ temppos;
7086                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7087                                                                                                         temppos=temppos-viewer;
7088                                                                                                         Normalise(&temppos);
7089                                                                                                         temppos+=viewer;
7090
7091                                                                                                         gLoc[0]=temppos.x;
7092                                                                                                         gLoc[1]=temppos.y;
7093                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
7094                                                                                                         vel[1]=0;
7095                                                                                                         vel[2]=0;
7096                                                                                                         int whichsoundplay;
7097                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7098                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7099                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7100                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7101                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7102                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7103                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7104                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7105                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7106                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7107                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7108                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7109                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7110                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7111                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7112                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7113                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7114                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7115                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7116                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7117                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
7118                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
7119                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
7120                                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7121                                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
7122                                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
7123                                                                                                         }
7124                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
7125                                                                                                                 hotspot[numhotspots]=player[0].coords;
7126                                                                                                                 hotspotsize[numhotspots]=10;
7127                                                                                                                 hotspottype[numhotspots]=-1;
7128
7129                                                                                                                 numhotspots++;
7130                                                                                                         }
7131                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
7132                                                                                                                 hostile=1;
7133                                                                                                         }
7134
7135                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
7136                                                                                                                 indialogue=-1;
7137                                                                                                                 directing=0;
7138                                                                                                                 cameramode=0;
7139                                                                                                         }
7140                                                                                                 }
7141                                                                                         }
7142                                                                                 }
7143                                                                                 if(!IsKeyDown(theKeyMap, MAC_1_KEY)&&!IsKeyDown(theKeyMap, MAC_2_KEY)&&!IsKeyDown(theKeyMap, MAC_3_KEY)&&!IsKeyDown(theKeyMap, MAC_4_KEY)&&!IsKeyDown(theKeyMap, MAC_5_KEY)
7144                                                                                         &&!IsKeyDown(theKeyMap, MAC_6_KEY)&&!IsKeyDown(theKeyMap, MAC_7_KEY)&&!IsKeyDown(theKeyMap, MAC_8_KEY)&&!IsKeyDown(theKeyMap, MAC_9_KEY)&&!IsKeyDown(theKeyMap, MAC_0_KEY)
7145                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7146                                                                                                 endkeydown=0;
7147                                                                                         }
7148                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7149                                                                                                 indialogue=-1;
7150                                                                                                 directing=0;
7151                                                                                                 cameramode=0;
7152                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
7153                                                                                                         hostile=1;
7154                                                                                                 }
7155                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
7156                                                                                                         windialogue=1;
7157                                                                                                 }
7158                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
7159                                                                                                         hostile=1;
7160                                                                                                         for(i=1;i<numplayers;i++){
7161                                                                                                                 player[i].aitype = attacktypecutoff;
7162                                                                                                         }
7163                                                                                                 }
7164                                                                                         }
7165                                                         }
7166                                                 }
7167
7168                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
7169                                                 else oldbuttondialogue=1;
7170
7171                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
7172
7173                                                 //Net updates
7174
7175                                                 /*keyrefreshdelay-=multiplier;
7176                                                 bigrefreshdelay-=multiplier;
7177
7178                                                 if(keyrefreshdelay<=0){
7179                                                 static int concat[4];
7180
7181                                                 concat[0]=player[0].forwardkeydown;
7182                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
7183                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
7184                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
7185                                                 concat[0]=concat[0]*2+player[0].backkeydown;
7186                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
7187                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
7188                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
7189
7190                                                 concat[1]=player[0].crouchtogglekeydown;
7191                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
7192                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
7193                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
7194                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
7195                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
7196
7197                                                 //concat[2]=(char)((int)(rotation/2)%180);
7198
7199                                                 //concat[3]=(char)((int)(rotation2/2)%180);
7200
7201                                                 chatname[0]=concat[0]-128;
7202                                                 chatname[1]=concat[1]-128;
7203                                                 //chatname[2]=concat[2]-128;
7204                                                 //chatname[3]=concat[3]-128;
7205                                                 int temppoint=2;
7206                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
7207                                                 temppoint+=sizeof(float);
7208                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
7209                                                 temppoint+=sizeof(float);
7210
7211                                                 chatname[temppoint]='\0';
7212
7213                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
7214                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
7215                                                 //keyrefreshdelay=.01;
7216                                                 keyrefreshdelay=.03;
7217                                                 }
7218
7219                                                 if(bigrefreshdelay<=0){
7220                                                 for(i=0;i<1;i++){
7221                                                 /*int temppoint=0;
7222                                                 memcpy(chatname+temppoint,&i,sizeof(int));
7223                                                 temppoint+=sizeof(int);
7224                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
7225                                                 temppoint+=sizeof(float);
7226                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
7227                                                 temppoint+=sizeof(float);
7228                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
7229                                                 temppoint+=sizeof(float);
7230                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
7231                                                 temppoint+=sizeof(float);
7232                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
7233                                                 temppoint+=sizeof(float);
7234                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
7235                                                 temppoint+=sizeof(int);
7236                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
7237                                                 temppoint+=sizeof(int);
7238                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
7239                                                 temppoint+=sizeof(float);
7240                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
7241                                                 temppoint+=sizeof(float);
7242                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
7243                                                 temppoint+=sizeof(float);
7244                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
7245                                                 temppoint+=sizeof(int);
7246                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
7247                                                 temppoint+=sizeof(int);
7248                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
7249                                                 temppoint+=sizeof(float);
7250                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
7251                                                 temppoint+=sizeof(float);
7252                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
7253                                                 temppoint+=sizeof(float);
7254                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
7255                                                 temppoint+=sizeof(int);
7256                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
7257                                                 temppoint+=sizeof(int);
7258                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
7259                                                 temppoint+=sizeof(int);
7260                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
7261                                                 temppoint+=sizeof(int);
7262                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
7263                                                 temppoint+=sizeof(int);
7264                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
7265                                                 temppoint+=sizeof(int);
7266                                                 chatname[temppoint]='\0';
7267
7268                                                 sprintf (chatname, "%d %f %f %f %f %f %d %d %f %f %f %d %d %f %f %f",i,player[i].coords.x,player[i].coords.y,player[i].coords.z,player[i].damage,player[i].target, player[i].targetanimation, player[i].currentanimation, player[i].velocity.x, player[i].velocity.y, player[i].velocity.z, player[i].targetframe, player[i].currentframe, player[i].rotation, player[i].targetrotation);
7269                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
7270                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
7271
7272                                                 sprintf (chatname, "%d %f %d %d %d %d %d %d %d %d %f",i,player[i].bloodloss, player[i].weaponactive, player[i].num_weapons, player[i].weaponids[0], player[i].weaponids[1], player[i].weaponids[2], player[i].weaponids[3],player[i].dead,player[i].skeleton.free,player[i].permanentdamage);
7273
7274                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
7275                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
7276                                                 }
7277                                                 //bigrefreshdelay=.02;
7278                                                 bigrefreshdelay=.1;
7279                                                 }
7280                                                 }*/
7281
7282                                                 if(!player[0].jumpkeydown){
7283                                                         player[0].jumptogglekeydown=0;
7284                                                 }
7285                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
7286
7287
7288                                                 dialoguetime+=multiplier;
7289                                                 skybox.cloudmove+=multiplier;
7290                                                 hawkrotation+=multiplier*25;
7291                                                 realhawkcoords=0;
7292                                                 realhawkcoords.x=25;
7293                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
7294                                                 hawkcalldelay-=multiplier/2;
7295
7296                                                 if(hawkcalldelay<=0)
7297                                                 {
7298                                                         static float gLoc[3];
7299                                                         static float vel[3];
7300                                                         gLoc[0]=realhawkcoords.x;
7301                                                         gLoc[1]=realhawkcoords.y;
7302                                                         gLoc[2]=realhawkcoords.z;
7303                                                         vel[0]=0;
7304                                                         vel[1]=0;
7305                                                         vel[2]=0;
7306                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, TRUE);
7307                                                         FSOUND_3D_SetAttributes(channels[hawksound], gLoc, vel);
7308                                                         FSOUND_SetVolume(channels[hawksound], 128);
7309                                                         FSOUND_SetPaused(channels[hawksound], FALSE);
7310
7311                                                         hawkcalldelay=16+abs(Random()%8);
7312                                                 }
7313                                                 static float temptexdetail;
7314
7315
7316                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7317                                                         player[0].damagetolerance=200000;
7318                                                         player[0].damage=0;
7319                                                         player[0].burnt=0;
7320                                                         player[0].permanentdamage=0;
7321                                                         player[0].superpermanentdamage=0;
7322                                                         /*
7323                                                         int whichchar;
7324                                                         whichchar = abs(Random()%7);
7325                                                         registrationname[whichchar]+=1;
7326                                                         */
7327                                                 }
7328
7329                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7330                                                         environment++;
7331                                                         if(environment>2)environment=0;
7332                                                         Setenvironment(environment);
7333
7334                                                         envtogglekeydown=1;
7335                                                 }
7336
7337
7338                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7339                                                         envtogglekeydown=0;
7340                                                 }
7341
7342                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7343                                                         cameramode=1-cameramode;
7344                                                         cameratogglekeydown=1;
7345                                                 }
7346
7347                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7348                                                         cameratogglekeydown=0;
7349                                                 }
7350
7351                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7352                                                         if(player[0].num_weapons>0){
7353                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7354                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7355                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7356                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7357                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7358                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7359                                                                         weapons.length[player[0].weaponids[0]]=.8;
7360                                                                 }
7361                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7362                                                                         weapons.mass[player[0].weaponids[0]]=2;
7363                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7364                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7365                                                                 }
7366
7367                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7368                                                                         weapons.mass[player[0].weaponids[0]]=1;
7369                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7370                                                                         weapons.length[player[0].weaponids[0]]=.25;
7371                                                                 }
7372                                                         }
7373
7374                                                         /*for(i=0;i<objects.numobjects;i++){
7375                                                         if(objects.type[i]==treeleavestype){
7376                                                         for(j=0;j<objects.numobjects;j++){
7377                                                         if(objects.type[j]==treetrunktype)
7378                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7379                                                         objects.scale[i]=objects.scale[j];      
7380                                                         }
7381                                                         }
7382                                                         }*/
7383                                                         detailtogglekeydown=1;
7384                                                 }
7385
7386                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7387                                                         int closest=-1;
7388                                                         float closestdist=-1;
7389                                                         float distance;
7390                                                         if(numplayers>1)
7391                                                                 for(i=1;i<numplayers;i++){
7392                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7393                                                                         if(closestdist==-1||distance<closestdist){
7394                                                                                 closestdist=distance;
7395                                                                                 closest=i;
7396                                                                         }
7397                                                                 }
7398                                                                 if(closest!=-1){
7399                                                                         if(player[closest].num_weapons)
7400                                                                         {
7401                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7402                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7403                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7404                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7405                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7406                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7407                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7408                                                                                 }
7409                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7410                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7411                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7412                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7413                                                                                 }
7414                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7415                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7416                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7417                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7418                                                                                 }
7419                                                                         }
7420                                                                         if(!player[closest].num_weapons)
7421                                                                         {
7422                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7423                                                                                 weapons.owner[weapons.numweapons]=closest;
7424                                                                                 weapons.type[weapons.numweapons]=knife;
7425                                                                                 weapons.damage[weapons.numweapons]=0;
7426                                                                                 weapons.numweapons++;
7427                                                                                 player[closest].num_weapons=1;
7428                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7429                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7430                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7431                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7432                                                                                 }
7433                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7434                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7435                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7436                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7437                                                                                 }
7438                                                                         }
7439                                                                 }
7440                                                                 detailtogglekeydown=1;
7441                                                 }
7442
7443                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7444                                                         int closest=-1;
7445                                                         float closestdist=-1;
7446                                                         float distance;
7447                                                         if(numplayers>1)
7448                                                                 for(i=1;i<numplayers;i++){
7449                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7450                                                                         if(closestdist==-1||distance<closestdist){
7451                                                                                 closestdist=distance;
7452                                                                                 closest=i;
7453                                                                         }
7454                                                                 }
7455
7456                                                                 player[closest].rotation+=multiplier*50;
7457                                                                 player[closest].targetrotation=player[closest].rotation;
7458                                                 }
7459
7460
7461                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7462                                                         int closest=-1;
7463                                                         float closestdist=-1;
7464                                                         float distance;
7465                                                         if(numplayers>1)
7466                                                                 for(i=1;i<numplayers;i++){
7467                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7468                                                                         if(closestdist==-1||distance<closestdist){
7469                                                                                 closestdist=distance;
7470                                                                                 closest=i;
7471                                                                         }
7472                                                                 }
7473                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7474
7475                                                                 if(closest!=-1){
7476                                                                         player[closest].whichskin++;
7477                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7478                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7479
7480                                                                         if(player[closest].creature==rabbittype){
7481                                                                                 if(player[closest].whichskin==0){
7482                                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7483                                                                                 }
7484                                                                                 else if(player[closest].whichskin==1){
7485                                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7486                                                                                 }
7487                                                                                 else if(player[closest].whichskin==2){
7488                                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7489                                                                                 }
7490                                                                                 else if(player[closest].whichskin==3){
7491                                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7492                                                                                 }
7493                                                                                 else if(player[closest].whichskin==4){
7494                                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7495                                                                                 }
7496                                                                                 else if(player[closest].whichskin==5){
7497                                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7498                                                                                 }
7499                                                                                 else if(player[closest].whichskin==6){
7500                                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7501                                                                                 }
7502                                                                                 else if(player[closest].whichskin==7){
7503                                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7504                                                                                 }
7505                                                                                 else if(player[closest].whichskin==8){
7506                                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7507                                                                                 }
7508                                                                                 else if(player[closest].whichskin==9){
7509                                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7510                                                                                 }
7511                                                                         }
7512                                                                         if(player[closest].creature==wolftype){
7513                                                                                 k=abs(Random()%3);
7514                                                                                 if(player[closest].whichskin==0){
7515                                                                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7516                                                                                 }
7517                                                                                 else if(player[closest].whichskin==1){
7518                                                                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7519                                                                                 }
7520                                                                                 else if(player[closest].whichskin==2){
7521                                                                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7522                                                                                 }
7523                                                                         }
7524                                                                 }
7525
7526                                                                 if(player[closest].numclothes){
7527                                                                         for(i=0;i<player[closest].numclothes;i++){
7528                                                                                 tintr=player[closest].clothestintr[i];
7529                                                                                 tintg=player[closest].clothestintg[i];
7530                                                                                 tintb=player[closest].clothestintb[i];
7531                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7532                                                                         }
7533                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7534                                                                 }
7535
7536                                                                 detailtogglekeydown=1;
7537                                                 }
7538
7539                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7540                                                         int closest=-1;
7541                                                         float closestdist=-1;
7542                                                         float distance;
7543                                                         if(numplayers>1)
7544                                                                 for(i=1;i<numplayers;i++){
7545                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7546                                                                         if(closestdist==-1||distance<closestdist){
7547                                                                                 closestdist=distance;
7548                                                                                 closest=i;
7549                                                                         }
7550                                                                 }
7551                                                                 if(closest!=-1){
7552                                                                         if(player[closest].creature==wolftype){
7553                                                                                 headprop=player[closest].proportionhead.x/1.1;
7554                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7555                                                                                 armprop=player[closest].proportionarms.x/1.1;
7556                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7557                                                                         }
7558
7559                                                                         if(player[closest].creature==rabbittype){
7560                                                                                 headprop=player[closest].proportionhead.x/1.2;
7561                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7562                                                                                 armprop=player[closest].proportionarms.x/1.00;
7563                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7564                                                                         }
7565
7566
7567                                                                         if(player[closest].creature==rabbittype){
7568                                                                                 player[closest].skeleton.id=closest;
7569                                                                                 player[closest].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
7570                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7571                                                                                 player[closest].whichskin=0;
7572                                                                                 player[closest].creature=wolftype;
7573
7574                                                                                 player[closest].proportionhead=1.1;
7575                                                                                 player[closest].proportionbody=1.1;
7576                                                                                 player[closest].proportionarms=1.1;
7577                                                                                 player[closest].proportionlegs=1.1;
7578                                                                                 player[closest].proportionlegs.y=1.1;
7579                                                                                 player[closest].scale=.23*5*player[0].scale;
7580
7581                                                                                 player[closest].damagetolerance=300;
7582                                                                         }
7583                                                                         else
7584                                                                         {
7585                                                                                 player[closest].skeleton.id=closest;
7586                                                                                 player[closest].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
7587                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7588                                                                                 player[closest].whichskin=0;
7589                                                                                 player[closest].creature=rabbittype;
7590
7591                                                                                 player[closest].proportionhead=1.2;
7592                                                                                 player[closest].proportionbody=1.05;
7593                                                                                 player[closest].proportionarms=1.00;
7594                                                                                 player[closest].proportionlegs=1.1;
7595                                                                                 player[closest].proportionlegs.y=1.05;
7596                                                                                 player[closest].scale=.2*5*player[0].scale;
7597
7598                                                                                 player[closest].damagetolerance=200;
7599                                                                         }
7600
7601                                                                         if(player[closest].creature==wolftype){
7602                                                                                 player[closest].proportionhead=1.1*headprop;
7603                                                                                 player[closest].proportionbody=1.1*bodyprop;
7604                                                                                 player[closest].proportionarms=1.1*armprop;
7605                                                                                 player[closest].proportionlegs=1.1*legprop;
7606                                                                         }
7607
7608                                                                         if(player[closest].creature==rabbittype){
7609                                                                                 player[closest].proportionhead=1.2*headprop;
7610                                                                                 player[closest].proportionbody=1.05*bodyprop;
7611                                                                                 player[closest].proportionarms=1.00*armprop;
7612                                                                                 player[closest].proportionlegs=1.1*legprop;
7613                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7614                                                                         }
7615
7616                                                                 }
7617                                                                 detailtogglekeydown=1;
7618                                                 }
7619
7620                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7621                                                         detailtogglekeydown=0;
7622                                                 }
7623
7624                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7625                                                         slomo=1-slomo;
7626                                                         slomodelay=1000;
7627                                                         slomotogglekeydown=1;
7628                                                 }
7629
7630
7631                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7632                                                         int closest=-1;
7633                                                         float closestdist=-1;
7634                                                         float distance;
7635                                                         XYZ flatfacing2,flatvelocity2;
7636                                                         XYZ blah;
7637                                                         if(numplayers>1)
7638                                                                 for(i=1;i<numplayers;i++){
7639                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7640                                                                         if(distance<144&&!player[i].headless)
7641                                                                                 if(closestdist==-1||distance<closestdist){
7642                                                                                         closestdist=distance;
7643                                                                                         closest=i;
7644                                                                                         blah = player[i].coords;
7645                                                                                 }
7646                                                                 }
7647
7648                                                                 if(closest!=-1){                
7649                                                                         XYZ headspurtdirection;
7650                                                                         int i = player[closest].skeleton.jointlabels[head];
7651                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7652                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7653                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7654                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
7655                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7656                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7657                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7658                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7659                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7660                                                                                 Normalise(&headspurtdirection);
7661                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7662                                                                                 flatvelocity2+=headspurtdirection*8;
7663                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7664                                                                         }
7665                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7666
7667                                                                         float gLoc[3];
7668                                                                         float vel[3];
7669                                                                         gLoc[0]=blah.x;
7670                                                                         gLoc[1]=blah.y;
7671                                                                         gLoc[2]=blah.z;
7672                                                                         vel[0]=0;
7673                                                                         vel[1]=0;
7674                                                                         vel[2]=0;
7675                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
7676                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7677                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7678                                                                         FSOUND_SetPaused(channels[splattersound], FALSE);
7679
7680                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
7681                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7682                                                                         FSOUND_SetVolume(channels[breaksound2], 100);
7683                                                                         FSOUND_SetPaused(channels[breaksound2], FALSE);
7684
7685                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7686                                                                         player[closest].RagDoll(0);
7687                                                                         player[closest].dead=2;
7688                                                                         player[closest].headless=1;
7689                                                                         player[closest].DoBloodBig(3,165);
7690
7691                                                                         camerashake+=.3;
7692                                                                 }
7693
7694                                                                 explodetogglekeydown=1;
7695                                                 }
7696
7697                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7698                                                         int closest=-1;
7699                                                         float closestdist=-1;
7700                                                         float distance;
7701                                                         XYZ flatfacing2,flatvelocity2;
7702                                                         XYZ blah;
7703                                                         if(numplayers>1)
7704                                                                 for(i=1;i<numplayers;i++){
7705                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7706                                                                         if(distance<144)
7707                                                                                 if(closestdist==-1||distance<closestdist){
7708                                                                                         closestdist=distance;
7709                                                                                         closest=i;
7710                                                                                         blah=player[i].coords;
7711                                                                                 }
7712                                                                 }
7713
7714                                                                 if(closest!=-1){                
7715                                                                         float gLoc[3];
7716                                                                         float vel[3];
7717                                                                         gLoc[0]=blah.x;
7718                                                                         gLoc[1]=blah.y;
7719                                                                         gLoc[2]=blah.z;
7720                                                                         vel[0]=0;
7721                                                                         vel[1]=0;
7722                                                                         vel[2]=0;
7723
7724                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
7725                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7726                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7727                                                                         FSOUND_SetPaused(channels[splattersound], FALSE);
7728
7729                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
7730                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7731                                                                         FSOUND_SetVolume(channels[breaksound2], 600);
7732                                                                         FSOUND_SetPaused(channels[breaksound2], FALSE);
7733
7734                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7735                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7736                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7737                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
7738                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7739                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7740                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7741                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7742                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7743                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7744                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7745                                                                         }
7746
7747                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7748                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7749                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7750                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
7751                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7752                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7753                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7754                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7755                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7756                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7757                                                                         }
7758
7759                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7760                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7761                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7762                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
7763                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7764                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7765                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7766                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7767                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7768                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7769                                                                         }
7770
7771                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7772                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7773                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7774                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
7775                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7776                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7777                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7778                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7779                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7780                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7781                                                                         }
7782
7783                                                                         XYZ temppos;
7784                                                                         for(j=0;j<numplayers; j++){
7785                                                                                 if(j!=closest){
7786                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7787                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7788                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7789                                                                                                 player[j].skeleton.longdead=0;
7790                                                                                                 player[j].RagDoll(0);
7791                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7792                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7793                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7794                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7795                                                                                                                 Normalise(&flatvelocity2);
7796                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7797                                                                                                         }
7798                                                                                                 }
7799                                                                                         }
7800                                                                                 }
7801                                                                         }
7802
7803                                                                         player[closest].DoDamage(10000);
7804                                                                         player[closest].RagDoll(0);
7805                                                                         player[closest].dead=2;
7806                                                                         player[closest].coords=20;
7807                                                                         player[closest].skeleton.free=2;
7808
7809                                                                         camerashake+=.6;
7810
7811                                                                 }
7812
7813                                                                 explodetogglekeydown=1;
7814                                                 }
7815
7816                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7817                                                         explodetogglekeydown=0;
7818                                                 }
7819
7820                                                 /*
7821                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7822                                                 FILE                    *tfile;
7823                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7824                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7825                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7826                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7827                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7828                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7829                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7830
7831                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7832                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7833                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7834                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7835                                                 for(j=0;j<player[0].num_weapons;j++){
7836                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7837                                                 }
7838                                                 fwrite( &environment, 1, sizeof(int), tfile );
7839
7840                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7841                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7842                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7843                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7844                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7845
7846                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7847                                                 if(numplayers>1&&numplayers<maxplayers)
7848                                                 for(i=1;i<numplayers;i++){
7849                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7850                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7851                                                 for(j=0;j<player[i].num_weapons;j++){
7852                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7853                                                 }
7854                                                 if(player[i].numwaypoints<30){
7855                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7856                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7857                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7858                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7859                                                 }
7860                                                 else{
7861                                                 player[i].numwaypoints=0;
7862                                                 player[i].waypoint=0;
7863                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7864                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7865                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7866                                                 }
7867                                                 }
7868
7869                                                 fclose(tfile);
7870
7871                                                 slomotogglekeydown=1;
7872                                                 }*/
7873
7874                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7875                                                         slomotogglekeydown=0;
7876                                                 }
7877
7878
7879                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7880                                                         player[0].onfire=1-player[0].onfire;
7881                                                         if(player[0].onfire){
7882                                                                 player[0].CatchFire();
7883                                                         }
7884                                                         if(!player[0].onfire){
7885                                                                 float gLoc[3];
7886                                                                 float vel[3];
7887                                                                 gLoc[0]=player[0].coords.x;
7888                                                                 gLoc[1]=player[0].coords.y;
7889                                                                 gLoc[2]=player[0].coords.z;
7890                                                                 vel[0]=0;
7891                                                                 vel[1]=0;
7892                                                                 vel[2]=0;
7893                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
7894                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7895                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
7896                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
7897                                                                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
7898                                                         }
7899                                                         slomotogglekeydown=1;
7900                                                 }
7901                                                 /*
7902                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7903                                                 if(player[0].bleeding<=0)
7904                                                 player[0].DoBlood(1,255);
7905                                                 }*/
7906
7907
7908                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7909                                                         int closest=-1;
7910                                                         float closestdist=-1;
7911                                                         float distance;
7912                                                         if(numplayers>1)
7913                                                                 for(i=1;i<numplayers;i++){
7914                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7915                                                                         if(closestdist==-1||distance<closestdist){
7916                                                                                 closestdist=distance;
7917                                                                                 closest=i;
7918                                                                         }
7919                                                                 }
7920                                                                 if(closestdist>0&&closest>=0){
7921                                                                         //player[closest]=player[numplayers-1];
7922                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7923                                                                         numplayers--;
7924                                                                 }
7925                                                                 drawmodetogglekeydown=1;
7926                                                 }
7927
7928                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7929                                                         int closest=-1;
7930                                                         float closestdist=-1;
7931                                                         float distance;
7932                                                         if(max_objects>1)
7933                                                                 for(i=1;i<max_objects;i++){
7934                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7935                                                                         if(closestdist==-1||distance<closestdist){
7936                                                                                 closestdist=distance;
7937                                                                                 closest=i;
7938                                                                         }
7939                                                                 }
7940                                                                 if(closestdist>0&&closest>=0){
7941                                                                         objects.position[closest].y-=500;
7942                                                                 }
7943                                                                 drawmodetogglekeydown=1;
7944                                                 }
7945
7946                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7947                                                         //drawmode++;
7948                                                         //if(drawmode>2)drawmode=0;
7949                                                         if(objects.numobjects<max_objects-1){                   
7950                                                                 XYZ boxcoords;
7951                                                                 boxcoords.x=player[0].coords.x;
7952                                                                 boxcoords.z=player[0].coords.z;
7953                                                                 boxcoords.y=player[0].coords.y-3;
7954                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7955                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7956                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7957                                                                 float temprotat,temprotat2;
7958                                                                 temprotat=editorrotation;
7959                                                                 temprotat2=editorrotation2;
7960                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7961                                                                 if(temprotat2<0)temprotat2=Random()%360;
7962
7963                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7964                                                                 if(editortype==treetrunktype)
7965                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7966                                                         }
7967
7968                                                         drawmodetogglekeydown=1;
7969                                                 }
7970
7971                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7972                                                         if(numplayers<maxplayers-1){
7973                                                                 player[numplayers].scale=.2*5*player[0].scale;
7974                                                                 player[numplayers].creature=rabbittype;
7975                                                                 player[numplayers].howactive=editoractive;
7976                                                                 player[numplayers].skeleton.id=numplayers;
7977                                                                 player[numplayers].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
7978
7979                                                                 //texsize=512*512*3/texdetail/texdetail;
7980                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7981                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7982
7983                                                                 k=abs(Random()%2)+1;
7984                                                                 if(k==0){
7985                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7986                                                                         player[numplayers].whichskin=0;
7987                                                                 }
7988                                                                 else if(k==1){
7989                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7990                                                                         player[numplayers].whichskin=1;
7991                                                                 }
7992                                                                 else {
7993                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7994                                                                         player[numplayers].whichskin=2;
7995                                                                 }
7996
7997                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7998                                                                 player[numplayers].power=1;
7999                                                                 player[numplayers].speedmult=1;
8000                                                                 player[numplayers].currentanimation=bounceidleanim;
8001                                                                 player[numplayers].targetanimation=bounceidleanim;
8002                                                                 player[numplayers].currentframe=0;
8003                                                                 player[numplayers].targetframe=1;
8004                                                                 player[numplayers].target=0;
8005                                                                 player[numplayers].bled=0;
8006                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
8007
8008                                                                 player[numplayers].targetrotation=player[0].targetrotation;
8009                                                                 player[numplayers].rotation=player[0].rotation;
8010
8011                                                                 player[numplayers].velocity=0;
8012                                                                 player[numplayers].coords=player[0].coords;
8013                                                                 player[numplayers].oldcoords=player[numplayers].coords;
8014                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
8015
8016                                                                 player[numplayers].id=numplayers;
8017                                                                 player[numplayers].skeleton.id=numplayers;
8018                                                                 player[numplayers].updatedelay=0;
8019                                                                 player[numplayers].normalsupdatedelay=0;
8020
8021                                                                 player[numplayers].aitype=passivetype;
8022                                                                 player[numplayers].aitarget=0;
8023
8024                                                                 if(player[0].creature==wolftype){
8025                                                                         headprop=player[0].proportionhead.x/1.1;
8026                                                                         bodyprop=player[0].proportionbody.x/1.1;
8027                                                                         armprop=player[0].proportionarms.x/1.1;
8028                                                                         legprop=player[0].proportionlegs.x/1.1;
8029                                                                 }
8030
8031                                                                 if(player[0].creature==rabbittype){
8032                                                                         headprop=player[0].proportionhead.x/1.2;
8033                                                                         bodyprop=player[0].proportionbody.x/1.05;
8034                                                                         armprop=player[0].proportionarms.x/1.00;
8035                                                                         legprop=player[0].proportionlegs.x/1.1;
8036                                                                 }
8037
8038                                                                 if(player[numplayers].creature==wolftype){
8039                                                                         player[numplayers].proportionhead=1.1*headprop;
8040                                                                         player[numplayers].proportionbody=1.1*bodyprop;
8041                                                                         player[numplayers].proportionarms=1.1*armprop;
8042                                                                         player[numplayers].proportionlegs=1.1*legprop;
8043                                                                 }
8044
8045                                                                 if(player[numplayers].creature==rabbittype){
8046                                                                         player[numplayers].proportionhead=1.2*headprop;
8047                                                                         player[numplayers].proportionbody=1.05*bodyprop;
8048                                                                         player[numplayers].proportionarms=1.00*armprop;
8049                                                                         player[numplayers].proportionlegs=1.1*legprop;
8050                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
8051                                                                 }
8052
8053                                                                 player[numplayers].headless=0;
8054                                                                 player[numplayers].onfire=0;
8055
8056                                                                 if(cellophane){
8057                                                                         player[numplayers].proportionhead.z=0;
8058                                                                         player[numplayers].proportionbody.z=0;
8059                                                                         player[numplayers].proportionarms.z=0;
8060                                                                         player[numplayers].proportionlegs.z=0;
8061                                                                 }
8062
8063                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
8064
8065                                                                 player[numplayers].damagetolerance=200;
8066
8067                                                                 player[numplayers].protectionhead=player[0].protectionhead;
8068                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
8069                                                                 player[numplayers].protectionlow=player[0].protectionlow;
8070                                                                 player[numplayers].armorhead=player[0].armorhead;
8071                                                                 player[numplayers].armorhigh=player[0].armorhigh;
8072                                                                 player[numplayers].armorlow=player[0].armorlow;
8073                                                                 player[numplayers].metalhead=player[0].metalhead;
8074                                                                 player[numplayers].metalhigh=player[0].metalhigh;
8075                                                                 player[numplayers].metallow=player[0].metallow;
8076
8077                                                                 player[numplayers].immobile=player[0].immobile;
8078
8079                                                                 player[numplayers].numclothes=player[0].numclothes;
8080                                                                 if(player[numplayers].numclothes)
8081                                                                         for(i=0;i<player[numplayers].numclothes;i++){
8082                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
8083                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
8084                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
8085                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
8086                                                                                 tintr=player[numplayers].clothestintr[i];
8087                                                                                 tintg=player[numplayers].clothestintg[i];
8088                                                                                 tintb=player[numplayers].clothestintb[i];
8089                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8090                                                                         }
8091                                                                         if(player[numplayers].numclothes){
8092                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
8093                                                                         }
8094
8095                                                                         player[numplayers].power=player[0].power;
8096                                                                         player[numplayers].speedmult=player[0].speedmult;
8097
8098                                                                         player[numplayers].damage=0;
8099                                                                         player[numplayers].permanentdamage=0;
8100                                                                         player[numplayers].superpermanentdamage=0;
8101                                                                         player[numplayers].deathbleeding=0;
8102                                                                         player[numplayers].bleeding=0;
8103                                                                         player[numplayers].numwaypoints=0;
8104                                                                         player[numplayers].waypoint=0;
8105                                                                         player[numplayers].jumppath=0;
8106                                                                         player[numplayers].weaponstuck=-1;
8107                                                                         player[numplayers].weaponactive=-1;
8108                                                                         player[numplayers].num_weapons=0;
8109                                                                         player[numplayers].bloodloss=0;
8110                                                                         player[numplayers].dead=0;
8111
8112                                                                         player[numplayers].loaded=1;
8113
8114                                                                         numplayers++;
8115                                                         }
8116                                                         drawmodetogglekeydown=1;
8117                                                 }
8118
8119                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
8120                                                         if(player[numplayers-1].numwaypoints<90){
8121                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
8122                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
8123                                                                 player[numplayers-1].numwaypoints++;
8124                                                         }
8125                                                         drawmodetogglekeydown=1;
8126                                                 }
8127
8128                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
8129                                                         if(numpathpoints<30){
8130                                                                 bool connected,alreadyconnected;
8131                                                                 connected=0;
8132                                                                 if(numpathpoints>1)
8133                                                                         for(i=0;i<numpathpoints;i++){
8134                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
8135                                                                                         alreadyconnected=0;
8136                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
8137                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
8138                                                                                         }
8139                                                                                         if(!alreadyconnected){
8140                                                                                                 numpathpointconnect[pathpointselected]++;
8141                                                                                                 connected=1;
8142                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
8143                                                                                         }
8144                                                                                 }
8145                                                                         }
8146                                                                         if(!connected){
8147                                                                                 numpathpoints++;
8148                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
8149                                                                                 numpathpointconnect[numpathpoints-1]=0;
8150                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
8151                                                                                         numpathpointconnect[pathpointselected]++;
8152                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
8153                                                                                 }
8154                                                                                 pathpointselected=numpathpoints-1;
8155                                                                         }
8156                                                         }
8157                                                         drawmodetogglekeydown=1;
8158                                                 }
8159
8160                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
8161                                                         pathpointselected++;
8162                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
8163                                                         drawmodetogglekeydown=1;
8164                                                 }
8165                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8166                                                         pathpointselected--;
8167                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
8168                                                         drawmodetogglekeydown=1;
8169                                                 }
8170                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8171                                                         if(pathpointselected!=-1){
8172                                                                 numpathpoints--;
8173                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
8174                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
8175                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
8176                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
8177                                                                 }
8178                                                                 for(i=0;i<numpathpoints;i++){
8179                                                                         for(j=0;j<numpathpointconnect[i];j++){
8180                                                                                 if(pathpointconnect[i][j]==pathpointselected){
8181                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
8182                                                                                         numpathpointconnect[i]--;
8183                                                                                 }
8184                                                                                 if(pathpointconnect[i][j]==numpathpoints){
8185                                                                                         pathpointconnect[i][j]=pathpointselected;
8186                                                                                 }
8187                                                                         }
8188                                                                 }
8189                                                                 pathpointselected=numpathpoints-1;
8190                                                         }
8191                                                         drawmodetogglekeydown=1;
8192                                                 }
8193
8194                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
8195                                                         editorenabled=1-editorenabled;
8196                                                         if(editorenabled){
8197                                                                 player[0].damagetolerance=100000;
8198                                                                 player[0].damage=0;
8199                                                                 player[0].superpermanentdamage=0;
8200                                                                 player[0].bloodloss=0;
8201                                                                 player[0].deathbleeding=0;
8202                                                         }
8203                                                         if(!editorenabled){
8204                                                                 player[0].damagetolerance=200;
8205                                                                 player[0].damage=0;
8206                                                                 player[0].permanentdamage=0;
8207                                                                 player[0].superpermanentdamage=0;
8208                                                                 player[0].bloodloss=0;
8209                                                                 player[0].deathbleeding=0;
8210                                                         }
8211                                                         drawmodetogglekeydown=1;
8212                                                 }
8213
8214                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8215                                                         editortype--;
8216                                                         if(editortype==treeleavestype||editortype==10)editortype--;
8217                                                         if(editortype<0)editortype=firetype;
8218                                                         drawmodetogglekeydown=1;
8219                                                 }
8220
8221                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8222                                                         editortype++;
8223                                                         if(editortype==treeleavestype||editortype==10)editortype++;
8224                                                         if(editortype>firetype)editortype=0;
8225                                                         drawmodetogglekeydown=1;
8226                                                 }
8227
8228                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8229                                                         editorrotation-=multiplier*100;
8230                                                         if(editorrotation<-.01)editorrotation=-.01;
8231                                                         drawmodetogglekeydown=1;
8232                                                 }
8233
8234                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8235                                                         editorrotation+=multiplier*100;
8236                                                         drawmodetogglekeydown=1;
8237                                                 }
8238
8239                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8240                                                         editorsize+=multiplier;
8241                                                         drawmodetogglekeydown=1;
8242                                                 }
8243
8244                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8245                                                         editorsize-=multiplier;
8246                                                         if(editorsize<.1)editorsize=.1;
8247                                                         drawmodetogglekeydown=1;
8248                                                 }
8249
8250
8251                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8252                                                         mapradius-=multiplier*10;
8253                                                 }
8254
8255                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8256                                                         mapradius+=multiplier*10;
8257                                                 }
8258                                                 /*
8259                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8260                                                 mapcenter.x+=multiplier*20;
8261                                                 }
8262
8263                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8264                                                 mapcenter.x-=multiplier*20;
8265                                                 }
8266
8267                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8268                                                 mapcenter.z+=multiplier*20;
8269                                                 }
8270
8271                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8272                                                 mapcenter.z-=multiplier*20;
8273                                                 }
8274                                                 */
8275                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8276                                                         editorrotation2+=multiplier*100;
8277                                                 }
8278
8279                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8280                                                         editorrotation2-=multiplier*100;
8281                                                         if(editorrotation2<-.01)editorrotation2=-.01;
8282                                                 }
8283                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
8284                                                         int closest=-1;
8285                                                         float closestdist=-1;
8286                                                         float distance;
8287                                                         for(i=0;i<objects.numobjects;i++){
8288                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
8289                                                                 if(closestdist==-1||distance<closestdist){
8290                                                                         closestdist=distance;
8291                                                                         closest=i;
8292                                                                 }
8293                                                         }
8294                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);             
8295                                                         drawmodetogglekeydown=1;
8296                                                 }
8297
8298
8299                                                 if(!IsKeyDown(theKeyMap, MAC_M_KEY)&&!IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&!IsKeyDown(theKeyMap, MAC_P_KEY)){
8300                                                         drawmodetogglekeydown=0;
8301                                                 }
8302
8303                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8304                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8305                                                         player[0].RagDoll(0);
8306                                                         //player[0].spurt=1;
8307                                                         //player[0].DoDamage(1000);
8308
8309                                                         float gLoc[3];
8310                                                         float vel[3];
8311                                                         gLoc[0]=player[0].coords.x;
8312                                                         gLoc[1]=player[0].coords.y;
8313                                                         gLoc[2]=player[0].coords.z;
8314                                                         vel[0]=player[0].velocity.x;
8315                                                         vel[1]=player[0].velocity.y;
8316                                                         vel[2]=player[0].velocity.z;
8317                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
8318                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8319                                                         FSOUND_SetVolume(channels[whooshsound], 128);
8320                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
8321                                                         //FSOUND_SetPaused(channels[whooshsound], TRUE);
8322
8323                                                         texturesizetogglekeydown=1;
8324                                                 }
8325
8326                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8327
8328                                                         int closest=-1;
8329                                                         float closestdist=-1;
8330                                                         float distance;
8331                                                         for(i=0;i<objects.numobjects;i++){
8332                                                                 if(objects.type[i]==treeleavestype){
8333                                                                         objects.scale[i]*=.9;
8334                                                                 }
8335                                                         }
8336                                                         texturesizetogglekeydown=1;
8337                                                 }
8338
8339                                                 static XYZ relative;
8340                                                 static int randattack;
8341                                                 //Attack
8342                                                 static bool playerrealattackkeydown=0;
8343
8344                                                 if(!buttons[0])oldbutton=0;
8345                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8346                                                 if(oldattackkey)player[0].attackkeydown=0;
8347                                                 if(oldattackkey)playerrealattackkeydown=0;
8348                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8349                                                 if((player[0].parriedrecently<=0||player[0].weaponactive==-1)&&(!oldattackkey||(realthreat&&player[0].lastattack!=swordslashanim&&player[0].lastattack!=knifeslashstartanim&&player[0].lastattack!=staffhitanim&&player[0].lastattack!=staffspinhitanim)))player[0].attackkeydown=IsKeyDown(theKeyMap, attackkey);
8350                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8351                                                         for(k=0;k<numplayers;k++){
8352                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8353                                                                         player[k].Reverse();
8354                                                         }
8355                                                 }
8356
8357                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8358
8359                                                 for(k=0;k<numplayers;k++){
8360                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8361                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8362                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
8363                                                                 if(player[k].attackkeydown&&player[k].jumppower<=1&&player[k].backkeydown&&player[k].targetanimation!=backhandspringanim&&(player[k].isIdle()||player[k].isStop()||player[k].isRun()||player[k].targetanimation==walkanim)){
8364                                                                         player[k].jumppower-=2;
8365                                                                 }
8366                                                                 if(player[k].attackkeydown&&player[k].jumppower>1&&player[k].backkeydown&&player[k].targetanimation!=backhandspringanim&&(player[k].isIdle()||player[k].isStop()||player[k].isRun()||player[k].targetanimation==walkanim)){
8367                                                                         for(i=0;i<numplayers;i++){
8368                                                                                 if(i==k)i++;
8369                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8370                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8371                                                                                                 player[k].targetanimation=dodgebackanim;
8372                                                                                                 player[k].target=0;
8373                                                                                                 player[k].targetframe=0;
8374                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8375                                                                                                 Normalise(&rotatetarget);
8376                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8377                                                                                                 player[k].targetrotation*=360/6.28;
8378                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8379
8380                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8381                                                                                         }
8382                                                                         }
8383                                                                         if(player[k].targetanimation!=dodgebackanim){
8384                                                                                 if(k==0)numflipped++;
8385                                                                                 player[k].targetanimation=backhandspringanim;
8386                                                                                 player[k].target=0;
8387                                                                                 player[k].targetframe=0;
8388                                                                                 player[k].targetrotation=-rotation+180;
8389                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8390                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8391                                                                                 player[k].rotation=player[k].targetrotation;
8392                                                                                 player[k].jumppower-=2;
8393                                                                         }
8394                                                                 }
8395                                                                 if(player[k].attackkeydown&&!animation[player[k].targetanimation].attack&&!player[k].backkeydown&&(player[k].isIdle()||player[k].isRun()||player[k].targetanimation==walkanim||player[k].targetanimation==sneakanim||player[k].isCrouch())){
8396                                                                         player[k].hasvictim=0;
8397                                                                         if(numplayers>1)
8398                                                                                 for(i=0;i<numplayers;i++){
8399                                                                                         if(i==k)i++;
8400                                                                                         if(!player[k].hasvictim)
8401                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){      
8402                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5&&!player[i].skeleton.free&&player[i].howactive<typedead1&&player[i].targetanimation!=jumpreversedanim&&player[i].targetanimation!=rabbitkickreversedanim&&player[i].targetanimation!=rabbitkickanim&&player[k].targetanimation!=rabbitkickanim&&player[i].targetanimation!=getupfrombackanim&&(player[i].targetanimation!=staggerbackhighanim&&(player[i].targetanimation!=staggerbackhardanim||animation[staggerbackhardanim].label[player[i].targetframe]==6))&&player[i].targetanimation!=jumpdownanim&&player[i].targetanimation!=jumpupanim&&player[i].targetanimation!=getupfromfrontanim){
8403                                                                                                                 player[k].victim=&player[i];
8404                                                                                                                 player[k].hasvictim=1;
8405                                                                                                                 if(player[k].aitype==playercontrolled){
8406                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&player[k].crouchkeydown&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8407                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive==-1&&!reversaltrain)player[k].targetanimation=winduppunchanim;
8408                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8409                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&player[k].weaponactive!=-1&&player[i].staggerdelay>0&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[i].bloodloss>player[i].damagetolerance/2)player[k].targetanimation=knifefollowanim;
8410                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[k].weaponmissdelay<=0)player[k].targetanimation=knifeslashstartanim;
8411                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword&&player[k].weaponmissdelay<=0)player[k].targetanimation=swordslashanim;
8412                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].forwardkeydown)player[k].targetanimation=staffhitanim;
8413                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0)player[k].targetanimation=staffspinhitanim;
8414                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8415                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height==lowheight&&animation[player[k].targetanimation].attack!=normalattack)player[k].targetanimation=lowkickanim;
8416                                                                                                                 }
8417                                                                                                                 else {
8418                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8419                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8420                                                                                                                                 else randattack=abs(Random()%5);
8421                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8422                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8423                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8424                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8425                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8426                                                                                                                                 }
8427                                                                                                                                 if(player[k].weaponactive!=-1){
8428                                                                                                                                         if((tutoriallevel!=1||player[k].weaponactive==-1)&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8429                                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)/*&&animation[player[i].targetanimation].height!=lowheight*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[k].weaponmissdelay<=0)player[k].targetanimation=knifeslashstartanim;
8430                                                                                                                                         //else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5&&player[k].weaponactive!=-1&&player[i].staggerdelay>0&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)player[k].targetanimation=knifefollowanim;
8431                                                                                                                                         else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword&&player[k].weaponmissdelay<=0)player[k].targetanimation=swordslashanim;
8432                                                                                                                                         else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&randattack<3)player[k].targetanimation=staffhitanim;
8433                                                                                                                                         else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&randattack>=3)player[k].targetanimation=staffspinhitanim;
8434                                                                                                                                         else if((tutoriallevel!=1||player[k].weaponactive==-1)&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&randattack==1&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8435                                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height==lowheight&&animation[player[k].targetanimation].attack!=normalattack)player[k].targetanimation=lowkickanim;
8436                                                                                                                                 }
8437                                                                                                                         }
8438                                                                                                                 }
8439                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8440                                                                                                         }
8441                                                                                                         if((tutoriallevel!=1||tutorialstage==22)&&player[i].howactive<typedead1&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)&&!player[i].skeleton.free&&player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim&&(((player[i].stunned>0&&player[k].madskills)||(player[i].surprised>0)||player[i].aitype==passivetype)||(player[k].weaponactive!=-1&&player[i].stunned>0))&&normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0&&(k==0)){
8442                                                                                                                 if(player[k].weaponactive==-1){
8443                                                                                                                         player[i].targetanimation=sneakattackedanim;
8444                                                                                                                         player[i].currentanimation=sneakattackedanim;
8445                                                                                                                         player[k].currentanimation=sneakattackanim;
8446                                                                                                                         player[k].targetanimation=sneakattackanim;
8447                                                                                                                         player[k].oldcoords=player[k].coords;
8448                                                                                                                         player[k].coords=player[i].coords;
8449                                                                                                                 }
8450                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8451                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8452                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8453                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8454                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8455                                                                                                                         player[i].oldcoords=player[i].coords;
8456                                                                                                                         player[i].coords=player[k].coords;
8457                                                                                                                 }
8458                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8459                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8460                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8461                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8462                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8463                                                                                                                         player[i].oldcoords=player[i].coords;
8464                                                                                                                         player[i].coords=player[k].coords;
8465                                                                                                                 }
8466                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8467                                                                                                                         player[k].victim=&player[i];
8468                                                                                                                         player[k].hasvictim=1;
8469                                                                                                                         player[i].targettilt2=0;
8470                                                                                                                         player[i].targetframe=1;
8471                                                                                                                         player[i].currentframe=0;
8472                                                                                                                         player[i].target=0;
8473                                                                                                                         player[i].velocity=0;
8474                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8475                                                                                                                         player[k].currentframe=player[i].currentframe;
8476                                                                                                                         player[k].targetframe=player[i].targetframe;
8477                                                                                                                         player[k].target=player[i].target;
8478                                                                                                                         player[k].velocity=0;
8479                                                                                                                         player[k].targetrotation=player[i].rotation;
8480                                                                                                                         player[k].rotation=player[i].rotation;
8481                                                                                                                         player[i].targetrotation=player[i].rotation;
8482                                                                                                                 }
8483                                                                                                         }
8484                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8485                                                                                                                 oldattackkey=1;
8486                                                                                                                 player[k].targetframe=0;
8487                                                                                                                 player[k].target=0;
8488                                                                                                                 //player[k].velocity=0;
8489
8490                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8491                                                                                                                 Normalise(&rotatetarget);
8492                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8493                                                                                                                 player[k].targetrotation*=360/6.28;
8494                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8495
8496                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8497
8498                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8499                                                                                                                 player[k].lastattack2=player[k].lastattack;
8500                                                                                                                 player[k].lastattack=player[k].targetanimation;
8501                                                                                                                 //player[k].targettilt2=0;
8502                                                                                                                 //slomo=1;
8503                                                                                                                 //slomodelay=.2;
8504                                                                                                         }
8505                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8506                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8507                                                                                                                 Normalise(&rotatetarget);
8508                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8509                                                                                                                 player[k].targetrotation*=360/6.28;
8510                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8511                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8512                                                                                                                 oldattackkey=1;
8513                                                                                                                 player[k].victim=&player[i];
8514                                                                                                                 player[k].hasvictim=1;
8515                                                                                                                 player[i].targetanimation=knifefollowedanim;
8516                                                                                                                 player[i].currentanimation=knifefollowedanim;
8517                                                                                                                 player[i].targettilt2=0;
8518                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8519                                                                                                                 player[i].targetframe=1;
8520                                                                                                                 player[i].currentframe=0;
8521                                                                                                                 player[i].target=0;
8522                                                                                                                 player[i].velocity=0;
8523                                                                                                                 player[k].currentanimation=knifefollowanim;
8524                                                                                                                 player[k].targetanimation=knifefollowanim;
8525                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8526                                                                                                                 player[k].currentframe=player[i].currentframe;
8527                                                                                                                 player[k].targetframe=player[i].targetframe;
8528                                                                                                                 player[k].target=player[i].target;
8529                                                                                                                 player[k].velocity=0;
8530                                                                                                                 player[k].oldcoords=player[k].coords;
8531                                                                                                                 player[i].coords=player[k].coords;
8532                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8533                                                                                                                 player[i].rotation=player[k].targetrotation;
8534                                                                                                                 player[k].rotation=player[k].targetrotation;
8535                                                                                                                 player[i].rotation=player[k].targetrotation;
8536                                                                                                         }
8537                                                                                                 }
8538                                                                                 }
8539                                                                                 bool hasstaff=0;
8540                                                                                 if(player[k].weaponactive!=-1){
8541                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8542                                                                                 }
8543                                                                                 if(numplayers>1)
8544                                                                                         for(i=0;i<numplayers;i++){
8545                                                                                                 if(i==k)i++;
8546                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){   
8547                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8548                                                                                                                 if(player[i].skeleton.free)
8549                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<3.5*(player[k].scale*5)*(player[k].scale*5)&&(player[i].dead||player[i].skeleton.longdead>1000||player[k].isRun()||(hasstaff)||(player[k].weaponactive!=-1&&player[i].skeleton.free&&(player[i].skeleton.longdead>2000||player[i].damage>player[i].damagetolerance/8||player[i].bloodloss>player[i].damagetolerance/2)&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)))){
8550                                                                                                                                 player[k].victim=&player[i];
8551                                                                                                                                 player[k].hasvictim=1;
8552                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8553                                                                                                                                         if(player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5))player[k].targetanimation=crouchstabanim;
8554                                                                                                                                         if(player[k].crouchkeydown&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)/*&&player[i].dead!=2*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)player[k].targetanimation=swordgroundstabanim;
8555                                                                                                                                         if(/*(player[k].crouchkeydown||!player[i].dead)&&*/findDistancefast(&player[k].coords,&player[i].coords)<3.5*(player[k].scale*5)*(player[k].scale*5)/*&&player[i].dead!=2*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)player[k].targetanimation=staffgroundsmashanim;
8556                                                                                                                                 }
8557                                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<2.5&&player[k].crouchkeydown&&player[k].targetanimation!=crouchstabanim&&(player[k].weaponactive==-1)&&player[i].dead&&player[i].skeleton.free&&player[i].skeleton.longdead>1000){
8558                                                                                                                                         player[k].targetanimation=killanim;
8559                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8560                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8561                                                                                                                                                         terrain.DeleteDecal(j);
8562                                                                                                                                                 }
8563                                                                                                                                         }
8564                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8565                                                                                                                                                 if(objects.model[l].type==decalstype)
8566                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8567                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8568                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8569                                                                                                                                                                 }
8570                                                                                                                                                         }
8571                                                                                                                                         }
8572                                                                                                                                 }
8573                                                                                                                                 if(!player[i].dead||musictype!=2)
8574                                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<3.5&&(player[k].isRun()||(player[k].isIdle()&&player[k].attackkeydown))&&(player[k].staggerdelay<=0&&(player[i].dead||(player[i].skeleton.longdead<300&&player[k].lastattack!=spinkickanim&&player[i].skeleton.free)))&&(!player[i].dead||musictype!=stream_music2)){
8575                                                                                                                                                 player[k].targetanimation=dropkickanim;
8576                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8577                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8578                                                                                                                                                                 terrain.DeleteDecal(j);
8579                                                                                                                                                         }
8580                                                                                                                                                 }
8581                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8582                                                                                                                                                         if(objects.model[l].type==decalstype)
8583                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8584                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8585                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8586                                                                                                                                                                         }
8587                                                                                                                                                                 }
8588                                                                                                                                                 }
8589                                                                                                                                         }
8590                                                                                                                         }
8591                                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free||player[k].targetanimation==killanim||player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim||player[k].targetanimation==dropkickanim)){
8592                                                                                                                                 oldattackkey=1;
8593                                                                                                                                 player[k].targetframe=0;
8594                                                                                                                                 player[k].target=0;
8595                                                                                                                                 //player[k].velocity=0;
8596
8597                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8598                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8599                                                                                                                                         rotatetarget=(player[i].coords+(player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position+player[i].skeleton.joints[player[i].skeleton.jointlabels[neck]].position)/2*player[i].scale)-player[k].coords;
8600                                                                                                                                 }
8601                                                                                                                                 Normalise(&rotatetarget);
8602                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8603                                                                                                                                 player[k].targetrotation*=360/6.28;
8604                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8605
8606                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8607                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8608                                                                                                                                 }
8609
8610                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8611                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8612
8613                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8614                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8615                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8616
8617                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8618                                                                                                                                         player[k].targetrotation+=30;
8619                                                                                                                                 }
8620                                                                                                                                 //player[k].targettilt2=0;
8621                                                                                                                                 //slomo=1;
8622                                                                                                                                 //slomodelay=.2;
8623                                                                                                                         }
8624                                                                                                 }
8625                                                                                         }
8626                                                                                         if(!player[k].hasvictim){
8627                                                                                                 for(i=0;i<numplayers;i++){
8628                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8629                                                                                                                 player[k].victim=&player[i];
8630                                                                                                                 player[k].hasvictim=1;
8631                                                                                                         }
8632                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8633                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8634                                                                                                                         player[k].victim=&player[i];
8635                                                                                                                 }
8636                                                                                                 }
8637                                                                                         }
8638                                                                                         if(player[k].aitype==playercontrolled)
8639                                                                                                 if(player[k].attackkeydown&&(player[k].isRun())&&player[k].wasRun()&&((player[k].hasvictim&&findDistancefast(&player[k].coords,&player[k].victim->coords)<12*(player[k].scale*5)*(player[k].scale*5)&&findDistancefast(&player[k].coords,&player[k].victim->coords)>7*(player[k].scale*5)*(player[k].scale*5)&&!player[k].victim->skeleton.free&&player[k].victim->targetanimation!=getupfrombackanim&&player[k].victim->targetanimation!=getupfromfrontanim&&animation[player[k].victim->targetanimation].height!=lowheight&&player[k].aitype!=playercontrolled&&normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&player[k].rabbitkickenabled)||player[k].jumpkeydown)){
8640                                                                                                         oldattackkey=1;
8641                                                                                                         player[k].targetanimation=rabbitkickanim;
8642                                                                                                         player[k].targetframe=0;
8643                                                                                                         player[k].target=0;
8644                                                                                                 }
8645                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8646                                                                                                         numattacks++;
8647                                                                                                         bool armedstaff=0;
8648                                                                                                         if(player[k].weaponactive!=-1){
8649                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8650                                                                                                         }
8651                                                                                                         bool armedsword=0;
8652                                                                                                         if(player[k].weaponactive!=-1){
8653                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8654                                                                                                         }
8655                                                                                                         bool armedknife=0;
8656                                                                                                         if(player[k].weaponactive!=-1){
8657                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8658                                                                                                         }
8659                                                                                                         if(armedstaff)numstaffattack++;
8660                                                                                                         else if(armedsword)numswordattack++;
8661                                                                                                         else if(armedknife)numknifeattack++;
8662                                                                                                         else numunarmedattack++;
8663                                                                                                 }
8664                                                                 }
8665                                                         }
8666                                                 }
8667
8668                                                 //Collisions
8669                                                 static float collisionradius;
8670                                                 if(numplayers>1)
8671                                                         for(k=0;k<numplayers;k++){
8672                                                                 for(i=k;i<numplayers;i++){
8673                                                                         if(i==k)i++;
8674                                                                         if(i<numplayers)
8675                                                                                 if((animation[player[i].targetanimation].attack!=reversed&&animation[player[i].targetanimation].attack!=reversal&&animation[player[k].targetanimation].attack!=reversed&&animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
8676                                                                                         if((animation[player[i].currentanimation].attack!=reversed&&animation[player[i].currentanimation].attack!=reversal&&animation[player[k].currentanimation].attack!=reversed&&animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
8677                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8678                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8679                                                                                                                 if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz&&player[k].skeleton.oldfree==player[k].skeleton.free&&player[i].skeleton.oldfree==player[i].skeleton.free&&player[i].targetanimation!=climbanim&&player[i].targetanimation!=hanganim&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim)
8680                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8681                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8682                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8683                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8684                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8685                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8686                                                                                                                                                                         if(findDistancefast(&player[i].coords,&player[k].coords)<3*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
8687                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8688                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8689                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8690                                                                                                                                                                                 }       
8691                                                                                                                                                                         }
8692
8693                                                                                                                                                                         tempcoords1=player[i].coords;
8694                                                                                                                                                                         tempcoords2=player[k].coords;
8695                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8696                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8697                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8698                                                                                                                                                                         if(player[0].hasvictim)
8699                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8700                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){   
8701                                                                                                                                                                                 if(k==0)
8702                                                                                                                                                                                         if(player[k].targetanimation==jumpdownanim&&!player[k].skeleton.oldfree&&!player[k].skeleton.free&&player[i].skeleton.oldfree&&player[i].skeleton.free&&player[i].dead&&player[k].lastcollide<=0&&abs(player[i].coords.y-player[k].coords.y)<.2&&findDistancefast(&player[k].coords,&player[i].coords)<.7*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
8703                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8704                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8705                                                                                                                                                                                                 player[i].skeleton.free=0;
8706                                                                                                                                                                                                 player[i].rotation=0;
8707                                                                                                                                                                                                 player[i].RagDoll(0);
8708                                                                                                                                                                                                 player[i].DoDamage(20);
8709                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8710                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8711                                                                                                                                                                                                 player[k].lastcollide=1;        
8712                                                                                                                                                                                         }
8713                                                                                                                                                                                         if(i==0)
8714                                                                                                                                                                                                 if(player[i].targetanimation==jumpdownanim&&!player[i].skeleton.oldfree&&!player[i].skeleton.free&&player[k].skeleton.oldfree&&player[k].skeleton.free&&player[k].dead&&player[i].lastcollide<=0&&abs(player[i].coords.y-player[k].coords.y)<.2&&findDistancefast(&player[k].coords,&player[i].coords)<.7*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
8715                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8716                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8717                                                                                                                                                                                                         player[k].skeleton.free=0;
8718                                                                                                                                                                                                         player[k].rotation=0;
8719                                                                                                                                                                                                         player[k].RagDoll(0);
8720                                                                                                                                                                                                         player[k].DoDamage(20);
8721                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8722                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8723                                                                                                                                                                                                         player[i].lastcollide=1;        
8724                                                                                                                                                                                                 }
8725
8726                                                                                                                                                                                                 if((player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||(player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){     
8727                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8728                                                                                                                                                                                                         if(((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim)||player[i].skeleton.free)&&((player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim)||player[k].skeleton.free))
8729                                                                                                                                                                                                                 if(((((findLengthfast(&rotatetarget)>150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&((i==0||k==0)||((player[i].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i].currentanimation].attack==neutral)||(player[i].isFlip()&&!player[i].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree))){
8730                                                                                                                                                                                                                         //If hit by body
8731                                                                                                                                                                                                                         if((i!=0||player[i].skeleton.free)&&(k!=0||player[k].skeleton.free)||(animation[player[i].targetanimation].height==highheight&&animation[player[k].targetanimation].height==highheight)){
8732                                                                                                                                                                                                                                 static float gLoc[3];
8733                                                                                                                                                                                                                                 static float vel[3];
8734                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8735                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8736                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8737                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8738                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8739                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8740                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8741                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, TRUE);
8742                                                                                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8743                                                                                                                                                                                                                                         FSOUND_SetVolume(channels[heavyimpactsound], 256);
8744                                                                                                                                                                                                                                         FSOUND_SetPaused(channels[heavyimpactsound], FALSE);
8745                                                                                                                                                                                                                                 }
8746                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8747                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8748
8749                                                                                                                                                                                                                                 player[i].RagDoll(0);
8750                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8751                                                                                                                                                                                                                                         bonus=aimbonus;
8752                                                                                                                                                                                                                                         bonustime=0;
8753                                                                                                                                                                                                                                         bonusvalue=150;
8754                                                                                                                                                                                                                                 }
8755                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8756                                                                                                                                                                                                                                 player[k].RagDoll(0);
8757                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8758                                                                                                                                                                                                                                         bonus=aimbonus;
8759                                                                                                                                                                                                                                         bonustime=0;
8760                                                                                                                                                                                                                                         bonusvalue=150;
8761                                                                                                                                                                                                                                 }
8762                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8763
8764                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8765                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8766                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8767                                                                                                                                                                                                                                 }
8768                                                                                                                                                                                                                                 //}
8769                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8770                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8771                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8772                                                                                                                                                                                                                                 }
8773                                                                                                                                                                                                                                 //}
8774
8775                                                                                                                                                                                                                         }
8776                                                                                                                                                                                                                 }
8777                                                                                                                                                                                                                 if((animation[player[i].targetanimation].attack==neutral||animation[player[i].targetanimation].attack==normalattack)&&(animation[player[k].targetanimation].attack==neutral||animation[player[k].targetanimation].attack==normalattack)){
8778                                                                                                                                                                                                                         //If bumped
8779                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8780                                                                                                                                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
8781                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8782                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8783                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8784                                                                                                                                                                                                                                         player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8785                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8786                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8787                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8788                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8789                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8790                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8791                                                                                                                                                                                                                                                                 player[k].target=0;
8792                                                                                                                                                                                                                                                         }
8793                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8794                                                                                                                                                                                                                                                         {
8795                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8796                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8797                                                                                                                                                                                                                                                                 player[k].target=0;
8798                                                                                                                                                                                                                                                         }
8799                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8800                                                                                                                                                                                                                                                 }
8801                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8802                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8803                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8804                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8805                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8806                                                                                                                                                                                                                                                                         player[i].target=0;
8807                                                                                                                                                                                                                                                                 }
8808                                                                                                                                                                                                                                                                 else
8809                                                                                                                                                                                                                                                                 {
8810                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8811                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8812                                                                                                                                                                                                                                                                         player[i].target=0;
8813                                                                                                                                                                                                                                                                 }
8814                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8815                                                                                                                                                                                                                                                         }
8816                                                                                                                                                                                                                                 }
8817                                                                                                                                                                                                                                 if(hostile){
8818                                                                                                                                                                                                                                         if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&!player[i].isCrouch()&&player[i].targetanimation!=rollanim&&!player[k].skeleton.oldfree&&!player[k].skeleton.free&&player[k].lastcollide<=0&&player[k].velocity.y<-10){
8819                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8820                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8821                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8822                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8823                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8824                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8825                                                                                                                                                                                                                                                 player[k].lastcollide=1;        
8826                                                                                                                                                                                                                                                 if(k==0){
8827                                                                                                                                                                                                                                                         bonus=AboveBonus;
8828                                                                                                                                                                                                                                                         bonustime=0;
8829                                                                                                                                                                                                                                                         bonusvalue=50;
8830                                                                                                                                                                                                                                                 }
8831                                                                                                                                                                                                                                         }
8832                                                                                                                                                                                                                                         if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&!player[k].isCrouch()&&player[k].targetanimation!=rollanim&&!player[i].skeleton.oldfree&&!player[i].skeleton.free&&player[i].lastcollide<=0&&player[i].velocity.y<-10){
8833                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8834                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8835                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8836                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8837                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8838                                                                                                                                                                                                                                                 player[k].RagDoll(0);   
8839                                                                                                                                                                                                                                                 player[i].lastcollide=1;        
8840                                                                                                                                                                                                                                                 if(i==0){
8841                                                                                                                                                                                                                                                         bonus=AboveBonus;
8842                                                                                                                                                                                                                                                         bonustime=0;
8843                                                                                                                                                                                                                                                         bonusvalue=50;
8844                                                                                                                                                                                                                                                 }
8845                                                                                                                                                                                                                                         }
8846                                                                                                                                                                                                                                 }
8847                                                                                                                                                                                                                         }
8848                                                                                                                                                                                                                 }
8849                                                                                                                                                                                                 }
8850                                                                                                                                                                                                 player[i].CheckKick();
8851                                                                                                                                                                                                 player[k].CheckKick();
8852                                                                                                                                                                         }
8853                                                                                                                                                                 }
8854                                                                 }
8855                                                         }
8856
8857                                                         for(k=0;k<numplayers;k++){
8858                                                                 for(i=k;i<numplayers;i++){
8859                                                                         if(i==k)i++;
8860                                                                         if(i<numplayers&&i!=k&&player[k].skeleton.free==0&&player[i].skeleton.oldfree==0&&(player[i].targetanimation==jumpupanim||player[k].targetanimation==jumpupanim)&&(player[i].aitype==playercontrolled||player[k].aitype==playercontrolled)&&((player[i].aitype==attacktypecutoff&&player[i].stunned<=0)||(player[k].aitype==attacktypecutoff&&player[k].stunned<=0))){
8861                                                                                 if(findDistancefast(&player[i].coords,&player[k].coords)<10*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)&&findDistancefastflat(&player[i].coords,&player[k].coords)<2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
8862                                                                                         if(player[i].targetanimation==jumpupanim&&player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim&&animation[player[k].targetanimation].height==middleheight&&normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&((player[k].aitype==playercontrolled&&player[k].attackkeydown)||player[k].aitype!=playercontrolled)){
8863                                                                                                 player[i].victim=&player[k];
8864                                                                                                 player[i].targetanimation=jumpreversedanim;
8865                                                                                                 player[i].currentanimation=jumpreversedanim;
8866                                                                                                 player[k].currentanimation=jumpreversalanim;
8867                                                                                                 player[k].targetanimation=jumpreversalanim;
8868                                                                                                 player[i].targettilt2=0;
8869                                                                                                 player[i].currentframe=0;
8870                                                                                                 player[i].targetframe=1;
8871                                                                                                 player[k].currentframe=0;
8872                                                                                                 player[k].targetframe=1;
8873                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8874                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8875                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8876                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8877                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8878                                                                                                         player[k].currentframe=1;
8879                                                                                                         player[k].targetframe=2;
8880                                                                                                         player[i].currentframe=1;
8881                                                                                                         player[i].targetframe=2;
8882                                                                                                 }
8883                                                                                                 player[k].targettilt2=0;
8884                                                                                                 player[i].target=0;
8885                                                                                                 player[i].velocity=0;
8886                                                                                                 player[k].velocity=0;
8887                                                                                                 player[k].oldcoords=player[k].coords;
8888                                                                                                 player[i].coords=player[k].coords;
8889                                                                                                 player[k].targetrotation=player[i].targetrotation;
8890                                                                                                 player[k].rotation=player[i].targetrotation;
8891                                                                                                 player[k].victim=&player[i];
8892                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8893                                                                                         }
8894                                                                                         if(player[k].targetanimation==jumpupanim&&player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim&&animation[player[i].targetanimation].height==middleheight&&normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&((player[i].aitype==playercontrolled&&player[i].attackkeydown)||player[i].aitype!=playercontrolled)){
8895                                                                                                 player[k].victim=&player[i];
8896                                                                                                 player[k].targetanimation=jumpreversedanim;
8897                                                                                                 player[k].currentanimation=jumpreversedanim;
8898                                                                                                 player[i].currentanimation=jumpreversalanim;
8899                                                                                                 player[i].targetanimation=jumpreversalanim;
8900                                                                                                 player[k].targettilt2=0;
8901                                                                                                 player[i].targettilt2=0;
8902                                                                                                 player[k].currentframe=0;
8903                                                                                                 player[k].targetframe=1;
8904                                                                                                 player[i].currentframe=0;
8905                                                                                                 player[i].targetframe=1;
8906                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8907                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8908                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8909                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8910                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8911                                                                                                         player[k].currentframe=1;
8912                                                                                                         player[k].targetframe=2;
8913                                                                                                         player[i].currentframe=1;
8914                                                                                                         player[i].targetframe=2;
8915                                                                                                 }
8916                                                                                                 player[k].target=0;
8917                                                                                                 player[k].velocity=0;
8918                                                                                                 player[i].velocity=0;
8919                                                                                                 player[i].oldcoords=player[i].coords;
8920                                                                                                 player[k].coords=player[i].coords;
8921                                                                                                 player[i].targetrotation=player[k].targetrotation;
8922                                                                                                 player[i].rotation=player[k].targetrotation;
8923                                                                                                 player[i].victim=&player[k];
8924                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8925                                                                                         }
8926                                                                                 }
8927                                                                         }
8928                                                                 }
8929                                                         }
8930
8931                                                         for(k=0;k<numplayers;k++)
8932                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8933
8934
8935                                                         //pile
8936                                                         /*
8937                                                         XYZ tempdiff;
8938                                                         XYZ tempoldpos;
8939                                                         XYZ temp1,temp2;
8940                                                         bool isgood;
8941                                                         static float checkdelay;
8942                                                         checkdelay-=multiplier;
8943                                                         int m;
8944                                                         static bool checkedcoll[maxplayers][maxplayers];
8945                                                         static bool above[maxplayers];
8946
8947                                                         for(i=0;i<maxplayers;i++){
8948                                                         for(j=0;j<maxplayers;j++){
8949                                                         checkedcoll[i][j]=0;
8950                                                         }
8951                                                         }
8952
8953                                                         if(numplayers>1&&checkdelay<=0){
8954                                                         checkdelay=.015;
8955                                                         for(k=0;k<numplayers;k++){
8956                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8957
8958                                                         for(i=k;i<numplayers;i++){
8959                                                         if(i==k)i++;
8960                                                         if(i<numplayers)
8961                                                         if(!checkedcoll[i][k]){
8962                                                         checkedcoll[i][k]=1;
8963                                                         checkedcoll[k][i]=1;
8964                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8965                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8966                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8967                                                         if(player[i].coords.y>player[k].coords.y-3)
8968                                                         if(player[i].coords.y<player[k].coords.y+3)
8969                                                         if(player[i].coords.x>player[k].coords.x-3)
8970                                                         if(player[i].coords.x<player[k].coords.x+3)
8971                                                         if(player[i].coords.z>player[k].coords.z-3)
8972                                                         if(player[i].coords.z<player[k].coords.z+3)
8973                                                         if(findDistancefast(&player[i].coords,&player[k].coords)<3*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
8974                                                         int stuck,moving;
8975                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8976                                                         stuck=i;
8977                                                         moving=k;
8978                                                         }
8979                                                         else
8980                                                         {
8981                                                         moving=i;
8982                                                         stuck=k;
8983                                                         }
8984                                                         isgood=1;
8985
8986                                                         if(isgood){
8987                                                         above[moving]=stuck;
8988                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8989                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8990                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8991                                                         {
8992                                                         player[moving].skeleton.joints[l].position.y+=.003;
8993                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8994
8995                                                         }
8996                                                         }
8997                                                         }
8998                                                         }
8999                                                         }
9000                                                         }
9001                                                         }
9002                                                         }
9003                                                         }
9004
9005                                                         */
9006
9007                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
9008                                                                 texturesizetogglekeydown=0;
9009                                                         }
9010
9011                                                         for(k=0;k<numplayers;k++){
9012                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
9013                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
9014                                                                                 player[k].DoDamage(1000);
9015                                                                         }
9016                                                                 }
9017                                                         }
9018
9019                                                         static bool respawnkeydown;
9020                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
9021                                                                 targetlevel=whichlevel;
9022                                                                 loading=1;
9023                                                                 leveltime=5;
9024                                                         }
9025                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
9026                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
9027
9028
9029
9030
9031                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
9032                                                                 targetlevel++;
9033                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
9034                                                                 loading=1;
9035                                                                 leveltime=5;
9036                                                                 slomotogglekeydown=1;
9037                                                         }
9038
9039                                                         /*
9040                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
9041                                                         //Respawn
9042                                                         FSOUND_SetPaused(channels[whooshsound], TRUE);
9043                                                         changedelay=0;
9044                                                         for(k=0;k<numplayers;k++){
9045                                                         player[k].dead=0;
9046                                                         player[k].damage=0;
9047                                                         player[k].permanentdamage=0;
9048                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
9049                                                         player[k].aitype=passivetype;
9050                                                         }
9051                                                         player[0].aitype=playercontrolled;
9052                                                         }
9053                                                         */
9054
9055                                                         static bool movekey;
9056                                                         static bool connected;
9057                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
9058                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
9059                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
9060                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
9061                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
9062                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
9063
9064                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
9065
9066                 for(int i=0;i<numplayers;i++){  
9067                                                                 if(!player[i].skeleton.free){
9068                                                                         oldtargetrotation=player[i].targetrotation;
9069                                                                         if(i==0&&indialogue==-1){
9070                                                                                 if(!animation[player[0].targetanimation].attack&&player[0].targetanimation!=staggerbackhighanim&&player[0].targetanimation!=staggerbackhardanim&&player[0].targetanimation!=crouchremoveknifeanim&&player[0].targetanimation!=removeknifeanim&&player[0].targetanimation!=backhandspringanim&&player[0].targetanimation!=dodgebackanim&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9071                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
9072                                                                                         if(cameramode)player[0].targetrotation=0;
9073                                                                                 }
9074
9075                                                                                 facing=0;
9076                                                                                 facing.z=-1;
9077
9078                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9079                                                                                 if(cameramode){facing=flatfacing;}
9080                                                                                 else{
9081                                                                                         facing=DoRotation(facing,-rotation2,0,0);
9082                                                                                         facing=DoRotation(facing,0,0-rotation,0);
9083                                                                                 }
9084
9085                                                                                 player[0].lookrotation=-rotation;
9086
9087                                                                                 player[i].targetheadrotation=rotation;
9088                                                                                 player[i].targetheadrotation2=rotation2;                        
9089                                                                         }
9090                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
9091                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim&&player[i].targetanimation!=walljumprightkickanim&&player[i].targetanimation!=walljumpleftkickanim){
9092                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
9093                                                                                 }
9094
9095                                                                                 facing=0;
9096                                                                                 facing.z=-1;
9097
9098                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9099
9100                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
9101                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
9102
9103                                                                                 player[i].targetheadrotation=player[i].lookrotation;
9104                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;                  
9105                                                                         }
9106                                                                         if(indialogue!=-1){
9107                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
9108                                                                                 Normalise(&rotatetarget);
9109                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
9110                                                                                 player[i].targetheadrotation*=360/6.28;
9111                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9112
9113                                                                                 player[i].targetheadrotation*=-1;
9114                                                                                 player[i].targetheadrotation+=180;
9115                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9116                                                                         }
9117
9118                                                                         bool pause;
9119
9120                                                                         if(leveltime<.5)
9121                                                                                 numenvsounds=0;
9122
9123                                                                         player[i].avoidsomething=0;
9124
9125                                                                         for(j=0;j<objects.numobjects;j++){
9126                                                                                 if(objects.onfire[j]){
9127                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
9128                                                                                         {
9129                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
9130                                                                                                         player[i].collided=0;
9131                                                                                                         player[i].avoidcollided=1;
9132                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9133                                                                                                                 player[i].avoidwhere=objects.position[j];
9134                                                                                                 }
9135                                                                                         }
9136                                                                                 }
9137                                                                         }
9138
9139                                                                         //Add avoidwhere to players
9140
9141                                                                         for(j=0;j<numplayers;j++){
9142                                                                                 if(player[j].onfire){
9143                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
9144                                                                                         {
9145                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
9146                                                                                                         player[i].collided=0;
9147                                                                                                         player[i].avoidcollided=1;
9148                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9149                                                                                                                 player[i].avoidwhere=objects.position[j];
9150                                                                                                 }
9151                                                                                         }
9152                                                                                 }
9153                                                                         }
9154
9155                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
9156                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
9157                                                                                 player[i].jumpclimb=0;
9158                                                                                 //AI
9159                                                                                 if(editorenabled)player[i].stunned=1;
9160
9161                                                                                 player[i].pause=0;
9162                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
9163                                                                                 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&player[0].coords.y>player[i].coords.y+2&&!player[0].onterrain)player[i].pause=1;
9164
9165                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
9166                                                                                 player[i].forwardkeydown=0;
9167                                                                                 player[i].leftkeydown=0;
9168                                                                                 player[i].backkeydown=0;
9169                                                                                 player[i].rightkeydown=0;
9170                                                                                 player[i].crouchkeydown=0;
9171                                                                                 player[i].attackkeydown=0;
9172                                                                                 player[i].jumpkeydown=0;
9173                                                                                 player[i].throwkeydown=0;
9174                                                                                 }*/
9175
9176                                                                                 if(player[i].aitype==pathfindtype){
9177                                                                                         if(player[i].finalpathfindpoint==-1){
9178                                                                                                 float closestdistance;
9179                                                                                                 float tempdist;
9180                                                                                                 int closest;
9181                                                                                                 XYZ colpoint;
9182                                                                                                 closest=-1;
9183                                                                                                 closestdistance=-1;
9184                                                                                                 for(j=0;j<numpathpoints;j++){
9185                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
9186                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
9187                                                                                                                 closest=j;
9188                                                                                                                 player[i].finaltarget=pathpoint[j];
9189                                                                                                         }
9190                                                                                                 }
9191                                                                                                 player[i].finalpathfindpoint=closest;
9192                                                                                                 for(j=0;j<numpathpoints;j++){
9193                                                                                                         if(numpathpointconnect[j])
9194                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9195                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9196                                                                                                                         if(tempdist*tempdist<closestdistance){
9197                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9198                                                                                                                                         closestdistance=tempdist*tempdist;
9199                                                                                                                                         closest=j;
9200                                                                                                                                         player[i].finaltarget=colpoint;
9201                                                                                                                                 }
9202                                                                                                                         }
9203                                                                                                                 }
9204                                                                                                 }
9205                                                                                                 player[i].finalpathfindpoint=closest;
9206
9207                                                                                         }
9208                                                                                         if(player[i].targetpathfindpoint==-1){
9209                                                                                                 float closestdistance;
9210                                                                                                 float tempdist;
9211                                                                                                 int closest;
9212                                                                                                 XYZ colpoint;
9213                                                                                                 closest=-1;
9214                                                                                                 closestdistance=-1;
9215                                                                                                 if(player[i].lastpathfindpoint==-1){
9216                                                                                                         for(j=0;j<numpathpoints;j++){
9217                                                                                                                 if(j!=player[i].lastpathfindpoint)
9218                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
9219                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
9220                                                                                                                                 closest=j;
9221                                                                                                                         }
9222                                                                                                         }
9223                                                                                                         player[i].targetpathfindpoint=closest;
9224                                                                                                         for(j=0;j<numpathpoints;j++){
9225                                                                                                                 if(j!=player[i].lastpathfindpoint)
9226                                                                                                                         if(numpathpointconnect[j])
9227                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9228                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9229                                                                                                                                         if(tempdist*tempdist<closestdistance){
9230                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9231                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
9232                                                                                                                                                         closestdistance=tempdist*tempdist;
9233                                                                                                                                                         closest=j;
9234                                                                                                                                                         //}
9235                                                                                                                                                 }
9236                                                                                                                                         }
9237                                                                                                                                 }
9238                                                                                                         }
9239                                                                                                         player[i].targetpathfindpoint=closest;
9240                                                                                                 }
9241                                                                                                 else
9242                                                                                                 {
9243                                                                                                         for(j=0;j<numpathpoints;j++){
9244                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
9245                                                                                                                 {
9246                                                                                                                         connected=0;
9247                                                                                                                         if(numpathpointconnect[j])
9248                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9249                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
9250                                                                                                                                 }
9251                                                                                                                                 if(!connected)
9252                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
9253                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
9254                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
9255                                                                                                                                                 }
9256                                                                                                                                                 if(connected){
9257                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
9258                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
9259                                                                                                                                                                 closestdistance=tempdist;
9260                                                                                                                                                                 closest=j;
9261                                                                                                                                                         }
9262                                                                                                                                                 }
9263                                                                                                                 }
9264                                                                                                         }
9265                                                                                                         player[i].targetpathfindpoint=closest;
9266                                                                                                 }
9267                                                                                         }
9268                                                                                         player[i].losupdatedelay-=multiplier;
9269
9270                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
9271                                                                                         Normalise(&rotatetarget);
9272                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9273                                                                                         player[i].targetrotation*=360/6.28;
9274                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9275                                                                                         player[i].lookrotation=player[i].targetrotation;
9276                                                                                         //player[i].aiupdatedelay=.05;
9277
9278                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
9279                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9280                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9281                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9282                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
9283                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9284                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9285                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9286                                                                                                 player[i].targetpathfindpoint=-1;
9287                                                                                         }
9288                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<findDistancefastflat(&player[i].coords,&player[i].finaltarget)||findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*(player[i].scale*5)*(player[i].scale*5)||player[i].lastpathfindpoint==player[i].finalpathfindpoint){
9289                                                                                                 player[i].aitype=passivetype;
9290                                                                                         }
9291
9292                                                                                         player[i].forwardkeydown=1;
9293                                                                                         player[i].leftkeydown=0;
9294                                                                                         player[i].backkeydown=0;
9295                                                                                         player[i].rightkeydown=0;
9296                                                                                         player[i].crouchkeydown=0;
9297                                                                                         player[i].attackkeydown=0;
9298                                                                                         player[i].throwkeydown=0;
9299
9300                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9301
9302                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9303                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9304
9305                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9306                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled&&(player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
9307                                                                                                         player[i].aitype=attacktypecutoff;
9308                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9309                                                                                                         player[i].aitype=attacktypecutoff;
9310
9311                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9312                                                                                                         player[i].losupdatedelay=.2;
9313                                                                                                         for(j=0;j<numplayers;j++){
9314                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9315                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9316                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9317                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9318                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9319                                                                                                                                                         if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords)&&!player[j].isWallJump())||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
9320                                                                                                                                                                 player[i].aitype=searchtype;
9321                                                                                                                                                                 player[i].lastchecktime=12;
9322                                                                                                                                                                 player[i].lastseen=player[j].coords;
9323                                                                                                                                                                 player[i].lastseentime=12;
9324                                                                                                                                                         }
9325                                                                                                                 }
9326                                                                                                         }
9327                                                                                                 }
9328                                                                                         }       
9329                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9330                                                                                                 if(player[i].creature!=wolftype){
9331                                                                                                         player[i].stunned=.6;
9332                                                                                                         player[i].surprised=.6;
9333                                                                                                 }
9334                                                                                         }
9335                                                                                 }
9336
9337                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9338                                                                                         player[i].howactive=typeactive;
9339                                                                                 }
9340
9341                                                                                 if(player[i].aitype==passivetype){
9342                                                                                         player[i].aiupdatedelay-=multiplier;
9343                                                                                         player[i].losupdatedelay-=multiplier;
9344                                                                                         player[i].lastseentime+=multiplier;
9345                                                                                         player[i].pausetime-=multiplier;
9346                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9347
9348                                                                                         if(player[i].aiupdatedelay<0){
9349                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9350                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9351                                                                                                         Normalise(&rotatetarget);
9352                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9353                                                                                                         player[i].targetrotation*=360/6.28;
9354                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9355                                                                                                         player[i].lookrotation=player[i].targetrotation;
9356                                                                                                         player[i].aiupdatedelay=.05;
9357
9358                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9359                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9360                                                                                                                 player[i].waypoint++;
9361                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9362
9363                                                                                                         }
9364                                                                                                 }                       
9365
9366                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9367                                                                                                 else player[i].forwardkeydown=0;
9368                                                                                                 player[i].leftkeydown=0;
9369                                                                                                 player[i].backkeydown=0;
9370                                                                                                 player[i].rightkeydown=0;
9371                                                                                                 player[i].crouchkeydown=0;
9372                                                                                                 player[i].attackkeydown=0;
9373                                                                                                 player[i].throwkeydown=0;
9374
9375                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9376                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9377                                                                                                         else{
9378                                                                                                                 XYZ leftpos,rightpos;
9379                                                                                                                 float leftdist,rightdist;
9380                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9381                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9382                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9383                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9384                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9385                                                                                                                 else player[i].targetrotation-=90;
9386                                                                                                         }
9387                                                                                                 }
9388                                                                                         }                       
9389                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9390                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9391
9392
9393                                                                                         if(!editorenabled){
9394                                                                                                 if(player[i].howactive<typesleeping)
9395                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9396                                                                                                                 for(j=0;j<numenvsounds;j++){
9397                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9398                                                                                                                                 player[i].aitype=attacktypecutoff;
9399                                                                                                                         }
9400                                                                                                                 }
9401
9402                                                                                                                 if(player[i].howactive==typesleeping)
9403                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9404                                                                                                                                 for(j=0;j<numenvsounds;j++){
9405                                                                                                                                         if(envsoundvol[j]>14)
9406                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9407                                                                                                                                                         player[i].aitype=attacktypecutoff;
9408                                                                                                                                                 }
9409                                                                                                                                 }
9410
9411                                                                                                                                 if(player[i].aitype!=passivetype){
9412                                                                                                                                         if(player[i].howactive==typesleeping){
9413                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9414                                                                                                                                                 player[i].targetframe=0;
9415                                                                                                                                                 player[i].target=0;
9416                                                                                                                                         }
9417
9418                                                                                                                                         player[i].howactive=typeactive;
9419                                                                                                                                 }
9420                                                                                         }                       
9421
9422                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9423                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9424                                                                                                         player[i].aitype=attacktypecutoff;
9425                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9426                                                                                                         player[i].aitype=attacktypecutoff;
9427
9428                                                                                                 if(player[i].creature==wolftype){
9429                                                                                                         XYZ windsmell;
9430                                                                                                         float smelldistance;
9431                                                                                                         smelldistance=50;
9432                                                                                                         for(j=0;j<numplayers;j++){
9433                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9434                                                                                                                         if(j==0&&player[j].num_weapons>0){
9435                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9436                                                                                                                                 if(player[j].num_weapons==2)
9437                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9438                                                                                                                         }
9439                                                                                                                         if(j!=0){
9440                                                                                                                                 smelldistance=100;
9441                                                                                                                         }
9442                                                                                                                         windsmell=windvector;
9443                                                                                                                         Normalise(&windsmell);
9444                                                                                                                         windsmell=windsmell*2+player[j].coords;
9445                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9446                                                                                                                                 player[i].aitype=attacktypecutoff;
9447                                                                                                                 }
9448                                                                                                         }
9449                                                                                                 }
9450
9451                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9452                                                                                                         player[i].losupdatedelay=.2;
9453                                                                                                         for(j=0;j<numplayers;j++){
9454                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9455                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9456                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9457                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9458                                                                                                                                                 if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords)&&!player[j].isWallJump())||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
9459                                                                                                                                                         player[i].lastseentime-=.2;
9460                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9461                                                                                                                                                         else player[i].lastseentime-=.6;                                                                
9462                                                                                                                                                 }
9463                                                                                                                                                 if(player[i].lastseentime<=0){
9464                                                                                                                                                         player[i].aitype=searchtype;
9465                                                                                                                                                         player[i].lastchecktime=12;
9466                                                                                                                                                         player[i].lastseen=player[j].coords;
9467                                                                                                                                                         player[i].lastseentime=12;
9468                                                                                                                                                 }
9469                                                                                                                 }
9470                                                                                                         }
9471                                                                                                 }
9472                                                                                         }
9473                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9474                                                                                                 if(player[i].creature!=wolftype){
9475                                                                                                         player[i].stunned=.6;
9476                                                                                                         player[i].surprised=.6;
9477                                                                                                 }
9478                                                                                                 if(player[i].creature==wolftype){
9479                                                                                                         player[i].stunned=.47;
9480                                                                                                         player[i].surprised=.47;
9481                                                                                                 }
9482                                                                                                 numseen++;
9483                                                                                         }
9484                                                                                 }               
9485
9486                                                                                 if(player[i].aitype==searchtype){
9487                                                                                         player[i].aiupdatedelay-=multiplier;
9488                                                                                         player[i].losupdatedelay-=multiplier;
9489                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9490                                                                                         player[i].lastchecktime-=multiplier;
9491
9492                                                                                         if(player[i].isRun()&&!player[i].onground){
9493                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9494                                                                                                         test2=player[i].coords+player[i].facing;
9495                                                                                                         test2.y+=5;
9496                                                                                                         test=player[i].coords+player[i].facing;
9497                                                                                                         test.y-=10;
9498                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9499                                                                                                         if(j==-1)j=checkcollide(test2,test);
9500                                                                                                         if(j==-1){
9501                                                                                                                 player[i].velocity=0;
9502                                                                                                                 player[i].targetanimation=player[i].getStop();
9503                                                                                                                 player[i].targetframe=0;
9504                                                                                                                 player[i].target=0;
9505                                                                                                                 player[i].targetrotation+=180;
9506                                                                                                                 player[i].stunned=.5;
9507                                                                                                                 //player[i].aitype=passivetype;
9508                                                                                                                 player[i].aitype=pathfindtype;
9509                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9510                                                                                                                 player[i].finalpathfindpoint=-1;
9511                                                                                                                 player[i].targetpathfindpoint=-1;
9512                                                                                                                 player[i].lastpathfindpoint=-1;
9513                                                                                                                 player[i].lastpathfindpoint2=-1;
9514                                                                                                                 player[i].lastpathfindpoint3=-1;
9515                                                                                                                 player[i].lastpathfindpoint4=-1;
9516                                                                                                         }
9517                                                                                                         else player[i].laststanding=j;
9518                                                                                                 }
9519                                                                                         }       
9520                                                                                         if(player[i].aiupdatedelay<0){
9521                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9522                                                                                                 Normalise(&rotatetarget);
9523                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9524                                                                                                 player[i].targetrotation*=360/6.28;
9525                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9526                                                                                                 player[i].lookrotation=player[i].targetrotation;
9527                                                                                                 player[i].aiupdatedelay=.05;
9528                                                                                                 player[i].forwardkeydown=1;
9529
9530                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9531                                                                                                         player[i].forwardkeydown=0;
9532                                                                                                         player[i].aiupdatedelay=1;
9533                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9534                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9535                                                                                                         player[i].lastchecktime=3;
9536                                                                                                 }
9537
9538                                                                                                 player[i].leftkeydown=0;
9539                                                                                                 player[i].backkeydown=0;
9540                                                                                                 player[i].rightkeydown=0;
9541                                                                                                 player[i].crouchkeydown=0;
9542                                                                                                 player[i].attackkeydown=0;
9543                                                                                                 player[i].throwkeydown=0;
9544
9545                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9546                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9547                                                                                                         else{
9548                                                                                                                 XYZ leftpos,rightpos;
9549                                                                                                                 float leftdist,rightdist;
9550                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9551                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9552                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9553                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9554                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9555                                                                                                                 else player[i].targetrotation-=90;
9556                                                                                                         }
9557                                                                                                 }
9558                                                                                         }
9559                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9560                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9561
9562                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9563                                                                                                 for(j=0;j<numenvsounds;j++){
9564                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9565                                                                                                                 player[i].aitype=attacktypecutoff;
9566                                                                                                         }
9567                                                                                                 }
9568
9569                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9570                                                                                                         player[i].losupdatedelay=.2;
9571                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9572                                                                                                         {player[i].aitype=attacktypecutoff;
9573                                                                                                         player[i].lastseentime=1;}
9574                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9575                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9576                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9577                                                                                                                                 if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position,0,player[0].rotation,0)*player[0].scale+player[0].coords))||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
9578                                                                                                                                         player[i].aitype=attacktypecutoff;
9579                                                                                                                                         player[i].lastseentime=1;
9580                                                                                                                                 }
9581                                                                                                 }
9582                                                                                                 if(player[i].lastseentime<0){
9583                                                                                                         //player[i].aitype=passivetype;
9584                                                                                                         numescaped++;
9585                                                                                                         player[i].aitype=pathfindtype;
9586                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9587                                                                                                         player[i].finalpathfindpoint=-1;
9588                                                                                                         player[i].targetpathfindpoint=-1;
9589                                                                                                         player[i].lastpathfindpoint=-1;
9590                                                                                                         player[i].lastpathfindpoint2=-1;
9591                                                                                                         player[i].lastpathfindpoint3=-1;
9592                                                                                                         player[i].lastpathfindpoint4=-1;
9593                                                                                                 }
9594                                                                                 }
9595
9596                                                                                 if(player[i].aitype!=gethelptype){
9597                                                                                         player[i].runninghowlong=0;
9598                                                                                 }
9599
9600                                                                                 if(player[i].aitype==gethelptype){
9601                                                                                         player[i].runninghowlong+=multiplier;
9602                                                                                         player[i].aiupdatedelay-=multiplier;
9603
9604                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9605                                                                                                 player[i].aiupdatedelay=.2;
9606
9607                                                                                                 int closest;
9608                                                                                                 float closestdist;
9609                                                                                                 closest=-1;
9610                                                                                                 closestdist=-1;
9611                                                                                                 float distance;
9612
9613                                                                                                 if(!player[i].ally){
9614                                                                                                         for(j=0;j<numplayers;j++){
9615                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9616                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9617                                                                                                                         if(closestdist==-1||distance<closestdist){
9618                                                                                                                                 closestdist=distance;
9619                                                                                                                                 closest=j;
9620                                                                                                                         }
9621                                                                                                                         closest=j;
9622                                                                                                                 }
9623                                                                                                         }
9624                                                                                                         if(closest!=-1)player[i].ally=closest;
9625                                                                                                         else player[i].ally=0;
9626                                                                                                         player[i].lastseen=player[0].coords;
9627                                                                                                         player[i].lastseentime=12;
9628                                                                                                 }
9629
9630
9631                                                                                                 player[i].lastchecktime=12;
9632                                                                                                 //player[i].lastseentime-=.5;
9633
9634                                                                                                 facing=player[i].coords;
9635                                                                                                 flatfacing=player[player[i].ally].coords;
9636                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9637                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9638                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9639                                                                                                         player[i].lastseentime-=.1;
9640
9641                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9642                                                                                                         player[i].aitype=searchtype;
9643                                                                                                         player[i].lastseentime=12;
9644                                                                                                 }
9645
9646                                                                                                 if(player[i].ally>0){
9647                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9648                                                                                                         Normalise(&rotatetarget);
9649                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9650                                                                                                         player[i].targetrotation*=360/6.28;
9651                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9652                                                                                                         player[i].lookrotation=player[i].targetrotation;
9653                                                                                                         player[i].aiupdatedelay=.05;
9654                                                                                                         player[i].forwardkeydown=1;                                     
9655
9656                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9657                                                                                                                 player[i].aitype=searchtype;
9658                                                                                                                 player[i].lastseentime=12;
9659                                                                                                                 player[player[i].ally].aitype=searchtype;
9660                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9661                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9662                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9663                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9664                                                                                                                 }
9665                                                                                                         }
9666
9667                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9668                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9669                                                                                                                 else{
9670                                                                                                                         XYZ leftpos,rightpos;
9671                                                                                                                         float leftdist,rightdist;
9672                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9673                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9674                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9675                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9676                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9677                                                                                                                         else player[i].targetrotation-=90;
9678                                                                                                                 }
9679                                                                                                         }
9680                                                                                                 }
9681
9682                                                                                                 player[i].leftkeydown=0;
9683                                                                                                 player[i].backkeydown=0;
9684                                                                                                 player[i].rightkeydown=0;
9685                                                                                                 player[i].crouchkeydown=0;
9686                                                                                                 player[i].attackkeydown=0;
9687                                                                                         }
9688                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9689                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9690                                                                                 }
9691
9692                                                                                 if(player[i].aitype==getweapontype){
9693                                                                                         player[i].aiupdatedelay-=multiplier;
9694                                                                                         player[i].lastchecktime-=multiplier;
9695
9696                                                                                         if(player[i].aiupdatedelay<0){
9697                                                                                                 player[i].aiupdatedelay=.2;
9698
9699                                                                                                 int closest;
9700                                                                                                 float closestdist;
9701                                                                                                 closest=-1;
9702                                                                                                 closestdist=-1;
9703                                                                                                 float distance;
9704
9705                                                                                                 if(player[i].ally<0){
9706                                                                                                         for(j=0;j<weapons.numweapons;j++){
9707                                                                                                                 if(weapons.owner[j]==-1){
9708                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9709                                                                                                                         if(closestdist==-1||distance<closestdist){
9710                                                                                                                                 closestdist=distance;
9711                                                                                                                                 closest=j;
9712                                                                                                                         }
9713                                                                                                                         closest=j;
9714                                                                                                                 }
9715                                                                                                         }
9716                                                                                                         if(closest!=-1)player[i].ally=closest;
9717                                                                                                         else player[i].ally=-1;
9718                                                                                                 }
9719
9720                                                                                                 player[i].lastseentime=12;
9721
9722                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9723                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9724                                                                                                                 player[i].aitype=attacktypecutoff;
9725                                                                                                                 player[i].lastseentime=1;
9726                                                                                                         }                                       
9727                                                                                                         if(!player[0].dead)
9728                                                                                                                 if(player[i].ally>=0){
9729                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9730                                                                                                                                 player[i].aitype=attacktypecutoff;
9731                                                                                                                                 player[i].lastseentime=1;
9732                                                                                                                         }
9733                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9734                                                                                                                         Normalise(&rotatetarget);
9735                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9736                                                                                                                         player[i].targetrotation*=360/6.28;
9737                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9738                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9739                                                                                                                         player[i].aiupdatedelay=.05;
9740                                                                                                                         player[i].forwardkeydown=1;                                     
9741
9742
9743                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9744                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9745                                                                                                                                 else{
9746                                                                                                                                         XYZ leftpos,rightpos;
9747                                                                                                                                         float leftdist,rightdist;
9748                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9749                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9750                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9751                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9752                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9753                                                                                                                                         else player[i].targetrotation-=90;
9754                                                                                                                                 }
9755                                                                                                                         }
9756                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9757                                                                                                                         if(abs(Random()%6)){
9758                                                                                                                         player[i].crouchkeydown=1;
9759                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9760                                                                                                                         if(player[i].isRun()){
9761                                                                                                                         player[i].targetframe=0;
9762                                                                                                                         player[i].target=0;
9763                                                                                                                         player[i].targetanimation=sneakanim;
9764                                                                                                                         }
9765                                                                                                                         }
9766                                                                                                                         else player[i].forwardkeydown=0;
9767                                                                                                                         }
9768                                                                                                                         else player[i].crouchkeydown=0;
9769                                                                                                                         }
9770                                                                                                                         else player[i].crouchkeydown=0;*/
9771                                                                                                                 }
9772
9773                                                                                                                 player[i].leftkeydown=0;
9774                                                                                                                 player[i].backkeydown=0;
9775                                                                                                                 player[i].rightkeydown=0;
9776                                                                                                                 player[i].attackkeydown=0;
9777                                                                                                                 player[i].throwkeydown=1;
9778                                                                                                                 player[i].crouchkeydown=0;      
9779                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9780                                                                                                                 player[i].drawkeydown=0;
9781                                                                                         }
9782                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9783                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9784                                                                                 }
9785
9786                                                                                 if(player[i].aitype==attacktypecutoff){
9787                                                                                         player[i].aiupdatedelay-=multiplier;
9788                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9789                                                                                                 if((player[0].targetanimation==rabbitkickanim||player[0].targetanimation==knifethrowanim||(player[0].isFlip()&&normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&!player[0].skeleton.free&&(player[i].aiupdatedelay<.1)){
9790                                                                                                         player[i].attackkeydown=0;
9791                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9792                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9793                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9794                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9795                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9796                                                                                                                                 else player[i].targetanimation=rollanim;
9797                                                                                                                                 player[i].target=0;
9798                                                                                                                                 player[i].targetframe=0;
9799                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9800                                                                                                                                 player[i].wentforweapon=0;
9801                                                                                                                         }
9802                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9803                                                                                                                                 player[i].targetanimation=flipanim;
9804                                                                                                                                 player[i].target=0;
9805                                                                                                                                 player[i].targetframe=0;
9806                                                                                                                         }
9807                                                                                                                 }
9808                                                                                                         }
9809                                                                                                         player[i].forwardkeydown=0;
9810                                                                                                         player[i].aiupdatedelay=.02;
9811                                                                                                 }
9812                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9813                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9814                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9815                                                                                                 }
9816                                                                                                 if(player[i].wentforweapon<3)
9817                                                                                                         for(j=0;j<weapons.numweapons;j++){
9818                                                                                                                 if(player[i].creature!=wolftype)
9819                                                                                                                         if(player[i].num_weapons==0&&weapons.owner[j]==-1&&weapons.velocity[i].x==0&&weapons.velocity[i].z==0&&weapons.velocity[i].y==0){
9820                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9821                                                                                                                                         player[i].wentforweapon++;
9822                                                                                                                                         player[i].lastchecktime=6;
9823                                                                                                                                         player[i].aitype=getweapontype;
9824                                                                                                                                         player[i].ally=-1;
9825                                                                                                                                 }
9826                                                                                                                         }
9827                                                                                                         }
9828                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9829                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9830                                                                                                                         if(player[i].damage<player[i].damagetolerance*.5&&((player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)&&((player[i].aiupdatedelay<.15&&difficulty==2)||(player[i].aiupdatedelay<.08&&difficulty!=2)))){
9831                                                                                                                                 player[i].crouchkeydown=1;
9832                                                                                                                         }
9833                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9834                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9835                                                                                                                                         test2=player[i].coords+player[i].facing;
9836                                                                                                                                         test2.y+=5;
9837                                                                                                                                         test=player[i].coords+player[i].facing;
9838                                                                                                                                         test.y-=10;
9839                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9840                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9841                                                                                                                                         if(j==-1){
9842                                                                                                                                                 player[i].velocity=0;
9843                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9844                                                                                                                                                 player[i].targetframe=0;
9845                                                                                                                                                 player[i].target=0;
9846                                                                                                                                                 player[i].targetrotation+=180;
9847                                                                                                                                                 player[i].stunned=.5;
9848                                                                                                                                                 //player[i].aitype=passivetype;
9849                                                                                                                                                 player[i].aitype=pathfindtype;
9850                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9851                                                                                                                                                 player[i].finalpathfindpoint=-1;
9852                                                                                                                                                 player[i].targetpathfindpoint=-1;
9853                                                                                                                                                 player[i].lastpathfindpoint=-1;
9854                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9855                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9856                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9857                                                                                                                                         }
9858                                                                                                                                         else player[i].laststanding=j;
9859                                                                                                                                 }
9860                                                                                                                         }
9861                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9862                                                                                                                                 player[i].aitype=pathfindtype;
9863                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9864                                                                                                                                 player[i].finalpathfindpoint=-1;
9865                                                                                                                                 player[i].targetpathfindpoint=-1;
9866                                                                                                                                 player[i].lastpathfindpoint=-1;
9867                                                                                                                                 player[i].lastpathfindpoint2=-1;
9868                                                                                                                                 player[i].lastpathfindpoint3=-1;
9869                                                                                                                                 player[i].lastpathfindpoint4=-1;
9870                                                                                                                         }       
9871                                                                                                                         if(player[i].aiupdatedelay<0&&!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
9872                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9873                                                                                                                                 else player[i].drawkeydown=0;
9874                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9875                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9876                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9877                                                                                                                                         rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity*findDistance(&player[player[i].aitarget].coords,&player[i].coords)/findLength(&player[i].velocity)-player[i].coords;
9878                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9879                                                                                                                                 Normalise(&rotatetarget);
9880                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9881                                                                                                                                 player[i].targetrotation*=360/6.28;
9882                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9883                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9884                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9885
9886                                                                                                                                 oldkey=player[i].forwardkeydown;
9887                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9888                                                                                                                                 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||findDistancefast(&player[i].coords,&player[0].coords)<9)&&player[0].weaponactive!=-1)player[i].forwardkeydown=1;
9889                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9890                                                                                                                                 else player[i].forwardkeydown=0;
9891                                                                                                                                 if(player[0].dead){
9892                                                                                                                                         player[i].forwardkeydown=0;
9893                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9894                                                                                                                                         if(Random()%100==0){
9895                                                                                                                                                 player[i].aitype=pathfindtype;
9896                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9897                                                                                                                                                 player[i].finalpathfindpoint=-1;
9898                                                                                                                                                 player[i].targetpathfindpoint=-1;
9899                                                                                                                                                 player[i].lastpathfindpoint=-1;
9900                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9901                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9902                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9903                                                                                                                                         }
9904                                                                                                                                 }
9905                                                                                                                                 player[i].leftkeydown=0;
9906                                                                                                                                 player[i].backkeydown=0;
9907                                                                                                                                 player[i].rightkeydown=0;
9908                                                                                                                                 player[i].crouchkeydown=0;
9909                                                                                                                                 player[i].throwkeydown=0;
9910
9911                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9912                                                                                                                                 /*for(j=0;j<numplayers;j++){
9913                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9914                                                                                                                                 player[i].crouchkeydown=1;
9915                                                                                                                                 }
9916                                                                                                                                 }*/
9917                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9918                                                                                                                                 else player[i].attackkeydown=0;
9919                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9920                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9921                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9922                                                                                                                                 player[i].attackkeydown=0;
9923                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9924                                                                                                                                 player[i].forwardkeydown=0;
9925                                                                                                                                 player[i].aiupdatedelay=.02;
9926                                                                                                                                 }*/
9927
9928                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9929                                                                                                                                         target=-2;
9930                                                                                                                                         for(j=0;j<numplayers;j++){
9931                                                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].hasvictim&&((tutoriallevel==1&&reversaltrain)||(Random()%2==0&&difficulty==2)||(Random()%4==0&&difficulty==1)||(Random()%8==0&&difficulty==0)||(player[j].lastattack2==player[j].targetanimation&&player[j].lastattack3==player[j].targetanimation&&(Random()%2==0||difficulty==2))||((player[i].isIdle()||player[i].isRun())&&player[j].weaponactive!=-1)||(player[j].targetanimation==swordslashanim&&player[i].weaponactive!=-1)||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim)){
9932                                                                                                                                                         if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim||player[j].targetanimation==spinkickanim||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim||player[j].targetanimation==winduppunchanim||player[j].targetanimation==upunchanim||player[j].targetanimation==wolfslapanim||player[j].targetanimation==knifeslashstartanim||((player[j].targetanimation==swordslashanim)&&(findDistancefast(&player[j].coords,&player[i].coords)<2||(player[i].weaponactive!=-1))))){
9933                                                                                                                                                                 if(target>=0)target=-1;
9934                                                                                                                                                                 else target=j;
9935                                                                                                                                                         }
9936                                                                                                                                                 }
9937                                                                                                                                         }
9938                                                                                                                                         if(target>=0)player[target].Reverse();
9939                                                                                                                                 }
9940
9941                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9942                                                                                                                                 if((player[i].collided>.8&&player[i].jumppower>=5)||(findDistancefast(&player[i].coords,&player[0].coords)>400&&player[i].onterrain&&player[i].creature==rabbittype))player[i].jumpkeydown=1;
9943                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9944                                                                                                                                         player[0].jumpkeydown=0;
9945                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9946                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9947                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9948
9949                                                                                                                                 if(tutoriallevel==1){
9950                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9951                                                                                                                                 }
9952
9953
9954                                                                                                                                 facing=player[i].coords;
9955                                                                                                                                 flatfacing=player[0].coords;
9956                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9957                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9958                                                                                                                                 if(player[i].occluded>=2)
9959                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9960                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9961                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9962                                                                                                                                                         player[i].aitype=searchtype;
9963                                                                                                                                                         player[i].lastchecktime=12;
9964                                                                                                                                                         player[i].lastseen=player[0].coords;
9965                                                                                                                                                         player[i].lastseentime=12;
9966                                                                                                                                                 }
9967                                                                                                                                         }
9968                                                                                                                                         else player[i].lastseentime=1;
9969                                                                                                                         }
9970                                                                                 }
9971                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9972                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9973                                                                                                 test=player[0].coords;
9974                                                                                                 test.y-=40;
9975                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9976                                                                                         }
9977                                                                                 }
9978                                                                                 // NOTE: Ask about logic of this call : NOTE
9979                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9980                                                                                         player[i].stunned>0 ||
9981                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9982                                                                                 {
9983                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9984                                                                                         player[i].targetrotation=player[i].rotation;
9985                                                                                         player[i].forwardkeydown=0;
9986                                                                                         player[i].leftkeydown=0;
9987                                                                                         player[i].backkeydown=0;
9988                                                                                         player[i].rightkeydown=0;
9989                                                                                         player[i].jumpkeydown=0;
9990                                                                                         player[i].attackkeydown=0;
9991                                                                                         player[i].crouchkeydown=0;
9992                                                                                         player[i].throwkeydown=0;
9993                                                                                 }
9994
9995
9996                                                                                 facing=0;
9997                                                                                 facing.z=-1;
9998
9999                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
10000                                                                                 facing=flatfacing;
10001
10002                                                                                 if(player[i].aitype==attacktypecutoff){
10003                                                                                         rotatetarget=player[0].coords-player[i].coords;
10004                                                                                         Normalise(&rotatetarget);
10005                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
10006                                                                                         player[i].targetheadrotation*=360/6.28;
10007                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
10008
10009                                                                                         player[i].targetheadrotation*=-1;
10010                                                                                         player[i].targetheadrotation+=180;
10011                                                                                         //player[i].targetheadrotation2=0;
10012                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
10013                                                                                 }
10014                                                                                 else if(player[i].howactive>=typesleeping){
10015                                                                                         player[i].targetheadrotation=player[i].targetrotation;
10016                                                                                         player[i].targetheadrotation2=0;
10017                                                                                 }
10018                                                                                 else {
10019                                                                                         if(player[i].interestdelay<=0){
10020                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
10021                                                                                                 player[i].headtarget=player[i].coords;
10022                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
10023                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
10024                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
10025                                                                                                 player[i].headtarget+=player[i].facing*1.5;
10026                                                                                         }
10027                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
10028                                                                                         Normalise(&rotatetarget);
10029                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
10030                                                                                         player[i].targetheadrotation*=360/6.28;
10031                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
10032
10033                                                                                         player[i].targetheadrotation*=-1;
10034                                                                                         player[i].targetheadrotation+=180;
10035                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
10036                                                                                 }
10037                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
10038                                                                         }
10039                                                                         if(animation[player[i].targetanimation].attack==reversed){
10040                                                                                 //player[i].targetrotation=player[i].rotation;
10041                                                                                 player[i].forwardkeydown=0;
10042                                                                                 player[i].leftkeydown=0;
10043                                                                                 player[i].backkeydown=0;
10044                                                                                 player[i].rightkeydown=0;
10045                                                                                 player[i].jumpkeydown=0;
10046                                                                                 player[i].attackkeydown=0;
10047                                                                                 //player[i].crouchkeydown=0;
10048                                                                                 player[i].throwkeydown=0;
10049                                                                         }
10050
10051                                                                         if(indialogue!=-1){
10052                                                                                 player[i].forwardkeydown=0;
10053                                                                                 player[i].leftkeydown=0;
10054                                                                                 player[i].backkeydown=0;
10055                                                                                 player[i].rightkeydown=0;
10056                                                                                 player[i].jumpkeydown=0;
10057                                                                                 player[i].crouchkeydown=0;
10058                                                                                 player[i].drawkeydown=0;
10059                                                                                 player[i].throwkeydown=0;
10060                                                                         }
10061
10062                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
10063                                                                         if(player[i].collided>1)player[i].collided=1;
10064                                                                         player[i].collided-=multiplier*4;
10065                                                                         player[i].whichdirectiondelay-=multiplier;
10066                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
10067                                                                                 player[i].avoidcollided=-.3;
10068                                                                                 player[i].whichdirection=abs(Random()%2);
10069                                                                                 player[i].whichdirectiondelay=.4;
10070                                                                         }
10071                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
10072                                                                         player[i].avoidcollided-=multiplier/4;
10073                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
10074                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
10075                                                                         if(player[i].surprised<=0&&player[i].aitype==attacktypecutoff&&i!=0&&!player[i].dead&&!player[i].skeleton.free&&animation[player[i].targetanimation].attack==neutral)numresponded=1;
10076
10077                                                                         if(!player[i].throwkeydown){
10078                                                                                 player[i].throwtogglekeydown=0;
10079                                                                         }
10080                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
10081                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons<2&&(player[i].isIdle()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim||player[i].isFlip()||player[i].isFlip()||player[i].aitype!=playercontrolled)){
10082                                                                                         for(j=0;j<weapons.numweapons;j++){
10083                                                                                                 if(((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[j]==-1&&player[i].weaponactive==-1)
10084                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
10085                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
10086                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
10087                                                                                                                                 player[i].throwtogglekeydown=1;
10088                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10089                                                                                                                                 player[i].target=0;
10090                                                                                                                                 player[i].targetframe=0;
10091                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10092                                                                                                                                 Normalise(&rotatetarget);
10093                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10094                                                                                                                                 player[i].targetrotation*=360/6.28;
10095                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10096                                                                                                                                 player[i].hasvictim=0;
10097                                                                                                                         }
10098                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10099                                                                                                                                 player[i].throwtogglekeydown=1;
10100                                                                                                                                 player[i].hasvictim=0;
10101
10102                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
10103                                                                                                                                 if((((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[j]==-1)||(player[i].victim&&weapons.owner[j]==player[i].victim->id))
10104                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
10105                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
10106                                                                                                                                                         float gLoc[3];
10107                                                                                                                                                         float vel[3];
10108                                                                                                                                                         gLoc[0]=player[i].coords.x;
10109                                                                                                                                                         gLoc[1]=player[i].coords.y;
10110                                                                                                                                                         gLoc[2]=player[i].coords.z;
10111                                                                                                                                                         vel[0]=player[i].velocity.x;
10112                                                                                                                                                         vel[1]=player[i].velocity.y;
10113                                                                                                                                                         vel[2]=player[i].velocity.z;
10114                                                                                                                                                         if(weapons.type[j]!=staff){
10115                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10116                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10117                                                                                                                                                                 FSOUND_SetVolume(channels[knifedrawsound], 128);
10118                                                                                                                                                                 FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10119                                                                                                                                                         }
10120
10121                                                                                                                                                         player[i].weaponactive=0;
10122                                                                                                                                                         weapons.owner[j]=player[i].id;
10123                                                                                                                                                         if(player[i].num_weapons>0){
10124                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10125                                                                                                                                                         }
10126                                                                                                                                                         player[i].num_weapons++;
10127                                                                                                                                                         player[i].weaponids[0]=j;
10128                                                                                                                                                 }
10129                                                                                                                                         }
10130                                                                                                                                         //}
10131                                                                                                                         }
10132                                                                                                                 }
10133                                                                                                                 else if ((player[i].isIdle()||player[i].isFlip()||player[i].aitype!=playercontrolled)&&findDistancefast(&player[i].coords,&weapons.position[j])<5&&player[i].coords.y<weapons.position[j].y){
10134                                                                                                                         if(!player[i].isFlip()){
10135                                                                                                                                 player[i].throwtogglekeydown=1;
10136                                                                                                                                 player[i].targetanimation=removeknifeanim;
10137                                                                                                                                 player[i].target=0;
10138                                                                                                                                 player[i].targetframe=0;
10139                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10140                                                                                                                                 Normalise(&rotatetarget);
10141                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10142                                                                                                                                 player[i].targetrotation*=360/6.28;
10143                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10144                                                                                                                         }
10145                                                                                                                         if(player[i].isFlip()){
10146                                                                                                                                 player[i].throwtogglekeydown=1;
10147                                                                                                                                 player[i].hasvictim=0;
10148
10149                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
10150                                                                                                                                         if(player[i].weaponactive==-1)
10151                                                                                                                                                 if((((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[k]==-1)||(player[i].victim&&weapons.owner[k]==player[i].victim->id))
10152                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
10153                                                                                                                                                                 float gLoc[3];
10154                                                                                                                                                                 float vel[3];
10155                                                                                                                                                                 gLoc[0]=player[i].coords.x;
10156                                                                                                                                                                 gLoc[1]=player[i].coords.y;
10157                                                                                                                                                                 gLoc[2]=player[i].coords.z;
10158                                                                                                                                                                 vel[0]=player[i].velocity.x;
10159                                                                                                                                                                 vel[1]=player[i].velocity.y;
10160                                                                                                                                                                 vel[2]=player[i].velocity.z;
10161                                                                                                                                                                 if(weapons.type[k]!=staff){
10162                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10163                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10164                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10165                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10166                                                                                                                                                                 }
10167
10168                                                                                                                                                                 player[i].weaponactive=0;
10169                                                                                                                                                                 weapons.owner[k]=player[i].id;
10170                                                                                                                                                                 if(player[i].num_weapons>0){
10171                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10172                                                                                                                                                                 }
10173                                                                                                                                                                 player[i].num_weapons++;
10174                                                                                                                                                                 player[i].weaponids[0]=k;
10175                                                                                                                                                         }
10176                                                                                                                                 }
10177                                                                                                                         }
10178                                                                                                                 }
10179                                                                                                         }
10180                                                                                         }
10181                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10182                                                                                                 if(numplayers>1)
10183                                                                                                         for(j=0;j<numplayers;j++){
10184                                                                                                                 if(player[i].weaponactive==-1)
10185                                                                                                                         if(j!=i)
10186                                                                                                                                 if(player[j].num_weapons&&player[j].skeleton.free&&findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&(((player[j].skeleton.forward.y<0&&player[j].weaponstuckwhere==0)||(player[j].skeleton.forward.y>0&&player[j].weaponstuckwhere==1))||player[j].weaponstuck==-1||player[j].num_weapons>1)){
10187                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
10188                                                                                                                                                 player[i].throwtogglekeydown=1;
10189                                                                                                                                                 player[i].victim=&player[j];
10190                                                                                                                                                 player[i].hasvictim=1;
10191                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10192                                                                                                                                                 player[i].target=0;
10193                                                                                                                                                 player[i].targetframe=0;
10194                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10195                                                                                                                                                 Normalise(&rotatetarget);
10196                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10197                                                                                                                                                 player[i].targetrotation*=360/6.28;
10198                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10199                                                                                                                                         }
10200                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10201                                                                                                                                                 player[i].throwtogglekeydown=1;
10202                                                                                                                                                 player[i].victim=&player[j];
10203                                                                                                                                                 player[i].hasvictim=1;
10204                                                                                                                                                 int k = player[j].weaponids[0];
10205                                                                                                                                                 if(player[i].hasvictim){
10206                                                                                                                                                         float gLoc[3];
10207                                                                                                                                                         float vel[3];
10208                                                                                                                                                         gLoc[0]=player[i].coords.x;
10209                                                                                                                                                         gLoc[1]=player[i].coords.y;
10210                                                                                                                                                         gLoc[2]=player[i].coords.z;
10211                                                                                                                                                         vel[0]=player[i].velocity.x;
10212                                                                                                                                                         vel[1]=player[i].velocity.y;
10213                                                                                                                                                         vel[2]=player[i].velocity.z;
10214                                                                                                                                                         bool fleshstuck;
10215                                                                                                                                                         fleshstuck=0;
10216                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
10217                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10218                                                                                                                                                                         fleshstuck=1;
10219                                                                                                                                                                 }
10220                                                                                                                                                         }
10221                                                                                                                                                         if(!fleshstuck){
10222                                                                                                                                                                 if(weapons.type[k]!=staff){
10223                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10224                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10225                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10226                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10227                                                                                                                                                                 }
10228                                                                                                                                                         }
10229                                                                                                                                                         if(fleshstuck){
10230                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, TRUE);
10231                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
10232                                                                                                                                                                 FSOUND_SetVolume(channels[fleshstabremovesound], 128);
10233                                                                                                                                                                 FSOUND_SetPaused(channels[fleshstabremovesound], FALSE);
10234                                                                                                                                                         }
10235
10236                                                                                                                                                         player[i].weaponactive=0;
10237                                                                                                                                                         if(weapons.owner[k]!=-1){
10238                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
10239                                                                                                                                                                 else player[i].victim->num_weapons=1;
10240
10241                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
10242                                                                                                                                                                 player[i].victim->skeleton.free=1;
10243                                                                                                                                                                 player[i].victim->skeleton.broken=0;
10244
10245                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
10246                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
10247                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
10248                                                                                                                                                                 }
10249
10250                                                                                                                                                                 XYZ relative;
10251                                                                                                                                                                 relative=0;
10252                                                                                                                                                                 relative.y=10;
10253                                                                                                                                                                 Normalise(&relative);
10254                                                                                                                                                                 XYZ footvel,footpoint;
10255                                                                                                                                                                 footvel=0;
10256                                                                                                                                                                 footpoint=weapons.position[k];
10257                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
10258                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10259                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
10260                                                                                                                                                                                 weapons.bloody[k]=2;
10261                                                                                                                                                                                 weapons.blooddrip[k]=5;
10262                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
10263                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
10264                                                                                                                                                                                 player[i].victim->DoDamage(2000);
10265                                                                                                                                                                         }
10266                                                                                                                                                                 }
10267                                                                                                                                                                 if(player[i].victim->num_weapons>0){
10268                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
10269                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
10270                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
10271                                                                                                                                                                 }
10272
10273                                                                                                                                                                 player[i].victim->weaponactive=-1;
10274
10275                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
10276                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
10277                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
10278                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
10279                                                                                                                                                         }
10280                                                                                                                                                         weapons.owner[k]=i;
10281                                                                                                                                                         if(player[i].num_weapons>0){
10282                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10283                                                                                                                                                         }
10284                                                                                                                                                         player[i].num_weapons++;
10285                                                                                                                                                         player[i].weaponids[0]=k;
10286                                                                                                                                                 }
10287                                                                                                                                         }
10288                                                                                                                                 }
10289                                                                                                         }
10290                                                                                         }
10291                                                                                 }
10292                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10293                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
10294                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
10295                                                                                                         if(numplayers>1)
10296                                                                                                                 for(j=0;j<numplayers;j++){
10297                                                                                                                         if(i!=j)
10298                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
10299                                                                                                                                         if(hostile)
10300                                                                                                                                                 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&findDistancefast(&player[i].coords,&player[j].coords)<100&&findDistancefast(&player[i].coords,&player[j].coords)>1.5&&!player[j].skeleton.free&&-1==checkcollide(DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){
10301                                                                                                                                                         if(!player[i].isFlip()){
10302                                                                                                                                                                 player[i].throwtogglekeydown=1;
10303                                                                                                                                                                 player[i].victim=&player[j];
10304                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10305                                                                                                                                                                 player[i].target=0;
10306                                                                                                                                                                 player[i].targetframe=0;
10307                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10308                                                                                                                                                                 Normalise(&rotatetarget);
10309                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10310                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10311                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10312
10313                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10314                                                                                                                                                         }
10315                                                                                                                                                         if(player[i].isFlip()){
10316                                                                                                                                                                 if(player[i].weaponactive!=-1){
10317                                                                                                                                                                         player[i].throwtogglekeydown=1;
10318                                                                                                                                                                         player[i].victim=&player[j];
10319                                                                                                                                                                         XYZ aim;
10320                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10321                                                                                                                                                                         aim=player[i].victim->coords+DoRotation(player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].position,0,player[i].victim->rotation,0)*player[i].victim->scale+player[i].victim->velocity*findDistance(&player[i].victim->coords,&player[i].coords)/50-(player[i].coords+DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[righthand]].position,0,player[i].rotation,0)*player[i].scale);                                                
10322                                                                                                                                                                         Normalise(&aim);
10323
10324                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10325
10326                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10327                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10328                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10329                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10330                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10331                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10332                                                                                                                                                                         player[i].num_weapons--;
10333                                                                                                                                                                         if(player[i].num_weapons){
10334                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10335                                                                                                                                                                         }
10336                                                                                                                                                                         player[i].weaponactive=-1;
10337                                                                                                                                                                 }               
10338                                                                                                                                                         }
10339                                                                                                                                                 }
10340                                                                                                                 }
10341                                                                                         }
10342                                                                                 }
10343                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10344                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10345                                                                                         {
10346                                                                                                 player[i].throwtogglekeydown=1;
10347                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10348                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10349                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10350                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10351                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10352                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10353                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10354                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10355                                                                                                 player[i].num_weapons--;
10356                                                                                                 if(player[i].num_weapons){
10357                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10358                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10359                                                                                                 }
10360
10361                                                                                                 player[i].weaponactive=-1;
10362                                                                                                 for(j=0;j<numplayers;j++){
10363                                                                                                         player[j].wentforweapon=0;
10364                                                                                                 }
10365                                                                                         }
10366                                                                                 }
10367
10368                                                                         }
10369
10370                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10371                                                                                 if((player[i].drawkeydown&&!player[i].drawtogglekeydown)||(player[i].num_weapons==2&&player[i].weaponactive==-1&&player[i].isIdle())||(player[0].dead&&player[i].weaponactive!=-1&&i!=0)){
10372                                                                                         //Setenvironment(1-environment);
10373                                                                                         bool isgood;
10374                                                                                         isgood=1;
10375                                                                                         if(player[i].weaponactive!=-1){
10376                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10377                                                                                         }
10378                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10379                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10380                                                                                                         player[i].targetanimation=drawrightanim;
10381                                                                                                         player[i].targetframe=0;
10382                                                                                                         player[i].target=0;
10383                                                                                                         player[i].drawtogglekeydown=1;
10384                                                                                                 }
10385                                                                                                 if((player[i].isIdle()||(player[i].aitype!=playercontrolled&&player[0].weaponactive!=-1&&player[i].isRun()))&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==sword){
10386                                                                                                         player[i].targetanimation=drawleftanim;
10387                                                                                                         player[i].targetframe=0;
10388                                                                                                         player[i].target=0;
10389                                                                                                         player[i].drawtogglekeydown=1;
10390                                                                                                 }
10391                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10392                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10393                                                                                                         player[i].targetframe=0;
10394                                                                                                         player[i].target=0;
10395                                                                                                         player[i].drawtogglekeydown=1;
10396                                                                                                 }
10397                                                                                         }                        
10398                                                                                 }
10399                                                                                 if(player[i].isCrouch()&&weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&bloodtoggle&&player[i].onterrain&&player[i].num_weapons&&player[i].weaponactive!=-1&&player[i].attackkeydown){
10400                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10401                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10402                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10403                                                                                                 player[i].targetframe=0;
10404                                                                                                 player[i].target=0;
10405                                                                                                 player[i].hasvictim=0;
10406                                                                                                 //player[i].attacktogglekeydown=1;
10407                                                                                         }
10408                                                                                 }
10409
10410                                                                                 if(!player[i].drawkeydown){
10411                                                                                         player[i].drawtogglekeydown=0;
10412                                                                                 }
10413
10414                                                                                 if(i==0){
10415                                                                                         absflatfacing=0;
10416                                                                                         absflatfacing.z=-1;
10417
10418                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10419                                                                                 }
10420                                                                                 else absflatfacing=flatfacing;
10421
10422                                                                                 if(indialogue!=-1){
10423                                                                                         player[i].forwardkeydown=0;
10424                                                                                         player[i].leftkeydown=0;
10425                                                                                         player[i].backkeydown=0;
10426                                                                                         player[i].rightkeydown=0;
10427                                                                                         player[i].jumpkeydown=0;
10428                                                                                         player[i].crouchkeydown=0;
10429                                                                                         player[i].drawkeydown=0;
10430                                                                                         player[i].throwkeydown=0;
10431                                                                                 }
10432                                                                                 movekey=0;
10433                                                                                 //Do controls
10434                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10435                                                                                         if(!player[i].forwardkeydown){
10436                                                                                                 player[i].forwardstogglekeydown=0;
10437                                                                                         }
10438                                                                                         if(player[i].crouchkeydown){
10439                                                                                                 //Crouch
10440                                                                                                 target=-2;
10441                                                                                                 if(i==0){
10442                                                                                                         player[i].superruntoggle=1;
10443                                                                                                         if(numplayers>1)
10444                                                                                                                 for(j=0;j<numplayers;j++){
10445                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10446                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10447                                                                                                                                         player[i].superruntoggle=0;
10448                                                                                                                                 }
10449                                                                                                                         }
10450                                                                                                                 }
10451                                                                                                 }
10452
10453                                                                                                 if(numplayers>1)
10454                                                                                                         for(j=0;j<numplayers;j++){
10455                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10456                                                                                                                         if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim||player[j].targetanimation==upunchanim||player[j].targetanimation==wolfslapanim||((player[j].targetanimation==swordslashanim||player[j].targetanimation==knifeslashstartanim||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim)&&findDistancefast(&player[j].coords,&player[i].coords)<2))){
10457                                                                                                                                 if(target>=0)target=-1;
10458                                                                                                                                 else target=j;
10459                                                                                                                         }
10460                                                                                                                 }
10461                                                                                                         }
10462                                                                                                         if(target>=0)player[target].Reverse();
10463                                                                                                         player[i].lowreversaldelay=.5;
10464
10465                                                                                                         if(player[i].isIdle()){
10466                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10467                                                                                                                 player[i].target=0;
10468                                                                                                                 player[i].targetframe=0;
10469                                                                                                                 player[i].transspeed=10;
10470                                                                                                         }
10471                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10472                                                                                                                 player[i].targetanimation=rollanim;
10473                                                                                                                 player[i].target=0;
10474                                                                                                                 player[i].targetframe=0;
10475                                                                                                                 player[i].transspeed=20;
10476                                                                                                         }
10477                                                                                         }
10478                                                                                         if(!player[i].crouchkeydown){
10479                                                                                                 //Uncrouch
10480                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10481                                                                                                 target=-2;
10482                                                                                                 if(player[i].isCrouch()){
10483                                                                                                         if(numplayers>1)
10484                                                                                                                 for(j=0;j<numplayers;j++){
10485                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10486                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10487                                                                                                                                         if(target>=0)target=-1;
10488                                                                                                                                         else target=j;
10489                                                                                                                                 }
10490                                                                                                                         }
10491                                                                                                                 }
10492                                                                                                                 if(target>=0)player[target].Reverse();
10493                                                                                                                 player[i].highreversaldelay=.5;
10494
10495                                                                                                                 if(player[i].isCrouch()){                                               
10496                                                                                                                         if(!player[i].wasCrouch()){
10497                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10498                                                                                                                                 player[i].currentframe=0;
10499                                                                                                                         }
10500                                                                                                                         player[i].target=0;
10501                                                                                                                         player[i].targetanimation=player[i].getIdle();
10502                                                                                                                         player[i].targetframe=0;
10503                                                                                                                         player[i].transspeed=10;
10504                                                                                                                 }
10505                                                                                                 }
10506                                                                                                 if(player[i].targetanimation==sneakanim){
10507                                                                                                         player[i].targetanimation=player[i].getIdle();
10508                                                                                                         player[i].target=0;
10509                                                                                                         player[i].targetframe=0;
10510                                                                                                         player[i].transspeed=10;
10511                                                                                                 }
10512                                                                                         }
10513                                                                                         if(player[i].forwardkeydown){
10514                                                                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
10515                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10516                                                                                                         else player[i].targetanimation=player[i].getRun();
10517                                                                                                         player[i].target=0;
10518                                                                                                         player[i].targetframe=0;
10519                                                                                                 }
10520                                                                                                 if(player[i].isCrouch()){
10521                                                                                                         player[i].targetanimation=sneakanim;
10522                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10523                                                                                                         player[i].targetframe=0;
10524                                                                                                 }
10525                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10526                                                                                                         player[i].targetanimation=climbanim;
10527                                                                                                         player[i].target=0;
10528                                                                                                         player[i].targetframe=1;
10529                                                                                                         player[i].jumpclimb=1;
10530                                                                                                 }
10531                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10532                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10533                                                                                                 }
10534                                                                                                 player[i].forwardstogglekeydown=1;
10535                                                                                                 movekey=1;
10536                                                                                         }
10537                                                                                         if (player[i].rightkeydown){
10538                                                                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
10539                                                                                                         player[i].targetanimation=player[i].getRun();
10540                                                                                                         player[i].target=0;
10541                                                                                                         player[i].targetframe=0;
10542                                                                                                 }
10543                                                                                                 if(player[i].isCrouch()){
10544                                                                                                         player[i].targetanimation=sneakanim;
10545                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10546                                                                                                         player[i].targetframe=0;
10547                                                                                                 }
10548                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10549                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10550                                                                                                 }
10551                                                                                                 player[i].targetrotation-=90;
10552                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10553                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10554                                                                                                 movekey=1;
10555                                                                                         }
10556                                                                                         if ( player[i].leftkeydown){
10557                                                                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
10558                                                                                                         player[i].targetanimation=player[i].getRun();
10559                                                                                                         player[i].target=0;
10560                                                                                                         player[i].targetframe=0;
10561                                                                                                 }
10562                                                                                                 if(player[i].isCrouch()){
10563                                                                                                         player[i].targetanimation=sneakanim;
10564                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10565                                                                                                         player[i].targetframe=0;
10566                                                                                                 }
10567                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10568                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10569                                                                                                 }
10570                                                                                                 player[i].targetrotation+=90;
10571                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10572                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10573                                                                                                 movekey=1;
10574                                                                                         }
10575                                                                                         if(player[i].backkeydown){
10576                                                                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
10577                                                                                                         player[i].targetanimation=player[i].getRun();
10578                                                                                                         player[i].target=0;
10579                                                                                                         player[i].targetframe=0;
10580                                                                                                 }
10581                                                                                                 if(player[i].isCrouch()){
10582                                                                                                         player[i].targetanimation=sneakanim;
10583                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10584                                                                                                         player[i].targetframe=0;
10585                                                                                                 }
10586                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10587                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10588                                                                                                 }
10589                                                                                                 if(player[i].targetanimation==hanganim){
10590                                                                                                         player[i].currentanimation=jumpdownanim;
10591                                                                                                         player[i].targetanimation=jumpdownanim;
10592                                                                                                         player[i].target=0;
10593                                                                                                         player[i].currentframe=0;
10594                                                                                                         player[i].targetframe=1;
10595                                                                                                         player[i].velocity=0;
10596                                                                                                         player[i].velocity.y+=gravity;
10597                                                                                                         player[i].coords.y-=1.4;
10598                                                                                                         player[i].grabdelay=1;
10599                                                                                                 }
10600                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10601                                                                                                         player[i].targetrotation+=180;
10602                                                                                                 movekey=1;
10603                                                                                         }
10604                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10605                                                                                                 if((((player[i].isLanding()&&player[i].targetframe>=3)||player[i].isRun()||player[i].targetanimation==walkanim||player[i].isCrouch()||player[i].targetanimation==sneakanim)&&player[i].jumppower>1)&&((player[i].targetanimation!=rabbitrunninganim&&player[i].targetanimation!=wolfrunninganim)||i!=0)){
10606                                                                                                         player[i].jumpstart=0;
10607                                                                                                         player[i].targetanimation=jumpupanim;
10608                                                                                                         player[i].target=0;
10609                                                                                                         player[i].targetframe=0;
10610                                                                                                         player[i].rotation=player[i].targetrotation;
10611                                                                                                         player[i].transspeed=20;
10612                                                                                                         player[i].FootLand(0,1);
10613                                                                                                         player[i].FootLand(1,1);
10614
10615                                                                                                         facing=0;
10616                                                                                                         facing.z=-1;
10617                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10618
10619                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10620                                                                                                         if(!movekey)player[i].velocity=0;
10621
10622                                                                                                         //Dodge sweep?
10623                                                                                                         target=-2;
10624                                                                                                         if(numplayers>1)
10625                                                                                                                 for(j=0;j<numplayers;j++){
10626                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10627                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10628                                                                                                                                         if(target>=0)target=-1;
10629                                                                                                                                         else target=j;
10630                                                                                                                                 }
10631                                                                                                                         }
10632                                                                                                                 }
10633                                                                                                                 if(target>=0)player[i].velocity.y=1;
10634                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10635                                                                                                                         player[i].velocity.y=7;
10636                                                                                                                         player[i].crouchtogglekeydown=1;
10637                                                                                                                 }
10638                                                                                                                 else player[i].velocity.y=5;
10639
10640                                                                                                                 if(mousejump&&i==0&&debugmode){
10641                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10642                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10643                                                                                                                 }
10644
10645                                                                                                                 player[i].coords.y+=.2;
10646                                                                                                                 player[i].jumppower-=1;
10647
10648                                                                                                                 static float gLoc[3];
10649                                                                                                                 static float vel[3];
10650                                                                                                                 gLoc[0]=player[i].coords.x;
10651                                                                                                                 gLoc[1]=player[i].coords.y;
10652                                                                                                                 gLoc[2]=player[i].coords.z;
10653                                                                                                                 vel[0]=player[i].velocity.x;
10654                                                                                                                 vel[1]=player[i].velocity.y;
10655                                                                                                                 vel[2]=player[i].velocity.z;
10656
10657                                                                                                                 if(i==0){
10658                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
10659                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10660                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
10661                                                                                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
10662                                                                                                                 }
10663
10664                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
10665                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10666                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
10667                                                                                                                 FSOUND_SetPaused(channels[jumpsound], FALSE);
10668                                                                                                 }               
10669                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10670                                                                                                         player[i].targetanimation=player[i].getLanding();
10671                                                                                                         player[i].landhard=0;
10672                                                                                                         player[i].target=0;
10673                                                                                                         player[i].targetframe=2;
10674                                                                                                         player[i].jumpstart=1;
10675                                                                                                         player[i].tempdeltav=deltav;
10676                                                                                                 }               
10677                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10678                                                                                                         if(player[i].jumppower>multiplier*6){
10679                                                                                                                 player[i].velocity.y+=multiplier*6;
10680                                                                                                                 player[i].jumppower-=multiplier*6;
10681                                                                                                         }
10682                                                                                                         if(player[i].jumppower<=multiplier*6){
10683                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10684                                                                                                                 player[i].jumppower=0;
10685                                                                                                         }
10686                                                                                                 }
10687                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;           
10688                                                                                         }
10689
10690                                                                                         if(!movekey){
10691                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10692                                                                                                         player[i].targetanimation=player[i].getStop();
10693                                                                                                         player[i].target=0;
10694                                                                                                         player[i].targetframe=0;
10695                                                                                                 }
10696                                                                                                 if(player[i].targetanimation==sneakanim){
10697                                                                                                         player[i].targetanimation=player[i].getCrouch();
10698                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10699                                                                                                         player[i].targetframe=0;
10700                                                                                                 }
10701                                                                                         }
10702                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10703                                                                                                 player[i].targetanimation=player[i].getStop();
10704                                                                                                 player[i].target=0;
10705                                                                                                 player[i].targetframe=0;
10706                                                                                         }
10707                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10708                                                                                                 player[i].targetanimation=player[i].getStop();
10709                                                                                                 player[i].target=0;
10710                                                                                                 player[i].targetframe=0;
10711                                                                                         }
10712                                                                                 }
10713                                                                 }
10714                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10715                                                         }
10716
10717                                                         //Rotation
10718                                                         for(k=0;k<numplayers;k++){
10719                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10720                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10721                                                                         else player[k].rotation+=360;
10722                                                                 }
10723
10724                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10725                                                                         player[k].targetanimation=player[k].getStop();
10726                                                                         player[k].targetframe=0;
10727                                                                         player[k].target=0;
10728                                                                 }
10729
10730                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10731                                                                         player[k].targettilt=0;
10732                                                                 }
10733                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10734                                                                         player[k].targettilt=0;
10735                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10736                                                                         player[k].jumppower+=multiplier*7;
10737                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10738                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10739                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10740                                                                 }
10741
10742                                                                 if(player[k].isRun()){
10743                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10744                                                                 }
10745
10746                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10747                                                                 else if(player[k].tilt>player[k].targettilt){
10748                                                                         player[k].tilt-=multiplier*150;
10749                                                                 }
10750                                                                 else if(player[k].tilt<player[k].targettilt){
10751                                                                         player[k].tilt+=multiplier*150;
10752                                                                 }
10753
10754                                                                 player[k].grabdelay-=multiplier;
10755                                                         }
10756
10757                                                         for(k=0;k<numplayers;k++){
10758                                                                 player[k].DoAnimations();
10759                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10760                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10761                                                         }
10762
10763                                                         objects.DoStuff();
10764                                                         /*
10765                                                         player[0].righthandmorphstart=0;
10766                                                         player[0].righthandmorphend=1;
10767                                                         player[0].lefthandmorphstart=0;
10768                                                         player[0].lefthandmorphend=1;
10769                                                         player[0].headmorphstart=0;
10770                                                         player[0].headmorphend=2;*/
10771
10772                                                         /*
10773                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10774                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10775                                                         player[0].righthandmorphend=1;
10776                                                         player[0].targetrighthandmorphness=1;
10777
10778                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10779                                                         player[0].lefthandmorphend=0;
10780                                                         player[0].targetlefthandmorphness=1;
10781
10782                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10783                                                         player[0].headmorphend=2;
10784                                                         player[0].targetheadmorphness=1;
10785                                                         }
10786                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10787                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10788                                                         player[0].righthandmorphend=0;
10789                                                         player[0].targetrighthandmorphness=1;
10790
10791                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10792                                                         player[0].lefthandmorphend=1;
10793                                                         player[0].targetlefthandmorphness=1;
10794
10795                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10796                                                         player[0].headmorphend=0;
10797                                                         player[0].targetheadmorphness=1;
10798                                                         }
10799                                                         */
10800                                                         if(numenvsounds!=0)
10801                                                                 for(j=numenvsounds-1;j>=0;j--){
10802                                                                         envsoundlife[j]-=multiplier;
10803                                                                         if(envsoundlife[j]<0){
10804                                                                                 numenvsounds--;
10805                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10806                                                                                 envsound[j]=envsound[numenvsounds];
10807                                                                         }
10808                                                                 }
10809                                                                 if(!slomo)FSOUND_SetFrequency(FSOUND_ALL, 22050);
10810                                                                 if(slomo)FSOUND_SetFrequency(FSOUND_ALL, slomofreq);
10811
10812                                                                 if(tutoriallevel==1){
10813                                                                         XYZ temp;
10814                                                                         XYZ temp2;
10815                                                                         XYZ temp3;
10816                                                                         XYZ oldtemp;
10817                                                                         XYZ oldtemp2;
10818                                                                         temp.x=1011;
10819                                                                         temp.y=84;
10820                                                                         temp.z=491;
10821                                                                         temp2.x=1025;
10822                                                                         temp2.y=75;
10823                                                                         temp2.z=447;
10824                                                                         temp3.x=1038;
10825                                                                         temp3.y=76;
10826                                                                         temp3.z=453;
10827                                                                         oldtemp=temp;
10828                                                                         oldtemp2=temp2;
10829                                                                         if(tutorialstage>=51)
10830                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10831                                                     FSOUND_StopSound(FSOUND_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
10832                                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
10833
10834                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10835                                                                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10836                                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
10837
10838                                                                                         gameon=0;
10839                                                                                         mainmenu=5;
10840
10841                                                                                         float gLoc[3]={0,0,0};
10842                                                                                         float vel[3]={0,0,0};
10843                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10844                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10845                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10846                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10847                                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10848                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10849
10850                                                                                         flashr=1;
10851                                                                                         flashg=0;
10852                                                                                         flashb=0;
10853                                                                                         flashamount=1;
10854                                                                                         flashdelay=1;
10855                                                                                 }
10856                                                                                 if(tutorialstage<51)
10857                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10858                                                                                                 float gLoc[3];
10859                                                                                                 float vel[3];
10860                                                                                                 gLoc[0]=player[0].coords.x;
10861                                                                                                 gLoc[1]=player[0].coords.y;
10862                                                                                                 gLoc[2]=player[0].coords.z;
10863                                                                                                 vel[0]=0;
10864                                                                                                 vel[1]=0;
10865                                                                                                 vel[2]=0;
10866                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10867                                                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10868                                                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
10869                                                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
10870
10871                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10872
10873                                                                                                 flashr=1;
10874                                                                                                 flashg=1;
10875                                                                                                 flashb=1;
10876                                                                                                 flashamount=1;
10877                                                                                                 flashdelay=1;
10878                                                                                         }
10879                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10880                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10881                                                                                                         float gLoc[3];
10882                                                                                                         float vel[3];
10883                                                                                                         gLoc[0]=player[1].coords.x;
10884                                                                                                         gLoc[1]=player[1].coords.y;
10885                                                                                                         gLoc[2]=player[1].coords.z;
10886                                                                                                         vel[0]=0;
10887                                                                                                         vel[1]=0;
10888                                                                                                         vel[2]=0;
10889                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10890                                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10891                                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10892                                                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10893
10894                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10895                                                                                                                 if(Random()%2==0){
10896                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10897                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10898                                                                                                                         if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
10899                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10900                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10901                                                                                                                 }
10902                                                                                                         }
10903
10904                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10905                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10906                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10907                                                                                                                 if(Random()%2==0){
10908                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10909                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10910                                                                                                                         if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
10911                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10912                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10913                                                                                                                 }
10914                                                                                                         }
10915                                                                                                 }
10916                                                                 }
10917
10918
10919                                                                 //3d sound
10920                                                                 static float gLoc[3];
10921                                                                 gLoc[0]=viewer.x;
10922                                                                 gLoc[1]=viewer.y;
10923                                                                 gLoc[2]=viewer.z;
10924                                                                 static float vel[3];
10925                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10926                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10927                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10928
10929                                                                 //Set orientation with forward and up vectors
10930                                                                 static XYZ upvector;
10931                                                                 upvector=0;
10932                                                                 upvector.z=-1;
10933
10934                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10935                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10936
10937                                                                 facing=0;
10938                                                                 facing.z=-1;
10939                                                                 
10940                                                                 facing=DoRotation(facing,-rotation2,0,0);
10941                                                                 facing=DoRotation(facing,0,0-rotation,0);
10942                 
10943                 
10944                                                                 static float ori[6];
10945                                                                 ori[0] = -facing.x;
10946                                                                 ori[1] = facing.y;
10947                                                                 ori[2] = -facing.z;
10948                                                                 ori[3] = -upvector.x;
10949                                                                 ori[4] = upvector.y;
10950                                                                 ori[5] = -upvector.z;
10951
10952                                                                 FSOUND_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10953                                                                 FSOUND_Update();
10954
10955                                                                 oldviewer=viewer;
10956                 }
10957         }
10958
10959         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10960                 Screenshot();
10961                 freezetogglekeydown=1;
10962         }
10963 }
10964
10965 void    Game::TickOnce(){
10966         //if(!console){
10967         if(!mainmenu)
10968                 if(directing||indialogue==-1){
10969                         rotation+=deltah*.7;
10970                         if(!invertmouse)rotation2+=deltav*.7;
10971                         if(invertmouse)rotation2-=deltav*.7;
10972                         if(rotation2>90)rotation2=90;
10973                         if(rotation2<-70)rotation2=-70;
10974                 }
10975                 if(mainmenu)rotation+=multiplier*5;
10976                 if(!mainmenu&&!indemo&&!registered){
10977                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
10978                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10979                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10980                         FSOUND_SetVolume(channels[stream_music3], 256);
10981
10982                         gameon=0;
10983                         mainmenu=12;
10984
10985                         float gLoc[3]={0,0,0};
10986                         float vel[3]={0,0,0};
10987                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10988                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10989                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10990                         FSOUND_SetVolume(channels[fireendsound], 256);
10991                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10992                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10993
10994                         flashr=1;
10995                         flashg=0;
10996                         flashb=0;
10997                         flashamount=1;
10998                         flashdelay=1;
10999                 }
11000
11001                 if(tryquit==1&&!registered&&mainmenu!=12){
11002                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
11003                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11004                         FSOUND_SetPaused(channels[stream_music3], FALSE);
11005                         FSOUND_SetVolume(channels[stream_music3], 256);
11006
11007                         gameon=0;
11008                         mainmenu=12;
11009
11010                         float gLoc[3]={0,0,0};
11011                         float vel[3]={0,0,0};
11012                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11013                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11014                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11015                         FSOUND_SetVolume(channels[fireendsound], 256);
11016                         FSOUND_SetPaused(channels[fireendsound], FALSE);
11017                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11018
11019                         flashr=1;
11020                         flashg=0;
11021                         flashb=0;
11022                         flashamount=1;
11023                         flashdelay=1;
11024                 }
11025                 //}
11026 }
11027
11028 void    Game::TickOnceAfter(){
11029         static XYZ colviewer;
11030         static XYZ coltarget;
11031         static XYZ target;
11032         static XYZ col;
11033         static float brotate;
11034         static XYZ facing;
11035         static int i,j;
11036         static float changedelay;
11037         static bool alldead;
11038         static float unseendelay;
11039         static float cameraspeed;
11040
11041         if(!mainmenu){
11042
11043                 if(environment==snowyenvironment)music1=stream_music1snow;
11044                 if(environment==grassyenvironment)music1=stream_music1grass;
11045                 if(environment==desertenvironment)music1=stream_music1desert;
11046
11047                 realthreat=0;
11048
11049                 musictype=music1;
11050                 for(i=0;i<numplayers;i++){
11051                         if((player[i].aitype==attacktypecutoff||player[i].aitype==getweapontype||player[i].aitype==gethelptype||player[i].aitype==searchtype)&&!player[i].dead/*&&player[i].surprised<=0*/&&(player[i].targetanimation!=sneakattackedanim&&player[i].targetanimation!=knifesneakattackedanim&&player[i].targetanimation!=swordsneakattackedanim)){
11052                                 musictype=stream_music2;
11053                                 realthreat=1;
11054                         }
11055                 }
11056                 if(player[0].dead)musictype=stream_music3;
11057
11058
11059                 if(musictype==stream_music2){
11060                         unseendelay=1;
11061                 }
11062
11063                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
11064                         unseendelay-=multiplier;
11065                         if(unseendelay>0){
11066                                 musictype=stream_music2;
11067                         }
11068                 }
11069
11070
11071                 if(loading==2){
11072                         musictype=stream_music3;
11073                         musicvolume[2]=512;
11074                         musicvolume[0]=0;
11075                         musicvolume[1]=0;
11076                         musicvolume[3]=0;
11077                 }       
11078
11079                 if(musictoggle){                        
11080                         if(musictype!=oldmusictype&&musictype==stream_music2){
11081                                 static float gLoc[3];
11082                                 static float vel[3];
11083                                 gLoc[0]=cameraloc.x;
11084                                 gLoc[1]=cameraloc.y;
11085                                 gLoc[2]=cameraloc.z;
11086                                 vel[0]=0;
11087                                 vel[1]=0;
11088                                 vel[2]=0;
11089                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, TRUE);
11090                                 FSOUND_SetVolume(channels[alarmsound], 512);
11091                                 FSOUND_SetPaused(channels[alarmsound], FALSE);
11092
11093                         }
11094                 }
11095                 musicselected=musictype;
11096
11097                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
11098                 else musicvolume[0]-=multiplier*450;
11099                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
11100                 else musicvolume[1]-=multiplier*450;
11101                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
11102                 else musicvolume[2]-=multiplier*450;
11103                 /*
11104                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
11105                 else musicvolume[0]-=multiplier*450;
11106                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
11107                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
11108                 else musicvolume[1]-=multiplier*100;
11109                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
11110                 else musicvolume[2]-=multiplier*450;*/
11111
11112                 for(i=0;i<3;i++){
11113                         if(musicvolume[i]<0)musicvolume[i]=0;
11114                         if(musicvolume[i]>512)musicvolume[i]=512;
11115                 }
11116
11117                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
11118
11119                 if(musictoggle){                
11120                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
11121                                 PlayStreamEx( music1, strm[music1], NULL, TRUE);
11122                                 FSOUND_SetPaused(channels[music1], FALSE);
11123                         }
11124                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
11125                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, TRUE);
11126                                 FSOUND_SetPaused(channels[stream_music2], FALSE);
11127                         }
11128                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
11129                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11130                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
11131                         }
11132                 }
11133
11134                 if(!musictoggle){               
11135                         FSOUND_SetPaused(channels[music1], TRUE);
11136                         FSOUND_SetPaused(channels[stream_music2], TRUE);
11137                         FSOUND_SetPaused(channels[stream_music3], TRUE);
11138
11139                         for(i=0;i<4;i++){
11140                                 oldmusicvolume[i]=0;
11141                                 musicvolume[i]=0;
11142                         }
11143                 }
11144
11145                 if(musictoggle){                
11146                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
11147                                 FSOUND_SetPaused(channels[music1], TRUE);
11148                         }
11149                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
11150                                 FSOUND_SetPaused(channels[stream_music2], TRUE);
11151                         }
11152                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
11153                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
11154                         }
11155
11156                         if(musicvolume[0]!=oldmusicvolume[0]){
11157                                 FSOUND_SetVolume(channels[music1], musicvolume[0]);
11158                         }
11159                         if(musicvolume[1]!=oldmusicvolume[1]){
11160                                 FSOUND_SetVolume(channels[stream_music2], musicvolume[1]);
11161                         }
11162                         if(musicvolume[2]!=oldmusicvolume[2]){
11163                                 FSOUND_SetVolume(channels[stream_music3], musicvolume[2]);
11164                         }
11165
11166                         for(i=0;i<3;i++){
11167                                 oldmusicvolume[i]=musicvolume[i];
11168                         }
11169                 }
11170
11171                 killhotspot=2;
11172                 if(numhotspots)
11173                         for(i=0;i<numhotspots;i++){
11174                                 if(hotspottype[i]>10&&hotspottype[i]<20){
11175                                         if(player[hotspottype[i]-10].dead==0){
11176                                                 killhotspot=0;
11177                                         }
11178                                         else if(killhotspot==2)
11179                                                 killhotspot=1;
11180                                 }
11181                         }
11182                         if(killhotspot==2)killhotspot=0;
11183
11184
11185                         winhotspot=0;
11186                         if(numhotspots)
11187                                 for(i=0;i<numhotspots;i++){
11188                                         if(hotspottype[i]==-1){
11189                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
11190                                                         winhotspot=1;
11191                                         }
11192                                 }
11193
11194                                 int numalarmed=0;
11195                                 if(numplayers>1)
11196                                         for(i=1;i<numplayers;i++){              
11197                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
11198                                         }
11199                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
11200
11201                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){          
11202                                                 if(player[0].dead&&changedelay<=0){
11203                                                         changedelay=1;
11204                                                         targetlevel=whichlevel;
11205                                                 }
11206                                                 alldead=1;
11207                                                 if(numplayers>1)
11208                                                         for(i=1;i<numplayers;i++){              
11209                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
11210                                                         }
11211
11212
11213                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
11214                                                                 changedelay=1;
11215                                                                 targetlevel=whichlevel+1;
11216                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11217                                                         }
11218                                                         if(winhotspot||windialogue){
11219                                                                 changedelay=0.1;
11220                                                                 targetlevel=whichlevel+1;
11221                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11222                                                         }
11223
11224
11225                                                         if(killhotspot){
11226                                                                 changedelay=1;
11227                                                                 targetlevel=whichlevel+1;
11228                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11229                                                         }
11230
11231                                                         if(changedelay>0&&!player[0].dead&&!won){
11232                                                                 //high scores, awards, win
11233                                                                 if(campaign){
11234                                                                         won=1;
11235                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11236                                                                         accountcampaignchoicesmade[accountactive]++;
11237                                                                         accountcampaignscore[accountactive]+=bonustotal;
11238                                                                         scoreadded=1;
11239                                                                         accountcampaigntime[accountactive]+=leveltime;
11240                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
11241
11242                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11243                                                                 }
11244                                                                 else
11245                                                                 {
11246                                                                         won=1;
11247                                                                         if(!debugmode){
11248                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
11249                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;            
11250                                                                         }
11251                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11252
11253                                                                 }
11254                                                         }
11255                                         }
11256
11257                                         if(!winfreeze){
11258
11259                                                 if(leveltime<1){
11260                                                         loading=0;
11261                                                         changedelay=.1;
11262                                                         alldead=0;
11263                                                         winhotspot=0;
11264                                                         killhotspot=0;
11265                                                 }
11266
11267                                                 if(!editorenabled&&gameon&&!mainmenu){
11268                                                         if(changedelay!=-999)changedelay-=multiplier/7;
11269                                                         if(player[0].dead)targetlevel=whichlevel;
11270                                                         if(loading==2&&!campaign){
11271                                                                 flashr=1;
11272                                                                 flashg=0;
11273                                                                 flashb=0;
11274                                                                 flashamount=1;
11275                                                                 flashdelay=1;
11276                                                                 loadtime=0;
11277
11278                                                                 float gLoc[3]={0,0,0};
11279                                                                 float vel[3]={0,0,0};
11280                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11281                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11282                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11283                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11284                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
11285                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11286
11287                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
11288                                                                         startbonustotal=bonustotal;
11289                                                                 }
11290                                                                 if(!player[0].dead)Loadlevel(targetlevel);
11291                                                                 if(player[0].dead)Loadlevel(whichlevel);
11292
11293                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11294                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11295                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11296                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11297                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
11298                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11299
11300                                                                 loading=3;
11301                                                         }
11302                                                         if(loading==2&&targetlevel==whichlevel){
11303                                                                 flashr=1;
11304                                                                 flashg=0;
11305                                                                 flashb=0;
11306                                                                 flashamount=1;
11307                                                                 flashdelay=1;
11308                                                                 loadtime=0;
11309
11310                                                                 float gLoc[3]={0,0,0};
11311                                                                 float vel[3]={0,0,0};
11312                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11313                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11314                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11315                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11316                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
11317                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11318
11319                                                                 for(i=0;i<255;i++){
11320                                                                         mapname[i]='\0';
11321                                                                 }
11322                                                                 mapname[0]=':';
11323                                                                 mapname[1]='D';
11324                                                                 mapname[2]='a';
11325                                                                 mapname[3]='t';
11326                                                                 mapname[4]='a';
11327                                                                 mapname[5]=':';
11328                                                                 mapname[6]='M';
11329                                                                 mapname[7]='a';
11330                                                                 mapname[8]='p';
11331                                                                 mapname[9]='s';
11332                                                                 mapname[10]=':';
11333                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
11334                                                                 Loadlevel(mapname);
11335
11336                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11337                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11338                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11339                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11340                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
11341                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11342
11343                                                                 loading=3;
11344                                                         }
11345                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
11346                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
11347                                                                 if(accountprogress[accountactive]>3&&!registered){
11348                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
11349                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11350                                                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
11351                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
11352
11353                                                                         gameon=0;
11354                                                                         mainmenu=12;
11355                                                                         accountprogress[accountactive]=3;
11356
11357                                                                         float gLoc[3]={0,0,0};
11358                                                                         float vel[3]={0,0,0};
11359                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11360                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11361                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11362                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
11363                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
11364                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11365
11366                                                                         flashr=1;
11367                                                                         flashg=0;
11368                                                                         flashb=0;
11369                                                                         flashamount=1;
11370                                                                         flashdelay=1;
11371                                                                 }
11372                                                                 else{
11373                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
11374                                                                                 winfreeze=1;
11375                                                                                 changedelay=-999;
11376                                                                         }
11377                                                                         if(player[0].dead)loading=1;
11378                                                                 }
11379                                                         }
11380                                                 }
11381
11382                                                 if(campaign)
11383                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11384                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11385                                                                         endgame=1;
11386                                                                 }
11387                                                         }
11388                                                         else if(mainmenu==0&&winfreeze){
11389                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11390                                                                         stealthloading=1;
11391                                                                 else stealthloading=0;
11392
11393                                                                 if(!stealthloading){
11394                                                                         float gLoc[3]={0,0,0};
11395                                                                         float vel[3]={0,0,0};
11396                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11397                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11398                                                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11399                                                                         FSOUND_SetVolume(channels[firestartsound], 256);
11400                                                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
11401                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11402
11403                                                                         flashr=1;
11404                                                                         flashg=0;
11405                                                                         flashb=0;
11406                                                                         flashamount=1;
11407                                                                         flashdelay=1;
11408                                                                 }
11409
11410                                                                 startbonustotal=0;
11411
11412                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
11413                                                                 //campaignnumlevels=0;
11414                                                                 //accountcampaignchoicesmade[accountactive]=0;
11415                                                                 ipstream.ignore(256,':');
11416                                                                 ipstream >> campaignnumlevels;
11417                                                                 for(i=0;i<campaignnumlevels;i++){
11418                                                                         ipstream.ignore(256,':');
11419                                                                         ipstream.ignore(256,':');
11420                                                                         ipstream.ignore(256,' ');
11421                                                                         ipstream >> campaignmapname[i];
11422                                                                         ipstream.ignore(256,':');
11423                                                                         ipstream >> campaigndescription[i];
11424                                                                         for(j=0;j<256;j++){
11425                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11426                                                                         }
11427                                                                         ipstream.ignore(256,':');
11428                                                                         ipstream >> campaignchoosenext[i];
11429                                                                         ipstream.ignore(256,':');
11430                                                                         ipstream >> campaignnumnext[i];
11431                                                                         if(campaignnumnext[i])
11432                                                                                 for(j=0;j<campaignnumnext[i];j++){
11433                                                                                         ipstream.ignore(256,':');
11434                                                                                         ipstream >> campaignnextlevel[i][j];
11435                                                                                         campaignnextlevel[i][j]-=1;
11436                                                                                 }
11437                                                                                 ipstream.ignore(256,':');
11438                                                                                 ipstream >> campaignlocationx[i];
11439                                                                                 ipstream.ignore(256,':');
11440                                                                                 ipstream >> campaignlocationy[i];
11441                                                                 }
11442                                                                 ipstream.close();
11443
11444                                                                 for(i=0;i<campaignnumlevels;i++){
11445                                                                         levelvisible[i]=0;
11446                                                                         levelhighlight[i]=0;
11447                                                                 }
11448
11449
11450                                                                 for(i=0;i<campaignnumlevels;i++){
11451                                                                         levelvisible[i]=0;
11452                                                                         levelhighlight[i]=0;
11453                                                                 }
11454
11455                                                                 levelorder[0]=0;
11456                                                                 levelvisible[0]=1;
11457                                                                 if(accountcampaignchoicesmade[accountactive])
11458                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11459                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11460                                                                                 levelvisible[levelorder[i+1]]=1;
11461                                                                         }
11462                                                                         int whichlevelstart;
11463                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11464                                                                         if(whichlevelstart<0){
11465                                                                                 campaignchoicenum=1;
11466                                                                                 campaignchoicewhich[0]=0;
11467                                                                         }
11468                                                                         else
11469                                                                         {
11470                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11471                                                                                 if(campaignchoicenum)
11472                                                                                         for(i=0;i<campaignchoicenum;i++){
11473                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11474                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11475                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11476                                                                                         }
11477                                                                         }
11478
11479                                                                         loading=2;
11480                                                                         loadtime=0;
11481                                                                         targetlevel=7;
11482                                                                         //if(firstload)TickOnceAfter();
11483                                                                         if(!firstload)LoadStuff();
11484                                                                         //else {
11485                                                                         for(i=0;i<255;i++){
11486                                                                                 mapname[i]='\0';
11487                                                                         }
11488                                                                         mapname[0]=':';
11489                                                                         mapname[1]='D';
11490                                                                         mapname[2]='a';
11491                                                                         mapname[3]='t';
11492                                                                         mapname[4]='a';
11493                                                                         mapname[5]=':';
11494                                                                         mapname[6]='M';
11495                                                                         mapname[7]='a';
11496                                                                         mapname[8]='p';
11497                                                                         mapname[9]='s';
11498                                                                         mapname[10]=':';
11499
11500                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11501                                                                         //accountcampaignchoicesmade[accountactive]++;
11502
11503
11504                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11505                                                                         whichchoice=0;
11506                                                                         visibleloading=1;
11507                                                                         stillloading=1;
11508                                                                         Loadlevel(mapname);
11509                                                                         campaign=1;
11510                                                                         mainmenu=0;
11511                                                                         gameon=1;
11512                                                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
11513
11514                                                                         stealthloading=0;
11515                                                         }
11516
11517                                                         if(loading==3)loading=0;
11518
11519                                         }
11520
11521                                         oldmusictype=musictype;
11522         }
11523
11524         facing=0;
11525         facing.z=-1;
11526
11527         facing=DoRotation(facing,-rotation2,0,0);
11528         facing=DoRotation(facing,0,0-rotation,0);
11529         viewerfacing=facing;
11530
11531         brotate=0;
11532         if(!cameramode){
11533                 if((animation[player[0].targetanimation].attack!=3&&animation[player[0].currentanimation].attack!=3)||player[0].skeleton.free)target=player[0].coords+player[0].currentoffset*(1-player[0].target)*player[0].scale+player[0].targetoffset*player[0].target*player[0].scale-player[0].facing*.05;
11534                 else target=player[0].oldcoords+player[0].currentoffset*(1-player[0].target)*player[0].scale+player[0].targetoffset*player[0].target*player[0].scale-player[0].facing*.05;
11535                 target.y+=.1;
11536                 if(player[0].skeleton.free){
11537                         for(i=0;i<player[0].skeleton.num_joints;i++){
11538                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)                         
11539                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11540                         }
11541                         target.y+=.1;
11542                 }
11543                 if(player[0].skeleton.free!=2&&!autocam){
11544                         cameraspeed=20;
11545                         if(findLengthfast(&player[0].velocity)>400){
11546                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11547                         }
11548                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11549                         coltarget=target-cameraloc;
11550                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11551                         else {
11552                                 Normalise(&coltarget);
11553                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11554                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11555                         }
11556                         if(editorenabled)cameraloc=target;
11557                         cameradist+=multiplier*5;
11558                         if(cameradist>2.3)cameradist=2.3;
11559                         viewer=cameraloc-facing*cameradist;
11560                         colviewer=viewer;
11561                         coltarget=cameraloc;
11562                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11563                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11564                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11565                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11566                                         colviewer=viewer;
11567                                         coltarget=cameraloc;
11568                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;     
11569                                 }
11570                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11571                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11572                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11573                                                 colviewer=viewer;
11574                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11575                                                         viewer=colviewer;
11576                                                 }
11577                                         }
11578                                         cameradist=findDistance(&viewer,&target);
11579                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11580                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11581                                         }
11582                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11583                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11584                                         }
11585                 }
11586                 if(player[0].skeleton.free!=2&&autocam){
11587                         cameraspeed=20;
11588                         if(findLengthfast(&player[0].velocity)>400){
11589                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11590                         }
11591                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11592                         cameradist+=multiplier*5;
11593                         if(cameradist>3.3)cameradist=3.3;
11594                         coltarget=target-cameraloc;
11595                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11596                         else if(findLengthfast(&coltarget)>1)
11597                         {
11598                                 Normalise(&coltarget);
11599                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11600                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11601                         }
11602                         if(editorenabled)cameraloc=target;
11603                         viewer=cameraloc;
11604                         colviewer=viewer;
11605                         coltarget=cameraloc;
11606                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11607                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11608                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11609                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11610                                         colviewer=viewer;
11611                                         coltarget=cameraloc;
11612                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;     
11613                                 }
11614                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11615                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11616                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11617                                                 colviewer=viewer;
11618                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11619                                                         viewer=colviewer;
11620                                                 }
11621                                         }
11622                                         cameradist=findDistance(&viewer,&target);
11623                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11624                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11625                                         }
11626                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11627                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11628                                         }
11629                 }
11630                 if(camerashake>.8)camerashake=.8;
11631                 //if(woozy>10)woozy=10;
11632                 //woozy+=multiplier;
11633                 woozy+=multiplier;
11634                 if(player[0].dead)camerashake=0;
11635                 if(player[0].dead)woozy=0;
11636                 camerashake-=multiplier*2;
11637                 blackout-=multiplier*2;
11638                 //if(player[0].isCrouch())woozy-=multiplier*8;
11639                 if(camerashake<0)camerashake=0;
11640                 if(blackout<0)blackout=0;
11641                 //if(woozy<0)woozy=0;
11642                 if(camerashake){
11643                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11644                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11645                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11646                 }
11647         }
11648 }