]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
Added newline to all the source/headers in Source.
[lugaru.git] / Source / GameTick.cpp
1 #include <direct.h>
2 #include <ctime>
3 #include "Game.h"
4
5 using namespace std;
6
7 extern float multiplier;
8 extern XYZ viewer;
9 extern int environment;
10 extern float texscale;
11 extern Terrain terrain;
12 extern FSOUND_SAMPLE    *samp[100];
13 extern int channels[100];
14 extern Sprites sprites;
15 extern int kTextureSize;
16 extern float screenwidth,screenheight;
17 extern float gravity;
18 extern int detail;
19 extern float texdetail;
20 extern Objects objects;
21 extern int slomo;
22 extern float slomodelay;
23 extern bool floatjump;
24 extern float volume;
25 extern Animation animation[animation_count];
26 extern Light light;
27 extern float texdetail;
28 extern GLubyte bloodText[512*512*3];
29 extern GLubyte wolfbloodText[512*512*3];
30 extern float terraindetail;
31 extern float camerashake;
32 extern float woozy;
33 extern float blackout;
34 extern bool cellophane;
35 extern bool musictoggle;
36 extern int difficulty;
37 extern Weapons weapons;
38 extern Person player[maxplayers];
39 extern int numplayers;
40 extern int bloodtoggle;
41 extern bool invertmouse;
42 extern float windvar;
43 extern float precipdelay;
44 extern XYZ viewerfacing;
45 extern bool ambientsound;
46 extern bool mousejump;
47 extern float viewdistance;
48 extern bool freeze;
49 extern bool autoslomo;
50 extern int newnetmessages;
51 extern char netmessages[256];
52 extern bool keyboardfrozen;
53 extern int netdatanew;
54 extern bool loadingstuff;
55 extern char mapname[256];
56 extern XYZ windvector;
57 extern bool buttons[3];
58 extern bool debugmode;
59 static int music1;
60 extern int mainmenu;
61 extern int oldmainmenu;
62 extern bool visibleloading;
63 extern int loadscreencolor;
64 extern float flashamount,flashr,flashg,flashb;
65 extern int flashdelay;
66 extern XYZ envsound[30];
67 extern float envsoundvol[30];
68 extern int numenvsounds;
69 extern float envsoundlife[30];
70 extern float usermousesensitivity;
71 extern bool ismotionblur;
72 extern bool foliage;
73 extern bool trilinear;
74 extern bool damageeffects;
75 extern bool showpoints;
76 extern bool texttoggle;
77 extern bool alwaysblur;
78 extern float gamespeed;
79 extern bool decals;
80 extern bool vblsync;
81 extern bool immediate;
82 extern bool velocityblur;
83 extern int bonus;
84 extern int oldbonus;
85 extern float bonusvalue;
86 extern float bonustotal;
87 extern float bonustime;
88 extern float startbonustotal;
89 extern float tintr,tintg,tintb;
90 extern float bonusnum[100];
91 extern bool skyboxtexture;
92 extern float skyboxr;
93 extern float skyboxg;
94 extern float skyboxb;
95 extern float skyboxlightr;
96 extern float skyboxlightg;
97 extern float skyboxlightb;
98 extern float fadestart;
99 extern float slomospeed;
100 extern float slomofreq;
101 extern int tutoriallevel;
102 extern float smoketex;
103 extern float tutorialstagetime;
104 extern int tutorialstage;
105 extern float tutorialmaxtime;
106 extern float tutorialsuccess;
107 extern bool againbonus;
108 extern bool reversaltrain;
109 extern bool canattack;
110 extern bool cananger;
111 extern float damagedealt;
112 extern float damagetaken;
113 extern int maptype;
114 extern int editoractive;
115 extern int editorpathtype;
116 extern bool oldbuttons[3];
117
118 extern float hostiletime;
119
120 extern bool gamestarted;
121
122 extern int numhotspots;
123 extern int winhotspot;
124 extern int windialogue;
125 extern int killhotspot;
126 extern XYZ hotspot[40];
127 extern int hotspottype[40];
128 extern float hotspotsize[40];
129 extern char hotspottext[40][256];
130 extern int currenthotspot;
131
132 extern int kBitsPerPixel;
133 extern int hostile;
134
135 extern int numaccounts;
136 extern int accountactive;
137 extern int accountdifficulty[10];
138 extern int accountprogress[10];
139 extern float accountpoints[10];
140 extern float accounthighscore[10][50];
141 extern float accountfasttime[10][50];
142 extern bool accountunlocked[10][60];
143 extern char accountname[10][256];
144
145 extern bool stillloading;
146 extern bool winfreeze;
147
148 extern int numfalls;
149 extern int numflipfail;
150 extern int numseen;
151 extern int numstaffattack;
152 extern int numswordattack;
153 extern int numknifeattack;
154 extern int numunarmedattack;
155 extern int numescaped;
156 extern int numflipped;
157 extern int numwallflipped;
158 extern int numthrowkill;
159 extern int numafterkill;
160 extern int numreversals;
161 extern int numattacks;
162 extern int maxalarmed;
163 extern int numresponded;
164
165 extern int numdialogues;
166 extern int numdialogueboxes[max_dialogues];
167 extern int dialoguetype[max_dialogues];
168 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
169 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
170 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
171 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
172 extern char dialoguename[max_dialogues][max_dialoguelength][64];
173 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
174 extern XYZ participantlocation[max_dialogues][10];
175 extern int participantfocus[max_dialogues][max_dialoguelength];
176 extern int participantaction[max_dialogues][max_dialoguelength];
177 extern float participantrotation[max_dialogues][10];
178 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
179 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
180 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
181 extern int indialogue;
182 extern int whichdialogue;
183 extern int directing;
184 extern float dialoguetime;
185 extern int dialoguegonethrough[20];
186
187 extern bool campaign;
188
189 extern float oldgamespeed;
190
191 extern float accountcampaignhighscore[10];
192 extern float accountcampaignfasttime[10];
193 extern float accountcampaignscore[10];
194 extern float accountcampaigntime[10];
195
196 extern int accountcampaignchoicesmade[10];
197 extern int accountcampaignchoices[10][5000];
198 /********************> Tick() <*****/
199 extern FSOUND_STREAM * strm[10];
200 extern "C"      void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
201 extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
202
203 extern void ScreenShot(const char * fname);
204 void Screenshot (void)
205 {
206         char temp[1024];
207         time_t  t = time(NULL);
208         struct  tm *tme = localtime(&t);
209         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);
210
211         mkdir("Screenshots");
212         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
213
214         /*FSSpec                                MAC_file;
215         GraphicsExportComponent         QT_exporter;
216         OSErr                           MAC_error_code;
217         CGrafPtr                        MAC_currentPort;
218         GDHandle                        MAC_currentDevice;
219         unsigned char*          MAC_pixels;
220         Rect                            MAC_picture_rectangle;
221         GWorldPtr                       MAC_offscreen_graphics_port;
222
223         static int numscreenshots=0;
224
225         // Make an FSSpec
226         static char buf[256];
227         if(numscreenshots==0){
228         buf[0]=26;
229         buf[1]=':';
230         buf[2]='S';
231         buf[3]='c';
232         buf[4]='r';
233         buf[5]='e';
234         buf[6]='e';
235         buf[7]='n';
236         buf[8]='s';
237         buf[9]='h';
238         buf[10]='o';
239         buf[11]='t';
240         buf[12]='s';
241         buf[13]=':';
242         buf[14]='S';
243         buf[15]='c';
244         buf[16]='r';
245         buf[17]='e';
246         buf[18]='e';
247         buf[19]='n';
248         buf[20]='s';
249         buf[21]='h';
250         buf[22]='o';
251         buf[23]='t';
252         buf[24]='0';
253         buf[25]='0';
254         buf[26]='0';
255         }
256
257         FInfo *fndrInfo;
258         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
259         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
260         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
261         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
262         numscreenshots++;
263         buf[26]++;
264         if(buf[26]==':'){
265         buf[26]='0';
266         buf[25]++;
267         if(buf[25]==':'){
268         buf[25]='0';
269         buf[24]++;
270         if(buf[24]==':'){
271         buf[24]='9';
272         buf[25]='9';
273         buf[26]='9';
274         }
275         }
276         }
277         }
278         }
279
280
281         // Get the GWorld
282         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
283         //assert(MAC_gWorld != NULL);
284
285         // Allocate memory for loading image
286         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
287         if (MAC_pixels == NULL) {
288         //UTIL_Error("Could not create Texture data.");
289         return;
290         }
291
292         // Get GWorld
293         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);      
294
295         // Make a picture Rectangle
296         MAC_picture_rectangle.left = 0;
297         MAC_picture_rectangle.right = screenwidth;
298         MAC_picture_rectangle.top = 0;
299         MAC_picture_rectangle.bottom = screenheight;    
300
301         // Create new offscreen GWorld
302         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
303         if (MAC_error_code)     {
304         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
305         delete MAC_pixels;
306         //UTIL_Error("Could not create offscreen GWorld. ");
307         return;
308
309         }
310
311         // Copy OpenGL Context to new GWorld
312         glReadBuffer(GL_FRONT); 
313         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
314
315         // Swizzle texture
316         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
317         unsigned char temp = MAC_pixels[byte+0];
318         MAC_pixels[byte+0] = MAC_pixels[byte+3];
319         MAC_pixels[byte+3] = MAC_pixels[byte+2];
320         MAC_pixels[byte+2] = MAC_pixels[byte+1];
321         MAC_pixels[byte+1] = temp;
322         }
323
324         // Flip the image  :(   This could probably be optimized
325         int vert;
326         int src_index;
327         int dst_index;
328         unsigned char temp;
329         for (int horz = 0; horz < screenwidth; ++horz)
330         for (vert = 0; vert < screenheight / 2; ++vert) {               
331         src_index = (screenwidth * vert + horz) * 4;
332         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
333
334         temp=MAC_pixels[src_index+0];
335         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
336         MAC_pixels[dst_index+0]=temp;
337
338         temp=MAC_pixels[src_index+1];
339         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
340         MAC_pixels[dst_index+1]=temp;
341
342         temp=MAC_pixels[src_index+2];
343         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
344         MAC_pixels[dst_index+2]=temp;
345
346         temp=MAC_pixels[src_index+3];
347         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
348         MAC_pixels[dst_index+3]=temp;
349         }
350
351
352
353         // Export the Gworld
354         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
355         if (MAC_error_code) {
356         //UTIL_Warning("Unable to export screenshot."); 
357         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
358         ::DisposeGWorld(MAC_offscreen_graphics_port);
359         delete MAC_pixels;
360         return;
361         }                                                                                               
362
363         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
364         if (MAC_error_code) {
365         ::CloseComponent(QT_exporter);
366         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
367         ::DisposeGWorld(MAC_offscreen_graphics_port);
368         delete MAC_pixels;
369         //UTIL_Warning("Unable to export screenshot.");
370         return;
371         }                                                               
372
373         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
374         if (MAC_error_code) {
375         ::CloseComponent(QT_exporter);
376         ::SetGWorld(MAC_currentPort, MAC_currentDevice);        
377         ::DisposeGWorld(MAC_offscreen_graphics_port);
378         delete MAC_pixels;
379         //UTIL_Warning("Unable to export screenshot.");
380         return;
381         }                                                       
382
383         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
384         if (MAC_error_code) {
385         ::CloseComponent(QT_exporter);
386         ::SetGWorld(MAC_currentPort, MAC_currentDevice);                        
387         ::DisposeGWorld(MAC_offscreen_graphics_port);
388         delete MAC_pixels;
389         //UTIL_Warning("Unable to export screenshot.");
390         return;
391         }                                               
392
393         ::CloseComponent(QT_exporter);
394         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
395         ::DisposeGWorld(MAC_offscreen_graphics_port);
396
397         delete MAC_pixels;*/
398 }
399
400
401
402 void    Game::SetUpLighting(){
403         if(environment==snowyenvironment){
404                 light.color[0]=.65;
405                 light.color[1]=.65;
406                 light.color[2]=.7;
407                 light.ambient[0]=.4;
408                 light.ambient[1]=.4;
409                 light.ambient[2]=.44;           
410         }
411         if(environment==desertenvironment){
412                 light.color[0]=.95;
413                 light.color[1]=.95;
414                 light.color[2]=.95;
415                 light.ambient[0]=.4;
416                 light.ambient[1]=.35;
417                 light.ambient[2]=.3;            
418         }
419
420         if(environment==grassyenvironment){
421                 light.color[0]=.95;
422                 light.color[1]=.95;
423                 light.color[2]=1;
424                 light.ambient[0]=.4;
425                 light.ambient[1]=.4;
426                 light.ambient[2]=.44;           
427         }
428         if(!skyboxtexture){
429                 light.color[0]=1;
430                 light.color[1]=1;
431                 light.color[2]=1;
432                 light.ambient[0]=.4;
433                 light.ambient[1]=.4;
434                 light.ambient[2]=.4;    
435         }
436         float average;
437         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
438         light.color[0]*=(skyboxlightr+average)/2;
439         light.color[1]*=(skyboxlightg+average)/2;
440         light.color[2]*=(skyboxlightb+average)/2;
441         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
442         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
443         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;   
444         /*
445         light.ambient[0]=0;
446         light.ambient[1]=0;
447         light.ambient[2]=0;     */
448 }
449
450 int Game::findPathDist(int start,int end){
451         int i,j,k,smallestcount,count,connected;
452         int last,last2,last3,last4;
453         int closest;
454
455         smallestcount=1000;
456         for(i=0;i<50;i++){
457                 count=0;
458                 last=start;
459                 last2=-1;
460                 last3=-1;
461                 last4=-1;
462                 while(last!=end&&count<30){
463                         closest=-1;
464                         for(j=0;j<numpathpoints;j++){
465                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
466                                 {
467                                         connected=0;
468                                         if(numpathpointconnect[j])
469                                                 for(k=0;k<numpathpointconnect[j];k++){
470                                                         if(pathpointconnect[j][k]==last)connected=1;
471                                                 }
472                                                 if(!connected)
473                                                         if(numpathpointconnect[last])
474                                                                 for(k=0;k<numpathpointconnect[last];k++){
475                                                                         if(pathpointconnect[last][k]==j)connected=1;
476                                                                 }
477                                                                 if(connected)
478                                                                         if(closest==-1||Random()%2==0){
479                                                                                 closest=j;
480                                                                         }
481                                 }
482                         }
483                         last4=last3;
484                         last3=last2;
485                         last2=last;
486                         last=closest;
487                         count++;
488                 }
489                 if(count<smallestcount)smallestcount=count;
490         }
491         return smallestcount;
492 }
493
494 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
495         static XYZ colpoint,colviewer,coltarget;
496         static float minx,minz,maxx,maxz,miny,maxy;
497         static int i;
498
499         //startpoint.y+=.7;
500         //endpoint.y+=.7;
501         //startpoint.y-=.1;
502         //endpoint.y-=.1;
503
504         minx=startpoint.x;
505         if(minx>endpoint.x)minx=endpoint.x;
506         miny=startpoint.y;
507         if(miny>endpoint.y)miny=endpoint.y;
508         minz=startpoint.z;
509         if(minz>endpoint.z)minz=endpoint.z;
510
511         maxx=startpoint.x;
512         if(maxx<endpoint.x)maxx=endpoint.x;
513         maxy=startpoint.y;
514         if(maxy<endpoint.y)maxy=endpoint.y;
515         maxz=startpoint.z;
516         if(maxz<endpoint.z)maxz=endpoint.z;
517
518         minx-=1;
519         miny-=1;
520         minz-=1;
521         maxx+=1;
522         maxy+=1;
523         maxz+=1;
524
525         for(i=0;i<objects.numobjects;i++){
526                 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){
527                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
528                                 colviewer=startpoint;
529                                 coltarget=endpoint;
530                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;  
531                         }
532                 }
533         }
534
535         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
536
537         return -1;
538 }
539
540 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
541         static XYZ colpoint,colviewer,coltarget;
542         static float minx,minz,maxx,maxz,miny,maxy;
543         static int i;
544
545         //startpoint.y+=.7;
546         //endpoint.y+=.7;
547         //startpoint.y-=.1;
548         //endpoint.y-=.1;
549
550         minx=startpoint.x;
551         if(minx>endpoint.x)minx=endpoint.x;
552         miny=startpoint.y;
553         if(miny>endpoint.y)miny=endpoint.y;
554         minz=startpoint.z;
555         if(minz>endpoint.z)minz=endpoint.z;
556
557         maxx=startpoint.x;
558         if(maxx<endpoint.x)maxx=endpoint.x;
559         maxy=startpoint.y;
560         if(maxy<endpoint.y)maxy=endpoint.y;
561         maxz=startpoint.z;
562         if(maxz<endpoint.z)maxz=endpoint.z;
563
564         minx-=1;
565         miny-=1;
566         minz-=1;
567         maxx+=1;
568         maxy+=1;
569         maxz+=1;
570
571         if(what!=1000){
572                 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){
573                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
574                                 colviewer=startpoint;
575                                 coltarget=endpoint;
576                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i; 
577                         }
578                 }
579         }
580
581         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
582
583         return -1;
584 }
585
586 void    Game::Setenvironment(int which)
587 {
588         LOGFUNC;
589
590         LOG(" Setting environment...");
591
592         float temptexdetail;
593         environment=which;
594 /*
595         FSOUND_SetPaused(channels[music1snow], TRUE);
596         FSOUND_SetPaused(channels[music1grass], TRUE);
597         FSOUND_SetPaused(channels[music1desert], TRUE);
598         FSOUND_SetPaused(channels[wind], TRUE);
599         FSOUND_SetPaused(channels[desertambient], TRUE);
600 */
601         FSOUND_SetPaused(channels[stream_music1snow], TRUE);
602         FSOUND_SetPaused(channels[stream_music1grass], TRUE);
603         FSOUND_SetPaused(channels[stream_music1desert], TRUE);
604         FSOUND_SetPaused(channels[stream_wind], TRUE);
605         FSOUND_SetPaused(channels[stream_desertambient], TRUE);
606
607
608         if(environment==snowyenvironment){
609                 windvector=0;
610                 windvector.z=3;
611                 if(ambientsound){
612                         //PlaySoundEx( wind, samp[wind], NULL, TRUE);
613                         PlayStreamEx(stream_wind, strm[stream_wind], 0, TRUE);
614                         FSOUND_SetPaused(channels[stream_wind], FALSE);
615                         FSOUND_SetVolume(channels[stream_wind], 256);
616                 }
617
618                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
619                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
620                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
621                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
622
623                 FSOUND_Sample_Free(samp[footstepsound]);
624                 FSOUND_Sample_Free(samp[footstepsound2]);
625                 FSOUND_Sample_Free(samp[footstepsound3]);
626                 FSOUND_Sample_Free(samp[footstepsound4]);
627                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0);
628                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0);
629                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0);
630                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0);
631                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
632                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
633                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
634                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
635
636                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
637
638                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
639
640                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
641
642
643
644
645                 temptexdetail=texdetail;
646                 if(texdetail>1)texdetail=4;
647                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
648                         ":Data:Textures:Skybox(snow):Left.jpg",
649                         ":Data:Textures:Skybox(snow):Back.jpg",
650                         ":Data:Textures:Skybox(snow):Right.jpg",
651                         ":Data:Textures:Skybox(snow):Up.jpg",
652                         ":Data:Textures:Skybox(snow):Down.jpg",
653                         ":Data:Textures:Skybox(snow):Cloud.jpg",
654                         ":Data:Textures:Skybox(snow):Reflect.jpg");
655
656
657
658
659                 texdetail=temptexdetail;
660         }
661         if(environment==desertenvironment){
662                 windvector=0;
663                 windvector.z=2;
664                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
665                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
666                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
667                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
668
669
670                 if(ambientsound){
671                         //PlaySoundEx( desertambient, samp[desertambient], NULL, TRUE);
672                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, TRUE);
673                         FSOUND_SetPaused(channels[stream_desertambient], FALSE);
674                         FSOUND_SetVolume(channels[stream_desertambient], 256);
675                 }
676
677                 FSOUND_Sample_Free(samp[footstepsound]);
678                 FSOUND_Sample_Free(samp[footstepsound2]);
679                 FSOUND_Sample_Free(samp[footstepsound3]);
680                 FSOUND_Sample_Free(samp[footstepsound4]);
681                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0);
682                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0);
683                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow1.ogg", FSOUND_HW3D, 0);
684                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepsnow2.ogg", FSOUND_HW3D, 0);
685                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
686                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
687                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
688                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
689
690                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
691
692                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
693
694                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
695
696
697
698                 temptexdetail=texdetail;
699                 if(texdetail>1)texdetail=4;
700                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
701                         ":Data:Textures:Skybox(sand):Left.jpg",
702                         ":Data:Textures:Skybox(sand):Back.jpg",
703                         ":Data:Textures:Skybox(sand):Right.jpg",
704                         ":Data:Textures:Skybox(sand):Up.jpg",
705                         ":Data:Textures:Skybox(sand):Down.jpg",
706                         ":Data:Textures:Skybox(sand):Cloud.jpg",
707                         ":Data:Textures:Skybox(sand):Reflect.jpg");
708
709
710
711
712                 texdetail=temptexdetail;
713         }
714         if(environment==grassyenvironment){
715                 windvector=0;
716                 windvector.z=2;
717                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
718                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
719                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
720                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
721
722                 if(ambientsound){
723                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, TRUE);
724                         FSOUND_SetPaused(channels[stream_wind], FALSE);
725                         FSOUND_SetVolume(channels[stream_wind], 100);
726                 }
727
728                 FSOUND_Sample_Free(samp[footstepsound]);
729                 FSOUND_Sample_Free(samp[footstepsound2]);
730                 FSOUND_Sample_Free(samp[footstepsound3]);
731                 FSOUND_Sample_Free(samp[footstepsound4]);
732                 samp[footstepsound] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass1.ogg", FSOUND_HW3D, 0);
733                 samp[footstepsound2] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepgrass2.ogg", FSOUND_HW3D, 0);
734                 samp[footstepsound3] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone1.ogg", FSOUND_HW3D, 0);
735                 samp[footstepsound4] = FSOUND_Sample_Load(FSOUND_FREE, ":Data:Sounds:footstepstone2.ogg", FSOUND_HW3D, 0);
736                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);    
737                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);   
738                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);   
739                 FSOUND_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);   
740
741                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
742
743                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
744
745                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
746
747
748
749                 temptexdetail=texdetail;
750                 if(texdetail>1)texdetail=4;
751                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
752                         ":Data:Textures:Skybox(grass):Left.jpg",
753                         ":Data:Textures:Skybox(grass):Back.jpg",
754                         ":Data:Textures:Skybox(grass):Right.jpg",
755                         ":Data:Textures:Skybox(grass):Up.jpg",
756                         ":Data:Textures:Skybox(grass):Down.jpg",
757                         ":Data:Textures:Skybox(grass):Cloud.jpg",
758                         ":Data:Textures:Skybox(grass):Reflect.jpg");
759
760
761
762                 texdetail=temptexdetail;
763         }
764         temptexdetail=texdetail;
765         texdetail=1;
766         terrain.load(":Data:Textures:heightmap.png");
767
768         texdetail=temptexdetail;
769 }
770
771
772 void    Game::Loadlevel(int which){
773         stealthloading=0;
774
775         if(which==0)Loadlevel((char *)":Data:Maps:map1");
776         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
777         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
778         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
779         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
780         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
781         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
782         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
783         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
784         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
785         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
786         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
787         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
788         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
789         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
790         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
791         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
792         else Loadlevel((char *)":Data:Maps:mapsave");
793
794         whichlevel=which;
795 }
796
797 /*char * Game::MD5_string (unsigned char *string){
798 char temp[50];
799 char temp2[100];
800
801 strcpy(temp2,(const char *)string);
802 strcat((char *)temp2,(const char *)"Lugaru");                                   
803 sprintf (temp, "%d",strlen((char *)temp2));
804 strcat((char *)temp2,temp);                                     
805
806 MD5 context;
807 unsigned int len = strlen ( (char *)temp2);
808
809 context.update   ((unsigned char *)temp2, len);
810 context.finalize ();
811
812 return context.hex_digest();
813 }*/
814
815
816
817 void    Game::Loadlevel(char *name){
818         int i,j,k,l,m;
819         static int oldlevel;
820         int templength;
821         float lamefloat;
822         int lameint;
823
824         float headprop,legprop,armprop,bodyprop;
825
826         LOGFUNC;
827
828         LOG(std::string("Loading level...") + name);
829
830         if(!gameon)visibleloading=1;
831
832         if(stealthloading)visibleloading=0;
833
834         if(!stillloading)loadtime=0;
835         gamestarted=1;
836
837         numenvsounds=0;
838         //visibleloading=1;
839         if(tutoriallevel!=-1)tutoriallevel=0;
840         else tutoriallevel=1;
841
842         if(tutoriallevel==1)tutorialstage=0;
843         if(tutorialstage==0){
844                 tutorialstagetime=0;
845                 tutorialmaxtime=1;
846         }
847         loadingstuff=1;
848         if(!firstload){
849                 oldlevel=50;
850         }
851         FSOUND_SetPaused(channels[whooshsound], TRUE);
852         FSOUND_SetPaused(channels[stream_firesound], TRUE);
853
854         int mapvers;
855         FILE                    *tfile;
856         tfile=fopen( name, "rb" );
857         if(tfile)
858         {
859                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
860
861
862                 scoreadded=0;
863                 windialogue=0;
864
865                 hostiletime=0;
866
867                 won=0;
868
869                 //campaign=0;
870                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
871
872                 numdialogues=0;
873
874                 for(i=0;i<20;i++)
875                 {
876                         dialoguegonethrough[i]=0;
877                 }
878
879                 indialogue=-1;
880                 cameramode=0;
881
882                 damagedealt=0;
883                 damagetaken=0;
884
885                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
886
887                 if(difficulty!=2)minimap=1;
888                 else minimap=0;
889
890                 numhotspots=0;
891                 currenthotspot=-1;
892                 bonustime=1;
893
894                 skyboxtexture=1;
895                 skyboxr=1;
896                 skyboxg=1;
897                 skyboxb=1;
898
899                 freeze=0;
900                 winfreeze=0;
901
902                 for(i=0;i<100;i++)
903                 {
904                         bonusnum[i]=0;
905                 }
906
907                 numfalls=0;
908                 numflipfail=0;
909                 numseen=0;
910                 numstaffattack=0;
911                 numswordattack=0;
912                 numknifeattack=0;
913                 numunarmedattack=0;
914                 numescaped=0;
915                 numflipped=0;
916                 numwallflipped=0;
917                 numthrowkill=0;
918                 numafterkill=0;
919                 numreversals=0;
920                 numattacks=0;
921                 maxalarmed=0;
922                 numresponded=0;
923
924                 bonustotal=startbonustotal;
925                 bonus=0;
926                 gameon=1;
927                 changedelay=0;
928                 if(console)
929                 {
930                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
931                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
932                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
933                         freeze=0;
934                         console=0;
935                 }
936
937                 if(!stealthloading)
938                 {
939                         terrain.numdecals=0;
940                         sprites.numsprites=0;
941                         for(i=0;i<objects.numobjects;i++)
942                         {
943                                 objects.model[i].numdecals=0;
944                         }
945
946                         j=objects.numobjects;
947                         for(i=0;i<j;i++)
948                         {
949                                 objects.DeleteObject(0);
950                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
951                         }
952
953                         for(i=0;i<subdivision;i++)
954                         {
955                                 for(j=0;j<subdivision;j++)
956                                 {
957                                         terrain.patchobjectnum[i][j]=0;
958                                 }
959                         }
960                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
961                 }
962
963                 weapons.numweapons=0;
964
965                 funpackf(tfile, "Bi", &mapvers);
966                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
967                 else indemo=0;
968                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
969                 else maptype=mapkilleveryone;
970                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
971                 else hostile=1;
972                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
973                 else
974                 {
975                         viewdistance=100;
976                         fadestart=.6;
977                 }
978                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
979                 else
980                 {
981                         skyboxtexture=1;
982                         skyboxr=1;
983                         skyboxg=1;
984                         skyboxb=1;
985                 }
986                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
987                 else
988                 {
989                         skyboxlightr=skyboxr;
990                         skyboxlightg=skyboxg;
991                         skyboxlightb=skyboxb;
992                 }
993                 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);
994                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
995                 player[0].originalcoords=player[0].coords;
996                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
997                 {
998                         for(j=0;j<player[0].num_weapons;j++)
999                         {
1000                                 player[0].weaponids[j]=weapons.numweapons;
1001                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1002                                 weapons.owner[weapons.numweapons]=0;
1003                                 weapons.numweapons++;
1004                         }
1005                 }
1006
1007                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1008
1009                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1010                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1011                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1012                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1013
1014                 funpackf(tfile, "Bi", &player[0].numclothes);
1015
1016                 if(mapvers>=9)
1017                 {
1018                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1019                 }
1020                 else
1021                 {
1022                         player[0].whichskin=0;
1023                         player[0].creature=rabbittype;
1024                 }
1025
1026                 for(i=0;i<max_dialogues;i++)
1027                 {
1028                         for(j=0;j<max_dialoguelength;j++)
1029                         {
1030                                 for(k=0;k<128;k++)
1031                                 {
1032                                         dialoguetext[i][j][k]='\0';
1033                                 }
1034                                 for(k=0;k<64;k++)
1035                                 {
1036                                         dialoguename[i][j][k]='\0';
1037                                 }
1038                         }
1039                 }
1040
1041                 player[0].lastattack=-1;
1042                 player[0].lastattack2=-1;
1043                 player[0].lastattack3=-1;
1044
1045                 if(mapvers>=8)
1046                 {
1047                         funpackf(tfile, "Bi", &numdialogues);
1048                         if(numdialogues)
1049                         {
1050                                 for(k=0;k<numdialogues;k++)
1051                                 {
1052                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1053                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1054                                         for(l=0;l<10;l++)
1055                                         {
1056                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1057                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1058                                         }
1059                                         if(numdialogueboxes)
1060                                         {
1061                                                 for(l=0;l<numdialogueboxes[k];l++)
1062                                                 {
1063                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1064                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1065                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1066                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1067                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1068
1069                                                         bool doneread;
1070
1071                                                         funpackf(tfile, "Bi",&templength);
1072                                                         if(templength>128||templength<=0)templength=128;
1073                                                         for(m=0;m<templength;m++){
1074                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1075                                                                 if(dialoguetext[k][l][m]=='\0')break;
1076                                                         }
1077
1078                                                         funpackf(tfile, "Bi",&templength);
1079                                                         if(templength>64||templength<=0)templength=64;
1080                                                         for(m=0;m<templength;m++){
1081                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1082                                                                 if(dialoguename[k][l][m]=='\0'){
1083                                                                         break;  
1084                                                                 }
1085                                                         }
1086                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1087                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1088                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1089
1090                                                         for(m=0;m<10;m++)
1091                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1092
1093                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1094                                                 }
1095                                         }
1096                                 }
1097                         }
1098                 }
1099                 else numdialogues=0;
1100
1101                 if(player[0].numclothes)
1102                 {
1103                         for(k=0;k<player[0].numclothes;k++)
1104                         {
1105                                 funpackf(tfile, "Bi", &templength);
1106                                 for(l=0;l<templength;l++)
1107                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1108                                 player[0].clothes[k][templength]='\0';
1109                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);                                                                        
1110                         }
1111                 }
1112
1113                 funpackf(tfile, "Bi", &environment);
1114
1115                 funpackf(tfile, "Bi", &objects.numobjects);
1116                 if(objects.numobjects)
1117                 {
1118                         for(i=0;i<objects.numobjects;i++)
1119                         {
1120                                 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]);
1121                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1122                         }
1123                 }
1124
1125                 if(mapvers>=7)
1126                 {
1127                         funpackf(tfile, "Bi", &numhotspots);
1128                         if(numhotspots)
1129                         {
1130                                 for(i=0;i<numhotspots;i++)
1131                                 {
1132                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1133                                         funpackf(tfile, "Bi", &templength);
1134                                         if(templength)
1135                                                 for(l=0;l<templength;l++)
1136                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1137                                         hotspottext[i][templength]='\0';
1138                                         if(hotspottype[i]==-111)indemo=1;
1139                                 }
1140                         }
1141                 }
1142                 else numhotspots=0;
1143
1144                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1145
1146                 if(!stealthloading)
1147                 {
1148                         objects.center=0;
1149                         for(i=0;i<objects.numobjects;i++)
1150                         {
1151                                 objects.center+=objects.position[i];    
1152                         }
1153                         objects.center/=objects.numobjects;
1154
1155
1156                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1157
1158                         float maxdistance=0;
1159                         float tempdist;
1160                         int whichclosest;
1161                         for(i=0;i<objects.numobjects;i++)
1162                         {
1163                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1164                                 if(tempdist>maxdistance)
1165                                 {
1166                                         whichclosest=i;
1167                                         maxdistance=tempdist;
1168                                 }
1169                         }
1170                         objects.radius=fast_sqrt(maxdistance);
1171                 }                               
1172
1173                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1174                 //mapcenter=objects.center;
1175                 //mapradius=objects.radius;
1176
1177                 funpackf(tfile, "Bi", &numplayers);
1178                 int howmanyremoved=0;
1179                 bool removeanother=0;
1180                 if(numplayers>1&&numplayers<maxplayers)
1181                 {
1182                         for(i=1;i<numplayers;i++)
1183                         {
1184                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1185                                 removeanother=0;
1186
1187                                 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);
1188                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1189                                 else player[i-howmanyremoved].howactive=typeactive;
1190                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1191                                 else player[i-howmanyremoved].scale=-1;
1192                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1193                                 else player[i-howmanyremoved].immobile=0;
1194                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1195                                 else player[i-howmanyremoved].rotation=0;
1196                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1197                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1198                                         removeanother=1;
1199                                         howmanyremoved++;
1200                                 }
1201                                 if(!removeanother)
1202                                 {
1203                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1204                                         {
1205                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1206                                                 {
1207                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1208                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1209                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1210                                                         weapons.numweapons++;
1211                                                 }
1212                                         }
1213                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1214                                         //player[i-howmanyremoved].numwaypoints=10;
1215                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1216                                         {
1217                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1218                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1219                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1220                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1221                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1222                                         }
1223
1224                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1225                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1226
1227                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1228                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1229                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1230                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1231
1232                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1233                                         else
1234                                         {
1235                                                 headprop=1;
1236                                                 bodyprop=1;
1237                                                 armprop=1;
1238                                                 legprop=1;
1239                                         }
1240                                         if(player[i-howmanyremoved].creature==wolftype)
1241                                         {
1242                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1243                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1244                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1245                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1246                                         }
1247
1248                                         if(player[i-howmanyremoved].creature==rabbittype)
1249                                         {
1250                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1251                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1252                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1253                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1254                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1255                                         }
1256
1257                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1258                                         if(player[i-howmanyremoved].numclothes)
1259                                         {
1260                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1261                                                 {
1262                                                         int templength;
1263                                                         funpackf(tfile, "Bi", &templength);
1264                                                         for(l=0;l<templength;l++)
1265                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1266                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1267                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);                                                                   
1268                                                 }
1269                                         }
1270                                 }
1271                         }
1272                 }
1273                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1274
1275                 numplayers-=howmanyremoved;
1276                 funpackf(tfile, "Bi", &numpathpoints);
1277                 if(numpathpoints>30||numpathpoints<0)
1278                         numpathpoints=0;
1279                 if(numpathpoints)
1280                 {
1281                         for(j=0;j<numpathpoints;j++)
1282                         {
1283                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1284                                 for(k=0;k<numpathpointconnect[j];k++){
1285                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1286                                 }
1287                         }
1288                 }
1289                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1290
1291                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1292
1293                 SetUpLighting();
1294                 if(environment!=oldenvironment)Setenvironment(environment);
1295                 oldenvironment=environment;
1296
1297                 if(!stealthloading)
1298                 {
1299                         j=objects.numobjects;
1300                         objects.numobjects=0;
1301                         for(i=0;i<j;i++)
1302                         {
1303                                 //if(objects.type[i]!=spiketype)
1304                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1305                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1306                         }
1307
1308                         //if(skyboxtexture){
1309                         terrain.DoShadows();
1310                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1311                         objects.DoShadows();
1312                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1313                         /*}
1314                         else terrain.DoLighting();
1315                         */
1316                 }
1317
1318                 fclose(tfile);
1319
1320                 oldlevel=whichlevel;
1321
1322
1323                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1324                 for(i=0;i<numplayers;i++)
1325                 {
1326                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1327                         player[i].burnt=0;
1328                         player[i].bled=0;
1329                         player[i].onfire=0;
1330                         if(i==0||player[i].scale<0)player[i].scale=.2;
1331                         player[i].skeleton.free=0;
1332                         player[i].skeleton.id=i;
1333                         //if(Random()%2==0)player[i].creature=wolftype;
1334                         //else player[i].creature=rabbittype;
1335                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1336                         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);
1337                         else
1338                         {
1339                                 if(player[i].creature!=wolftype){
1340                                         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);
1341                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1342                                 }
1343                                 if(player[i].creature==wolftype){
1344                                         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);
1345                                 }
1346                         }
1347
1348
1349                         int texsize;
1350                         texsize=512*512*3/texdetail/texdetail;
1351                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1352                         //player[i].skeleton.skinText.resize(texsize);
1353
1354                         if(player[i].creature==rabbittype)
1355                         {
1356                                 if(player[i].whichskin==0){
1357                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1358                                 }
1359                                 else if(player[i].whichskin==1){
1360                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1361                                 }
1362                                 else if(player[i].whichskin==2){
1363                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1364                                 }
1365                                 else if(player[i].whichskin==3){
1366                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1367                                 }
1368                                 else if(player[i].whichskin==4){
1369                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1370                                 }
1371                                 else if(player[i].whichskin==5){
1372                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1373                                 }
1374                                 else if(player[i].whichskin==6){
1375                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1376                                 }
1377                                 else if(player[i].whichskin==7){
1378                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1379                                 }
1380                                 else if(player[i].whichskin==8){
1381                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1382                                 }
1383                                 else if(player[i].whichskin==9){
1384                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1385                                 }
1386                         }
1387                         if(player[i].creature==wolftype)
1388                         {
1389                                 //k=abs(Random()%3);
1390                                 if(player[i].whichskin==0){
1391                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1392                                 }
1393                                 else if(player[i].whichskin==1){
1394                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1395                                 }
1396                                 else if(player[i].whichskin==2){
1397                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1398                                 }
1399                         }
1400
1401                         if(player[i].numclothes)
1402                         {
1403                                 for(j=0;j<player[i].numclothes;j++)
1404                                 {
1405                                         tintr=player[i].clothestintr[j];
1406                                         tintg=player[i].clothestintg[j];
1407                                         tintb=player[i].clothestintb[j];
1408                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1409                                 }
1410                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1411                         }
1412
1413                         player[i].currentanimation=bounceidleanim;
1414                         player[i].targetanimation=bounceidleanim;
1415                         player[i].currentframe=0;
1416                         player[i].targetframe=1;
1417                         player[i].target=0;
1418                         player[i].speed=1+(float)(Random()%100)/1000;
1419                         if(difficulty==0)player[i].speed-=.2;
1420                         if(difficulty==1)player[i].speed-=.1;
1421
1422                         player[i].velocity=0;
1423                         player[i].oldcoords=player[i].coords;
1424                         player[i].realoldcoords=player[i].coords;
1425
1426                         player[i].id=i;
1427                         player[i].skeleton.id=i;
1428                         player[i].updatedelay=0;
1429                         player[i].normalsupdatedelay=0;
1430
1431                         player[i].aitype=passivetype;
1432                         player[i].aitarget=0;
1433                         player[i].madskills=0;
1434
1435                         if(i==0)
1436                         {
1437                                 player[i].proportionhead=1.2;
1438                                 player[i].proportionbody=1.05;
1439                                 player[i].proportionarms=1.00;
1440                                 player[i].proportionlegs=1.1;
1441                                 player[i].proportionlegs.y=1.05;
1442                         }
1443                         player[i].headless=0;
1444                         player[i].currentoffset=0;
1445                         player[i].targetoffset=0;
1446                         /*player[i].armorhead=1;
1447                         player[i].armorhigh=1;
1448                         player[i].armorlow=1;
1449                         player[i].protectionhead=1;
1450                         player[i].protectionhigh=1;
1451                         player[i].protectionlow=1;
1452                         player[i].metalhead=1;
1453                         player[i].metalhigh=1;
1454                         player[i].metallow=1;
1455                         player[i].power=1;
1456                         player[i].speedmult=1;*/
1457
1458                         player[i].damagetolerance=200;
1459
1460                         if(player[i].creature==wolftype)
1461                         {
1462                                 /*player[i].proportionhead=1.1;
1463                                 player[i].proportionbody=1.1;
1464                                 player[i].proportionarms=1.1;
1465                                 player[i].proportionlegs=1.1;
1466                                 player[i].proportionlegs.y=1.1;*/
1467                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1468
1469                                 player[i].damagetolerance=300;
1470                         }                               
1471
1472                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1473                         if(cellophane)
1474                         {
1475                                 player[i].proportionhead.z=0;
1476                                 player[i].proportionbody.z=0;
1477                                 player[i].proportionarms.z=0;
1478                                 player[i].proportionlegs.z=0;
1479                         }
1480
1481                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1482
1483                         player[i].headmorphness=0;
1484                         player[i].targetheadmorphness=1;
1485                         player[i].headmorphstart=0;
1486                         player[i].headmorphend=0;
1487
1488                         player[i].pausetime=0;
1489
1490                         player[i].dead=0;
1491                         player[i].jumppower=5;
1492                         player[i].damage=0;
1493                         player[i].permanentdamage=0;
1494                         player[i].superpermanentdamage=0;
1495
1496                         player[i].forwardkeydown=0;
1497                         player[i].leftkeydown=0;
1498                         player[i].backkeydown=0;
1499                         player[i].rightkeydown=0;
1500                         player[i].jumpkeydown=0;
1501                         player[i].crouchkeydown=0;
1502                         player[i].throwkeydown=0;
1503
1504                         player[i].collided=-10;
1505                         player[i].loaded=1;
1506                         player[i].bloodloss=0;
1507                         player[i].weaponactive=-1;
1508                         player[i].weaponstuck=-1;
1509                         player[i].bleeding=0;
1510                         player[i].deathbleeding=0;
1511                         player[i].stunned=0;
1512                         player[i].hasvictim=0;
1513                         player[i].wentforweapon=0;
1514                 }
1515
1516                 player[0].aitype=playercontrolled;
1517                 player[0].weaponactive=-1;
1518
1519                 if(difficulty==1)
1520                 {
1521                         //player[0].speedmult=1/.9;
1522                         player[0].power=1/.9;
1523                 }
1524
1525                 if(difficulty==0)
1526                 {
1527                         //player[0].speedmult=1/.8;
1528                         player[0].power=1/.8;
1529                 }
1530
1531                 //player[0].weaponstuck=1;
1532
1533                 if(difficulty==1)player[0].damagetolerance=250;
1534                 if(difficulty==0)player[0].damagetolerance=300;
1535                 if(difficulty==0)player[0].armorhead*=1.5;
1536                 if(difficulty==0)player[0].armorhigh*=1.5;
1537                 if(difficulty==0)player[0].armorlow*=1.5;
1538                 cameraloc=player[0].coords;
1539                 cameraloc.y+=5;
1540                 rotation=player[0].rotation;
1541
1542                 hawkcoords=player[0].coords;
1543                 hawkcoords.y+=30;
1544
1545                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1546                 //weapons.numweapons=numplayers;
1547                 for(i=0;i<weapons.numweapons;i++)
1548                 {
1549                         weapons.bloody[i]=0;
1550                         weapons.blooddrip[i]=0;
1551                         weapons.blooddripdelay[i]=0;
1552                         weapons.onfire[i]=0;
1553                         weapons.flamedelay[i]=0;
1554                         weapons.damage[i]=0;
1555                         //weapons.type[i]=sword;
1556                         if(weapons.type[i]==sword){
1557                                 weapons.mass[i]=1.5;
1558                                 weapons.tipmass[i]=1;
1559                                 weapons.length[i]=.8;
1560                         }
1561                         if(weapons.type[i]==staff){
1562                                 weapons.mass[i]=2;
1563                                 weapons.tipmass[i]=1;
1564                                 weapons.length[i]=1.5;
1565                         }
1566                         if(weapons.type[i]==knife){
1567                                 weapons.mass[i]=1;
1568                                 weapons.tipmass[i]=1.2;
1569                                 weapons.length[i]=.25;
1570                         }
1571                         weapons.position[i]=-1000;
1572                         weapons.tippoint[i]=-1000;
1573                 }
1574
1575 /*              for(i=0;i<32;i++){
1576                         //if(i<16||i>20)                                
1577                         FSOUND_StopSound(i);
1578                 }
1579 */
1580                 LOG("Starting background music...");
1581
1582                 FSOUND_StopSound(FSOUND_ALL);
1583                 if(environment==snowyenvironment)
1584                 {
1585                         if(ambientsound)
1586                         {
1587                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
1588                                 FSOUND_SetPaused(channels[stream_wind], FALSE);
1589                                 FSOUND_SetVolume(channels[stream_wind], 256);
1590                         }
1591                 }
1592                 else if(environment==desertenvironment)
1593                 {
1594                         if(ambientsound)
1595                         {
1596                                 //PlaySoundEx(desertambient,
1597                                 //      samp[desertambient], NULL, TRUE);
1598                                 PlayStreamEx(stream_desertambient,
1599                                         strm[stream_desertambient], NULL, TRUE);
1600                                 FSOUND_SetPaused(channels[stream_desertambient], FALSE);
1601                                 FSOUND_SetVolume(channels[stream_desertambient], 256);
1602                         }
1603                 }
1604                 else if(environment==grassyenvironment)
1605                 {
1606                         if(ambientsound)
1607                         {
1608                                 //PlaySoundEx(wind, samp[wind], NULL, TRUE);
1609                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, TRUE);
1610                                 FSOUND_SetPaused(channels[stream_wind], FALSE);
1611                                 FSOUND_SetVolume(channels[stream_wind], 100);
1612                         }
1613                 }
1614                 oldmusicvolume[0]=0;
1615                 oldmusicvolume[1]=0;
1616                 oldmusicvolume[2]=0;
1617                 oldmusicvolume[3]=0;
1618
1619
1620                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1621                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1622                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1623                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1624                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1625                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1626                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1627                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1628                 */
1629
1630                 if(!firstload)
1631                 {
1632                         firstload=1;
1633                 }
1634         }
1635         leveltime=0;
1636         loadingstuff=0;
1637         visibleloading=0;
1638 }
1639
1640 void    Game::Tick()
1641 {
1642         static int i,k,j,l,m;
1643         static XYZ facing,flatfacing,absflatfacing;
1644         static XYZ rotatetarget;
1645         static bool oldkey;
1646         static float oldtargetrotation;
1647         static int target, numgood;
1648         static XYZ tempcoords1,tempcoords2;
1649         static XYZ test;
1650         static XYZ test2;
1651         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1652         static int whichhit;
1653         static bool donesomething;
1654         static bool oldjumpkeydown;
1655
1656         int templength;
1657
1658         float headprop,bodyprop,armprop,legprop;
1659
1660         if(newnetmessages){
1661                 newnetmessages=0;
1662                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
1663                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
1664                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
1665
1666                 for(k=14;k>=2;k--){
1667                         for(j=0;j<255;j++){
1668                                 consoletext[k][j]=consoletext[k-1][j];
1669                         }
1670                         consolechars[k]=consolechars[k-1];
1671                 }
1672                 for(k=14;k>=2;k--){
1673                         for(j=0;j<255;j++){
1674                                 displaytext[k][j]=displaytext[k-1][j];
1675                         }
1676                         displaychars[k]=displaychars[k-1];
1677                         displaytime[k]=displaytime[k-1];
1678                 }
1679                 for(j=0;j<255;j++){
1680                         consoletext[1][j]=' ';
1681                         displaytext[1][j]=' ';
1682                 }
1683                 sprintf (consoletext[1], netmessages);
1684                 sprintf (displaytext[1], netmessages);
1685                 consolechars[1]=255;
1686                 displaychars[1]=255;
1687                 displaytime[1]=0;
1688         }
1689
1690         for(i=0;i<15;i++){
1691                 displaytime[i]+=multiplier;
1692         }
1693
1694         static unsigned char    theKeyMap[16];
1695         GetKeys( theKeyMap );
1696
1697         keyboardfrozen=0;
1698
1699
1700         static bool mainmenutogglekeydown;
1701         if(!console){
1702                 if(mainmenu&&endgame==1)mainmenu=10;
1703                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1704                         for(j=0;j<255;j++){
1705                                 displaytext[0][j]=' ';
1706                         }
1707                         displaychars[0]=0;
1708                         displayselected=0;
1709                         entername=0;
1710                         mainmenutogglekeydown=1;
1711                 }
1712                 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)){
1713                         selected=-1;
1714                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1715                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1716                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1717                                 else if(mainmenu==0&&winfreeze){
1718                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1719                                         stealthloading=1;
1720                                         else stealthloading=0;
1721
1722                                         if(!stealthloading){
1723                                         float gLoc[3]={0,0,0};
1724                                         float vel[3]={0,0,0};
1725                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
1726                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
1727                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1728                                         FSOUND_SetVolume(channels[firestartsound], 256);
1729                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
1730                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1731
1732                                         flashr=1;
1733                                         flashg=0;
1734                                         flashb=0;
1735                                         flashamount=1;
1736                                         flashdelay=1;
1737                                         }
1738
1739                                         startbonustotal=0;
1740
1741                                         for(i=0;i<campaignnumlevels;i++){
1742                                         levelvisible[i]=0;
1743                                         levelhighlight[i]=0;
1744                                         }
1745
1746                                         levelorder[0]=0;
1747                                         levelvisible[0]=1;
1748                                         if(accountcampaignchoicesmade[accountactive])
1749                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1750                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1751                                         levelvisible[levelorder[i+1]]=1;
1752                                         }
1753                                         int whichlevelstart;
1754                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1755                                         if(whichlevelstart<0){
1756                                         campaignchoicenum=1;
1757                                         campaignchoicewhich[0]=0;
1758                                         }
1759                                         else
1760                                         {
1761                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1762                                         if(campaignchoicenum)
1763                                         for(i=0;i<campaignchoicenum;i++){
1764                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1765                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1766                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1767                                         }
1768                                         }
1769
1770                                         loading=2;
1771                                         loadtime=0;
1772                                         targetlevel=7;
1773                                         if(firstload)TickOnceAfter();
1774                                         if(!firstload)LoadStuff();
1775                                         //else {
1776                                         for(i=0;i<255;i++){
1777                                         mapname[i]='\0';
1778                                         }
1779                                         mapname[0]=':';
1780                                         mapname[1]='D';
1781                                         mapname[2]='a';
1782                                         mapname[3]='t';
1783                                         mapname[4]='a';
1784                                         mapname[5]=':';
1785                                         mapname[6]='M';
1786                                         mapname[7]='a';
1787                                         mapname[8]='p';
1788                                         mapname[9]='s';
1789                                         mapname[10]=':';
1790
1791                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1792                                         //accountcampaignchoicesmade[accountactive]++;
1793
1794
1795                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1796                                         whichchoice=0;
1797                                         visibleloading=1;
1798                                         stillloading=1;
1799                                         Loadlevel(mapname);
1800                                         campaign=1;
1801                                         mainmenu=0;
1802                                         gameon=1;
1803                                         FSOUND_SetPaused(channels[music3], TRUE);
1804
1805                                         stealthloading=0;*/
1806                                 }
1807                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1808                                 if(mainmenu&&musictoggle){
1809                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1810                                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
1811                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
1812                                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
1813                                                 FSOUND_SetVolume(channels[stream_music3], 256);
1814                                                 FSOUND_SetPaused(channels[music1], TRUE);
1815                                         }
1816                                 }
1817                                 if(!mainmenu){
1818                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
1819                                         FSOUND_SetPaused(channels[music1], FALSE);
1820                                 }
1821                         }
1822                         if(mainmenu==3){
1823                                 float gLoc[3]={0,0,0};
1824                                 float vel[3]={0,0,0};
1825                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1826                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1827                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1828                                 FSOUND_SetVolume(channels[fireendsound], 256);
1829                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1830                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1831
1832                                 flashr=1;
1833                                 flashg=0;
1834                                 flashb=0;
1835                                 flashamount=1;
1836                                 flashdelay=1;
1837
1838                                 if(newdetail>2)newdetail=detail;
1839                                 if(newdetail<0)newdetail=detail;
1840                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
1841                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1842                                 if(newscreenheight>3000)newscreenheight=screenheight;
1843                                 if(newscreenheight<0)newscreenheight=screenheight;
1844
1845                                 //ofstream opstream(":Data:config.txt"); 
1846                                 ofstream opstream("./Data/config.txt"); 
1847                                 opstream << "Screenwidth:\n";
1848                                 opstream << newscreenwidth;
1849                                 opstream << "\nScreenheight:\n";
1850                                 opstream << newscreenheight;
1851                                 opstream << "\nMouse sensitivity:\n";
1852                                 opstream << usermousesensitivity;
1853                                 opstream << "\nBlur(0,1):\n";
1854                                 opstream << ismotionblur;
1855                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1856                                 opstream << newdetail;
1857                                 opstream << "\nFloating jump:\n";
1858                                 opstream << floatjump;
1859                                 opstream << "\nMouse jump:\n";
1860                                 opstream << mousejump;
1861                                 opstream << "\nAmbient sound:\n";
1862                                 opstream << ambientsound;
1863                                 opstream << "\nBlood (0,1,2):\n";
1864                                 opstream << bloodtoggle;
1865                                 opstream << "\nAuto slomo:\n";
1866                                 opstream << autoslomo;
1867                                 opstream << "\nFoliage:\n";
1868                                 opstream << foliage;
1869                                 opstream << "\nMusic:\n";
1870                                 opstream << musictoggle;
1871                                 opstream << "\nTrilinear:\n";
1872                                 opstream << trilinear;
1873                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1874                                 opstream << decals;
1875                                 opstream << "\nInvert mouse:\n";
1876                                 opstream << invertmouse;
1877                                 opstream << "\nGamespeed:\n";
1878                                 if(oldgamespeed==0)oldgamespeed=1;
1879                                 opstream << oldgamespeed;
1880                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1881                                 opstream << difficulty;
1882                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1883                                 opstream << damageeffects;
1884                                 opstream << "\nText:\n";
1885                                 opstream << texttoggle;
1886                                 opstream << "\nDebug:\n";
1887                                 opstream << debugmode;
1888                                 opstream << "\nVBL Sync:\n";
1889                                 opstream << vblsync;
1890                                 opstream << "\nShow Points:\n";
1891                                 opstream << showpoints;
1892                                 opstream << "\nAlways Blur:\n";
1893                                 opstream << alwaysblur;
1894                                 opstream << "\nImmediate mode (turn on on G5):\n";
1895                                 opstream << immediate;
1896                                 opstream << "\nVelocity blur:\n";
1897                                 opstream << velocityblur;
1898                             opstream << "\nVolume:\n";
1899                         opstream << volume;
1900                                 opstream << "\nForward key:\n";
1901                                 opstream << KeyToChar(forwardkey);
1902                                 opstream << "\nBack key:\n";
1903                                 opstream << KeyToChar(backkey);
1904                                 opstream << "\nLeft key:\n";
1905                                 opstream << KeyToChar(leftkey);
1906                                 opstream << "\nRight key:\n";
1907                                 opstream << KeyToChar(rightkey);
1908                                 opstream << "\nJump key:\n";
1909                                 opstream << KeyToChar(jumpkey);
1910                                 opstream << "\nCrouch key:\n";
1911                                 opstream << KeyToChar(crouchkey);
1912                                 opstream << "\nDraw key:\n";
1913                                 opstream << KeyToChar(drawkey);
1914                                 opstream << "\nThrow key:\n";
1915                                 opstream << KeyToChar(throwkey);
1916                                 opstream << "\nAttack key:\n";
1917                                 opstream << KeyToChar(attackkey);
1918                                 opstream << "\nChat key:\n";
1919                                 opstream << KeyToChar(chatkey);
1920                                 opstream.close();
1921                         }       
1922                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==10||mainmenu==11||mainmenu==100){
1923                                 float gLoc[3]={0,0,0};
1924                                 float vel[3]={0,0,0};
1925                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
1926                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
1927                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1928                                 FSOUND_SetVolume(channels[fireendsound], 256);
1929                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
1930                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
1931
1932                                 flashr=1;
1933                                 flashg=0;
1934                                 flashb=0;
1935                                 flashamount=1;
1936                                 flashdelay=1;
1937                         }       
1938                         if(mainmenu==3&&gameon)mainmenu=2;
1939                         if(mainmenu==3&&!gameon)mainmenu=1;
1940                         if(mainmenu==5&&gameon)mainmenu=2;
1941                         if(mainmenu==5&&!gameon)mainmenu=1;
1942                         if(mainmenu==4)mainmenu=3;
1943                         if(mainmenu==6)mainmenu=5;
1944                         if(mainmenu==7)mainmenu=1;
1945                         if(mainmenu==9)mainmenu=5;
1946                         if(mainmenu==11)mainmenu=5;
1947                         if(mainmenu==12)mainmenu=5;
1948                         if(mainmenu==13)mainmenu=12;
1949                         if(mainmenu==14)mainmenu=13;
1950                         if(mainmenu==10)mainmenu=5;
1951                         if(mainmenu==100){
1952                                 mainmenu=5;
1953                                 gameon=0;
1954                                 winfreeze=0;
1955                         }
1956                         mainmenutogglekeydown=1;
1957                 }
1958                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1959                         mainmenutogglekeydown=0;
1960                 }
1961         }
1962
1963         /*static bool minimaptogglekeydown;
1964         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1965         minimap=1-minimap;
1966         minimaptogglekeydown=1;
1967         }
1968         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1969         minimaptogglekeydown=0;
1970         }
1971         */
1972
1973         static bool minimaptogglekeydown;
1974         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
1975                 if(tutorialstage!=51)
1976                         tutorialstagetime=tutorialmaxtime;
1977                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
1978                 FSOUND_SetVolume(channels[consolefailsound], 128);
1979                 FSOUND_SetPaused(channels[consolefailsound], FALSE);
1980                 minimaptogglekeydown=1;
1981         }
1982         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1983                 minimaptogglekeydown=0;
1984         }
1985
1986         if(mainmenu){
1987                 //menu buttons
1988                 if(mainmenu==1||mainmenu==2){
1989                         if(Button()&&!oldbutton&&selected==1){
1990                                 if(!gameon){
1991                                         float gLoc[3]={0,0,0};
1992                                         float vel[3]={0,0,0};
1993                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
1994                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
1995                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1996                                         FSOUND_SetVolume(channels[firestartsound], 256);
1997                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
1998                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
1999
2000                                         flashr=1;
2001                                         flashg=0;
2002                                         flashb=0;
2003                                         flashamount=1;
2004                                         flashdelay=1;
2005
2006                                         //new game
2007                                         if(accountactive!=-1)mainmenu=5;
2008                                         else mainmenu=7;
2009                                         /*
2010                                         startbonustotal=0;
2011
2012                                         loading=2;
2013                                         loadtime=0;
2014                                         if(firstload)TickOnceAfter();
2015                                         if(!firstload)LoadStuff();
2016                                         else {
2017                                         Loadlevel(0);
2018                                         }
2019                                         mainmenu=0;
2020                                         gameon=1;
2021                                         FSOUND_SetPaused(channels[music3], TRUE);       */                      
2022                                 }
2023                                 else
2024                                 {
2025                                         //resume
2026                                         mainmenu=0;
2027                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
2028                                         FSOUND_SetPaused(channels[music1], FALSE);
2029                                 }
2030                         }
2031
2032                         if(Button()&&!oldbutton&&selected==2){
2033                                 float gLoc[3]={0,0,0};
2034                                 float vel[3]={0,0,0};
2035                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2036                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2037                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2038                                 FSOUND_SetVolume(channels[firestartsound], 256);
2039                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2040                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2041
2042                                 flashr=1;
2043                                 flashg=0;
2044                                 flashb=0;
2045                                 flashamount=1;
2046                                 flashdelay=1;
2047
2048                                 //options
2049
2050                                 mainmenu=3;                     
2051
2052                                 if(newdetail>2)newdetail=detail;
2053                                 if(newdetail<0)newdetail=detail;
2054                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2055                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2056                                 if(newscreenheight>3000)newscreenheight=screenheight;
2057                                 if(newscreenheight<0)newscreenheight=screenheight;      
2058                         }
2059
2060                         if(Button()&&!oldbutton&&selected==3){
2061                                 float gLoc[3]={0,0,0};
2062                                 float vel[3]={0,0,0};
2063                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2064                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2065                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2066                                 FSOUND_SetVolume(channels[fireendsound], 256);
2067                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2068                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2069
2070                                 flashr=1;
2071                                 flashg=0;
2072                                 flashb=0;
2073                                 flashamount=1;
2074                                 flashdelay=1;
2075
2076                                 if(!gameon){
2077                                         //quit
2078                                         tryquit=1;
2079                                         if(registered)FSOUND_SetPaused(channels[stream_music3], TRUE);
2080                                 }
2081                                 else{
2082                                         //end game
2083                                         gameon=0;
2084                                         mainmenu=1;
2085                                 }
2086                         }
2087                         if(Button())oldbutton=1;
2088                         else oldbutton=0;
2089                 }
2090
2091                 if(mainmenu==3){
2092                         if(Button()&&!oldbutton&&selected!=-1){
2093                                 float gLoc[3]={0,0,0};
2094                                 float vel[3]={0,0,0};
2095                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2096                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2097                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2098                                 FSOUND_SetVolume(channels[firestartsound], 256);
2099                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2100                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2101                         }
2102                         if(Button()&&!oldbutton&&selected==0){
2103                                 int whichres;
2104                                 whichres=-1;
2105                                 if(newscreenwidth==640&&newscreenheight==480)whichres=0;
2106                                 if(newscreenwidth==800&&newscreenheight==600)whichres=1;
2107                                 if(newscreenwidth==1024&&newscreenheight==768)whichres=2;
2108                                 if(newscreenwidth==1280&&newscreenheight==1024)whichres=3;
2109                                 if(newscreenwidth==1600&&newscreenheight==1200)whichres=4;
2110                                 if(newscreenwidth==840&&newscreenheight==524)whichres=5;
2111                                 if(newscreenwidth==1024&&newscreenheight==640)whichres=6;
2112                                 if(newscreenwidth==1344&&newscreenheight==840)whichres=7;
2113
2114                                 if(whichres==-1||whichres==7){
2115                                         newscreenwidth=640;
2116                                         newscreenheight=480;
2117                                 }
2118                                 if(whichres==0){
2119                                         newscreenwidth=800;
2120                                         newscreenheight=600;
2121                                 }
2122                                 if(whichres==1){
2123                                         newscreenwidth=1024;
2124                                         newscreenheight=768;
2125                                 }
2126                                 if(whichres==2){
2127                                         newscreenwidth=1280;
2128                                         newscreenheight=1024;
2129                                 }
2130                                 if(whichres==3){
2131                                         newscreenwidth=1600;
2132                                         newscreenheight=1200;
2133                                 }
2134                                 if(whichres==4){
2135                                         newscreenwidth=840;
2136                                         newscreenheight=524;
2137                                 }
2138                                 if(whichres==5){
2139                                         newscreenwidth=1024;
2140                                         newscreenheight=640;
2141                                 }
2142                                 if(whichres==6){
2143                                         newscreenwidth=1344;
2144                                         newscreenheight=840;
2145                                 }
2146                         }
2147                         if(Button()&&!oldbutton&&selected==1){
2148                                 newdetail++;
2149                                 if(newdetail>2)newdetail=0;
2150                         }
2151                         if(Button()&&!oldbutton&&selected==2){
2152                                 bloodtoggle++;
2153                                 if(bloodtoggle>2)bloodtoggle=0;
2154                         }
2155                         if(Button()&&!oldbutton&&selected==3){
2156                                 difficulty++;
2157                                 if(difficulty>2)difficulty=0;
2158                         }
2159                         if(Button()&&!oldbutton&&selected==4){
2160                                 ismotionblur=1-ismotionblur;
2161                         }
2162                         if(Button()&&!oldbutton&&selected==5){
2163                                 decals=1-decals;
2164                         }
2165                         if(Button()&&!oldbutton&&selected==6){
2166                                 musictoggle=1-musictoggle;
2167
2168                                 if(!musictoggle){
2169                                         FSOUND_SetPaused(channels[music1], TRUE);
2170                                         FSOUND_SetPaused(channels[stream_music2], TRUE);
2171                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
2172
2173                                         for(i=0;i<4;i++){
2174                                                 oldmusicvolume[i]=0;
2175                                                 musicvolume[i]=0;
2176                                         }
2177                                 }
2178
2179                                 if(musictoggle){
2180                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
2181                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
2182                                         FSOUND_SetVolume(channels[stream_music3], 256);                         
2183                                 }
2184                         }
2185                         if(Button()&&!oldbutton&&selected==9){
2186                                 invertmouse=1-invertmouse;
2187                         }
2188                         if(Button()&&!oldbutton&&selected==10){
2189                                 usermousesensitivity+=.2;
2190                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2191                         }
2192                         if(Button()&&!oldbutton&&selected==11){
2193                                 volume+=.1f;
2194                                 if(volume>1.0001f)volume=0;
2195                                 FSOUND_SetSFXMasterVolume((int)(volume*255));
2196                         }
2197                         if(Button()&&!oldbutton&&selected==7){
2198                                 /*float gLoc[3]={0,0,0};
2199                                 float vel[3]={0,0,0};
2200                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2201                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2202                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2203                                 FSOUND_SetVolume(channels[firestartsound], 256);
2204                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2205                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2206                                 */
2207                                 flashr=1;
2208                                 flashg=0;
2209                                 flashb=0;
2210                                 flashamount=1;
2211                                 flashdelay=1;
2212
2213                                 //options
2214
2215                                 mainmenu=4;             
2216                                 keyselect=-1;
2217                         }
2218                         if(Button()&&!oldbutton&&selected==8){
2219                                 float gLoc[3]={0,0,0};
2220                                 float vel[3]={0,0,0};
2221                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2222                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2223                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2224                                 FSOUND_SetVolume(channels[fireendsound], 256);
2225                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2226                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2227
2228                                 flashr=1;
2229                                 flashg=0;
2230                                 flashb=0;
2231                                 flashamount=1;
2232                                 flashdelay=1;
2233
2234                                 if(newdetail>2)newdetail=detail;
2235                                 if(newdetail<0)newdetail=detail;
2236                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2237                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2238                                 if(newscreenheight>3000)newscreenheight=screenheight;
2239                                 if(newscreenheight<0)newscreenheight=screenheight;
2240
2241
2242                                 //ofstream opstream(":Data:config.txt"); 
2243                                 ofstream opstream("./Data/config.txt"); 
2244                                 opstream << "Screenwidth:\n";
2245                                 opstream << newscreenwidth;
2246                                 opstream << "\nScreenheight:\n";
2247                                 opstream << newscreenheight;
2248                                 opstream << "\nMouse sensitivity:\n";
2249                                 opstream << usermousesensitivity;
2250                                 opstream << "\nBlur(0,1):\n";
2251                                 opstream << ismotionblur;
2252                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2253                                 opstream << newdetail;
2254                                 opstream << "\nFloating jump:\n";
2255                                 opstream << floatjump;
2256                                 opstream << "\nMouse jump:\n";
2257                                 opstream << mousejump;
2258                                 opstream << "\nAmbient sound:\n";
2259                                 opstream << ambientsound;
2260                                 opstream << "\nBlood (0,1,2):\n";
2261                                 opstream << bloodtoggle;
2262                                 opstream << "\nAuto slomo:\n";
2263                                 opstream << autoslomo;
2264                                 opstream << "\nFoliage:\n";
2265                                 opstream << foliage;
2266                                 opstream << "\nMusic:\n";
2267                                 opstream << musictoggle;
2268                                 opstream << "\nTrilinear:\n";
2269                                 opstream << trilinear;
2270                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2271                                 opstream << decals;
2272                                 opstream << "\nInvert mouse:\n";
2273                                 opstream << invertmouse;
2274                                 opstream << "\nGamespeed:\n";
2275                                 if(oldgamespeed==0)oldgamespeed=1;
2276                                 opstream << oldgamespeed;
2277                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2278                                 opstream << difficulty;
2279                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2280                                 opstream << damageeffects;
2281                                 opstream << "\nText:\n";
2282                                 opstream << texttoggle;
2283                                 opstream << "\nDebug:\n";
2284                                 opstream << debugmode;
2285                                 opstream << "\nVBL Sync:\n";
2286                                 opstream << vblsync;
2287                                 opstream << "\nShow Points:\n";
2288                                 opstream << showpoints;
2289                                 opstream << "\nAlways Blur:\n";
2290                                 opstream << alwaysblur;
2291                                 opstream << "\nImmediate mode (turn on on G5):\n";
2292                                 opstream << immediate;
2293                                 opstream << "\nVelocity blur:\n";
2294                                 opstream << velocityblur;
2295                             opstream << "\nVolume:\n";
2296                         opstream << volume;
2297                                 opstream << "\nForward key:\n";
2298                                 opstream << KeyToChar(forwardkey);
2299                                 opstream << "\nBack key:\n";
2300                                 opstream << KeyToChar(backkey);
2301                                 opstream << "\nLeft key:\n";
2302                                 opstream << KeyToChar(leftkey);
2303                                 opstream << "\nRight key:\n";
2304                                 opstream << KeyToChar(rightkey);
2305                                 opstream << "\nJump key:\n";
2306                                 opstream << KeyToChar(jumpkey);
2307                                 opstream << "\nCrouch key:\n";
2308                                 opstream << KeyToChar(crouchkey);
2309                                 opstream << "\nDraw key:\n";
2310                                 opstream << KeyToChar(drawkey);
2311                                 opstream << "\nThrow key:\n";
2312                                 opstream << KeyToChar(throwkey);
2313                                 opstream << "\nAttack key:\n";
2314                                 opstream << KeyToChar(attackkey);
2315                                 opstream << "\nChat key:\n";
2316                                 opstream << KeyToChar(chatkey);
2317                                 opstream.close();
2318
2319                                 if(mainmenu==3&&gameon)mainmenu=2;
2320                                 if(mainmenu==3&&!gameon)mainmenu=1;
2321                         }
2322                         if(Button())oldbutton=1;
2323                         else oldbutton=0;
2324                 }
2325                 if(mainmenu==4){
2326                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2327                                 float gLoc[3]={0,0,0};
2328                                 float vel[3]={0,0,0};
2329                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2330                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2331                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2332                                 FSOUND_SetVolume(channels[firestartsound], 256);
2333                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2334                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2335                         }
2336                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2337                                 keyselect=selected;
2338                                 oldbuttons[0]=1;
2339                                 oldbuttons[1]=1;
2340                                 oldbuttons[2]=1;
2341                         }
2342                         if(keyselect!=-1){
2343                                 for(i=0;i<3;i++)
2344                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2345                                 for(i=0;i<140;i++){
2346                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2347                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2348                                                         float gLoc[3]={0,0,0};
2349                                                         float vel[3]={0,0,0};
2350                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2351                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2352                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2353                                                         FSOUND_SetVolume(channels[fireendsound], 256);
2354                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
2355                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2356
2357                                                         int keynum;
2358                                                         keynum=i;
2359                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2360                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2361
2362
2363
2364                                                         if(keyselect==0)forwardkey=keynum;
2365                                                         if(keyselect==1)backkey=keynum;
2366                                                         if(keyselect==2)leftkey=keynum;
2367                                                         if(keyselect==3)rightkey=keynum;
2368                                                         if(keyselect==4)crouchkey=keynum;
2369                                                         if(keyselect==5)jumpkey=keynum;
2370                                                         if(keyselect==6)drawkey=keynum;
2371                                                         if(keyselect==7)throwkey=keynum;
2372                                                         if(keyselect==8)attackkey=keynum;
2373                                                         keyselect=-1;
2374                                                 }
2375                                         }
2376                                 }}
2377                         if(Button()&&!oldbutton&&selected==9){
2378                                 float gLoc[3]={0,0,0};
2379                                 float vel[3]={0,0,0};
2380                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2381                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2382                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2383                                 FSOUND_SetVolume(channels[fireendsound], 256);
2384                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2385                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2386
2387                                 flashr=1;
2388                                 flashg=0;
2389                                 flashb=0;
2390                                 flashamount=1;
2391                                 flashdelay=1;
2392
2393                                 mainmenu=3;
2394
2395                                 if(newdetail>2)newdetail=detail;
2396                                 if(newdetail<0)newdetail=detail;
2397                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2398                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2399                                 if(newscreenheight>3000)newscreenheight=screenheight;
2400                                 if(newscreenheight<0)newscreenheight=screenheight;
2401                         }
2402                 }
2403
2404                 if(mainmenu==5){
2405                         if(accountcampaignchoicesmade[accountactive]>8&&!registered){
2406                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
2407                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
2408                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
2409                                 FSOUND_SetVolume(channels[stream_music3], 256);
2410
2411                                 gameon=0;
2412                                 mainmenu=12;
2413                                 accountcampaignchoicesmade[accountactive]=0;
2414                                 accountcampaignscore[accountactive]=0;
2415                                 accountcampaigntime[accountactive]=0;
2416
2417                                 float gLoc[3]={0,0,0};
2418                                 float vel[3]={0,0,0};
2419                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2420                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2421                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2422                                 FSOUND_SetVolume(channels[fireendsound], 256);
2423                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2424                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2425
2426                                 flashr=1;
2427                                 flashg=0;
2428                                 flashb=0;
2429                                 flashamount=1;
2430                                 flashdelay=1;
2431                         }
2432
2433                         if(endgame==2){
2434                                 accountcampaignchoicesmade[accountactive]=0;
2435                                 accountcampaignscore[accountactive]=0;
2436                                 accountcampaigntime[accountactive]=0;
2437                                 endgame=0;
2438                         }
2439
2440                         if(Button()&&!oldbutton&&selected==1){                  
2441                                 float gLoc[3]={0,0,0};
2442                                 float vel[3]={0,0,0};
2443                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2444                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2445                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2446                                 FSOUND_SetVolume(channels[firestartsound], 256);
2447                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2448                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2449
2450                                 flashr=1;
2451                                 flashg=0;
2452                                 flashb=0;
2453                                 flashamount=1;
2454                                 flashdelay=1;
2455
2456                                 startbonustotal=0;
2457
2458                                 loading=2;
2459                                 loadtime=0;
2460                                 targetlevel=-1;
2461                                 if(firstload)TickOnceAfter();
2462                                 if(!firstload)LoadStuff();
2463                                 else {
2464                                         Loadlevel(-1);
2465                                 }
2466
2467                                 mainmenu=0;
2468                                 gameon=1;
2469                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2470                         }
2471                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){                       
2472                                 float gLoc[3]={0,0,0};
2473                                 float vel[3]={0,0,0};
2474                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2475                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2476                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2477                                 FSOUND_SetVolume(channels[firestartsound], 256);
2478                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2479                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2480
2481                                 flashr=1;
2482                                 flashg=0;
2483                                 flashb=0;
2484                                 flashamount=1;
2485                                 flashdelay=1;
2486
2487                                 startbonustotal=0;
2488
2489                                 loading=2;
2490                                 loadtime=0;
2491                                 targetlevel=7;
2492                                 if(firstload)TickOnceAfter();
2493                                 if(!firstload)LoadStuff();
2494                                 //else {
2495                                 for(i=0;i<255;i++){
2496                                         mapname[i]='\0';
2497                                 }
2498                                 mapname[0]=':';
2499                                 mapname[1]='D';
2500                                 mapname[2]='a';
2501                                 mapname[3]='t';
2502                                 mapname[4]='a';
2503                                 mapname[5]=':';
2504                                 mapname[6]='M';
2505                                 mapname[7]='a';
2506                                 mapname[8]='p';
2507                                 mapname[9]='s';
2508                                 mapname[10]=':';
2509                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2510                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2511                                 visibleloading=1;
2512                                 stillloading=1;
2513                                 Loadlevel(mapname);
2514                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2515                                 //}
2516                                 campaign=1;
2517                                 mainmenu=0;
2518                                 gameon=1;
2519                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2520                         }
2521                         if(Button()&&!oldbutton&&selected==4){
2522                                 float gLoc[3]={0,0,0};
2523                                 float vel[3]={0,0,0};
2524                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2525                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2526                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2527                                 FSOUND_SetVolume(channels[fireendsound], 256);
2528                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2529                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2530
2531                                 flashr=1;
2532                                 flashg=0;
2533                                 flashb=0;
2534                                 flashamount=1;
2535                                 flashdelay=1;
2536
2537                                 if(mainmenu==5&&gameon)mainmenu=2;
2538                                 if(mainmenu==5&&!gameon)mainmenu=1;
2539                         }
2540                         if(Button()&&!oldbutton&&selected==5){
2541                                 float gLoc[3]={0,0,0};
2542                                 float vel[3]={0,0,0};
2543                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2544                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2545                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2546                                 FSOUND_SetVolume(channels[fireendsound], 256);
2547                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2548                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2549
2550                                 flashr=1;
2551                                 flashg=0;
2552                                 flashb=0;
2553                                 flashamount=1;
2554                                 flashdelay=1;
2555
2556                                 mainmenu=7;
2557                         }
2558                         if(Button()&&!oldbutton&&selected==3){
2559                                 float gLoc[3]={0,0,0};
2560                                 float vel[3]={0,0,0};
2561                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2562                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2563                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2564                                 FSOUND_SetVolume(channels[firestartsound], 256);
2565                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2566                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2567
2568                                 flashr=1;
2569                                 flashg=0;
2570                                 flashb=0;
2571                                 flashamount=1;
2572                                 flashdelay=1;
2573
2574                                 mainmenu=6;
2575                         }
2576                         if(Button()&&!oldbutton&&selected==2){
2577                                 float gLoc[3]={0,0,0};
2578                                 float vel[3]={0,0,0};
2579                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2580                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2581                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2582                                 FSOUND_SetVolume(channels[firestartsound], 256);
2583                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2584                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2585
2586                                 flashr=1;
2587                                 flashg=0;
2588                                 flashb=0;
2589                                 flashamount=1;
2590                                 flashdelay=1;
2591
2592                                 mainmenu=9;
2593                         }
2594                         if(Button())oldbutton=1;
2595                         else oldbutton=0;
2596                 }
2597                 if(mainmenu==9){
2598                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){                   
2599                                 float gLoc[3]={0,0,0};
2600                                 float vel[3]={0,0,0};
2601                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2602                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2603                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2604                                 FSOUND_SetVolume(channels[firestartsound], 256);
2605                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2606                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2607
2608                                 flashr=1;
2609                                 flashg=0;
2610                                 flashb=0;
2611                                 flashamount=1;
2612                                 flashdelay=1;
2613
2614                                 startbonustotal=0;
2615
2616                                 loading=2;
2617                                 loadtime=0;
2618                                 targetlevel=selected;
2619                                 if(firstload)TickOnceAfter();
2620                                 if(!firstload)LoadStuff();
2621                                 else {
2622                                         Loadlevel(selected);
2623                                 }
2624                                 campaign=0;
2625
2626                                 mainmenu=0;
2627                                 gameon=1;
2628                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2629                         }
2630                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2631                                 float gLoc[3]={0,0,0};
2632                                 float vel[3]={0,0,0};
2633                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2634                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2635                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2636                                 FSOUND_SetVolume(channels[fireendsound], 256);
2637                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2638                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2639
2640                                 flashr=1;
2641                                 flashg=0;
2642                                 flashb=0;
2643                                 flashamount=1;
2644                                 flashdelay=1;
2645
2646                                 mainmenu=5;
2647                         }
2648                         if(Button())oldbutton=1;
2649                         else oldbutton=0;
2650                 }
2651                 if(mainmenu==11){
2652                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){                   
2653                                 float gLoc[3]={0,0,0};
2654                                 float vel[3]={0,0,0};
2655                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2656                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2657                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2658                                 FSOUND_SetVolume(channels[firestartsound], 256);
2659                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2660                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2661
2662                                 flashr=1;
2663                                 flashg=0;
2664                                 flashb=0;
2665                                 flashamount=1;
2666                                 flashdelay=1;
2667
2668                                 startbonustotal=0;
2669
2670                                 loading=2;
2671                                 loadtime=0;
2672                                 targetlevel=selected;
2673                                 if(firstload)TickOnceAfter();
2674                                 if(!firstload)LoadStuff();
2675                                 else {
2676                                         Loadlevel(selected);
2677                                 }
2678                                 campaign=0;
2679
2680                                 mainmenu=0;
2681                                 gameon=1;
2682                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
2683                         }
2684                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2685                                 float gLoc[3]={0,0,0};
2686                                 float vel[3]={0,0,0};
2687                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2688                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2689                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2690                                 FSOUND_SetVolume(channels[fireendsound], 256);
2691                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2692                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2693
2694                                 flashr=1;
2695                                 flashg=0;
2696                                 flashb=0;
2697                                 flashamount=1;
2698                                 flashdelay=1;
2699
2700                                 mainmenu=5;
2701                         }
2702                         if(Button())oldbutton=1;
2703                         else oldbutton=0;
2704                 }
2705                 if(mainmenu==10){
2706                         endgame=2;
2707                         if(Button()&&!oldbutton&&selected==3){
2708                                 float gLoc[3]={0,0,0};
2709                                 float vel[3]={0,0,0};
2710                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2711                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2712                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2713                                 FSOUND_SetVolume(channels[fireendsound], 256);
2714                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2715                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2716
2717                                 flashr=1;
2718                                 flashg=0;
2719                                 flashb=0;
2720                                 flashamount=1;
2721                                 flashdelay=1;
2722
2723                                 mainmenu=5;
2724                         }
2725                         if(Button())oldbutton=1;
2726                         else oldbutton=0;
2727                 }
2728
2729                 if(mainmenu==15||mainmenu==16){
2730                         if(Button()&&!oldbutton&&selected==1){
2731                                 float gLoc[3]={0,0,0};
2732                                 float vel[3]={0,0,0};
2733                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2734                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2735                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2736                                 FSOUND_SetVolume(channels[fireendsound], 256);
2737                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2738                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2739
2740                                 flashr=1;
2741                                 flashg=0;
2742                                 flashb=0;
2743                                 flashamount=1;
2744                                 flashdelay=1;
2745
2746                                 if(mainmenu==15)mainmenu=5;
2747                                 else mainmenu=12;
2748                         }
2749                         if(Button())oldbutton=1;
2750                         else oldbutton=0;
2751                 }
2752
2753                 if(mainmenu==12){
2754                         endgame=2;
2755                         if(Button()&&!oldbutton&&selected==3){
2756                                 if(tryquit)quit=1;
2757                                 float gLoc[3]={0,0,0};
2758                                 float vel[3]={0,0,0};
2759                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2760                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2761                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2762                                 FSOUND_SetVolume(channels[fireendsound], 256);
2763                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2764                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2765
2766                                 flashr=1;
2767                                 flashg=0;
2768                                 flashb=0;
2769                                 flashamount=1;
2770                                 flashdelay=1;
2771
2772                                 mainmenu=5;
2773                         }
2774
2775                         if(Button()&&!oldbutton&&selected==4){
2776                                 registernow=1;
2777                                 quit=1;
2778                                 float gLoc[3]={0,0,0};
2779                                 float vel[3]={0,0,0};
2780                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2781                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2782                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2783                                 FSOUND_SetVolume(channels[fireendsound], 256);
2784                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2785                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2786
2787                                 flashr=1;
2788                                 flashg=0;
2789                                 flashb=0;
2790                                 flashamount=1;
2791                                 flashdelay=1;
2792                         }
2793
2794
2795                         if(Button()&&!oldbutton&&selected==5){
2796                                 tryquit=0;
2797                                 float gLoc[3]={0,0,0};
2798                                 float vel[3]={0,0,0};
2799                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2800                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2801                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2802                                 FSOUND_SetVolume(channels[fireendsound], 256);
2803                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2804                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2805
2806                                 flashr=1;
2807                                 flashg=0;
2808                                 flashb=0;
2809                                 flashamount=1;
2810                                 flashdelay=1;
2811
2812                                 mainmenu=13;
2813                         }
2814                         if(Button())oldbutton=1;
2815                         else oldbutton=0;
2816                 }
2817                 if(mainmenu==6){
2818                         if(Button()&&!oldbutton&&selected!=-1){
2819                                 float gLoc[3]={0,0,0};
2820                                 float vel[3]={0,0,0};
2821                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2822                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2823                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2824                                 FSOUND_SetVolume(channels[firestartsound], 256);
2825                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2826                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2827                         }
2828                         if(Button()&&!oldbutton&&selected==1){
2829                                 float gLoc[3]={0,0,0};
2830                                 float vel[3]={0,0,0};
2831                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2832                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2833                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2834                                 FSOUND_SetVolume(channels[fireendsound], 256);
2835                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2836                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2837
2838                                 flashr=1;
2839                                 flashg=0;
2840                                 flashb=0;
2841                                 flashamount=1;
2842                                 flashdelay=1;
2843
2844                                 for(i=accountactive;i<numaccounts-1;i++){
2845                                         accountdifficulty[i]=accountdifficulty[i+1];
2846                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2847                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2848                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2849                                         }
2850                                         accountpoints[i]=accountpoints[i+1];
2851                                         for(j=0;j<50;j++){
2852                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2853                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2854                                         }
2855                                         for(j=0;j<60;j++){
2856                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2857                                         }
2858                                         for(j=0;j<256;j++){
2859                                                 accountname[i][j]=accountname[i+1][j];
2860                                         }
2861                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2862                                         accountprogress[i]=accountprogress[i+1];
2863                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2864                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2865                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2866                                 }
2867
2868                                 numaccounts--;
2869                                 accountactive=-1;
2870
2871
2872                                 mainmenu=7;
2873                         }
2874                         if(Button()&&!oldbutton&&selected==2){
2875                                 float gLoc[3]={0,0,0};
2876                                 float vel[3]={0,0,0};
2877                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2878                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2879                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2880                                 FSOUND_SetVolume(channels[fireendsound], 256);
2881                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2882                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2883
2884                                 flashr=1;
2885                                 flashg=0;
2886                                 flashb=0;
2887                                 flashamount=1;
2888                                 flashdelay=1;
2889
2890                                 mainmenu=5;
2891                         }
2892                         if(Button())oldbutton=1;
2893                         else oldbutton=0;
2894                 }
2895                 if(mainmenu==7){
2896                         if(Button()&&!oldbutton&&selected!=-1){
2897                                 float gLoc[3]={0,0,0};
2898                                 float vel[3]={0,0,0};
2899                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2900                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2901                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2902                                 FSOUND_SetVolume(channels[firestartsound], 256);
2903                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2904                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2905                         }
2906                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2907                                 entername=1;
2908                         }
2909                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2910                                 accountactive=selected-1;
2911                                 mainmenu=5;
2912                                 flashr=1;
2913                                 flashg=0;
2914                                 flashb=0;
2915                                 flashamount=1;
2916                                 flashdelay=1;
2917                         }
2918                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2919                                 float gLoc[3]={0,0,0};
2920                                 float vel[3]={0,0,0};
2921                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
2922                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
2923                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2924                                 FSOUND_SetVolume(channels[fireendsound], 256);
2925                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
2926                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
2927
2928                                 flashr=1;
2929                                 flashg=0;
2930                                 flashb=0;
2931                                 flashamount=1;
2932                                 flashdelay=1;
2933
2934                                 mainmenu=1;
2935
2936                                 for(j=0;j<255;j++){
2937                                         displaytext[0][j]=' ';
2938                                 }
2939                                 displaychars[0]=0;
2940                                 displayselected=0;
2941                                 entername=0;
2942                         }
2943                         if(Button())oldbutton=1;
2944                         else oldbutton=0;
2945                 }
2946                 if(mainmenu==8){
2947                         if(Button()&&!oldbutton&&selected!=-1){
2948                                 float gLoc[3]={0,0,0};
2949                                 float vel[3]={0,0,0};
2950                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
2951                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
2952                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2953                                 FSOUND_SetVolume(channels[firestartsound], 256);
2954                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
2955                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
2956
2957                                 if(selected==0)accountdifficulty[accountactive]=0;
2958                                 if(selected==1)accountdifficulty[accountactive]=1;
2959                                 if(selected==2)accountdifficulty[accountactive]=2;
2960
2961                                 mainmenu=5;     
2962
2963                                 flashr=1;
2964                                 flashg=0;
2965                                 flashb=0;
2966                                 flashamount=1;
2967                                 flashdelay=1;
2968
2969                         }
2970                         if(Button())oldbutton=1;
2971                         else oldbutton=0;
2972                 }
2973
2974
2975                 if(Button())oldbutton=1;
2976                 else oldbutton=0;
2977
2978                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
2979                         tryquit=1;
2980                         if(mainmenu==3){
2981                                 if(newdetail>2)newdetail=detail;
2982                                 if(newdetail<0)newdetail=detail;
2983                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2984                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2985                                 if(newscreenheight>3000)newscreenheight=screenheight;
2986                                 if(newscreenheight<0)newscreenheight=screenheight;
2987
2988                                 //ofstream opstream(":Data:config.txt"); 
2989                                 ofstream opstream("./Data/config.txt"); 
2990                                 opstream << "Screenwidth:\n";
2991                                 opstream << newscreenwidth;
2992                                 opstream << "\nScreenheight:\n";
2993                                 opstream << newscreenheight;
2994                                 opstream << "\nMouse sensitivity:\n";
2995                                 opstream << usermousesensitivity;
2996                                 opstream << "\nBlur(0,1):\n";
2997                                 opstream << ismotionblur;
2998                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2999                                 opstream << newdetail;
3000                                 opstream << "\nFloating jump:\n";
3001                                 opstream << floatjump;
3002                                 opstream << "\nMouse jump:\n";
3003                                 opstream << mousejump;
3004                                 opstream << "\nAmbient sound:\n";
3005                                 opstream << ambientsound;
3006                                 opstream << "\nBlood (0,1,2):\n";
3007                                 opstream << bloodtoggle;
3008                                 opstream << "\nAuto slomo:\n";
3009                                 opstream << autoslomo;
3010                                 opstream << "\nFoliage:\n";
3011                                 opstream << foliage;
3012                                 opstream << "\nMusic:\n";
3013                                 opstream << musictoggle;
3014                                 opstream << "\nTrilinear:\n";
3015                                 opstream << trilinear;
3016                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
3017                                 opstream << decals;
3018                                 opstream << "\nInvert mouse:\n";
3019                                 opstream << invertmouse;
3020                                 opstream << "\nGamespeed:\n";
3021                                 if(oldgamespeed==0)oldgamespeed=1;
3022                                 opstream << oldgamespeed;
3023                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
3024                                 opstream << difficulty;
3025                                 opstream << "\nDamage effects(blackout, doublevision):\n";
3026                                 opstream << damageeffects;
3027                                 opstream << "\nText:\n";
3028                                 opstream << texttoggle;
3029                                 opstream << "\nDebug:\n";
3030                                 opstream << debugmode;
3031                                 opstream << "\nVBL Sync:\n";
3032                                 opstream << vblsync;
3033                                 opstream << "\nShow Points:\n";
3034                                 opstream << showpoints;
3035                                 opstream << "\nAlways Blur:\n";
3036                                 opstream << alwaysblur;
3037                                 opstream << "\nImmediate mode (turn on on G5):\n";
3038                                 opstream << immediate;
3039                                 opstream << "\nVelocity blur:\n";
3040                                 opstream << velocityblur;
3041                             opstream << "\nVolume:\n";
3042                         opstream << volume;
3043                                 opstream << "\nForward key:\n";
3044                                 opstream << KeyToChar(forwardkey);
3045                                 opstream << "\nBack key:\n";
3046                                 opstream << KeyToChar(backkey);
3047                                 opstream << "\nLeft key:\n";
3048                                 opstream << KeyToChar(leftkey);
3049                                 opstream << "\nRight key:\n";
3050                                 opstream << KeyToChar(rightkey);
3051                                 opstream << "\nJump key:\n";
3052                                 opstream << KeyToChar(jumpkey);
3053                                 opstream << "\nCrouch key:\n";
3054                                 opstream << KeyToChar(crouchkey);
3055                                 opstream << "\nDraw key:\n";
3056                                 opstream << KeyToChar(drawkey);
3057                                 opstream << "\nThrow key:\n";
3058                                 opstream << KeyToChar(throwkey);
3059                                 opstream << "\nAttack key:\n";
3060                                 opstream << KeyToChar(attackkey);
3061                                 opstream << "\nChat key:\n";
3062                                 opstream << KeyToChar(chatkey);
3063                                 opstream.close();
3064                         }
3065                 }
3066
3067                 if(mainmenu==1||mainmenu==2){
3068                         if(loaddistrib>4)transition+=multiplier/8;
3069                         if(transition>1){
3070                                 transition=0;
3071                                 anim++;
3072                                 if(anim>4)anim=0;
3073                                 loaddistrib=0;
3074                         }
3075                 }
3076                 FSOUND_SetFrequency(channels[stream_music3], 22050);            
3077
3078                 if(entername||mainmenu==13||mainmenu==14){
3079                         for(i=0;i<140;i++){
3080                                 if(IsKeyDown(theKeyMap, i)){
3081                                         togglekeydelay[i]+=multiplier;
3082                                         if(togglekeydelay[i]>.4){
3083                                                 togglekey[i]=0;
3084                                                 togglekeydelay[i]=.36;
3085                                         }
3086                                         if(!togglekey[i]){
3087                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3088                                                         for(j=255;j>=displayselected+1;j--){
3089                                                                 displaytext[0][j]=displaytext[0][j-1];
3090                                                         }
3091                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3092                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3093                                                         displayselected++;
3094                                                         displaychars[0]++;
3095                                                 }
3096                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3097                                                         for(j=displayselected-1;j<255;j++){
3098                                                                 displaytext[0][j]=displaytext[0][j+1];
3099                                                         }
3100                                                         displaytext[0][255]=' ';
3101                                                         displayselected--;
3102                                                         displaychars[0]--;
3103                                                 }
3104                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3105                                                         displayselected--;
3106                                                 }
3107                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3108                                                         displayselected++;
3109                                                 }
3110                                                 if(i==MAC_RETURN_KEY&&entername){
3111                                                         if(displaychars[0]){
3112                                                                 numaccounts++;
3113                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
3114                                                                 accountactive=numaccounts-1;
3115                                                                 accountdifficulty[accountactive]=1;
3116                                                                 accountprogress[accountactive]=0;
3117                                                                 accountpoints[accountactive]=0;
3118                                                                 accountcampaigntime[accountactive]=0;
3119                                                                 accountcampaignscore[accountactive]=0;
3120                                                                 accountcampaignfasttime[accountactive]=0;
3121                                                                 accountcampaignhighscore[accountactive]=0;
3122                                                                 for(j=0;j<50;j++){
3123                                                                         accounthighscore[accountactive][j]=0;
3124                                                                         accountfasttime[accountactive][j]=0;
3125                                                                 }
3126                                                                 for(j=0;j<60;j++){
3127                                                                         accountunlocked[accountactive][j]=0;
3128                                                                 }
3129                                                                 accountcampaignchoicesmade[accountactive]=0;
3130
3131                                                                 for(j=0;j<255;j++){
3132                                                                         displaytext[0][j]=' ';
3133                                                                 }
3134                                                                 displaychars[0]=0;
3135                                                                 displayselected=0;
3136                                                                 entername=0;
3137
3138                                                                 mainmenu=8;
3139
3140                                                                 flashr=1;
3141                                                                 flashg=0;
3142                                                                 flashb=0;
3143                                                                 flashamount=1;
3144                                                                 flashdelay=1;
3145
3146                                                                 float gLoc[3]={0,0,0};
3147                                                                 float vel[3]={0,0,0};
3148                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3149                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3150                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3151                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3152                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3153                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3154
3155                                                                 for(j=0;j<255;j++){
3156                                                                         displaytext[0][j]=' ';
3157                                                                 }
3158                                                                 displaychars[0]=0;
3159
3160
3161                                                                 displayselected=0;
3162                                                         }}
3163
3164                                                 if(i==MAC_RETURN_KEY&&mainmenu==14){
3165                                                         if(displaychars[0]){
3166                                                                 char serialstring[256];
3167                                                                 char tempstring[256];
3168                                                                 sprintf (tempstring, "%s-windows", registrationname);
3169                                                                 long num1;
3170                                                                 long num2;
3171                                                                 long num3;
3172                                                                 long num4;
3173                                                                 long long longnum;
3174                                                                 longnum = MD5_string ( tempstring);
3175                                                                 //longnum = 1111111111111111;
3176                                                                 num1 = longnum/100000000;
3177                                                                 num2 = longnum%100000000;
3178                                                                 sprintf (tempstring, "%d-%d-%d-%d\0\0\0\0\0", num1/10000, num1%10000, num2/10000, num2%10000);
3179
3180                                                                 int goodcode=3;
3181                                                                 int numchars=3;
3182                                                                 if(num1/10000>999)numchars+=4;
3183                                                                 else if(num1/10000>99)numchars+=3;
3184                                                                 else if(num1/10000>9)numchars+=2;
3185                                                                 else numchars+=1;
3186                                                                 if(num1%10000>999)numchars+=4;
3187                                                                 else if(num1%10000>99)numchars+=3;
3188                                                                 else if(num1%10000>9)numchars+=2;
3189                                                                 else numchars+=1;
3190                                                                 if(num2/10000>999)numchars+=4;
3191                                                                 else if(num2/10000>99)numchars+=3;
3192                                                                 else if(num2/10000>9)numchars+=2;
3193                                                                 else numchars+=1;
3194                                                                 if(num2%10000>999)numchars+=4;
3195                                                                 else if(num2%10000>99)numchars+=3;
3196                                                                 else if(num2%10000>9)numchars+=2;
3197                                                                 else numchars+=1;
3198
3199                                                                 //numchars=12;
3200
3201                                                                 for(j=0;j<numchars;j++){
3202                                                                         if(displaytext[0][j]!=tempstring[j]&&tempstring[j]!=' '&&tempstring[j]!='\0')goodcode--;
3203                                                                 }
3204
3205                                                                 if(longnum==5077041556214789)goodcode=-1;
3206
3207                                                                 if(goodcode<0)goodcode=0;
3208
3209                                                                 if(goodcode){
3210                                                                         registered=1;
3211                                                                         mainmenu=15;
3212
3213                                                                         FILE                    *tfile;
3214                                                                         tfile=fopen( ":Data:Sounds:flame.ogg", "wb" );
3215                                                                         if (tfile)
3216                                                                         {
3217                                                                                 int numchars;
3218                                                                                 numchars=strlen(registrationname);
3219                                                                                 fpackf(tfile, "Bb", registered);
3220                                                                                 fpackf(tfile, "Bi", numchars);
3221                                                                                 if(numchars>0)
3222                                                                                 {
3223                                                                                         for(j=0;j<numchars;j++)
3224                                                                                         {
3225                                                                                                 fpackf(tfile, "Bb",  registrationname[j]);
3226                                                                                         }
3227                                                                                 }
3228                                                                                 fpackf(tfile, "Bi", num1);
3229                                                                                 fpackf(tfile, "Bi", num2);
3230                                                                                 fclose(tfile);
3231                                                                         }
3232                                                                 }
3233                                                                 else
3234                                                                 {
3235                                                                         mainmenu=16;
3236                                                                 }
3237                                                                 flashr=1;
3238                                                                 flashg=0;
3239                                                                 flashb=0;
3240                                                                 flashamount=1;
3241                                                                 flashdelay=1;
3242
3243                                                                 float gLoc[3]={0,0,0};
3244                                                                 float vel[3]={0,0,0};
3245                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3246                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3247                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3248                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3249                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3250                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3251
3252                                                                 for(j=0;j<255;j++){
3253                                                                         displaytext[0][j]=' ';
3254                                                                 }
3255                                                                 displaychars[0]=0;
3256                                                                 displayselected=0;
3257                                                         }}
3258
3259                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3260                                                         if(displaychars[0]){
3261                                                                 sprintf (registrationname, "%s", displaytext[0]);
3262                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3263
3264                                                                 mainmenu=14;
3265
3266                                                                 flashr=1;
3267                                                                 flashg=0;
3268                                                                 flashb=0;
3269                                                                 flashamount=1;
3270                                                                 flashdelay=1;
3271
3272                                                                 float gLoc[3]={0,0,0};
3273                                                                 float vel[3]={0,0,0};
3274                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
3275                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
3276                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3277                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
3278                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
3279                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
3280
3281                                                                 for(j=0;j<255;j++){
3282                                                                         displaytext[0][j]=' ';
3283                                                                 }
3284                                                                 displaychars[0]=0;
3285
3286                                                                 /*char tempstring[50];
3287                                                                 sprintf (tempstring, registrationname);
3288                                                                 long num1;
3289                                                                 long num2;
3290                                                                 long num3;
3291                                                                 long num4;
3292                                                                 long long longnum;
3293                                                                 longnum = MD5_string ( tempstring);
3294                                                                 num1 = longnum/100000000;
3295                                                                 num2 = longnum%100000000;
3296                                                                 sprintf (displaytext[0], "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
3297
3298                                                                 displaychars[0]=strlen(displaytext[0]);
3299                                                                 */
3300                                                                 displayselected=0;
3301                                                         }}
3302                                         }
3303                                         togglekey[i]=1;
3304                                 }
3305                                 else {
3306                                         togglekey[i]=0;
3307                                         togglekeydelay[i]=0;
3308                                 }
3309                         }
3310
3311                         displayblinkdelay-=multiplier;
3312                         if(displayblinkdelay<=0){
3313                                 displayblinkdelay=.3;
3314                                 displayblink=1-displayblink;
3315                         }
3316                 }
3317         }
3318
3319         if(!mainmenu){  
3320                 if(hostile==1)hostiletime+=multiplier;
3321                 else hostiletime=0;
3322                 if(!winfreeze)leveltime+=multiplier;
3323                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3324                         chatting=0;
3325                         console=0;
3326                         freeze=0;
3327                         displaychars[0]=0;
3328                 }
3329
3330                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3331                         chatting=1;
3332                         chattogglekeydown=1;
3333                         togglekey[chatkey]=1;
3334                         togglekeydelay[chatkey]=-20;
3335                 }
3336
3337                 if(!IsKeyDown(theKeyMap, chatkey)){
3338                         chattogglekeydown=0;
3339                 }
3340
3341                 if(chatting){
3342                         for(i=0;i<140;i++){
3343                                 if(IsKeyDown(theKeyMap, i)){
3344                                         togglekeydelay[i]+=multiplier;
3345                                         if(togglekeydelay[i]>.4){
3346                                                 togglekey[i]=0;
3347                                                 togglekeydelay[i]=.36;
3348                                         }
3349                                         if(!togglekey[i]){
3350                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3351                                                         for(j=255;j>=displayselected+1;j--){
3352                                                                 displaytext[0][j]=displaytext[0][j-1];
3353                                                         }
3354                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3355                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3356                                                         displayselected++;
3357                                                         displaychars[0]++;
3358                                                 }
3359                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3360                                                         for(j=displayselected-1;j<255;j++){
3361                                                                 displaytext[0][j]=displaytext[0][j+1];
3362                                                         }
3363                                                         displaytext[0][255]=' ';
3364                                                         displayselected--;
3365                                                         displaychars[0]--;
3366                                                 }
3367                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3368                                                         displayselected--;
3369                                                 }
3370                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3371                                                         displayselected++;
3372                                                 }
3373                                                 if(i==MAC_RETURN_KEY){
3374                                                         if(displaychars[0]){
3375                                                                 /*for(j=0;j<displaychars[0];j++){
3376                                                                 talkname[j]=displaytext[0][j];
3377                                                                 }
3378                                                                 talkname[displaychars[0]]='\0';
3379                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3380                                                                 //NetworkSendInformation(chatname);
3381                                                                 */
3382                                                                 for(j=0;j<255;j++){
3383                                                                         displaytext[0][j]=' ';
3384                                                                 }
3385                                                                 displaychars[0]=0;
3386                                                                 displayselected=0;
3387                                                                 chatting=0;
3388                                                         }
3389                                                 }
3390                                         }
3391                                         togglekey[i]=1;
3392                                 }
3393                                 else {
3394                                         togglekey[i]=0;
3395                                         togglekeydelay[i]=0;
3396                                 }
3397                         }
3398
3399                         displayblinkdelay-=multiplier;
3400                         if(displayblinkdelay<=0){
3401                                 displayblinkdelay=.3;
3402                                 displayblink=1-displayblink;
3403                         }
3404                 }
3405
3406                 if(chatting)keyboardfrozen=1;
3407
3408                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3409                         freeze=1-freeze;
3410                         if(freeze){
3411                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3412                         }
3413                         freezetogglekeydown=1;
3414                 }
3415
3416                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3417                         freezetogglekeydown=0;
3418                 }
3419
3420                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3421                         console=1-console;
3422                         if(!console)freeze=0;
3423                         if(console){
3424                                 FSOUND_SetFrequency(FSOUND_ALL, 0.001);
3425                         }
3426                         consoletogglekeydown=1;
3427                 }
3428
3429                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3430                         consoletogglekeydown=0;
3431                 }
3432
3433                 if(console)freeze=1;
3434
3435                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3436                         for(i=0;i<140;i++){
3437                                 if(IsKeyDown(theKeyMap, i)){
3438                                         togglekeydelay[i]+=multiplier;
3439                                         if(togglekeydelay[i]>.4){
3440                                                 togglekey[i]=0;
3441                                                 togglekeydelay[i]=.36;
3442                                         }
3443                                         if(!togglekey[i]){
3444                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3445                                                         for(j=255;j>=consoleselected+1;j--){
3446                                                                 consoletext[0][j]=consoletext[0][j-1];
3447                                                         }
3448                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3449                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3450                                                         consoleselected++;
3451                                                         consolechars[0]++;
3452                                                 }
3453                                                 else if(i==MAC_ENTER_KEY){
3454                                                         for(j=255;j>=consoleselected+1;j--){
3455                                                                 consoletext[0][j]=consoletext[0][j-1];
3456                                                         }
3457                                                         consoletext[0][consoleselected]='\n';
3458                                                         consoleselected++;
3459                                                         consolechars[0]++;
3460                                                 }
3461                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3462                                                         for(j=consoleselected-1;j<255;j++){
3463                                                                 consoletext[0][j]=consoletext[0][j+1];
3464                                                         }
3465                                                         consoletext[0][255]=' ';
3466                                                         consoleselected--;
3467                                                         consolechars[0]--;
3468                                                 }
3469                                                 if(i==MAC_ARROW_UP_KEY){
3470                                                         if(archiveselected<14)archiveselected++;
3471                                                         for(j=0;j<255;j++){
3472                                                                 consolechars[0]=consolechars[archiveselected];
3473                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3474                                                                 consoleselected=consolechars[0];
3475                                                         }
3476                                                 }
3477                                                 if(i==MAC_ARROW_DOWN_KEY){
3478                                                         if(archiveselected>0)archiveselected--;
3479                                                         for(j=0;j<255;j++){
3480                                                                 consolechars[0]=consolechars[archiveselected];
3481                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3482                                                                 consoleselected=consolechars[0];
3483                                                         }
3484                                                 }
3485                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3486                                                         consoleselected--;
3487                                                 }
3488                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3489                                                         consoleselected++;
3490                                                 }
3491                                                 if(i==MAC_RETURN_KEY){
3492                                                         archiveselected=0;
3493                                                         donesomething=0;
3494                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3495                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3496                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3497                                                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3498                                                                 donesomething=1;
3499                                                                 tryquit=1;
3500                                                         }
3501                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3502                                                         for(j=5;j<consolechars[0];j++){
3503                                                         talkname[j-5]=consoletext[0][j];
3504                                                         }
3505                                                         talkname[consolechars[0]-5]='\0';
3506                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3507                                                         //NetworkSendInformation(chatname);
3508                                                         donesomething=1;
3509                                                         }
3510                                                         if(Compare(consoletext[0],"name ",0,4)){
3511                                                         int numchars;
3512                                                         numchars=consolechars[0]-5;
3513                                                         if(numchars>32)numchars=32;
3514                                                         for(j=5;j<numchars+5;j++){
3515                                                         talkname[j-5]=consoletext[0][j];
3516                                                         }
3517                                                         talkname[numchars]='\0';
3518                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3519                                                         //NetworkSendInformation(chatname);
3520                                                         sprintf (playerName, "%s",talkname);
3521                                                         //NetworkSendName(playerName);
3522                                                         donesomething=1;
3523                                                         }*/
3524                                                         if(Compare(consoletext[0],"map ",0,3)){
3525                                                                 mapname[0]=':';
3526                                                                 mapname[1]='D';
3527                                                                 mapname[2]='a';
3528                                                                 mapname[3]='t';
3529                                                                 mapname[4]='a';
3530                                                                 mapname[5]=':';
3531                                                                 mapname[6]='M';
3532                                                                 mapname[7]='a';
3533                                                                 mapname[8]='p';
3534                                                                 mapname[9]='s';
3535                                                                 mapname[10]=':';
3536                                                                 for(j=4;j<consolechars[0];j++){
3537                                                                         mapname[j-4+11]=consoletext[0][j];
3538                                                                 }
3539                                                                 mapname[consolechars[0]-4+11]='\0';
3540                                                                 Loadlevel(mapname);
3541                                                                 whichlevel=-2;
3542                                                                 campaign=0;
3543                                                                 donesomething=1;
3544                                                         }
3545                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3546                                                         int v;
3547                                                         unsigned char playerNameStr[32];
3548                                                         char theIPAddress[256];
3549                                                         char thePort[32];
3550                                                         NMUInt32 port = 25710;
3551
3552                                                         strcpy(playerName, "Client");
3553                                                         GameC2PStr( playerName, playerNameStr );
3554
3555                                                         for(j=0;j<consolechars[0]-8;j++){
3556                                                         theIPAddress[j]=consoletext[0][j+8];
3557                                                         }
3558                                                         theIPAddress[consolechars[0]-8]='\0';
3559
3560                                                         sprintf( thePort, "%li", port );
3561                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3562                                                         if(v)
3563                                                         {
3564                                                         if(consolechars[0]>0){
3565                                                         for(k=14;k>=1;k--){
3566                                                         for(j=0;j<255;j++){
3567                                                         consoletext[k][j]=consoletext[k-1][j];
3568                                                         }
3569                                                         consolechars[k]=consolechars[k-1];
3570                                                         }
3571                                                         for(j=0;j<255;j++){
3572                                                         consoletext[0][j]=' ';
3573                                                         }
3574                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3575                                                         else sprintf (consoletext[0], "Could not open connection");
3576
3577                                                         consolechars[0]=255;
3578                                                         consoleselected=0;
3579                                                         }
3580                                                         }
3581                                                         else 
3582                                                         {
3583                                                         donesomething=1;
3584                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3585                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3586                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3587
3588                                                         if(consolechars[0]>0){
3589                                                         for(k=14;k>=1;k--){
3590                                                         for(j=0;j<255;j++){
3591                                                         consoletext[k][j]=consoletext[k-1][j];
3592                                                         }
3593                                                         consolechars[k]=consolechars[k-1];
3594                                                         }
3595                                                         for(j=0;j<255;j++){
3596                                                         consoletext[0][j]=' ';
3597                                                         }
3598                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3599
3600                                                         consolechars[0]=255;
3601                                                         consoleselected=0;
3602                                                         }
3603                                                         }
3604                                                         }
3605
3606                                                         if(Compare(consoletext[0],"host ",0,4)){
3607                                                         unsigned char gameNameStr[32], playerNameStr[32];
3608                                                         char gameName[32];//, playerName[32];
3609                                                         NMUInt32 port;
3610                                                         int players;
3611                                                         int v;
3612
3613                                                         port = 25710;
3614                                                         players =4;
3615
3616                                                         strcpy(gameName, "Host's game");
3617                                                         strcpy(playerName, "Host");
3618                                                         GameC2PStr( gameName, gameNameStr );
3619                                                         GameC2PStr( playerName, playerNameStr );
3620
3621                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3622                                                         if(v)
3623                                                         {
3624                                                         if(consolechars[0]>0){
3625                                                         for(k=14;k>=1;k--){
3626                                                         for(j=0;j<255;j++){
3627                                                         consoletext[k][j]=consoletext[k-1][j];
3628                                                         }
3629                                                         consolechars[k]=consolechars[k-1];
3630                                                         }
3631                                                         for(j=0;j<255;j++){
3632                                                         consoletext[0][j]=' ';
3633                                                         }
3634                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3635
3636                                                         consolechars[0]=255;
3637                                                         consoleselected=0;
3638                                                         }
3639                                                         }
3640                                                         else
3641                                                         {
3642                                                         donesomething=1;
3643                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3644                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
3645                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3646
3647                                                         if(consolechars[0]>0){
3648                                                         for(k=14;k>=1;k--){
3649                                                         for(j=0;j<255;j++){
3650                                                         consoletext[k][j]=consoletext[k-1][j];
3651                                                         }
3652                                                         consolechars[k]=consolechars[k-1];
3653                                                         }
3654                                                         for(j=0;j<255;j++){
3655                                                         consoletext[0][j]=' ';
3656                                                         }
3657                                                         sprintf (consoletext[0], "Game hosted");
3658
3659                                                         consolechars[0]=255;
3660                                                         consoleselected=0;
3661                                                         }
3662                                                         }
3663                                                         }
3664                                                         */
3665                                                         if(Compare(consoletext[0],"save ",0,4)){
3666                                                                 mapname[0]=':';
3667                                                                 mapname[1]='D';
3668                                                                 mapname[2]='a';
3669                                                                 mapname[3]='t';
3670                                                                 mapname[4]='a';
3671                                                                 mapname[5]=':';
3672                                                                 mapname[6]='M';
3673                                                                 mapname[7]='a';
3674                                                                 mapname[8]='p';
3675                                                                 mapname[9]='s';
3676                                                                 mapname[10]=':';
3677                                                                 for(j=5;j<consolechars[0];j++){
3678                                                                         mapname[j-5+11]=consoletext[0][j];
3679                                                                 }
3680                                                                 mapname[consolechars[0]-5+11]='\0';
3681
3682                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
3683                                                                 FSOUND_SetVolume(channels[consolesuccesssound], 256);
3684                                                                 FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
3685
3686                                                                 int mapvers;
3687                                                                 mapvers=12;
3688
3689
3690                                                                 FILE                    *tfile;
3691                                                                 tfile=fopen( mapname, "wb" );
3692                                                                 fpackf(tfile, "Bi", mapvers);
3693                                                                 //fpackf(tfile, "Bi", indemo);
3694                                                                 fpackf(tfile, "Bi", maptype);
3695                                                                 fpackf(tfile, "Bi", hostile);
3696                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3697                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3698                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3699                                                                 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);
3700                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3701                                                                         for(j=0;j<player[0].num_weapons;j++){
3702                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3703                                                                         }
3704
3705                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3706                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3707                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3708                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3709
3710                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3711
3712                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3713
3714                                                                         fpackf(tfile, "Bi", numdialogues);
3715                                                                         if(numdialogues)
3716                                                                                 for(k=0;k<numdialogues;k++){
3717                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3718                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3719                                                                                         for(l=0;l<10;l++){
3720                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3721                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3722                                                                                         }
3723                                                                                         if(numdialogueboxes)
3724                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3725                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3726                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3727                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3728                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3729                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3730
3731                                                                                                         templength=strlen(dialoguetext[k][l]);
3732                                                                                                         fpackf(tfile, "Bi",(templength));
3733                                                                                                         for(m=0;m<templength;m++){
3734                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3735                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3736                                                                                                         }
3737
3738                                                                                                         templength=strlen(dialoguename[k][l]);
3739                                                                                                         fpackf(tfile, "Bi",templength);
3740                                                                                                         for(m=0;m<templength;m++){
3741                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3742                                                                                                                 if(dialoguename[k][l][m]=='\0')break;   
3743                                                                                                         }
3744
3745                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3746                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3747                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3748
3749                                                                                                         for(m=0;m<10;m++)
3750                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3751
3752                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3753                                                                                                 }
3754                                                                                 }
3755
3756                                                                                 if(player[0].numclothes)
3757                                                                                         for(k=0;k<player[0].numclothes;k++){
3758                                                                                                 templength=strlen(player[0].clothes[k]);
3759                                                                                                 fpackf(tfile, "Bi", templength);
3760                                                                                                 for(l=0;l<templength;l++)
3761                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3762                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);                                                                                                                                             
3763                                                                                         }
3764
3765                                                                                         fpackf(tfile, "Bi", environment);
3766
3767                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3768
3769                                                                                         if(objects.numobjects)
3770                                                                                                 for(k=0;k<objects.numobjects;k++){
3771                                                                                                         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]);
3772                                                                                                 }
3773
3774                                                                                                 fpackf(tfile, "Bi", numhotspots);
3775                                                                                                 if(numhotspots)
3776                                                                                                         for(i=0;i<numhotspots;i++){
3777                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3778                                                                                                                 templength=strlen(hotspottext[i]);
3779                                                                                                                 fpackf(tfile, "Bi",templength);
3780                                                                                                                 for(l=0;l<templength;l++)
3781                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3782                                                                                                         }
3783
3784                                                                                                         fpackf(tfile, "Bi", numplayers);
3785                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3786                                                                                                                 for(j=1;j<numplayers;j++){
3787                                                                                                                         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);
3788                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3789                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3790                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3791                                                                                                                                 }
3792                                                                                                                                 if(player[j].numwaypoints<30){
3793                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3794                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3795                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3796                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3797                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3798                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3799                                                                                                                                         }
3800                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3801                                                                                                                                 }
3802                                                                                                                                 else{
3803                                                                                                                                         player[j].numwaypoints=0;
3804                                                                                                                                         player[j].waypoint=0;
3805                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3806                                                                                                                                 }
3807
3808                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3809                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3810                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3811                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3812
3813                                                                                                                                 if(player[j].creature==wolftype){
3814                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3815                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3816                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3817                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3818                                                                                                                                 }
3819
3820                                                                                                                                 if(player[j].creature==rabbittype){
3821                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3822                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3823                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3824                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3825                                                                                                                                 }
3826
3827                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3828
3829
3830
3831                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3832                                                                                                                                 if(player[j].numclothes)
3833                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3834                                                                                                                                                 int templength;
3835                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3836                                                                                                                                                 fpackf(tfile, "Bi", templength);
3837                                                                                                                                                 for(l=0;l<templength;l++)
3838                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3839                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);                                                                                                                             
3840                                                                                                                                         }
3841                                                                                                                 }
3842
3843                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3844                                                                                                                 if(numpathpoints)
3845                                                                                                                         for(j=0;j<numpathpoints;j++){
3846                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3847                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3848                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3849                                                                                                                                 }
3850                                                                                                                         }
3851
3852                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3853
3854
3855                                                                                                                         fclose(tfile);
3856                                                                                                                         donesomething=1;
3857
3858                                                                                                                         /*
3859                                                                                                                         FILE                    *tfile;
3860                                                                                                                         tfile=fopen( mapname, "wb" );
3861                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3862                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3863                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3864                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3865                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3866                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3867                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3868                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3869                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3870                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3871                                                                                                                         }
3872
3873                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3874                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3875                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3876                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3877                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3878                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3879                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3880                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3881                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3882                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3883                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3884
3885                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3886                                                                                                                         if(player[0].numclothes)
3887                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3888                                                                                                                         int templength;
3889                                                                                                                         templength=strlen(player[0].clothes[k]);
3890                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);       
3891                                                                                                                         for(l=0;l<templength;l++)
3892                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3893                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);      
3894                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);      
3895                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);                                                                              
3896                                                                                                                         }
3897
3898                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3899
3900                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3901
3902                                                                                                                         for(k=0;k<objects.numobjects;k++){
3903                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3904                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3905                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3906                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3907                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3908                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3909                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3910                                                                                                                         }
3911
3912                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3913                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3914                                                                                                                         for(j=1;j<numplayers;j++){
3915                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3916                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3917                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3918                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3919                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3920                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3921                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3922                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3923                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3924                                                                                                                         }
3925                                                                                                                         if(player[j].numwaypoints<30){
3926                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3927                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3928                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3929                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3930                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3931                                                                                                                         }
3932                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3933                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3934                                                                                                                         }
3935                                                                                                                         else{
3936                                                                                                                         player[j].numwaypoints=0;
3937                                                                                                                         player[j].waypoint=0;
3938                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3939                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3940                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3941                                                                                                                         }
3942                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
3943                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
3944                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
3945                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
3946                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
3947                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
3948                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
3949                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
3950                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
3951                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
3952                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
3953
3954                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
3955                                                                                                                         if(player[j].numclothes)
3956                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3957                                                                                                                         int templength;
3958                                                                                                                         templength=strlen(player[j].clothes[k]);
3959                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);       
3960                                                                                                                         for(l=0;l<templength;l++)
3961                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
3962                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);      
3963                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);      
3964                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);                                                                              
3965                                                                                                                         }
3966                                                                                                                         }
3967                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3968                                                                                                                         if(numpathpoints)
3969                                                                                                                         for(j=0;j<numpathpoints;j++){
3970                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
3971                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
3972                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
3973                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3974                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
3975                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3976                                                                                                                         }
3977                                                                                                                         }
3978
3979                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
3980                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
3981                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
3982
3983                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
3984
3985                                                                                                                         fclose(tfile);
3986                                                                                                                         donesomething=1;*/
3987                                                         }
3988                                                         /*
3989                                                         if(Compare(consoletext[0],"save ",0,4)){
3990                                                         mapname[0]=':';
3991                                                         mapname[1]='D';
3992                                                         mapname[2]='a';
3993                                                         mapname[3]='t';
3994                                                         mapname[4]='a';
3995                                                         mapname[5]=':';
3996                                                         mapname[6]='M';
3997                                                         mapname[7]='a';
3998                                                         mapname[8]='p';
3999                                                         mapname[9]='s';
4000                                                         mapname[10]=':';
4001                                                         for(j=5;j<consolechars[0];j++){
4002                                                         mapname[j-5+11]=consoletext[0][j];
4003                                                         }
4004                                                         mapname[consolechars[0]-5+11]='\0';
4005
4006                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
4007                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
4008                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
4009
4010                                                         FILE                    *tfile;
4011                                                         tfile=fopen( mapname, "wb" );
4012                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
4013                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
4014                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
4015                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
4016                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
4017                                                         for(j=0;j<player[0].num_weapons;j++){
4018                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
4019                                                         }
4020                                                         fwrite( &environment, 1, sizeof(int), tfile );
4021
4022                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
4023                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
4024                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
4025                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
4026                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
4027
4028                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4029                                                         if(numplayers>1&&numplayers<maxplayers)
4030                                                         for(j=1;j<numplayers;j++){
4031                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
4032                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4033                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4034                                                         for(k=0;k<player[j].num_weapons;k++){
4035                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4036                                                         }
4037                                                         if(player[j].numwaypoints<30){
4038                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4039                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
4040                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4041                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4042                                                         }
4043                                                         else{
4044                                                         player[j].numwaypoints=0;
4045                                                         player[j].waypoint=0;
4046                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4047                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4048                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4049                                                         }
4050                                                         }
4051                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4052                                                         if(numpathpoints)
4053                                                         for(j=0;j<numpathpoints;j++){
4054                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
4055                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4056                                                         for(k=0;k<numpathpointconnect[j];k++){
4057                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4058                                                         }
4059                                                         }
4060                                                         fclose(tfile);
4061                                                         donesomething=1;
4062                                                         }*/
4063                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
4064                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4065                                                                 donesomething=1;
4066                                                         }
4067                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
4068                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
4069                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
4070                                                         donesomething=1;
4071                                                         }*/
4072
4073                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
4074                                                                 for(j=6;j<consolechars[0];j++){
4075                                                                         mapname[j-6]=consoletext[0][j];
4076                                                                 }
4077
4078                                                                 tintr=atof(mapname);
4079
4080                                                                 donesomething=1;
4081                                                         }
4082
4083                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
4084                                                                 for(j=6;j<consolechars[0];j++){
4085                                                                         mapname[j-6]=consoletext[0][j];
4086                                                                 }
4087
4088                                                                 player[0].speedmult=atof(mapname);
4089
4090                                                                 donesomething=1;
4091                                                         }
4092
4093                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
4094                                                                 for(j=9;j<consolechars[0];j++){
4095                                                                         mapname[j-9]=consoletext[0][j];
4096                                                                 }
4097
4098                                                                 player[0].power=atof(mapname);
4099
4100                                                                 donesomething=1;
4101                                                         }
4102
4103                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
4104                                                                 for(j=13;j<consolechars[0];j++){
4105                                                                         mapname[j-13]=consoletext[0][j];
4106                                                                 }
4107
4108                                                                 viewdistance=atof(mapname)*100;
4109
4110                                                                 donesomething=1;
4111                                                         }
4112
4113                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
4114                                                                 for(j=10;j<consolechars[0];j++){
4115                                                                         mapname[j-10]=consoletext[0][j];
4116                                                                 }
4117
4118                                                                 fadestart=atof(mapname);
4119
4120                                                                 donesomething=1;
4121                                                         }
4122
4123                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
4124                                                                 for(j=6;j<consolechars[0];j++){
4125                                                                         mapname[j-6]=consoletext[0][j];
4126                                                                 }
4127
4128                                                                 player[0].power=atof(mapname);
4129
4130                                                                 donesomething=1;
4131                                                         }
4132
4133                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
4134                                                                 for(j=6;j<consolechars[0];j++){
4135                                                                         mapname[j-6]=consoletext[0][j];
4136                                                                 }
4137
4138                                                                 slomospeed=atof(mapname);
4139                                                                 slomo=1-slomo;
4140                                                                 slomodelay=1000;
4141
4142                                                                 donesomething=1;
4143                                                         }
4144
4145                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
4146                                                                 for(j=8;j<consolechars[0];j++){
4147                                                                         mapname[j-8]=consoletext[0][j];
4148                                                                 }
4149
4150                                                                 slomofreq=atoi(mapname);
4151
4152                                                                 donesomething=1;
4153                                                         }
4154
4155                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
4156                                                                 for(j=5;j<consolechars[0];j++){
4157                                                                         mapname[j-5]=consoletext[0][j];
4158                                                                 }
4159
4160                                                                 player[0].scale=atof(mapname)*.2;
4161
4162                                                                 donesomething=1;
4163                                                         }
4164
4165                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
4166                                                                 int closest=-1;
4167                                                                 float closestdist=-1;
4168                                                                 float distance;
4169                                                                 if(numplayers>1)
4170                                                                         for(i=1;i<numplayers;i++){
4171                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4172                                                                                 if(closestdist==-1||distance<closestdist){
4173                                                                                         closestdist=distance;
4174                                                                                         closest=i;
4175                                                                                 }
4176                                                                         }
4177
4178                                                                         for(j=9;j<consolechars[0];j++){
4179                                                                                 mapname[j-9]=consoletext[0][j];
4180                                                                         }
4181
4182                                                                         player[closest].scale=atof(mapname)*.2;
4183
4184                                                                         donesomething=1;
4185                                                         }
4186
4187                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
4188                                                                 int startpoint;
4189                                                                 int alldone;
4190
4191                                                                 int closest=-1;
4192                                                                 float closestdist=-1;
4193                                                                 float distance;
4194                                                                 if(numplayers>1)
4195                                                                         for(i=1;i<numplayers;i++){
4196                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4197                                                                                 if(closestdist==-1||distance<closestdist){
4198                                                                                         closestdist=distance;
4199                                                                                         closest=i;
4200                                                                                 }
4201                                                                         }
4202
4203                                                                         alldone=0;
4204                                                                         startpoint=15;
4205                                                                         j=startpoint;
4206                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4207                                                                                 mapname[j-startpoint]=consoletext[0][j];
4208                                                                                 j++;
4209                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4210                                                                         }
4211                                                                         mapname[j-startpoint]='\0';
4212
4213                                                                         headprop=atof(mapname);
4214
4215                                                                         j++;
4216                                                                         startpoint=j;
4217                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4218                                                                                 mapname[j-startpoint]=consoletext[0][j];
4219                                                                                 j++;
4220                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4221                                                                         }
4222                                                                         mapname[j-startpoint]='\0';
4223
4224                                                                         bodyprop=atof(mapname);
4225
4226                                                                         j++;
4227                                                                         startpoint=j;
4228                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4229                                                                                 mapname[j-startpoint]=consoletext[0][j];
4230                                                                                 j++;
4231                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4232                                                                         }
4233                                                                         mapname[j-startpoint]='\0';
4234
4235                                                                         armprop=atof(mapname);
4236
4237                                                                         j++;
4238                                                                         startpoint=j;
4239                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4240                                                                                 mapname[j-startpoint]=consoletext[0][j];
4241                                                                                 j++;
4242                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4243                                                                         }
4244                                                                         mapname[j-startpoint]='\0';
4245
4246                                                                         legprop=atof(mapname);
4247
4248                                                                         if(player[closest].creature==wolftype){
4249                                                                                 player[closest].proportionhead=1.1*headprop;
4250                                                                                 player[closest].proportionbody=1.1*bodyprop;
4251                                                                                 player[closest].proportionarms=1.1*armprop;
4252                                                                                 player[closest].proportionlegs=1.1*legprop;
4253                                                                         }
4254
4255                                                                         if(player[closest].creature==rabbittype){
4256                                                                                 player[closest].proportionhead=1.2*headprop;
4257                                                                                 player[closest].proportionbody=1.05*bodyprop;
4258                                                                                 player[closest].proportionarms=1.00*armprop;
4259                                                                                 player[closest].proportionlegs=1.1*legprop;
4260                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4261                                                                         }
4262
4263                                                                         donesomething=1;
4264                                                         }
4265
4266
4267                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4268                                                                 for(i=1;i<numplayers;i++){
4269                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4270                                                                 }
4271
4272                                                                 donesomething=1;
4273                                                         }
4274
4275                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4276                                                                 for(j=9;j<consolechars[0];j++){
4277                                                                         mapname[j-9]=consoletext[0][j];
4278                                                                 }
4279
4280                                                                 tutoriallevel=atoi(mapname);
4281
4282                                                                 donesomething=1;
4283                                                         }
4284
4285
4286                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4287                                                                 for(j=6;j<consolechars[0];j++){
4288                                                                         mapname[j-6]=consoletext[0][j];
4289                                                                 }
4290
4291                                                                 tintg=atof(mapname);
4292
4293                                                                 donesomething=1;
4294                                                         }
4295
4296                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4297                                                                 for(j=6;j<consolechars[0];j++){
4298                                                                         mapname[j-6]=consoletext[0][j];
4299                                                                 }
4300
4301                                                                 tintb=atof(mapname);
4302
4303                                                                 donesomething=1;
4304                                                         }
4305
4306                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4307                                                                 for(j=8;j<consolechars[0];j++){
4308                                                                         mapname[j-8]=consoletext[0][j];
4309                                                                 }
4310
4311                                                                 hostile=atoi(mapname);
4312
4313                                                                 donesomething=1;
4314                                                         }
4315
4316
4317                                                         if(Compare(consoletext[0],"type active ",0,11)){
4318                                                                 editoractive=typeactive;
4319
4320                                                                 donesomething=1;
4321                                                         }
4322
4323                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4324                                                                 indemo=1;
4325                                                                 hotspot[numhotspots]=player[0].coords;
4326                                                                 hotspotsize[numhotspots]=0;
4327                                                                 hotspottype[numhotspots]=-111;
4328                                                                 mapname[0]='\0';
4329                                                                 strcpy(hotspottext[numhotspots],"mapname");
4330                                                                 numhotspots++;
4331
4332                                                                 donesomething=1;
4333                                                         }
4334
4335                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4336                                                                 indemo=0;
4337                                                                 numhotspots--;
4338
4339                                                                 donesomething=1;
4340                                                         }
4341
4342                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4343                                                                 editoractive=typesitting;
4344
4345                                                                 donesomething=1;
4346                                                         }
4347
4348                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4349                                                                 editoractive=typesittingwall;
4350
4351                                                                 donesomething=1;
4352                                                         }
4353
4354                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4355                                                                 editoractive=typesleeping;
4356
4357                                                                 donesomething=1;
4358                                                         }
4359                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4360                                                                 editoractive=typedead1;
4361
4362                                                                 donesomething=1;
4363                                                         }
4364                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4365                                                                 editoractive=typedead2;
4366
4367                                                                 donesomething=1;
4368                                                         }
4369                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4370                                                                 editoractive=typedead3;
4371                                                                 donesomething=1;
4372                                                         }
4373                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4374                                                                 editoractive=typedead4;
4375
4376                                                                 donesomething=1;
4377                                                         }
4378
4379                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4380                                                                 editorpathtype=wpkeepwalking;
4381
4382                                                                 donesomething=1;
4383                                                         }
4384
4385                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4386                                                                 editorpathtype=wppause;
4387
4388                                                                 donesomething=1;
4389                                                         }
4390
4391                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4392                                                                 maptype=mapkilleveryone;
4393
4394                                                                 donesomething=1;
4395                                                         }
4396
4397                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4398                                                                 maptype=mapgosomewhere;
4399
4400                                                                 donesomething=1;
4401                                                         }
4402
4403                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4404                                                                 maptype=mapkillsomeone;
4405
4406                                                                 donesomething=1;
4407
4408                                                         }
4409
4410                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4411                                                                 maptype=mapkillmost;
4412
4413                                                                 donesomething=1;
4414
4415                                                         }
4416
4417                                                         if(Compare(consoletext[0],"hs ",0,2)){
4418                                                                 int startpoint;
4419                                                                 int alldone;
4420
4421                                                                 hotspot[numhotspots]=player[0].coords;
4422
4423                                                                 alldone=0;
4424                                                                 startpoint=3;
4425                                                                 j=startpoint;
4426                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4427                                                                         mapname[j-startpoint]=consoletext[0][j];
4428                                                                         j++;
4429                                                                         if(consoletext[0][j]=='\0')alldone=1;
4430                                                                 }
4431                                                                 mapname[j-startpoint]='\0';
4432
4433                                                                 hotspotsize[numhotspots]=atof(mapname);
4434
4435                                                                 j++;
4436                                                                 startpoint=j;
4437                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4438                                                                         mapname[j-startpoint]=consoletext[0][j];
4439                                                                         j++;
4440                                                                         if(consoletext[0][j]=='\0')alldone=1;
4441                                                                 }
4442                                                                 mapname[j-startpoint]='\0';
4443
4444                                                                 hotspottype[numhotspots]=atoi(mapname);
4445
4446                                                                 j++;
4447                                                                 startpoint=j;
4448                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4449                                                                         mapname[j-startpoint]=consoletext[0][j];
4450                                                                         j++;
4451                                                                         if(consoletext[0][j]=='\0')alldone=1;
4452                                                                 }
4453                                                                 mapname[j-startpoint]='\n';
4454                                                                 mapname[j-startpoint+1]='\0';
4455
4456                                                                 strcpy(hotspottext[numhotspots],mapname);
4457
4458                                                                 numhotspots++;
4459
4460                                                                 donesomething=1;
4461                                                         }
4462
4463                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4464                                                                 int startpoint;
4465                                                                 int alldone;
4466
4467                                                                 alldone=0;
4468                                                                 startpoint=9;
4469                                                                 j=startpoint;
4470                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4471                                                                         mapname[j-startpoint]=consoletext[0][j];
4472                                                                         j++;
4473                                                                         if(consoletext[0][j]=='\0')alldone=1;
4474                                                                 }
4475                                                                 mapname[j-startpoint]='\0';
4476                                                                 startpoint=j+1;
4477
4478                                                                 dialoguetype[numdialogues]=atoi(mapname);
4479
4480                                                                 mapname[0]=':';
4481                                                                 mapname[1]='D';
4482                                                                 mapname[2]='a';
4483                                                                 mapname[3]='t';
4484                                                                 mapname[4]='a';
4485                                                                 mapname[5]=':';
4486                                                                 mapname[6]='D';
4487                                                                 mapname[7]='i';
4488                                                                 mapname[8]='a';
4489                                                                 mapname[9]='l';
4490                                                                 mapname[10]='o';
4491                                                                 mapname[11]='g';
4492                                                                 mapname[12]='u';
4493                                                                 mapname[13]='e';
4494                                                                 mapname[14]='s';
4495                                                                 mapname[15]=':';
4496                                                                 for(j=startpoint;j<consolechars[0];j++){
4497                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4498                                                                 }
4499                                                                 mapname[consolechars[0]-startpoint+16]='.';
4500                                                                 mapname[consolechars[0]-startpoint+17]='t';
4501                                                                 mapname[consolechars[0]-startpoint+18]='x';
4502                                                                 mapname[consolechars[0]-startpoint+19]='t';
4503                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4504
4505                                                                 for(j=0;j<max_dialoguelength;j++){
4506                                                                         for(k=0;k<128;k++){
4507                                                                                 dialoguetext[numdialogues][j][k]='\0';
4508                                                                         }
4509                                                                         for(k=0;k<64;k++){
4510                                                                                 dialoguename[numdialogues][j][k]='\0';
4511                                                                         }
4512                                                                 }
4513
4514                                                                 ifstream ipstream(mapname);
4515                                                                 ipstream.ignore(256,':');
4516                                                                 ipstream >> numdialogueboxes[numdialogues];
4517                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4518                                                                         ipstream.ignore(256,':');
4519                                                                         ipstream.ignore(256,':');
4520                                                                         ipstream.ignore(256,' ');
4521                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4522                                                                         ipstream.ignore(256,':');
4523                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4524                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4525                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4526                                                                         ipstream.ignore(256,':');
4527                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4528                                                                         ipstream.ignore(256,':');
4529                                                                         ipstream.ignore(256,' ');
4530                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4531                                                                         for(j=0;j<128;j++){
4532                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4533                                                                         }
4534                                                                         ipstream.ignore(256,':');
4535                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4536                                                                 }
4537
4538                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4539                                                                         for(j=0;j<numplayers;j++){
4540                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4541                                                                         }
4542                                                                 }
4543                                                                 ipstream.close();
4544
4545                                                                 directing=1;
4546                                                                 indialogue=0;
4547                                                                 whichdialogue=numdialogues;
4548
4549
4550                                                                 numdialogues++;
4551
4552                                                                 donesomething=1;
4553                                                         }
4554
4555                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4556                                                                 int startpoint;
4557                                                                 int alldone;
4558                                                                 int whichdi;
4559
4560                                                                 alldone=0;
4561                                                                 startpoint=12;
4562                                                                 j=startpoint;
4563                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4564                                                                         mapname[j-startpoint]=consoletext[0][j];
4565                                                                         j++;
4566                                                                         if(consoletext[0][j]=='\0')alldone=1;
4567                                                                 }
4568                                                                 mapname[j-startpoint]='\0';
4569                                                                 startpoint=j+1;
4570
4571                                                                 whichdi=atoi(mapname);
4572
4573                                                                 mapname[0]=':';
4574                                                                 mapname[1]='D';
4575                                                                 mapname[2]='a';
4576                                                                 mapname[3]='t';
4577                                                                 mapname[4]='a';
4578                                                                 mapname[5]=':';
4579                                                                 mapname[6]='D';
4580                                                                 mapname[7]='i';
4581                                                                 mapname[8]='a';
4582                                                                 mapname[9]='l';
4583                                                                 mapname[10]='o';
4584                                                                 mapname[11]='g';
4585                                                                 mapname[12]='u';
4586                                                                 mapname[13]='e';
4587                                                                 mapname[14]='s';
4588                                                                 mapname[15]=':';
4589                                                                 for(j=startpoint;j<consolechars[0];j++){
4590                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4591                                                                 }
4592                                                                 mapname[consolechars[0]-startpoint+16]='.';
4593                                                                 mapname[consolechars[0]-startpoint+17]='t';
4594                                                                 mapname[consolechars[0]-startpoint+18]='x';
4595                                                                 mapname[consolechars[0]-startpoint+19]='t';
4596                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4597
4598                                                                 for(j=0;j<max_dialoguelength;j++){
4599                                                                         for(k=0;k<128;k++){
4600                                                                                 dialoguetext[whichdi][j][k]='\0';
4601                                                                         }
4602                                                                         for(k=0;k<64;k++){
4603                                                                                 dialoguename[whichdi][j][k]='\0';
4604                                                                         }
4605                                                                 }
4606
4607                                                                 ifstream ipstream(mapname);
4608                                                                 ipstream.ignore(256,':');
4609                                                                 ipstream >> numdialogueboxes[whichdi];
4610                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4611                                                                         ipstream.ignore(256,':');
4612                                                                         ipstream.ignore(256,':');
4613                                                                         ipstream.ignore(256,' ');
4614                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4615                                                                         ipstream.ignore(256,':');
4616                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4617                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4618                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4619                                                                         ipstream.ignore(256,':');
4620                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4621                                                                         ipstream.ignore(256,':');
4622                                                                         ipstream.ignore(256,' ');
4623                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4624                                                                         for(j=0;j<128;j++){
4625                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4626                                                                         }
4627                                                                         ipstream.ignore(256,':');
4628                                                                         ipstream >> dialogueboxsound[whichdi][i];
4629                                                                 }
4630
4631                                                                 ipstream.close();
4632
4633                                                                 donesomething=1;
4634                                                         }
4635
4636                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4637                                                                 int startpoint;
4638                                                                 int alldone;
4639                                                                 int whichdi;
4640
4641                                                                 alldone=0;
4642                                                                 startpoint=8;
4643                                                                 j=startpoint;
4644                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4645                                                                         mapname[j-startpoint]=consoletext[0][j];
4646                                                                         j++;
4647                                                                         if(consoletext[0][j]=='\0')alldone=1;
4648                                                                 }
4649                                                                 mapname[j-startpoint]='\0';
4650                                                                 dialoguetype[0]=atoi(mapname);
4651
4652                                                                 startpoint=j+1;
4653
4654                                                                 donesomething=1;
4655                                                         }
4656
4657
4658                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4659                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4660
4661                                                                 donesomething=1;
4662                                                         }
4663
4664                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4665                                                                 numdialogues--;
4666                                                                 if(numdialogues<0)numdialogues=0;
4667
4668                                                                 donesomething=1;
4669                                                         }
4670
4671                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4672                                                                 player[0].immobile=1;
4673                                                                 donesomething=1;
4674                                                         }
4675
4676                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4677                                                                 player[0].immobile=0;
4678                                                                 donesomething=1;
4679                                                         }
4680
4681                                                         if(Compare(consoletext[0],"play ",0,4)){
4682                                                                 int startpoint;
4683                                                                 int alldone;
4684
4685                                                                 alldone=0;
4686                                                                 startpoint=5;
4687                                                                 j=startpoint;
4688                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4689                                                                         mapname[j-startpoint]=consoletext[0][j];
4690                                                                         j++;
4691                                                                         if(consoletext[0][j]=='\0')alldone=1;
4692                                                                 }
4693                                                                 mapname[j-startpoint]='\0';
4694                                                                 startpoint=j+1;
4695
4696                                                                 whichdialogue=atoi(mapname);
4697
4698                                                                 if(numdialogues>whichdialogue){
4699                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4700                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4701                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4702                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4703                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4704                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4705                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4706                                                                         }
4707
4708                                                                         directing=0;
4709                                                                         indialogue=0;
4710
4711                                                                         donesomething=1;
4712
4713                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4714                                                                         float gLoc[3];
4715                                                                         float vel[3];
4716                                                                         XYZ temppos;
4717                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4718                                                                         temppos=temppos-viewer;
4719                                                                         Normalise(&temppos);
4720                                                                         temppos+=viewer;
4721
4722                                                                         gLoc[0]=temppos.x;
4723                                                                         gLoc[1]=temppos.y;
4724                                                                         gLoc[2]=temppos.z;
4725                                                                         vel[0]=0;
4726                                                                         vel[1]=0;
4727                                                                         vel[2]=0;
4728                                                                         int whichsoundplay;
4729                                                                         whichsoundplay=rabbitchitter;
4730                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4731                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4732                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4733                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4734                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4735                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4736                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4737                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4738                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4739                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4740                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4741                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4742                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4743                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4744                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4745                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4746                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4747                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4748                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4749                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
4750                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4751                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
4752                                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
4753                                                                         //}
4754                                                                 }
4755                                                         }
4756
4757
4758
4759
4760                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4761                                                                 numhotspots--;
4762                                                                 if(numhotspots<0)numhotspots=0;
4763                                                                 donesomething=1;
4764                                                         }
4765
4766
4767                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4768                                                                 int startpoint;
4769                                                                 int alldone;
4770
4771                                                                 alldone=0;
4772                                                                 startpoint=11;
4773                                                                 j=startpoint;
4774                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4775                                                                         mapname[j-startpoint]=consoletext[0][j];
4776                                                                         j++;
4777                                                                         if(consoletext[0][j]=='\0')alldone=1;
4778                                                                 }
4779                                                                 mapname[j-startpoint]='\0';
4780
4781                                                                 headprop=atof(mapname);
4782
4783                                                                 j++;
4784                                                                 startpoint=j;
4785                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4786                                                                         mapname[j-startpoint]=consoletext[0][j];
4787                                                                         j++;
4788                                                                         if(consoletext[0][j]=='\0')alldone=1;
4789                                                                 }
4790                                                                 mapname[j-startpoint]='\0';
4791
4792                                                                 bodyprop=atof(mapname);
4793
4794                                                                 j++;
4795                                                                 startpoint=j;
4796                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4797                                                                         mapname[j-startpoint]=consoletext[0][j];
4798                                                                         j++;
4799                                                                         if(consoletext[0][j]=='\0')alldone=1;
4800                                                                 }
4801                                                                 mapname[j-startpoint]='\0';
4802
4803                                                                 armprop=atof(mapname);
4804
4805                                                                 j++;
4806                                                                 startpoint=j;
4807                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4808                                                                         mapname[j-startpoint]=consoletext[0][j];
4809                                                                         j++;
4810                                                                         if(consoletext[0][j]=='\0')alldone=1;
4811                                                                 }
4812                                                                 mapname[j-startpoint]='\0';
4813
4814                                                                 legprop=atof(mapname);
4815
4816                                                                 if(player[0].creature==wolftype){
4817                                                                         player[0].proportionhead=1.1*headprop;
4818                                                                         player[0].proportionbody=1.1*bodyprop;
4819                                                                         player[0].proportionarms=1.1*armprop;
4820                                                                         player[0].proportionlegs=1.1*legprop;
4821                                                                 }
4822
4823                                                                 if(player[0].creature==rabbittype){
4824                                                                         player[0].proportionhead=1.2*headprop;
4825                                                                         player[0].proportionbody=1.05*bodyprop;
4826                                                                         player[0].proportionarms=1.00*armprop;
4827                                                                         player[0].proportionlegs=1.1*legprop;
4828                                                                         player[0].proportionlegs.y=1.05*legprop;
4829                                                                 }
4830
4831                                                                 donesomething=1;
4832                                                         }
4833
4834                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4835                                                                 for(i=0;i<numplayers;i++){
4836                                                                         if(i>0)player[i].immobile=1;
4837                                                                 }
4838                                                                 donesomething=1;
4839                                                         }
4840
4841
4842                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4843                                                                 player[0].armorhead=1;
4844                                                                 player[0].armorhigh=1;
4845                                                                 player[0].armorlow=1;
4846                                                                 player[0].protectionhead=1;
4847                                                                 player[0].protectionhigh=1;
4848                                                                 player[0].protectionlow=1;
4849                                                                 player[0].metalhead=1;
4850                                                                 player[0].metalhigh=1;
4851                                                                 player[0].metallow=1;
4852                                                                 player[0].power=1;
4853                                                                 player[0].speedmult=1;
4854                                                                 player[0].scale=1;
4855
4856                                                                 if(player[0].creature==wolftype){
4857                                                                         player[0].proportionhead=1.1;
4858                                                                         player[0].proportionbody=1.1;
4859                                                                         player[0].proportionarms=1.1;
4860                                                                         player[0].proportionlegs=1.1;
4861                                                                 }
4862
4863                                                                 if(player[0].creature==rabbittype){
4864                                                                         player[0].proportionhead=1.2;
4865                                                                         player[0].proportionbody=1.05;
4866                                                                         player[0].proportionarms=1.00;
4867                                                                         player[0].proportionlegs=1.1;
4868                                                                         player[0].proportionlegs.y=1.05;
4869                                                                 }
4870
4871                                                                 player[0].numclothes=0;
4872                                                                 if(player[0].whichskin==0){
4873                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4874                                                                 }
4875                                                                 else if(player[0].whichskin==1){
4876                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4877                                                                 }
4878                                                                 else if(player[0].whichskin==2){
4879                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4880                                                                 }
4881                                                                 else if(player[0].whichskin==3){
4882                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4883                                                                 }
4884                                                                 else if(player[0].whichskin==4){
4885                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4886                                                                 }
4887                                                                 else if(player[0].whichskin==5){
4888                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4889                                                                 }
4890                                                                 else if(player[0].whichskin==6){
4891                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4892                                                                 }
4893                                                                 else if(player[0].whichskin==7){
4894                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4895                                                                 }
4896                                                                 else if(player[0].whichskin==8){
4897                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4898                                                                 }
4899                                                                 else if(player[0].whichskin==9){
4900                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4901                                                                 }
4902
4903                                                                 editoractive=typeactive;
4904                                                                 player[0].immobile=0;
4905
4906
4907
4908                                                                 donesomething=1;
4909                                                         }
4910
4911                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4912                                                                 int startpoint;
4913                                                                 int alldone;
4914                                                                 alldone=0;
4915                                                                 startpoint=5;
4916                                                                 j=startpoint;
4917                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4918                                                                         mapname[j-startpoint]=consoletext[0][j];
4919                                                                         j++;
4920                                                                         if(consoletext[0][j]=='\0')alldone=1;
4921                                                                 }
4922                                                                 mapname[j-startpoint]='\0';
4923
4924                                                                 tintr=atof(mapname);
4925
4926                                                                 j++;
4927                                                                 startpoint=j;
4928                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4929                                                                         mapname[j-startpoint]=consoletext[0][j];
4930                                                                         j++;
4931                                                                         if(consoletext[0][j]=='\0')alldone=1;
4932                                                                 }
4933                                                                 mapname[j-startpoint]='\0';
4934
4935                                                                 tintg=atof(mapname);
4936
4937                                                                 j++;
4938                                                                 startpoint=j;
4939                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4940                                                                         mapname[j-startpoint]=consoletext[0][j];
4941                                                                         j++;
4942                                                                         if(consoletext[0][j]=='\0')alldone=1;
4943                                                                 }
4944                                                                 mapname[j-startpoint]='\0';
4945
4946                                                                 tintb=atof(mapname);
4947
4948                                                                 donesomething=1;
4949                                                         }
4950
4951                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
4952                                                                 int startpoint;
4953                                                                 int alldone;
4954                                                                 alldone=0;
4955                                                                 startpoint=9;
4956                                                                 j=startpoint;
4957                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4958                                                                         mapname[j-startpoint]=consoletext[0][j];
4959                                                                         j++;
4960                                                                         if(consoletext[0][j]=='\0')alldone=1;
4961                                                                 }
4962                                                                 mapname[j-startpoint]='\0';
4963
4964                                                                 skyboxr=atof(mapname);
4965
4966                                                                 j++;
4967                                                                 startpoint=j;
4968                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4969                                                                         mapname[j-startpoint]=consoletext[0][j];
4970                                                                         j++;
4971                                                                         if(consoletext[0][j]=='\0')alldone=1;
4972                                                                 }
4973                                                                 mapname[j-startpoint]='\0';
4974
4975                                                                 skyboxg=atof(mapname);
4976
4977                                                                 j++;
4978                                                                 startpoint=j;
4979                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4980                                                                         mapname[j-startpoint]=consoletext[0][j];
4981                                                                         j++;
4982                                                                         if(consoletext[0][j]=='\0')alldone=1;
4983                                                                 }
4984                                                                 mapname[j-startpoint]='\0';
4985
4986                                                                 skyboxb=atof(mapname);
4987
4988                                                                 skyboxlightr=skyboxr;
4989                                                                 skyboxlightg=skyboxg;
4990                                                                 skyboxlightb=skyboxb;
4991
4992                                                                 SetUpLighting();
4993
4994                                                                 //if(skyboxtexture){
4995                                                                 terrain.DoShadows();
4996                                                                 objects.DoShadows();
4997                                                                 /*}
4998                                                                 else terrain.DoLighting();
4999                                                                 */
5000                                                                 donesomething=1;
5001                                                         } 
5002
5003                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
5004                                                                 int startpoint;
5005                                                                 int alldone;
5006                                                                 alldone=0;
5007                                                                 startpoint=10;
5008                                                                 j=startpoint;
5009                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5010                                                                         mapname[j-startpoint]=consoletext[0][j];
5011                                                                         j++;
5012                                                                         if(consoletext[0][j]=='\0')alldone=1;
5013                                                                 }
5014                                                                 mapname[j-startpoint]='\0';
5015
5016                                                                 skyboxlightr=atof(mapname);
5017
5018                                                                 j++;
5019                                                                 startpoint=j;
5020                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5021                                                                         mapname[j-startpoint]=consoletext[0][j];
5022                                                                         j++;
5023                                                                         if(consoletext[0][j]=='\0')alldone=1;
5024                                                                 }
5025                                                                 mapname[j-startpoint]='\0';
5026
5027                                                                 skyboxlightg=atof(mapname);
5028
5029                                                                 j++;
5030                                                                 startpoint=j;
5031                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5032                                                                         mapname[j-startpoint]=consoletext[0][j];
5033                                                                         j++;
5034                                                                         if(consoletext[0][j]=='\0')alldone=1;
5035                                                                 }
5036                                                                 mapname[j-startpoint]='\0';
5037
5038                                                                 skyboxlightb=atof(mapname);
5039
5040                                                                 SetUpLighting();
5041
5042                                                                 //if(skyboxtexture){
5043                                                                 terrain.DoShadows();
5044                                                                 objects.DoShadows();
5045                                                                 /*}
5046                                                                 else terrain.DoLighting();
5047                                                                 */
5048                                                                 donesomething=1;
5049                                                         } 
5050
5051                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
5052                                                                 skyboxtexture=1-skyboxtexture;
5053
5054                                                                 SetUpLighting();
5055                                                                 //if(skyboxtexture){
5056                                                                 terrain.DoShadows();
5057                                                                 objects.DoShadows();
5058                                                                 /*}
5059                                                                 else terrain.DoLighting();
5060                                                                 */
5061                                                                 donesomething=1;
5062                                                         }
5063
5064                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
5065                                                                 int startpoint;
5066                                                                 int alldone;
5067                                                                 alldone=0;
5068                                                                 startpoint=11;
5069                                                                 j=startpoint;
5070                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5071                                                                         mapname[j-startpoint]=consoletext[0][j];
5072                                                                         j++;
5073                                                                         if(consoletext[0][j]=='\0')alldone=1;
5074                                                                 }
5075                                                                 mapname[j-startpoint]='\0';
5076
5077                                                                 player[0].protectionhead=atof(mapname);
5078
5079                                                                 j++;
5080                                                                 startpoint=j;
5081                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5082                                                                         mapname[j-startpoint]=consoletext[0][j];
5083                                                                         j++;
5084                                                                         if(consoletext[0][j]=='\0')alldone=1;
5085                                                                 }
5086                                                                 mapname[j-startpoint]='\0';
5087
5088                                                                 player[0].protectionhigh=atof(mapname);
5089
5090                                                                 j++;
5091                                                                 startpoint=j;
5092                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5093                                                                         mapname[j-startpoint]=consoletext[0][j];
5094                                                                         j++;
5095                                                                         if(consoletext[0][j]=='\0')alldone=1;
5096                                                                 }
5097                                                                 mapname[j-startpoint]='\0';
5098
5099                                                                 player[0].protectionlow=atof(mapname);
5100
5101                                                                 donesomething=1;
5102                                                         }
5103
5104                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
5105                                                                 int startpoint;
5106                                                                 int alldone;
5107                                                                 alldone=0;
5108                                                                 startpoint=6;
5109                                                                 j=startpoint;
5110                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5111                                                                         mapname[j-startpoint]=consoletext[0][j];
5112                                                                         j++;
5113                                                                         if(consoletext[0][j]=='\0')alldone=1;
5114                                                                 }
5115                                                                 mapname[j-startpoint]='\0';
5116
5117                                                                 player[0].armorhead=atof(mapname);
5118
5119                                                                 j++;
5120                                                                 startpoint=j;
5121                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5122                                                                         mapname[j-startpoint]=consoletext[0][j];
5123                                                                         j++;
5124                                                                         if(consoletext[0][j]=='\0')alldone=1;
5125                                                                 }
5126                                                                 mapname[j-startpoint]='\0';
5127
5128                                                                 player[0].armorhigh=atof(mapname);
5129
5130                                                                 j++;
5131                                                                 startpoint=j;
5132                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5133                                                                         mapname[j-startpoint]=consoletext[0][j];
5134                                                                         j++;
5135                                                                         if(consoletext[0][j]=='\0')alldone=1;
5136                                                                 }
5137                                                                 mapname[j-startpoint]='\0';
5138
5139                                                                 player[0].armorlow=atof(mapname);
5140
5141                                                                 donesomething=1;
5142                                                         }
5143
5144                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
5145                                                                 for(i=0;i<numplayers;i++){
5146                                                                         player[i].protectionhead=1.0;
5147                                                                         player[i].protectionhigh=1.0;
5148                                                                         player[i].protectionlow=1.0;
5149                                                                         player[i].armorhead=1.0;
5150                                                                         player[i].armorhigh=1.0;
5151                                                                         player[i].armorlow=1.0;
5152                                                                 }
5153
5154                                                                 donesomething=1;
5155                                                         }
5156
5157                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
5158                                                                 int closest=-1;
5159                                                                 float closestdist=-1;
5160                                                                 float distance;
5161                                                                 if(numplayers>1)
5162                                                                         for(i=1;i<numplayers;i++){
5163                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5164                                                                                 if(closestdist==-1||distance<closestdist){
5165                                                                                         closestdist=distance;
5166                                                                                         closest=i;
5167                                                                                 }
5168                                                                         }
5169
5170                                                                         int startpoint;
5171                                                                         int alldone;
5172                                                                         alldone=0;
5173                                                                         startpoint=15;
5174                                                                         j=startpoint;
5175                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5176                                                                                 mapname[j-startpoint]=consoletext[0][j];
5177                                                                                 j++;
5178                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5179                                                                         }
5180                                                                         mapname[j-startpoint]='\0';
5181
5182                                                                         player[closest].protectionhead=atof(mapname);
5183
5184                                                                         j++;
5185                                                                         startpoint=j;
5186                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5187                                                                                 mapname[j-startpoint]=consoletext[0][j];
5188                                                                                 j++;
5189                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5190                                                                         }
5191                                                                         mapname[j-startpoint]='\0';
5192
5193                                                                         player[closest].protectionhigh=atof(mapname);
5194
5195                                                                         j++;
5196                                                                         startpoint=j;
5197                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5198                                                                                 mapname[j-startpoint]=consoletext[0][j];
5199                                                                                 j++;
5200                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5201                                                                         }
5202                                                                         mapname[j-startpoint]='\0';
5203
5204                                                                         player[closest].protectionlow=atof(mapname);
5205
5206                                                                         donesomething=1;
5207                                                         }
5208
5209                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
5210                                                                 int closest=-1;
5211                                                                 float closestdist=-1;
5212                                                                 float distance;
5213                                                                 if(numplayers>1)
5214                                                                         for(i=1;i<numplayers;i++){
5215                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5216                                                                                 if(closestdist==-1||distance<closestdist){
5217                                                                                         closestdist=distance;
5218                                                                                         closest=i;
5219                                                                                 }
5220                                                                         }
5221                                                                         int startpoint;
5222                                                                         int alldone;
5223                                                                         alldone=0;
5224                                                                         startpoint=10;
5225                                                                         j=startpoint;
5226                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5227                                                                                 mapname[j-startpoint]=consoletext[0][j];
5228                                                                                 j++;
5229                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5230                                                                         }
5231                                                                         mapname[j-startpoint]='\0';
5232
5233                                                                         player[closest].armorhead=atof(mapname);
5234
5235                                                                         j++;
5236                                                                         startpoint=j;
5237                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5238                                                                                 mapname[j-startpoint]=consoletext[0][j];
5239                                                                                 j++;
5240                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5241                                                                         }
5242                                                                         mapname[j-startpoint]='\0';
5243
5244                                                                         player[closest].armorhigh=atof(mapname);
5245
5246                                                                         j++;
5247                                                                         startpoint=j;
5248                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5249                                                                                 mapname[j-startpoint]=consoletext[0][j];
5250                                                                                 j++;
5251                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5252                                                                         }
5253                                                                         mapname[j-startpoint]='\0';
5254
5255                                                                         player[closest].armorlow=atof(mapname);
5256
5257                                                                         donesomething=1;
5258                                                         }
5259
5260
5261                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5262                                                                 int startpoint;
5263                                                                 int alldone;
5264                                                                 alldone=0;
5265                                                                 startpoint=6;
5266                                                                 j=startpoint;
5267                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5268                                                                         mapname[j-startpoint]=consoletext[0][j];
5269                                                                         j++;
5270                                                                         if(consoletext[0][j]=='\0')alldone=1;
5271                                                                 }
5272                                                                 mapname[j-startpoint]='\0';
5273
5274                                                                 player[0].metalhead=atof(mapname);
5275
5276                                                                 j++;
5277                                                                 startpoint=j;
5278                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5279                                                                         mapname[j-startpoint]=consoletext[0][j];
5280                                                                         j++;
5281                                                                         if(consoletext[0][j]=='\0')alldone=1;
5282                                                                 }
5283                                                                 mapname[j-startpoint]='\0';
5284
5285                                                                 player[0].metalhigh=atof(mapname);
5286
5287                                                                 j++;
5288                                                                 startpoint=j;
5289                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5290                                                                         mapname[j-startpoint]=consoletext[0][j];
5291                                                                         j++;
5292                                                                         if(consoletext[0][j]=='\0')alldone=1;
5293                                                                 }
5294
5295                                                                 mapname[j-startpoint]='\0';
5296
5297                                                                 player[0].metallow=atof(mapname);
5298
5299                                                                 donesomething=1;
5300                                                         }
5301
5302                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5303                                                                 int closest=-1;
5304                                                                 float closestdist=-1;
5305                                                                 float distance;
5306                                                                 if(numplayers>1)
5307                                                                         for(i=1;i<numplayers;i++){
5308                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5309                                                                                 if(closestdist==-1||distance<closestdist){
5310                                                                                         closestdist=distance;
5311                                                                                         closest=i;
5312                                                                                 }
5313                                                                         }
5314                                                                         player[closest].numclothes=0;
5315                                                                         if(player[closest].whichskin==0){
5316                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5317                                                                         }
5318                                                                         else if(player[closest].whichskin==1){
5319                                                                                 LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5320                                                                         }
5321                                                                         else if(player[closest].whichskin==2){
5322                                                                                 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5323                                                                         }
5324                                                                         else if(player[closest].whichskin==3){
5325                                                                                 LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5326                                                                         }
5327                                                                         else if(player[closest].whichskin==4){
5328                                                                                 LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5329                                                                         }
5330                                                                         else if(player[closest].whichskin==5){
5331                                                                                 LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5332                                                                         }
5333                                                                         else if(player[closest].whichskin==6){
5334                                                                                 LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5335                                                                         }
5336                                                                         else if(player[closest].whichskin==7){
5337                                                                                 LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5338                                                                         }
5339                                                                         else if(player[closest].whichskin==8){
5340                                                                                 LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5341                                                                         }
5342                                                                         else if(player[closest].whichskin==9){
5343                                                                                 LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5344                                                                         }
5345
5346                                                                         donesomething=1;
5347                                                         }
5348
5349                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5350                                                                 int closest=0;
5351
5352                                                                 player[closest].numclothes=0;
5353                                                                 if(player[closest].whichskin==0){
5354                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5355                                                                 }
5356                                                                 else if(player[closest].whichskin==1){
5357                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5358                                                                 }
5359                                                                 else if(player[closest].whichskin==2){
5360                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5361                                                                 }
5362                                                                 else if(player[closest].whichskin==3){
5363                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5364                                                                 }
5365                                                                 else if(player[closest].whichskin==4){
5366                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5367                                                                 }
5368                                                                 else if(player[closest].whichskin==5){
5369                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5370                                                                 }
5371                                                                 else if(player[closest].whichskin==6){
5372                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5373                                                                 }
5374                                                                 else if(player[closest].whichskin==7){
5375                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5376                                                                 }
5377                                                                 else if(player[closest].whichskin==8){
5378                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5379                                                                 }
5380                                                                 else if(player[closest].whichskin==9){
5381                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5382                                                                 }
5383
5384                                                                 donesomething=1;
5385                                                         }
5386
5387                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5388                                                                 mapname[0]=':';
5389                                                                 mapname[1]='D';
5390                                                                 mapname[2]='a';
5391                                                                 mapname[3]='t';
5392                                                                 mapname[4]='a';
5393                                                                 mapname[5]=':';
5394                                                                 mapname[6]='T';
5395                                                                 mapname[7]='e';
5396                                                                 mapname[8]='x';
5397                                                                 mapname[9]='t';
5398                                                                 mapname[10]='u';
5399                                                                 mapname[11]='r';
5400                                                                 mapname[12]='e';
5401                                                                 mapname[13]='s';
5402                                                                 mapname[14]=':';
5403                                                                 for(j=8;j<consolechars[0];j++){
5404                                                                         mapname[j-8+15]=consoletext[0][j];
5405                                                                 }
5406                                                                 mapname[consolechars[0]-8+15]='.';
5407                                                                 mapname[consolechars[0]-8+16]='p';
5408                                                                 mapname[consolechars[0]-8+17]='n';
5409                                                                 mapname[consolechars[0]-8+18]='g';
5410                                                                 mapname[consolechars[0]-8+19]='\0';
5411
5412                                                                 //:Data:Textures:Pants.png
5413
5414                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5415                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5416                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5417                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5418                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5419                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5420                                                                         player[0].numclothes++;
5421                                                                 }
5422
5423                                                                 donesomething=1;
5424                                                         }
5425
5426                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5427                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5428
5429                                                                 donesomething=1;
5430                                                         }
5431
5432                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5433                                                                 cellophane=1-cellophane;
5434
5435                                                                 if(cellophane){
5436                                                                         for(i=0;i<numplayers;i++){
5437                                                                                 player[i].proportionhead.z=0;
5438                                                                                 player[i].proportionbody.z=0;
5439                                                                                 player[i].proportionarms.z=0;
5440                                                                                 player[i].proportionlegs.z=0;
5441                                                                         }
5442                                                                 }
5443
5444                                                                 if(!cellophane){
5445                                                                         for(i=0;i<numplayers;i++){
5446                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5447                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5448                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5449                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5450                                                                         }
5451                                                                 }
5452
5453                                                                 donesomething=1;
5454                                                         }
5455
5456                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5457                                                                 mapname[0]=':';
5458                                                                 mapname[1]='D';
5459                                                                 mapname[2]='a';
5460                                                                 mapname[3]='t';
5461                                                                 mapname[4]='a';
5462                                                                 mapname[5]=':';
5463                                                                 mapname[6]='T';
5464                                                                 mapname[7]='e';
5465                                                                 mapname[8]='x';
5466                                                                 mapname[9]='t';
5467                                                                 mapname[10]='u';
5468                                                                 mapname[11]='r';
5469                                                                 mapname[12]='e';
5470                                                                 mapname[13]='s';
5471                                                                 mapname[14]=':';
5472                                                                 for(j=12;j<consolechars[0];j++){
5473                                                                         mapname[j-12+15]=consoletext[0][j];
5474                                                                 }
5475                                                                 mapname[consolechars[0]-12+15]='.';
5476                                                                 mapname[consolechars[0]-12+16]='p';
5477                                                                 mapname[consolechars[0]-12+17]='n';
5478                                                                 mapname[consolechars[0]-12+18]='g';
5479                                                                 mapname[consolechars[0]-12+19]='\0';
5480
5481                                                                 //:Data:Textures:Pants.png
5482                                                                 int closest=-1;
5483                                                                 float closestdist=-1;
5484                                                                 float distance;
5485                                                                 if(numplayers>1)
5486                                                                         for(i=1;i<numplayers;i++){
5487                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5488                                                                                 if(closestdist==-1||distance<closestdist){
5489                                                                                         closestdist=distance;
5490                                                                                         closest=i;
5491                                                                                 }
5492                                                                         }
5493
5494                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5495                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5496                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5497                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5498                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5499                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5500                                                                                 player[closest].numclothes++;
5501                                                                         }
5502
5503                                                                         donesomething=1;
5504                                                         }
5505
5506                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5507                                                                 player[0].skeleton.id=0;
5508                                                                 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);
5509                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5510                                                                 player[0].creature=rabbittype;
5511                                                                 player[0].scale=.2;
5512
5513                                                                 player[0].proportionhead=1.2;
5514                                                                 player[0].proportionbody=1.05;
5515                                                                 player[0].proportionarms=1.00;
5516                                                                 player[0].proportionlegs=1.1;
5517                                                                 player[0].proportionlegs.y=1.05;
5518                                                                 player[0].headless=0;
5519
5520                                                                 player[0].damagetolerance=200;
5521
5522                                                                 donesomething=1;
5523                                                         }
5524                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5525                                                                 player[0].skeleton.id=0;
5526                                                                 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);
5527                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5528                                                                 player[0].creature=wolftype;
5529
5530                                                                 player[0].proportionhead=1.1;
5531                                                                 player[0].proportionbody=1.1;
5532                                                                 player[0].proportionarms=1.1;
5533                                                                 player[0].proportionlegs=1.1;
5534                                                                 player[0].proportionlegs.y=1.1;
5535                                                                 player[0].scale=.23;
5536
5537                                                                 player[0].damagetolerance=300;
5538
5539                                                                 donesomething=1;
5540                                                         }
5541                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5542                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5543                                                         donesomething=1;
5544                                                         }
5545                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5546                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5547                                                         donesomething=1;
5548                                                         }
5549                                                         if(Compare(consoletext[0],"david ",0,5)){
5550                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5551                                                         donesomething=1;
5552                                                         }*/
5553                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5554                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5555                                                                 donesomething=1;
5556                                                         }
5557                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5558                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5559                                                                 donesomething=1;
5560                                                         }
5561                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5562                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5563                                                                 donesomething=1;
5564                                                         }/*
5565                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5566                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5567                                                          donesomething=1;
5568                                                          }*/
5569                                                         if(Compare(consoletext[0],"white ",0,5)){
5570                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5571                                                                 donesomething=1;
5572                                                         }
5573                                                         if(Compare(consoletext[0],"brown ",0,5)){
5574                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5575                                                                 donesomething=1;
5576                                                         }
5577                                                         if(Compare(consoletext[0],"black ",0,5)){
5578                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5579                                                                 donesomething=1;
5580                                                         }
5581                                                         if(consolechars[0]>0){
5582                                                                 for(k=14;k>=1;k--){
5583                                                                         for(j=0;j<255;j++){
5584                                                                                 consoletext[k][j]=consoletext[k-1][j];
5585                                                                         }
5586                                                                         consolechars[k]=consolechars[k-1];
5587                                                                 }
5588                                                                 for(j=0;j<255;j++){
5589                                                                         consoletext[0][j]=' ';
5590                                                                 }
5591                                                                 consolechars[0]=0;
5592                                                                 consoleselected=0;
5593
5594                                                                 if(!donesomething){
5595                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, TRUE);
5596                                                                         FSOUND_SetVolume(channels[consolefailsound], 256);
5597                                                                         FSOUND_SetPaused(channels[consolefailsound], FALSE);
5598                                                                 }
5599                                                         }
5600                                                 }
5601                                         }
5602                                         togglekey[i]=1;
5603                                 }
5604                                 else {
5605                                         togglekey[i]=0;
5606                                         togglekeydelay[i]=0;
5607                                 }
5608                         }
5609
5610                         consoleblinkdelay-=multiplier;
5611                         if(consoleblinkdelay<=0){
5612                                 consoleblinkdelay=.3;
5613                                 consoleblink=1-consoleblink;
5614                         }
5615                 }
5616
5617                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5618                         tryquit=1;
5619                         if(mainmenu==3){
5620                                 if(newdetail>2)newdetail=detail;
5621                                 if(newdetail<0)newdetail=detail;
5622                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
5623                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5624                                 if(newscreenheight>3000)newscreenheight=screenheight;
5625                                 if(newscreenheight<0)newscreenheight=screenheight;
5626
5627                                 //ofstream opstream(":Data:config.txt"); 
5628                                 ofstream opstream("./Data/config.txt"); 
5629                                 opstream << "Screenwidth:\n";
5630                                 opstream << newscreenwidth;
5631                                 opstream << "\nScreenheight:\n";
5632                                 opstream << newscreenheight;
5633                                 opstream << "\nMouse sensitivity:\n";
5634                                 opstream << usermousesensitivity;
5635                                 opstream << "\nBlur(0,1):\n";
5636                                 opstream << ismotionblur;
5637                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5638                                 opstream << newdetail;
5639                                 opstream << "\nFloating jump:\n";
5640                                 opstream << floatjump;
5641                                 opstream << "\nMouse jump:\n";
5642                                 opstream << mousejump;
5643                                 opstream << "\nAmbient sound:\n";
5644                                 opstream << ambientsound;
5645                                 opstream << "\nBlood (0,1,2):\n";
5646                                 opstream << bloodtoggle;
5647                                 opstream << "\nAuto slomo:\n";
5648                                 opstream << autoslomo;
5649                                 opstream << "\nFoliage:\n";
5650                                 opstream << foliage;
5651                                 opstream << "\nMusic:\n";
5652                                 opstream << musictoggle;
5653                                 opstream << "\nTrilinear:\n";
5654                                 opstream << trilinear;
5655                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5656                                 opstream << decals;
5657                                 opstream << "\nInvert mouse:\n";
5658                                 opstream << invertmouse;
5659                                 opstream << "\nGamespeed:\n";
5660                                 if(oldgamespeed==0)oldgamespeed=1;
5661                                 opstream << oldgamespeed;
5662                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5663                                 opstream << difficulty;
5664                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5665                                 opstream << damageeffects;
5666                                 opstream << "\nText:\n";
5667                                 opstream << texttoggle;
5668                                 opstream << "\nDebug:\n";
5669                                 opstream << debugmode;
5670                                 opstream << "\nVBL Sync:\n";
5671                                 opstream << vblsync;
5672                                 opstream << "\nShow Points:\n";
5673                                 opstream << showpoints;
5674                                 opstream << "\nAlways Blur:\n";
5675                                 opstream << alwaysblur;
5676                                 opstream << "\nImmediate mode (turn on on G5):\n";
5677                                 opstream << immediate;
5678                                 opstream << "\nVelocity blur:\n";
5679                                 opstream << velocityblur;
5680                             opstream << "\nVolume:\n";
5681                         opstream << volume;
5682                                 opstream << "\nForward key:\n";
5683                                 opstream << KeyToChar(forwardkey);
5684                                 opstream << "\nBack key:\n";
5685                                 opstream << KeyToChar(backkey);
5686                                 opstream << "\nLeft key:\n";
5687                                 opstream << KeyToChar(leftkey);
5688                                 opstream << "\nRight key:\n";
5689                                 opstream << KeyToChar(rightkey);
5690                                 opstream << "\nJump key:\n";
5691                                 opstream << KeyToChar(jumpkey);
5692                                 opstream << "\nCrouch key:\n";
5693                                 opstream << KeyToChar(crouchkey);
5694                                 opstream << "\nDraw key:\n";
5695                                 opstream << KeyToChar(drawkey);
5696                                 opstream << "\nThrow key:\n";
5697                                 opstream << KeyToChar(throwkey);
5698                                 opstream << "\nAttack key:\n";
5699                                 opstream << KeyToChar(attackkey);
5700                                 opstream << "\nChat key:\n";
5701                                 opstream << KeyToChar(chatkey);
5702                                 opstream.close();
5703                         }
5704                 }
5705
5706                 static int oldwinfreeze;
5707                 if(winfreeze&&!oldwinfreeze){
5708                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
5709                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
5710                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
5711                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
5712                 }
5713                 if(winfreeze==0)oldwinfreeze=winfreeze;
5714                 else oldwinfreeze++;
5715
5716                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5717                         if(winfreeze)winfreeze=0;
5718                         oldjumpkeydown=1;
5719                 }
5720                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5721                         if(winfreeze){
5722                                 mainmenu=9;
5723                                 gameon=0;
5724                         }
5725                 }
5726                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5727                         oldjumpkeydown=1;
5728                 }
5729                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5730
5731                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5732
5733                         static bool oldbuttondialogue;
5734
5735                         if(indialogue!=-1)talkdelay=1;
5736                         talkdelay-=multiplier;
5737
5738                         if(talkdelay<=0)
5739                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5740                                         for(i=0;i<numdialogues;i++){
5741                                                 int realdialoguetype;
5742                                                 bool special;
5743                                                 if(dialoguetype[i]>49){
5744                                                         realdialoguetype=dialoguetype[i]-50; 
5745                                                         special=1;
5746                                                 }
5747                                                 else if(dialoguetype[i]>39){
5748                                                         realdialoguetype=dialoguetype[i]-40; 
5749                                                         special=1;
5750                                                 }
5751                                                 else if(dialoguetype[i]>29){
5752                                                         realdialoguetype=dialoguetype[i]-30; 
5753                                                         special=1;
5754                                                 }
5755                                                 else if(dialoguetype[i]>19){
5756                                                         realdialoguetype=dialoguetype[i]-20; 
5757                                                         special=1;
5758                                                 }
5759                                                 else if(dialoguetype[i]>9){
5760                                                         realdialoguetype=dialoguetype[i]-10; 
5761                                                         special=1;
5762                                                 }
5763                                                 else {
5764                                                         realdialoguetype=dialoguetype[i];
5765                                                         special=0;
5766                                                 }
5767                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5768                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5769                                                                 whichdialogue=i;
5770                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5771                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5772                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5773                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5774                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5775                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5776                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5777                                                                 }
5778                                                                 directing=0;
5779                                                                 indialogue=0;
5780                                                                 dialoguetime=0;
5781                                                                 dialoguegonethrough[i]++;
5782                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5783                                                                         static float gLoc[3];
5784                                                                         static float vel[3];
5785                                                                         XYZ temppos;
5786                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5787                                                                         temppos=temppos-viewer;
5788                                                                         Normalise(&temppos);
5789                                                                         temppos+=viewer;
5790
5791                                                                         gLoc[0]=temppos.x;
5792                                                                         gLoc[1]=temppos.y;
5793                                                                         gLoc[2]=temppos.z;vel[0]=0;
5794                                                                         vel[1]=0;
5795                                                                         vel[2]=0;
5796                                                                         int whichsoundplay;
5797                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5798                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5799                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5800                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5801                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5802                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5803                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5804                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5805                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5806                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5807                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5808                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5809                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5810                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5811                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5812                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5813                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5814                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5815                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5816                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5817                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
5818                                                                         FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5819                                                                         FSOUND_SetVolume(channels[whichsoundplay], 256);
5820                                                                         FSOUND_SetPaused(channels[whichsoundplay], FALSE);
5821                                                                 }
5822                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5823                                                         }
5824                                                 }
5825                                         }
5826
5827                                         windvar+=multiplier;
5828                                         smoketex+=multiplier;
5829                                         tutorialstagetime+=multiplier;
5830
5831                                         static float hotspotvisual[40];
5832                                         if(numhotspots){
5833                                                 XYZ hotspotsprite;
5834                                                 if(editorenabled)
5835                                                         for(i=0;i<numhotspots;i++)
5836                                                                 hotspotvisual[i]-=multiplier/320;
5837
5838                                                 for(i=0;i<numhotspots;i++){
5839                                                         //if(hotspottype[i]<=10)
5840                                                         while(hotspotvisual[i]<0){
5841                                                                 hotspotsprite=0;
5842                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5843                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5844                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5845                                                                 hotspotsprite+=hotspot[i];
5846                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5847                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5848                                                         }                               
5849                                                 }
5850
5851                                                 for(i=0;i<numhotspots;i++){
5852                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5853                                                                 hotspot[i]=player[hotspottype[i]].coords;
5854                                                         }
5855                                                 }
5856                                         }
5857
5858                                         //Tutorial
5859                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5860                                                 tutorialstage++;
5861                                                 tutorialsuccess=0;
5862                                                 if(tutorialstage<=1){
5863                                                         canattack=0;
5864                                                         cananger=0;
5865                                                         reversaltrain=0;
5866                                                 }
5867                                                 if(tutorialstage==1){
5868                                                         tutorialmaxtime=5;
5869                                                 }
5870                                                 if(tutorialstage==2){
5871                                                         tutorialmaxtime=2;
5872                                                 }
5873                                                 if(tutorialstage==3){
5874                                                         tutorialmaxtime=600;
5875                                                 }
5876                                                 if(tutorialstage==4){
5877                                                         tutorialmaxtime=1000;
5878                                                 }
5879                                                 if(tutorialstage==5){
5880                                                         tutorialmaxtime=600;
5881                                                 }
5882                                                 if(tutorialstage==6){
5883                                                         tutorialmaxtime=600;
5884                                                 }
5885                                                 if(tutorialstage==7){
5886                                                         tutorialmaxtime=600;
5887                                                 }
5888                                                 if(tutorialstage==8){
5889                                                         tutorialmaxtime=600;
5890                                                 }
5891                                                 if(tutorialstage==9){
5892                                                         tutorialmaxtime=600;
5893                                                 }
5894                                                 if(tutorialstage==10){
5895                                                         tutorialmaxtime=2;
5896                                                 }
5897                                                 if(tutorialstage==11){
5898                                                         tutorialmaxtime=1000;
5899                                                 }
5900                                                 if(tutorialstage==12){
5901                                                         tutorialmaxtime=1000;
5902                                                 }
5903                                                 if(tutorialstage==13){
5904                                                         tutorialmaxtime=2;
5905                                                 }
5906                                                 if(tutorialstage==14){
5907                                                         tutorialmaxtime=3;
5908
5909                                                         XYZ temp,temp2;
5910
5911                                                         temp.x=1011;
5912                                                         temp.y=84;
5913                                                         temp.z=491;
5914                                                         temp2.x=1025;
5915                                                         temp2.y=75;
5916                                                         temp2.z=447;
5917
5918                                                         player[1].coords=(temp+temp2)/2;
5919
5920                                                         float gLoc[3];
5921                                                         float vel[3];
5922                                                         gLoc[0]=player[1].coords.x;
5923                                                         gLoc[1]=player[1].coords.y;
5924                                                         gLoc[2]=player[1].coords.z;
5925                                                         vel[0]=0;
5926                                                         vel[1]=0;
5927                                                         vel[2]=0;
5928                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
5929                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5930                                                         FSOUND_SetVolume(channels[fireendsound], 256);
5931                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
5932
5933                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5934                                                                 if(Random()%2==0){
5935                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5936                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5937                                                                         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;
5938                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5939                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5940                                                                 }
5941                                                         }
5942
5943                                                 }
5944                                                 if(tutorialstage==15){
5945                                                         tutorialmaxtime=500;
5946                                                 }
5947                                                 if(tutorialstage==16){
5948                                                         tutorialmaxtime=500;
5949                                                 }
5950                                                 if(tutorialstage==17){
5951                                                         tutorialmaxtime=500;
5952                                                 }
5953                                                 if(tutorialstage==18){
5954                                                         tutorialmaxtime=500;
5955                                                 }
5956                                                 if(tutorialstage==19){
5957                                                         tutorialstage=20;
5958                                                         //tutorialmaxtime=500;
5959                                                 }
5960                                                 if(tutorialstage==20){
5961                                                         tutorialmaxtime=500;
5962                                                 }
5963                                                 if(tutorialstage==21){
5964                                                         tutorialmaxtime=500;
5965                                                         if(bonus==cannon){
5966                                                                 bonus=Slicebonus;
5967                                                                 againbonus=1;
5968                                                         }
5969                                                         else againbonus=0;
5970                                                 }
5971                                                 if(tutorialstage==22){
5972                                                         tutorialmaxtime=500;
5973                                                 }
5974                                                 if(tutorialstage==23){
5975                                                         tutorialmaxtime=500;
5976                                                 }
5977                                                 if(tutorialstage==24){
5978                                                         tutorialmaxtime=500;
5979                                                 }
5980                                                 if(tutorialstage==25){
5981                                                         tutorialmaxtime=500;
5982                                                 }
5983                                                 if(tutorialstage==26){
5984                                                         tutorialmaxtime=2;
5985                                                 }
5986                                                 if(tutorialstage==27){
5987                                                         tutorialmaxtime=4;
5988                                                         reversaltrain=1;
5989                                                         cananger=1;
5990                                                         player[1].aitype=attacktypecutoff;
5991                                                 }
5992                                                 if(tutorialstage==28){
5993                                                         tutorialmaxtime=400;
5994                                                 }
5995                                                 if(tutorialstage==29){
5996                                                         tutorialmaxtime=400;
5997                                                         player[0].escapednum=0;
5998                                                 }
5999                                                 if(tutorialstage==30){
6000                                                         tutorialmaxtime=4;
6001                                                         reversaltrain=0;
6002                                                         cananger=0;
6003                                                         player[1].aitype=passivetype;
6004                                                 }
6005                                                 if(tutorialstage==31){
6006                                                         tutorialmaxtime=13;
6007                                                 }
6008                                                 if(tutorialstage==32){
6009                                                         tutorialmaxtime=8;
6010                                                 }
6011                                                 if(tutorialstage==33){
6012                                                         tutorialmaxtime=400;
6013                                                         cananger=1;
6014                                                         canattack=1;
6015                                                         player[1].aitype=attacktypecutoff;
6016                                                 }
6017                                                 if(tutorialstage==34){
6018                                                         tutorialmaxtime=400;
6019                                                 }
6020                                                 if(tutorialstage==35){
6021                                                         tutorialmaxtime=400;
6022                                                 }
6023                                                 if(tutorialstage==36){
6024                                                         tutorialmaxtime=2;
6025                                                         reversaltrain=0;
6026                                                         cananger=0;
6027                                                         player[1].aitype=passivetype;
6028                                                 }
6029                                                 if(tutorialstage==37){
6030                                                         damagedealt=0;
6031                                                         damagetaken=0;
6032                                                         tutorialmaxtime=50;
6033                                                         cananger=1;
6034                                                         canattack=1;
6035                                                         player[1].aitype=attacktypecutoff;
6036                                                 }
6037                                                 if(tutorialstage==38){
6038                                                         tutorialmaxtime=4;
6039                                                         canattack=0;
6040                                                         cananger=0;
6041                                                         player[1].aitype=passivetype;
6042                                                 }
6043                                                 if(tutorialstage==39){
6044                                                         XYZ temp,temp2;
6045
6046                                                         temp.x=1011;
6047                                                         temp.y=84;
6048                                                         temp.z=491;
6049                                                         temp2.x=1025;
6050                                                         temp2.y=75;
6051                                                         temp2.z=447;
6052
6053
6054                                                         weapons.owner[weapons.numweapons]=-1;
6055                                                         weapons.type[weapons.numweapons]=knife;
6056                                                         weapons.damage[weapons.numweapons]=0;
6057                                                         weapons.mass[weapons.numweapons]=1;
6058                                                         weapons.tipmass[weapons.numweapons]=1.2;
6059                                                         weapons.length[weapons.numweapons]=.25;
6060                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6061                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6062
6063                                                         weapons.velocity[weapons.numweapons]=0.1;
6064                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6065                                                         weapons.missed[weapons.numweapons]=1;
6066                                                         weapons.hitsomething[weapons.numweapons]=0;
6067                                                         weapons.freetime[weapons.numweapons]=0;
6068                                                         weapons.firstfree[weapons.numweapons]=1;
6069                                                         weapons.physics[weapons.numweapons]=1;
6070
6071                                                         weapons.numweapons++;
6072                                                 }
6073                                                 if(tutorialstage==40){
6074                                                         tutorialmaxtime=300;
6075                                                 }
6076                                                 if(tutorialstage==41){
6077                                                         tutorialmaxtime=300;
6078                                                 }
6079                                                 if(tutorialstage==42){
6080                                                         tutorialmaxtime=8;
6081                                                 }
6082                                                 if(tutorialstage==43){
6083                                                         tutorialmaxtime=300;
6084                                                 }
6085                                                 if(tutorialstage==44){
6086                                                         weapons.owner[0]=1;
6087                                                         player[0].weaponactive=-1;
6088                                                         player[0].num_weapons=0;
6089                                                         player[1].weaponactive=0;
6090                                                         player[1].num_weapons=1;
6091                                                         player[1].weaponids[0]=0;
6092
6093                                                         cananger=1;
6094                                                         canattack=1;
6095                                                         player[1].aitype=attacktypecutoff;
6096
6097                                                         tutorialmaxtime=300;
6098                                                 }
6099                                                 if(tutorialstage==45){
6100                                                         weapons.owner[0]=1;
6101                                                         player[0].weaponactive=-1;
6102                                                         player[0].num_weapons=0;
6103                                                         player[1].weaponactive=0;
6104                                                         player[1].num_weapons=1;
6105                                                         player[1].weaponids[0]=0;
6106
6107                                                         tutorialmaxtime=300;
6108                                                 }
6109                                                 if(tutorialstage==46){
6110                                                         weapons.owner[0]=1;
6111                                                         player[0].weaponactive=-1;
6112                                                         player[0].num_weapons=0;
6113                                                         player[1].weaponactive=0;
6114                                                         player[1].num_weapons=1;
6115                                                         player[1].weaponids[0]=0;
6116
6117                                                         weapons.type[0]=sword;
6118
6119                                                         tutorialmaxtime=300;
6120                                                 }
6121
6122                                                 if(tutorialstage==47){
6123                                                         tutorialmaxtime=10;
6124
6125                                                         XYZ temp,temp2;
6126
6127                                                         temp.x=1011;
6128                                                         temp.y=84;
6129                                                         temp.z=491;
6130                                                         temp2.x=1025;
6131                                                         temp2.y=75;
6132                                                         temp2.z=447;
6133
6134                                                         weapons.owner[weapons.numweapons]=-1;
6135                                                         weapons.type[weapons.numweapons]=sword;
6136                                                         weapons.damage[weapons.numweapons]=0;
6137                                                         weapons.mass[weapons.numweapons]=1;
6138                                                         weapons.tipmass[weapons.numweapons]=1.2;
6139                                                         weapons.length[weapons.numweapons]=.25;
6140                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6141                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6142
6143                                                         weapons.velocity[weapons.numweapons]=0.1;
6144                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6145                                                         weapons.missed[weapons.numweapons]=1;
6146                                                         weapons.hitsomething[weapons.numweapons]=0;
6147                                                         weapons.freetime[weapons.numweapons]=0;
6148                                                         weapons.firstfree[weapons.numweapons]=1;
6149                                                         weapons.physics[weapons.numweapons]=1;
6150
6151                                                         weapons.owner[0]=1;
6152                                                         weapons.owner[1]=0;
6153                                                         player[0].weaponactive=0;
6154                                                         player[0].num_weapons=1;
6155                                                         player[0].weaponids[0]=1;       
6156                                                         player[1].weaponactive=0;
6157                                                         player[1].num_weapons=1;
6158                                                         player[1].weaponids[0]=0;       
6159
6160                                                         weapons.numweapons++;
6161                                                 }
6162                                                 if(tutorialstage==48){
6163                                                         canattack=0;
6164                                                         cananger=0;
6165                                                         player[1].aitype=passivetype;
6166
6167                                                         tutorialmaxtime=15;
6168
6169                                                         weapons.owner[0]=1;
6170                                                         weapons.owner[1]=0;
6171                                                         player[0].weaponactive=0;
6172                                                         player[0].num_weapons=1;
6173                                                         player[0].weaponids[0]=1;       
6174                                                         player[1].weaponactive=0;
6175                                                         player[1].num_weapons=1;
6176                                                         player[1].weaponids[0]=0;
6177
6178                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
6179                                                         else weapons.type[0]=staff;
6180
6181                                                         weapons.numweapons++;
6182                                                 }
6183                                                 if(tutorialstage==49){
6184                                                         canattack=0;
6185                                                         cananger=0;
6186                                                         player[1].aitype=passivetype;
6187
6188                                                         tutorialmaxtime=200;
6189
6190                                                         weapons.position[1]=1000;
6191                                                         weapons.tippoint[1]=1000;
6192
6193                                                         weapons.numweapons=1;
6194                                                         weapons.owner[0]=0;
6195                                                         player[1].weaponactive=-1;
6196                                                         player[1].num_weapons=0;
6197                                                         player[0].weaponactive=0;
6198                                                         player[0].num_weapons=1;
6199                                                         player[0].weaponids[0]=0;       
6200
6201                                                         weapons.type[0]=knife;
6202
6203                                                         weapons.numweapons++;
6204                                                 }
6205                                                 if(tutorialstage==50){
6206                                                         tutorialmaxtime=8;
6207
6208                                                         XYZ temp,temp2;
6209                                                         float gLoc[3];
6210                                                         float vel[3];
6211                                                         gLoc[0]=player[1].coords.x;
6212                                                         gLoc[1]=player[1].coords.y;
6213                                                         gLoc[2]=player[1].coords.z;
6214                                                         vel[0]=0;
6215                                                         vel[1]=0;
6216                                                         vel[2]=0;
6217                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
6218                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6219                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6220                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6221
6222                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6223                                                                 if(Random()%2==0){
6224                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6225                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6226                                                                         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;
6227                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6228                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6229                                                                 }
6230                                                         }
6231
6232                                                         player[1].num_weapons=0;
6233                                                         player[1].weaponstuck=-1;
6234                                                         player[1].weaponactive=-1;
6235
6236                                                         weapons.numweapons=0;
6237
6238                                                         weapons.owner[0]=-1;
6239                                                         weapons.velocity[0]=0.1;
6240                                                         weapons.tipvelocity[0]=-0.1;
6241                                                         weapons.missed[0]=1;
6242                                                         weapons.hitsomething[0]=0;
6243                                                         weapons.freetime[0]=0;
6244                                                         weapons.firstfree[0]=1;
6245                                                         weapons.physics[0]=1;
6246                                                 }
6247                                                 if(tutorialstage==51){
6248                                                         tutorialmaxtime=80000;
6249                                                 }
6250                                                 if(tutorialstage<=51)tutorialstagetime=0;
6251                                         }
6252
6253                                         //Tutorial success
6254                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6255                                                 if(tutorialstage==3){
6256                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6257                                                 }
6258                                                 if(tutorialstage==4){
6259                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6260                                                 }
6261                                                 if(tutorialstage==5){
6262                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6263                                                 }
6264                                                 if(tutorialstage==6){
6265                                                         if(player[0].isCrouch())tutorialsuccess=1;
6266                                                 }
6267                                                 if(tutorialstage==7){
6268                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6269                                                 }
6270                                                 if(tutorialstage==8){
6271                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6272                                                 }
6273                                                 if(tutorialstage==9){
6274                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6275                                                 }
6276                                                 if(tutorialstage==11){
6277                                                         if(player[0].isWallJump())tutorialsuccess=1;
6278                                                 }
6279                                                 if(tutorialstage==12){
6280                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6281                                                 }
6282                                                 if(tutorialstage==15){
6283                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6284                                                 }
6285                                                 if(tutorialstage==16){
6286                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6287                                                 }
6288                                                 if(tutorialstage==17){
6289                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6290                                                 }
6291                                                 if(tutorialstage==18){
6292                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6293                                                 }
6294                                                 if(tutorialstage==19){
6295                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6296                                                 }
6297                                                 if(tutorialstage==20){
6298                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6299                                                 }
6300                                                 if(tutorialstage==21){
6301                                                         if(bonus==cannon)tutorialsuccess=1;
6302                                                 }
6303                                                 if(tutorialstage==22){
6304                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6305                                                 }
6306                                                 if(tutorialstage==23){
6307                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6308                                                 }
6309                                                 if(tutorialstage==24){
6310                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6311                                                 }
6312                                                 if(tutorialstage==25){
6313                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6314                                                 }
6315                                                 if(tutorialstage==28){
6316                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6317                                                 }
6318                                                 if(tutorialstage==29){
6319                                                         if(player[0].escapednum==2){
6320                                                                 tutorialsuccess=1;
6321                                                                 reversaltrain=0;
6322                                                                 cananger=0;
6323                                                                 player[1].aitype=passivetype;
6324                                                         }
6325                                                 }
6326                                                 if(tutorialstage==33){
6327                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6328                                                 }
6329                                                 if(tutorialstage==34){
6330                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6331                                                 }
6332                                                 if(tutorialstage==35){
6333                                                         if(animation[player[0].targetanimation].attack==reversal){
6334                                                                 tutorialsuccess=1;
6335                                                                 reversaltrain=0;
6336                                                                 cananger=0;
6337                                                                 player[1].aitype=passivetype;
6338                                                         }
6339                                                 }
6340                                                 if(tutorialstage==40){
6341                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6342                                                 }
6343                                                 if(tutorialstage==41){
6344                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6345                                                 }
6346                                                 if(tutorialstage==43){
6347                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6348                                                 }
6349                                                 if(tutorialstage==44){
6350                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6351                                                 }
6352                                                 if(tutorialstage==45){
6353                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6354                                                 }
6355                                                 if(tutorialstage==46){
6356                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6357                                                 }
6358                                                 if(tutorialstage==49){
6359                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6360                                                 }
6361                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6362
6363
6364                                                 if(tutorialstagetime==tutorialmaxtime-3){
6365                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
6366                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6367                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
6368                                                 }
6369
6370                                                 if(tutorialsuccess>=1){
6371                                                         if(tutorialstage==34||tutorialstage==35)
6372                                                                 tutorialstagetime=tutorialmaxtime-1;
6373                                                 }
6374                                         }
6375
6376                                         if(tutoriallevel){
6377                                                 if(tutorialstage<14||tutorialstage>=50){
6378                                                         player[1].coords.y=300;
6379                                                         player[1].velocity=0;
6380                                                 }
6381                                         }
6382
6383                                         if(tutoriallevel!=1){
6384                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6385                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, TRUE);
6386                                                         FSOUND_SetVolume(channels[consolesuccesssound], 256);
6387                                                         FSOUND_SetPaused(channels[consolesuccesssound], FALSE);
6388                                                 }
6389                                         }
6390                                         else
6391                                                 if(bonustime==0){
6392                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
6393                                                         FSOUND_SetVolume(channels[fireendsound], 256);
6394                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
6395                                                 }
6396                                                 if(bonustime==0){
6397                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6398                                                         else bonusnum[bonus]+=0.15;
6399                                                         if(tutoriallevel)bonusvalue=0;
6400                                                         bonusvalue/=bonusnum[bonus];
6401                                                         bonustotal+=bonusvalue;
6402                                                 }
6403                                                 bonustime+=multiplier;
6404
6405                                                 if(environment==snowyenvironment){
6406                                                         precipdelay-=multiplier;
6407                                                         while(precipdelay<0){
6408                                                                 precipdelay+=.04;
6409                                                                 if(!detail)precipdelay+=.04;
6410                                                                 XYZ footvel,footpoint;
6411
6412                                                                 footvel=0;
6413                                                                 footpoint=viewer+viewerfacing*6;
6414                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6415                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6416                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6417                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6418                                                         }
6419                                                 }
6420                                                 for(k=0;k<numplayers;k++){
6421                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6422                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6423
6424                                                         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){
6425                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6426                                                                 else if(player[k].rotation>player[k].targetrotation){
6427                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6428                                                                 }
6429                                                                 else if(player[k].rotation<player[k].targetrotation){
6430                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6431                                                                 }
6432                                                         }
6433
6434
6435                                                         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))){
6436                                                                 player[k].turnspeed*=2;
6437                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6438                                                                 else if(player[k].rotation>player[k].targetrotation){
6439                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6440                                                                 }
6441                                                                 else if(player[k].rotation<player[k].targetrotation){
6442                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6443                                                                 }
6444                                                                 player[k].turnspeed/=2;
6445                                                         }
6446
6447                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6448                                                                 player[k].turnspeed*=4;
6449                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6450                                                                 else if(player[k].rotation>player[k].targetrotation){
6451                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6452                                                                 }
6453                                                                 else if(player[k].rotation<player[k].targetrotation){
6454                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6455                                                                 }
6456                                                                 player[k].turnspeed/=4;
6457                                                         }
6458
6459                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6460                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6461
6462                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6463                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6464                                                                         bool tempcollide=0;
6465
6466                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6467                                                                         if(player[k].collide>1)player[k].collide=1;
6468                                                                         player[k].collide-=multiplier*30;
6469
6470                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6471                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6472                                                                         }
6473                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6474                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6475                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6476                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6477                                                                                                 lowpoint=player[k].coords;
6478                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6479                                                                                                 else lowpoint.y+=1.3;
6480                                                                                                 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){
6481                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6482                                                                                                 }
6483                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6484                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6485                                                                                                 */
6486                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6487                                                                                                         flatfacing=lowpoint-player[k].coords;
6488                                                                                                         player[k].coords=lowpoint;
6489                                                                                                         player[k].coords.y-=1.3;
6490                                                                                                         player[k].collide=1;
6491                                                                                                         tempcollide=1;
6492                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6493                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6494                                                                                                                 tempcoords1=lowpoint;
6495                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6496                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6497                                                                                                                         player[k].target=0;
6498                                                                                                                         player[k].targetanimation=walljumpleftanim;
6499                                                                                                                         player[k].targetframe=0;
6500                                                                                                                         float gLoc[3];
6501                                                                                                                         float vel[3];
6502                                                                                                                         gLoc[0]=player[k].coords.x;
6503                                                                                                                         gLoc[1]=player[k].coords.y;
6504                                                                                                                         gLoc[2]=player[k].coords.z;
6505                                                                                                                         vel[0]=0;
6506                                                                                                                         vel[1]=0;
6507                                                                                                                         vel[2]=0;
6508                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6509                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6510                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6511                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6512                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6513
6514                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6515                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6516                                                                                                                         player[k].rotation*=360/6.28;
6517                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6518                                                                                                                         player[k].targetrotation=player[k].rotation;
6519                                                                                                                         player[k].lowrotation=player[k].rotation;
6520                                                                                                                         if(k==0)numwallflipped++;
6521                                                                                                                 }
6522                                                                                                                 else
6523                                                                                                                 {
6524                                                                                                                         lowpoint=tempcoords1;
6525                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6526                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6527                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6528                                                                                                                                 player[k].target=0;
6529                                                                                                                                 player[k].targetanimation=walljumprightanim;
6530                                                                                                                                 player[k].targetframe=0;
6531                                                                                                                                 float gLoc[3];
6532                                                                                                                                 float vel[3];
6533                                                                                                                                 gLoc[0]=player[k].coords.x;
6534                                                                                                                                 gLoc[1]=player[k].coords.y;
6535                                                                                                                                 gLoc[2]=player[k].coords.z;
6536                                                                                                                                 vel[0]=0;
6537                                                                                                                                 vel[1]=0;
6538                                                                                                                                 vel[2]=0;
6539                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6540                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6541                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6542                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6543                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6544
6545                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6546                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6547                                                                                                                                 player[k].rotation*=360/6.28;
6548                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6549                                                                                                                                 player[k].targetrotation=player[k].rotation;
6550                                                                                                                                 player[k].lowrotation=player[k].rotation;
6551                                                                                                                                 if(k==0)numwallflipped++;
6552                                                                                                                         }
6553                                                                                                                         else
6554                                                                                                                         {
6555                                                                                                                                 lowpoint=tempcoords1;
6556                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6557                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6558                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6559                                                                                                                                         player[k].target=0;
6560                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6561                                                                                                                                         player[k].targetframe=0;
6562                                                                                                                                         float gLoc[3];
6563                                                                                                                                         float vel[3];
6564                                                                                                                                         gLoc[0]=player[k].coords.x;
6565                                                                                                                                         gLoc[1]=player[k].coords.y;
6566                                                                                                                                         gLoc[2]=player[k].coords.z;
6567                                                                                                                                         vel[0]=0;
6568                                                                                                                                         vel[1]=0;
6569                                                                                                                                         vel[2]=0;
6570                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6571                                                                                                                                         FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6572                                                                                                                                         FSOUND_SetVolume(channels[movewhooshsound], 256);
6573                                                                                                                                         FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6574                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6575
6576                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6577                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6578                                                                                                                                         player[k].rotation*=360/6.28;
6579                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6580                                                                                                                                         player[k].targetrotation=player[k].rotation;
6581                                                                                                                                         player[k].lowrotation=player[k].rotation;
6582                                                                                                                                         if(k==0)numwallflipped++;
6583                                                                                                                                 }
6584                                                                                                                                 else
6585                                                                                                                                 {
6586                                                                                                                                         lowpoint=tempcoords1;
6587                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6588                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6589                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6590                                                                                                                                                 player[k].target=0;
6591                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6592                                                                                                                                                 player[k].targetframe=0;
6593                                                                                                                                                 float gLoc[3];
6594                                                                                                                                                 float vel[3];
6595                                                                                                                                                 gLoc[0]=player[k].coords.x;
6596                                                                                                                                                 gLoc[1]=player[k].coords.y;
6597                                                                                                                                                 gLoc[2]=player[k].coords.z;
6598                                                                                                                                                 vel[0]=0;
6599                                                                                                                                                 vel[1]=0;
6600                                                                                                                                                 vel[2]=0;
6601                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, TRUE);
6602                                                                                                                                                 FSOUND_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6603                                                                                                                                                 FSOUND_SetVolume(channels[movewhooshsound], 256);
6604                                                                                                                                                 FSOUND_SetPaused(channels[movewhooshsound], FALSE);
6605                                                                                                                                                 if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6606
6607                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6608                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6609                                                                                                                                                 player[k].rotation*=360/6.28;
6610                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6611                                                                                                                                                 player[k].rotation+=180;
6612                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6613                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6614                                                                                                                                                 if(k==0)numwallflipped++;
6615                                                                                                                                         }
6616                                                                                                                                 }
6617                                                                                                                         }
6618                                                                                                                 }
6619                                                                                                         }
6620                                                                                                 }
6621                                                                                         }
6622                                                                                         else if(objects.type[i]==rocktype){
6623                                                                                                 lowpoint2=player[k].coords;
6624                                                                                                 lowpoint=player[k].coords;
6625                                                                                                 lowpoint.y+=2;
6626                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6627                                                                                                         player[k].coords=colpoint;
6628                                                                                                         player[k].collide=1;
6629                                                                                                         tempcollide=1;
6630
6631                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6632                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6633
6634                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6635                                                                                                                 player[k].target=0;
6636                                                                                                                 player[k].targetframe=0;        
6637                                                                                                                 player[k].onterrain=1;
6638
6639                                                                                                                 if(player[k].id==0){
6640                                                                                                                         FSOUND_SetPaused(channels[whooshsound], TRUE);
6641                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 0);
6642                                                                                                                 }
6643
6644                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6645                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6646                                                                                                                         player[k].targetanimation=player[k].getLanding();
6647                                                                                                                         float gLoc[3];
6648                                                                                                                         float vel[3];
6649                                                                                                                         gLoc[0]=player[k].coords.x;
6650                                                                                                                         gLoc[1]=player[k].coords.y;
6651                                                                                                                         gLoc[2]=player[k].coords.z;
6652                                                                                                                         vel[0]=player[k].velocity.x;
6653                                                                                                                         vel[1]=player[k].velocity.y;
6654                                                                                                                         vel[2]=player[k].velocity.z;
6655                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, TRUE);
6656                                                                                                                         FSOUND_3D_SetAttributes(channels[landsound], gLoc, vel);
6657                                                                                                                         FSOUND_SetVolume(channels[landsound], 128);
6658                                                                                                                         FSOUND_SetPaused(channels[landsound], FALSE);
6659                                                                                                                         if(k==0){
6660                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6661                                                                                                                                 envsoundvol[numenvsounds]=16;
6662                                                                                                                                 envsoundlife[numenvsounds]=.4;
6663                                                                                                                                 numenvsounds++;
6664                                                                                                                         }
6665
6666                                                                                                                 }
6667                                                                                                         }
6668                                                                                                 }                               
6669                                                                                         }
6670                                                                                 }
6671                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6672                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6673                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6674                                                                                                 lowpoint=player[k].coords;
6675                                                                                                 lowpoint.y+=1.35;
6676                                                                                                 if(objects.type[i]!=rocktype)
6677                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6678                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;               
6679                                                                                                                 player[k].coords=lowpoint;
6680                                                                                                                 player[k].coords.y-=1.35;
6681                                                                                                                 player[k].collide=1;    
6682
6683                                                                                                                 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)){
6684                                                                                                                         lowpoint=player[k].coords;
6685                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6686                                                                                                                         lowpoint=player[k].coords;
6687                                                                                                                         lowpoint.y+=.05;
6688                                                                                                                         facing=0;
6689                                                                                                                         facing.z=-1;
6690                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6691                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6692                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6693                                                                                                                         if(whichhit!=-1){
6694                                                                                                                                 lowpoint=player[k].coords;
6695                                                                                                                                 lowpoint.y+=.1;
6696                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6697                                                                                                                                 lowpoint2=lowpoint;
6698                                                                                                                                 lowpointtarget2=lowpointtarget;
6699                                                                                                                                 lowpoint3=lowpoint;
6700                                                                                                                                 lowpointtarget3=lowpointtarget;
6701                                                                                                                                 lowpoint4=lowpoint;
6702                                                                                                                                 lowpointtarget4=lowpointtarget;
6703                                                                                                                                 lowpoint5=lowpoint;
6704                                                                                                                                 lowpointtarget5=lowpointtarget;
6705                                                                                                                                 lowpoint6=lowpoint;
6706                                                                                                                                 lowpointtarget6=lowpointtarget;
6707                                                                                                                                 lowpoint7=lowpoint;
6708                                                                                                                                 lowpointtarget7=lowpoint;
6709                                                                                                                                 lowpoint2.x+=.1;
6710                                                                                                                                 lowpointtarget2.x+=.1;
6711                                                                                                                                 lowpoint3.z+=.1;
6712                                                                                                                                 lowpointtarget3.z+=.1;
6713                                                                                                                                 lowpoint4.x-=.1;
6714                                                                                                                                 lowpointtarget4.x-=.1;
6715                                                                                                                                 lowpoint5.z-=.1;
6716                                                                                                                                 lowpointtarget5.z-=.1;
6717                                                                                                                                 lowpoint6.y+=45/13;
6718                                                                                                                                 lowpointtarget6.y+=45/13;
6719                                                                                                                                 lowpointtarget6+=facing*.6;
6720                                                                                                                                 lowpointtarget7.y+=90/13;
6721                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6722                                                                                                                                 if(objects.friction[i]>.5)
6723                                                                                                                                         if(whichhit!=-1){
6724                                                                                                                                                 //if(k==0){
6725                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6726                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6727                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6728                                                                                                                                                                 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)
6729                                                                                                                                                                         for(j=0;j<45;j++){
6730                                                                                                                                                                                 lowpoint=player[k].coords;
6731                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6732                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6733                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6734                                                                                                                                                                                         if(j<=6){
6735                                                                                                                                                                                                 j=100;
6736                                                                                                                                                                                         }
6737                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6738                                                                                                                                                                                         j=100;
6739                                                                                                                                                                                         }*/
6740                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6741                                                                                                                                                                                                 j=100;
6742                                                                                                                                                                                         }
6743                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6744                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6745                                                                                                                                                                                                 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)*/){
6746                                                                                                                                                                                                         lowpoint=player[k].coords;
6747                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6748                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6749                                                                                                                                                                                                         flatfacing=player[k].coords;
6750                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6751                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6752                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6753
6754                                                                                                                                                                                                         if(j>10||!player[k].isRun()){                                                                                                   
6755                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6756                                                                                                                                                                                                                         if(k==0)FSOUND_SetPaused(channels[whooshsound], TRUE);
6757                                                                                                                                                                                                                 }
6758                                                                                                                                                                                                                 float gLoc[3];
6759                                                                                                                                                                                                                 float vel[3];
6760                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6761                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6762                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6763                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6764                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6765                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6766                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
6767                                                                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6768                                                                                                                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
6769                                                                                                                                                                                                                 FSOUND_SetPaused(channels[jumpsound], FALSE);
6770
6771                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6772                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6773                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6774                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6775                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6776                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6777
6778                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6779                                                                                                                                                                                                                 player[k].velocity=0;
6780
6781                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6782                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6783                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6784                                                                                                                                                                                                                         player[k].jumppower=0;
6785                                                                                                                                                                                                                         player[k].jumpclimb=1;
6786                                                                                                                                                                                                                 }
6787                                                                                                                                                                                                                 player[k].transspeed=6;
6788                                                                                                                                                                                                                 player[k].target=0;
6789
6790                                                                                                                                                                                                                 //player[k].currentframe=1;
6791                                                                                                                                                                                                                 player[k].targetframe=1;
6792                                                                                                                                                                                                                 if(j>25){
6793                                                                                                                                                                                                                         //player[k].currentframe=0;
6794                                                                                                                                                                                                                         player[k].targetframe=0;
6795                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6796                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6797                                                                                                                                                                                                                         player[k].jumppower=0;
6798                                                                                                                                                                                                                 }       
6799                                                                                                                                                                                                         }
6800                                                                                                                                                                                                         j=100;
6801                                                                                                                                                                                                 }
6802                                                                                                                                                                                         }
6803                                                                                                                                                                                 }
6804                                                                                                                                                                         }
6805                                                                                                                                                                         //}
6806                                                                                                                                         }
6807                                                                                                                         }
6808                                                                                                                 }
6809                                                                                                         }
6810                                                                                         }
6811                                                                                         if(player[k].collide<=0){
6812                                                                                                 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()){
6813                                                                                                         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)){
6814                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6815                                                                                                                 player[k].targetanimation=jumpdownanim;
6816                                                                                                                 player[k].targetframe=0;
6817                                                                                                                 player[k].target=0;
6818
6819                                                                                                                 float gLoc[3];
6820                                                                                                                 float vel[3];
6821                                                                                                                 gLoc[0]=player[k].coords.x;
6822                                                                                                                 gLoc[1]=player[k].coords.y;
6823                                                                                                                 gLoc[2]=player[k].coords.z;
6824                                                                                                                 vel[0]=player[k].velocity.x;
6825                                                                                                                 vel[1]=player[k].velocity.y;
6826                                                                                                                 vel[2]=player[k].velocity.z;
6827                                                                                                                 if(k==0){
6828                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
6829                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6830                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
6831                                                                                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
6832                                                                                                                 }
6833                                                                                                         }
6834                                                                                                         player[k].velocity.y+=gravity;
6835                                                                                                 }
6836                                                                                         }
6837                                                                 }
6838                                                         }
6839                                                         player[k].realoldcoords=player[k].coords;
6840                                                 }
6841
6842                                                 static XYZ oldviewer;
6843
6844                                                 if(indialogue==-1){
6845                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6846                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6847                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6848                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6849                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6850                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6851                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6852                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6853                                                 }
6854                                                 else
6855                                                 {
6856                                                         player[0].forwardkeydown=0;
6857                                                         player[0].leftkeydown=0;
6858                                                         player[0].backkeydown=0;
6859                                                         player[0].rightkeydown=0;
6860                                                         player[0].jumpkeydown=0;
6861                                                         player[0].crouchkeydown=0;
6862                                                         player[0].drawkeydown=0;
6863                                                         player[0].throwkeydown=0;
6864                                                 }
6865
6866                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6867
6868
6869                                                 static bool endkeydown;
6870                                                 if(indialogue!=-1){
6871                                                         cameramode=1;
6872                                                         if(directing){  
6873                                                                 facing=0;
6874                                                                 facing.z=-1;
6875
6876                                                                 facing=DoRotation(facing,-rotation2,0,0);
6877                                                                 facing=DoRotation(facing,0,0-rotation,0);
6878
6879                                                                 flatfacing=0;
6880                                                                 flatfacing.z=-1;
6881
6882                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6883
6884                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6885                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6886                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6887                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6888                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6889                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6890                                                                 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)
6891                                                                         ||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)
6892                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6893                                                                                 int whichend;
6894                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6895                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6896                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6897                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6898                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6899                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6900                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6901                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6902                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6903                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6904                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6905                                                                                 if(whichend!=-1){
6906                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6907                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6908                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6909                                                                                 }
6910                                                                                 if(whichend==-1){
6911                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6912                                                                                 }
6913                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6914                                                                                         indialogue=-1;
6915                                                                                         directing=0;
6916                                                                                         cameramode=0;
6917                                                                                 }
6918                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6919                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6920                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6921                                                                                 indialogue++;
6922                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6923                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6924                                                                                                 static float gLoc[3];
6925                                                                                                 static float vel[3];
6926                                                                                                 XYZ temppos;
6927                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6928                                                                                                 temppos=temppos-viewer;
6929                                                                                                 Normalise(&temppos);
6930                                                                                                 temppos+=viewer;
6931
6932                                                                                                 gLoc[0]=temppos.x;
6933                                                                                                 gLoc[1]=temppos.y;
6934                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
6935                                                                                                 vel[1]=0;
6936                                                                                                 vel[2]=0;
6937                                                                                                 int whichsoundplay;
6938                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6939                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6940                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6941                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6942                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6943                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6944                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6945                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6946                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6947                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6948                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6949                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6950                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6951                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6952                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6953                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6954                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6955                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6956                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6957                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6958                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
6959                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6960                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
6961                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
6962                                                                                         }
6963                                                                                 }
6964
6965                                                                                 for(j=0;j<numplayers;j++){
6966                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6967                                                                                 }
6968
6969                                                                                 endkeydown=1;
6970                                                                         }
6971                                                                         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)
6972                                                                                 ||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)
6973                                                                                 )){
6974                                                                                         int whichend;
6975                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
6976                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
6977                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
6978                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
6979                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
6980                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
6981                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
6982                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
6983                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
6984                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
6985                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
6986                                                                                 }
6987                                                                                 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)
6988                                                                                         &&!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)
6989                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6990                                                                                                 endkeydown=0;
6991                                                                                         }
6992                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6993                                                                                                 indialogue=-1;
6994                                                                                                 directing=0;
6995                                                                                                 cameramode=0;
6996                                                                                         }
6997                                                         }
6998                                                         if(!directing){ 
6999                                                                 FSOUND_SetPaused(channels[whooshsound], TRUE);
7000                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
7001                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
7002                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
7003                                                                 }                               
7004                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
7005                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
7006                                                                 if(dialoguetime>0.5)
7007                                                                         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)
7008                                                                                 ||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)
7009                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
7010                                                                                         indialogue++;
7011                                                                                         endkeydown=1;
7012                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
7013                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
7014                                                                                                         static float gLoc[3];
7015                                                                                                         static float vel[3];
7016                                                                                                         XYZ temppos;
7017                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7018                                                                                                         temppos=temppos-viewer;
7019                                                                                                         Normalise(&temppos);
7020                                                                                                         temppos+=viewer;
7021
7022                                                                                                         gLoc[0]=temppos.x;
7023                                                                                                         gLoc[1]=temppos.y;
7024                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
7025                                                                                                         vel[1]=0;
7026                                                                                                         vel[2]=0;
7027                                                                                                         int whichsoundplay;
7028                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7029                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7030                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7031                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7032                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7033                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7034                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7035                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7036                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7037                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7038                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7039                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7040                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7041                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7042                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7043                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7044                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7045                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7046                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7047                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7048                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
7049                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
7050                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, TRUE);
7051                                                                                                                 FSOUND_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7052                                                                                                                 FSOUND_SetVolume(channels[whichsoundplay], 256);
7053                                                                                                                 FSOUND_SetPaused(channels[whichsoundplay], FALSE);
7054                                                                                                         }
7055                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
7056                                                                                                                 hotspot[numhotspots]=player[0].coords;
7057                                                                                                                 hotspotsize[numhotspots]=10;
7058                                                                                                                 hotspottype[numhotspots]=-1;
7059
7060                                                                                                                 numhotspots++;
7061                                                                                                         }
7062                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
7063                                                                                                                 hostile=1;
7064                                                                                                         }
7065
7066                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
7067                                                                                                                 indialogue=-1;
7068                                                                                                                 directing=0;
7069                                                                                                                 cameramode=0;
7070                                                                                                         }
7071                                                                                                 }
7072                                                                                         }
7073                                                                                 }
7074                                                                                 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)
7075                                                                                         &&!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)
7076                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7077                                                                                                 endkeydown=0;
7078                                                                                         }
7079                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7080                                                                                                 indialogue=-1;
7081                                                                                                 directing=0;
7082                                                                                                 cameramode=0;
7083                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
7084                                                                                                         hostile=1;
7085                                                                                                 }
7086                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
7087                                                                                                         windialogue=1;
7088                                                                                                 }
7089                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
7090                                                                                                         hostile=1;
7091                                                                                                         for(i=1;i<numplayers;i++){
7092                                                                                                                 player[i].aitype = attacktypecutoff;
7093                                                                                                         }
7094                                                                                                 }
7095                                                                                         }
7096                                                         }
7097                                                 }
7098
7099                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
7100                                                 else oldbuttondialogue=1;
7101
7102                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
7103
7104                                                 //Net updates
7105
7106                                                 /*keyrefreshdelay-=multiplier;
7107                                                 bigrefreshdelay-=multiplier;
7108
7109                                                 if(keyrefreshdelay<=0){
7110                                                 static int concat[4];
7111
7112                                                 concat[0]=player[0].forwardkeydown;
7113                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
7114                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
7115                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
7116                                                 concat[0]=concat[0]*2+player[0].backkeydown;
7117                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
7118                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
7119                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
7120
7121                                                 concat[1]=player[0].crouchtogglekeydown;
7122                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
7123                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
7124                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
7125                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
7126                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
7127
7128                                                 //concat[2]=(char)((int)(rotation/2)%180);
7129
7130                                                 //concat[3]=(char)((int)(rotation2/2)%180);
7131
7132                                                 chatname[0]=concat[0]-128;
7133                                                 chatname[1]=concat[1]-128;
7134                                                 //chatname[2]=concat[2]-128;
7135                                                 //chatname[3]=concat[3]-128;
7136                                                 int temppoint=2;
7137                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
7138                                                 temppoint+=sizeof(float);
7139                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
7140                                                 temppoint+=sizeof(float);
7141
7142                                                 chatname[temppoint]='\0';
7143
7144                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
7145                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
7146                                                 //keyrefreshdelay=.01;
7147                                                 keyrefreshdelay=.03;
7148                                                 }
7149
7150                                                 if(bigrefreshdelay<=0){
7151                                                 for(i=0;i<1;i++){
7152                                                 /*int temppoint=0;
7153                                                 memcpy(chatname+temppoint,&i,sizeof(int));
7154                                                 temppoint+=sizeof(int);
7155                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
7156                                                 temppoint+=sizeof(float);
7157                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
7158                                                 temppoint+=sizeof(float);
7159                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
7160                                                 temppoint+=sizeof(float);
7161                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
7162                                                 temppoint+=sizeof(float);
7163                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
7164                                                 temppoint+=sizeof(float);
7165                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
7166                                                 temppoint+=sizeof(int);
7167                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
7168                                                 temppoint+=sizeof(int);
7169                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
7170                                                 temppoint+=sizeof(float);
7171                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
7172                                                 temppoint+=sizeof(float);
7173                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
7174                                                 temppoint+=sizeof(float);
7175                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
7176                                                 temppoint+=sizeof(int);
7177                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
7178                                                 temppoint+=sizeof(int);
7179                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
7180                                                 temppoint+=sizeof(float);
7181                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
7182                                                 temppoint+=sizeof(float);
7183                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
7184                                                 temppoint+=sizeof(float);
7185                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
7186                                                 temppoint+=sizeof(int);
7187                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
7188                                                 temppoint+=sizeof(int);
7189                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
7190                                                 temppoint+=sizeof(int);
7191                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
7192                                                 temppoint+=sizeof(int);
7193                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
7194                                                 temppoint+=sizeof(int);
7195                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
7196                                                 temppoint+=sizeof(int);
7197                                                 chatname[temppoint]='\0';
7198
7199                                                 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);
7200                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
7201                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
7202
7203                                                 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);
7204
7205                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
7206                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
7207                                                 }
7208                                                 //bigrefreshdelay=.02;
7209                                                 bigrefreshdelay=.1;
7210                                                 }
7211                                                 }*/
7212
7213                                                 if(!player[0].jumpkeydown){
7214                                                         player[0].jumptogglekeydown=0;
7215                                                 }
7216                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
7217
7218
7219                                                 dialoguetime+=multiplier;
7220                                                 skybox.cloudmove+=multiplier;
7221                                                 hawkrotation+=multiplier*25;
7222                                                 realhawkcoords=0;
7223                                                 realhawkcoords.x=25;
7224                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
7225                                                 hawkcalldelay-=multiplier/2;
7226
7227                                                 if(hawkcalldelay<=0)
7228                                                 {
7229                                                         static float gLoc[3];
7230                                                         static float vel[3];
7231                                                         gLoc[0]=realhawkcoords.x;
7232                                                         gLoc[1]=realhawkcoords.y;
7233                                                         gLoc[2]=realhawkcoords.z;
7234                                                         vel[0]=0;
7235                                                         vel[1]=0;
7236                                                         vel[2]=0;
7237                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, TRUE);
7238                                                         FSOUND_3D_SetAttributes(channels[hawksound], gLoc, vel);
7239                                                         FSOUND_SetVolume(channels[hawksound], 128);
7240                                                         FSOUND_SetPaused(channels[hawksound], FALSE);
7241
7242                                                         hawkcalldelay=16+abs(Random()%8);
7243                                                 }
7244                                                 static float temptexdetail;
7245
7246
7247                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7248                                                         player[0].damagetolerance=200000;
7249                                                         player[0].damage=0;
7250                                                         player[0].burnt=0;
7251                                                         player[0].permanentdamage=0;
7252                                                         player[0].superpermanentdamage=0;
7253                                                         /*
7254                                                         int whichchar;
7255                                                         whichchar = abs(Random()%7);
7256                                                         registrationname[whichchar]+=1;
7257                                                         */
7258                                                 }
7259
7260                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7261                                                         environment++;
7262                                                         if(environment>2)environment=0;
7263                                                         Setenvironment(environment);
7264
7265                                                         envtogglekeydown=1;
7266                                                 }
7267
7268
7269                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7270                                                         envtogglekeydown=0;
7271                                                 }
7272
7273                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7274                                                         cameramode=1-cameramode;
7275                                                         cameratogglekeydown=1;
7276                                                 }
7277
7278                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7279                                                         cameratogglekeydown=0;
7280                                                 }
7281
7282                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7283                                                         if(player[0].num_weapons>0){
7284                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7285                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7286                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7287                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7288                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7289                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7290                                                                         weapons.length[player[0].weaponids[0]]=.8;
7291                                                                 }
7292                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7293                                                                         weapons.mass[player[0].weaponids[0]]=2;
7294                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7295                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7296                                                                 }
7297
7298                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7299                                                                         weapons.mass[player[0].weaponids[0]]=1;
7300                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7301                                                                         weapons.length[player[0].weaponids[0]]=.25;
7302                                                                 }
7303                                                         }
7304
7305                                                         /*for(i=0;i<objects.numobjects;i++){
7306                                                         if(objects.type[i]==treeleavestype){
7307                                                         for(j=0;j<objects.numobjects;j++){
7308                                                         if(objects.type[j]==treetrunktype)
7309                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7310                                                         objects.scale[i]=objects.scale[j];      
7311                                                         }
7312                                                         }
7313                                                         }*/
7314                                                         detailtogglekeydown=1;
7315                                                 }
7316
7317                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7318                                                         int closest=-1;
7319                                                         float closestdist=-1;
7320                                                         float distance;
7321                                                         if(numplayers>1)
7322                                                                 for(i=1;i<numplayers;i++){
7323                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7324                                                                         if(closestdist==-1||distance<closestdist){
7325                                                                                 closestdist=distance;
7326                                                                                 closest=i;
7327                                                                         }
7328                                                                 }
7329                                                                 if(closest!=-1){
7330                                                                         if(player[closest].num_weapons)
7331                                                                         {
7332                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7333                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7334                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7335                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7336                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7337                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7338                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7339                                                                                 }
7340                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7341                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7342                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7343                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7344                                                                                 }
7345                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7346                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7347                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7348                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7349                                                                                 }
7350                                                                         }
7351                                                                         if(!player[closest].num_weapons)
7352                                                                         {
7353                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7354                                                                                 weapons.owner[weapons.numweapons]=closest;
7355                                                                                 weapons.type[weapons.numweapons]=knife;
7356                                                                                 weapons.damage[weapons.numweapons]=0;
7357                                                                                 weapons.numweapons++;
7358                                                                                 player[closest].num_weapons=1;
7359                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7360                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7361                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7362                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7363                                                                                 }
7364                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7365                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7366                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7367                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7368                                                                                 }
7369                                                                         }
7370                                                                 }
7371                                                                 detailtogglekeydown=1;
7372                                                 }
7373
7374                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7375                                                         int closest=-1;
7376                                                         float closestdist=-1;
7377                                                         float distance;
7378                                                         if(numplayers>1)
7379                                                                 for(i=1;i<numplayers;i++){
7380                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7381                                                                         if(closestdist==-1||distance<closestdist){
7382                                                                                 closestdist=distance;
7383                                                                                 closest=i;
7384                                                                         }
7385                                                                 }
7386
7387                                                                 player[closest].rotation+=multiplier*50;
7388                                                                 player[closest].targetrotation=player[closest].rotation;
7389                                                 }
7390
7391
7392                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7393                                                         int closest=-1;
7394                                                         float closestdist=-1;
7395                                                         float distance;
7396                                                         if(numplayers>1)
7397                                                                 for(i=1;i<numplayers;i++){
7398                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7399                                                                         if(closestdist==-1||distance<closestdist){
7400                                                                                 closestdist=distance;
7401                                                                                 closest=i;
7402                                                                         }
7403                                                                 }
7404                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7405
7406                                                                 if(closest!=-1){
7407                                                                         player[closest].whichskin++;
7408                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7409                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7410
7411                                                                         if(player[closest].creature==rabbittype){
7412                                                                                 if(player[closest].whichskin==0){
7413                                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7414                                                                                 }
7415                                                                                 else if(player[closest].whichskin==1){
7416                                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7417                                                                                 }
7418                                                                                 else if(player[closest].whichskin==2){
7419                                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7420                                                                                 }
7421                                                                                 else if(player[closest].whichskin==3){
7422                                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7423                                                                                 }
7424                                                                                 else if(player[closest].whichskin==4){
7425                                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7426                                                                                 }
7427                                                                                 else if(player[closest].whichskin==5){
7428                                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7429                                                                                 }
7430                                                                                 else if(player[closest].whichskin==6){
7431                                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7432                                                                                 }
7433                                                                                 else if(player[closest].whichskin==7){
7434                                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7435                                                                                 }
7436                                                                                 else if(player[closest].whichskin==8){
7437                                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7438                                                                                 }
7439                                                                                 else if(player[closest].whichskin==9){
7440                                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7441                                                                                 }
7442                                                                         }
7443                                                                         if(player[closest].creature==wolftype){
7444                                                                                 k=abs(Random()%3);
7445                                                                                 if(player[closest].whichskin==0){
7446                                                                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7447                                                                                 }
7448                                                                                 else if(player[closest].whichskin==1){
7449                                                                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7450                                                                                 }
7451                                                                                 else if(player[closest].whichskin==2){
7452                                                                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7453                                                                                 }
7454                                                                         }
7455                                                                 }
7456
7457                                                                 if(player[closest].numclothes){
7458                                                                         for(i=0;i<player[closest].numclothes;i++){
7459                                                                                 tintr=player[closest].clothestintr[i];
7460                                                                                 tintg=player[closest].clothestintg[i];
7461                                                                                 tintb=player[closest].clothestintb[i];
7462                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7463                                                                         }
7464                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7465                                                                 }
7466
7467                                                                 detailtogglekeydown=1;
7468                                                 }
7469
7470                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7471                                                         int closest=-1;
7472                                                         float closestdist=-1;
7473                                                         float distance;
7474                                                         if(numplayers>1)
7475                                                                 for(i=1;i<numplayers;i++){
7476                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7477                                                                         if(closestdist==-1||distance<closestdist){
7478                                                                                 closestdist=distance;
7479                                                                                 closest=i;
7480                                                                         }
7481                                                                 }
7482                                                                 if(closest!=-1){
7483                                                                         if(player[closest].creature==wolftype){
7484                                                                                 headprop=player[closest].proportionhead.x/1.1;
7485                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7486                                                                                 armprop=player[closest].proportionarms.x/1.1;
7487                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7488                                                                         }
7489
7490                                                                         if(player[closest].creature==rabbittype){
7491                                                                                 headprop=player[closest].proportionhead.x/1.2;
7492                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7493                                                                                 armprop=player[closest].proportionarms.x/1.00;
7494                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7495                                                                         }
7496
7497
7498                                                                         if(player[closest].creature==rabbittype){
7499                                                                                 player[closest].skeleton.id=closest;
7500                                                                                 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);
7501                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7502                                                                                 player[closest].whichskin=0;
7503                                                                                 player[closest].creature=wolftype;
7504
7505                                                                                 player[closest].proportionhead=1.1;
7506                                                                                 player[closest].proportionbody=1.1;
7507                                                                                 player[closest].proportionarms=1.1;
7508                                                                                 player[closest].proportionlegs=1.1;
7509                                                                                 player[closest].proportionlegs.y=1.1;
7510                                                                                 player[closest].scale=.23*5*player[0].scale;
7511
7512                                                                                 player[closest].damagetolerance=300;
7513                                                                         }
7514                                                                         else
7515                                                                         {
7516                                                                                 player[closest].skeleton.id=closest;
7517                                                                                 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);
7518                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7519                                                                                 player[closest].whichskin=0;
7520                                                                                 player[closest].creature=rabbittype;
7521
7522                                                                                 player[closest].proportionhead=1.2;
7523                                                                                 player[closest].proportionbody=1.05;
7524                                                                                 player[closest].proportionarms=1.00;
7525                                                                                 player[closest].proportionlegs=1.1;
7526                                                                                 player[closest].proportionlegs.y=1.05;
7527                                                                                 player[closest].scale=.2*5*player[0].scale;
7528
7529                                                                                 player[closest].damagetolerance=200;
7530                                                                         }
7531
7532                                                                         if(player[closest].creature==wolftype){
7533                                                                                 player[closest].proportionhead=1.1*headprop;
7534                                                                                 player[closest].proportionbody=1.1*bodyprop;
7535                                                                                 player[closest].proportionarms=1.1*armprop;
7536                                                                                 player[closest].proportionlegs=1.1*legprop;
7537                                                                         }
7538
7539                                                                         if(player[closest].creature==rabbittype){
7540                                                                                 player[closest].proportionhead=1.2*headprop;
7541                                                                                 player[closest].proportionbody=1.05*bodyprop;
7542                                                                                 player[closest].proportionarms=1.00*armprop;
7543                                                                                 player[closest].proportionlegs=1.1*legprop;
7544                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7545                                                                         }
7546
7547                                                                 }
7548                                                                 detailtogglekeydown=1;
7549                                                 }
7550
7551                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7552                                                         detailtogglekeydown=0;
7553                                                 }
7554
7555                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7556                                                         slomo=1-slomo;
7557                                                         slomodelay=1000;
7558                                                         slomotogglekeydown=1;
7559                                                 }
7560
7561
7562                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7563                                                         int closest=-1;
7564                                                         float closestdist=-1;
7565                                                         float distance;
7566                                                         XYZ flatfacing2,flatvelocity2;
7567                                                         XYZ blah;
7568                                                         if(numplayers>1)
7569                                                                 for(i=1;i<numplayers;i++){
7570                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7571                                                                         if(distance<144&&!player[i].headless)
7572                                                                                 if(closestdist==-1||distance<closestdist){
7573                                                                                         closestdist=distance;
7574                                                                                         closest=i;
7575                                                                                         blah = player[i].coords;
7576                                                                                 }
7577                                                                 }
7578
7579                                                                 if(closest!=-1){                
7580                                                                         XYZ headspurtdirection;
7581                                                                         int i = player[closest].skeleton.jointlabels[head];
7582                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7583                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7584                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7585                                                                                 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;
7586                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7587                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7588                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7589                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7590                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7591                                                                                 Normalise(&headspurtdirection);
7592                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7593                                                                                 flatvelocity2+=headspurtdirection*8;
7594                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7595                                                                         }
7596                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7597
7598                                                                         float gLoc[3];
7599                                                                         float vel[3];
7600                                                                         gLoc[0]=blah.x;
7601                                                                         gLoc[1]=blah.y;
7602                                                                         gLoc[2]=blah.z;
7603                                                                         vel[0]=0;
7604                                                                         vel[1]=0;
7605                                                                         vel[2]=0;
7606                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
7607                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7608                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7609                                                                         FSOUND_SetPaused(channels[splattersound], FALSE);
7610
7611                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
7612                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7613                                                                         FSOUND_SetVolume(channels[breaksound2], 100);
7614                                                                         FSOUND_SetPaused(channels[breaksound2], FALSE);
7615
7616                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7617                                                                         player[closest].RagDoll(0);
7618                                                                         player[closest].dead=2;
7619                                                                         player[closest].headless=1;
7620                                                                         player[closest].DoBloodBig(3,165);
7621
7622                                                                         camerashake+=.3;
7623                                                                 }
7624
7625                                                                 explodetogglekeydown=1;
7626                                                 }
7627
7628                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7629                                                         int closest=-1;
7630                                                         float closestdist=-1;
7631                                                         float distance;
7632                                                         XYZ flatfacing2,flatvelocity2;
7633                                                         XYZ blah;
7634                                                         if(numplayers>1)
7635                                                                 for(i=1;i<numplayers;i++){
7636                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7637                                                                         if(distance<144)
7638                                                                                 if(closestdist==-1||distance<closestdist){
7639                                                                                         closestdist=distance;
7640                                                                                         closest=i;
7641                                                                                         blah=player[i].coords;
7642                                                                                 }
7643                                                                 }
7644
7645                                                                 if(closest!=-1){                
7646                                                                         float gLoc[3];
7647                                                                         float vel[3];
7648                                                                         gLoc[0]=blah.x;
7649                                                                         gLoc[1]=blah.y;
7650                                                                         gLoc[2]=blah.z;
7651                                                                         vel[0]=0;
7652                                                                         vel[1]=0;
7653                                                                         vel[2]=0;
7654
7655                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, TRUE);
7656                                                                         FSOUND_3D_SetAttributes(channels[splattersound], gLoc, vel);
7657                                                                         FSOUND_SetVolume(channels[splattersound], 256);
7658                                                                         FSOUND_SetPaused(channels[splattersound], FALSE);
7659
7660                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE);
7661                                                                         FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7662                                                                         FSOUND_SetVolume(channels[breaksound2], 600);
7663                                                                         FSOUND_SetPaused(channels[breaksound2], FALSE);
7664
7665                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7666                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7667                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7668                                                                                 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;
7669                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7670                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7671                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7672                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7673                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7674                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7675                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7676                                                                         }
7677
7678                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7679                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7680                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7681                                                                                 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;
7682                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7683                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7684                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7685                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7686                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7687                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7688                                                                         }
7689
7690                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7691                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7692                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7693                                                                                 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;
7694                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7695                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7696                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7697                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7698                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7699                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7700                                                                         }
7701
7702                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7703                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7704                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7705                                                                                 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;
7706                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7707                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7708                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7709                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7710                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7711                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7712                                                                         }
7713
7714                                                                         XYZ temppos;
7715                                                                         for(j=0;j<numplayers; j++){
7716                                                                                 if(j!=closest){
7717                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7718                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7719                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7720                                                                                                 player[j].skeleton.longdead=0;
7721                                                                                                 player[j].RagDoll(0);
7722                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7723                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7724                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7725                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7726                                                                                                                 Normalise(&flatvelocity2);
7727                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7728                                                                                                         }
7729                                                                                                 }
7730                                                                                         }
7731                                                                                 }
7732                                                                         }
7733
7734                                                                         player[closest].DoDamage(10000);
7735                                                                         player[closest].RagDoll(0);
7736                                                                         player[closest].dead=2;
7737                                                                         player[closest].coords=20;
7738                                                                         player[closest].skeleton.free=2;
7739
7740                                                                         camerashake+=.6;
7741
7742                                                                 }
7743
7744                                                                 explodetogglekeydown=1;
7745                                                 }
7746
7747                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7748                                                         explodetogglekeydown=0;
7749                                                 }
7750
7751                                                 /*
7752                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7753                                                 FILE                    *tfile;
7754                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7755                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7756                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7757                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7758                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7759                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7760                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7761
7762                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7763                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7764                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7765                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7766                                                 for(j=0;j<player[0].num_weapons;j++){
7767                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7768                                                 }
7769                                                 fwrite( &environment, 1, sizeof(int), tfile );
7770
7771                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7772                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7773                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7774                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7775                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7776
7777                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7778                                                 if(numplayers>1&&numplayers<maxplayers)
7779                                                 for(i=1;i<numplayers;i++){
7780                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7781                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7782                                                 for(j=0;j<player[i].num_weapons;j++){
7783                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7784                                                 }
7785                                                 if(player[i].numwaypoints<30){
7786                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7787                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7788                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7789                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7790                                                 }
7791                                                 else{
7792                                                 player[i].numwaypoints=0;
7793                                                 player[i].waypoint=0;
7794                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7795                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7796                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7797                                                 }
7798                                                 }
7799
7800                                                 fclose(tfile);
7801
7802                                                 slomotogglekeydown=1;
7803                                                 }*/
7804
7805                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7806                                                         slomotogglekeydown=0;
7807                                                 }
7808
7809
7810                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7811                                                         player[0].onfire=1-player[0].onfire;
7812                                                         if(player[0].onfire){
7813                                                                 player[0].CatchFire();
7814                                                         }
7815                                                         if(!player[0].onfire){
7816                                                                 float gLoc[3];
7817                                                                 float vel[3];
7818                                                                 gLoc[0]=player[0].coords.x;
7819                                                                 gLoc[1]=player[0].coords.y;
7820                                                                 gLoc[2]=player[0].coords.z;
7821                                                                 vel[0]=0;
7822                                                                 vel[1]=0;
7823                                                                 vel[2]=0;
7824                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
7825                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7826                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
7827                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
7828                                                                 FSOUND_SetPaused(channels[stream_firesound], TRUE);
7829                                                         }
7830                                                         slomotogglekeydown=1;
7831                                                 }
7832                                                 /*
7833                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7834                                                 if(player[0].bleeding<=0)
7835                                                 player[0].DoBlood(1,255);
7836                                                 }*/
7837
7838
7839                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7840                                                         int closest=-1;
7841                                                         float closestdist=-1;
7842                                                         float distance;
7843                                                         if(numplayers>1)
7844                                                                 for(i=1;i<numplayers;i++){
7845                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7846                                                                         if(closestdist==-1||distance<closestdist){
7847                                                                                 closestdist=distance;
7848                                                                                 closest=i;
7849                                                                         }
7850                                                                 }
7851                                                                 if(closestdist>0&&closest>=0){
7852                                                                         //player[closest]=player[numplayers-1];
7853                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7854                                                                         numplayers--;
7855                                                                 }
7856                                                                 drawmodetogglekeydown=1;
7857                                                 }
7858
7859                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7860                                                         int closest=-1;
7861                                                         float closestdist=-1;
7862                                                         float distance;
7863                                                         if(max_objects>1)
7864                                                                 for(i=1;i<max_objects;i++){
7865                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7866                                                                         if(closestdist==-1||distance<closestdist){
7867                                                                                 closestdist=distance;
7868                                                                                 closest=i;
7869                                                                         }
7870                                                                 }
7871                                                                 if(closestdist>0&&closest>=0){
7872                                                                         objects.position[closest].y-=500;
7873                                                                 }
7874                                                                 drawmodetogglekeydown=1;
7875                                                 }
7876
7877                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7878                                                         //drawmode++;
7879                                                         //if(drawmode>2)drawmode=0;
7880                                                         if(objects.numobjects<max_objects-1){                   
7881                                                                 XYZ boxcoords;
7882                                                                 boxcoords.x=player[0].coords.x;
7883                                                                 boxcoords.z=player[0].coords.z;
7884                                                                 boxcoords.y=player[0].coords.y-3;
7885                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7886                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7887                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7888                                                                 float temprotat,temprotat2;
7889                                                                 temprotat=editorrotation;
7890                                                                 temprotat2=editorrotation2;
7891                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7892                                                                 if(temprotat2<0)temprotat2=Random()%360;
7893
7894                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7895                                                                 if(editortype==treetrunktype)
7896                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7897                                                         }
7898
7899                                                         drawmodetogglekeydown=1;
7900                                                 }
7901
7902                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7903                                                         if(numplayers<maxplayers-1){
7904                                                                 player[numplayers].scale=.2*5*player[0].scale;
7905                                                                 player[numplayers].creature=rabbittype;
7906                                                                 player[numplayers].howactive=editoractive;
7907                                                                 player[numplayers].skeleton.id=numplayers;
7908                                                                 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);
7909
7910                                                                 //texsize=512*512*3/texdetail/texdetail;
7911                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7912                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7913
7914                                                                 k=abs(Random()%2)+1;
7915                                                                 if(k==0){
7916                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7917                                                                         player[numplayers].whichskin=0;
7918                                                                 }
7919                                                                 else if(k==1){
7920                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7921                                                                         player[numplayers].whichskin=1;
7922                                                                 }
7923                                                                 else {
7924                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7925                                                                         player[numplayers].whichskin=2;
7926                                                                 }
7927
7928                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7929                                                                 player[numplayers].power=1;
7930                                                                 player[numplayers].speedmult=1;
7931                                                                 player[numplayers].currentanimation=bounceidleanim;
7932                                                                 player[numplayers].targetanimation=bounceidleanim;
7933                                                                 player[numplayers].currentframe=0;
7934                                                                 player[numplayers].targetframe=1;
7935                                                                 player[numplayers].target=0;
7936                                                                 player[numplayers].bled=0;
7937                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
7938
7939                                                                 player[numplayers].targetrotation=player[0].targetrotation;
7940                                                                 player[numplayers].rotation=player[0].rotation;
7941
7942                                                                 player[numplayers].velocity=0;
7943                                                                 player[numplayers].coords=player[0].coords;
7944                                                                 player[numplayers].oldcoords=player[numplayers].coords;
7945                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
7946
7947                                                                 player[numplayers].id=numplayers;
7948                                                                 player[numplayers].skeleton.id=numplayers;
7949                                                                 player[numplayers].updatedelay=0;
7950                                                                 player[numplayers].normalsupdatedelay=0;
7951
7952                                                                 player[numplayers].aitype=passivetype;
7953                                                                 player[numplayers].aitarget=0;
7954
7955                                                                 if(player[0].creature==wolftype){
7956                                                                         headprop=player[0].proportionhead.x/1.1;
7957                                                                         bodyprop=player[0].proportionbody.x/1.1;
7958                                                                         armprop=player[0].proportionarms.x/1.1;
7959                                                                         legprop=player[0].proportionlegs.x/1.1;
7960                                                                 }
7961
7962                                                                 if(player[0].creature==rabbittype){
7963                                                                         headprop=player[0].proportionhead.x/1.2;
7964                                                                         bodyprop=player[0].proportionbody.x/1.05;
7965                                                                         armprop=player[0].proportionarms.x/1.00;
7966                                                                         legprop=player[0].proportionlegs.x/1.1;
7967                                                                 }
7968
7969                                                                 if(player[numplayers].creature==wolftype){
7970                                                                         player[numplayers].proportionhead=1.1*headprop;
7971                                                                         player[numplayers].proportionbody=1.1*bodyprop;
7972                                                                         player[numplayers].proportionarms=1.1*armprop;
7973                                                                         player[numplayers].proportionlegs=1.1*legprop;
7974                                                                 }
7975
7976                                                                 if(player[numplayers].creature==rabbittype){
7977                                                                         player[numplayers].proportionhead=1.2*headprop;
7978                                                                         player[numplayers].proportionbody=1.05*bodyprop;
7979                                                                         player[numplayers].proportionarms=1.00*armprop;
7980                                                                         player[numplayers].proportionlegs=1.1*legprop;
7981                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
7982                                                                 }
7983
7984                                                                 player[numplayers].headless=0;
7985                                                                 player[numplayers].onfire=0;
7986
7987                                                                 if(cellophane){
7988                                                                         player[numplayers].proportionhead.z=0;
7989                                                                         player[numplayers].proportionbody.z=0;
7990                                                                         player[numplayers].proportionarms.z=0;
7991                                                                         player[numplayers].proportionlegs.z=0;
7992                                                                 }
7993
7994                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
7995
7996                                                                 player[numplayers].damagetolerance=200;
7997
7998                                                                 player[numplayers].protectionhead=player[0].protectionhead;
7999                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
8000                                                                 player[numplayers].protectionlow=player[0].protectionlow;
8001                                                                 player[numplayers].armorhead=player[0].armorhead;
8002                                                                 player[numplayers].armorhigh=player[0].armorhigh;
8003                                                                 player[numplayers].armorlow=player[0].armorlow;
8004                                                                 player[numplayers].metalhead=player[0].metalhead;
8005                                                                 player[numplayers].metalhigh=player[0].metalhigh;
8006                                                                 player[numplayers].metallow=player[0].metallow;
8007
8008                                                                 player[numplayers].immobile=player[0].immobile;
8009
8010                                                                 player[numplayers].numclothes=player[0].numclothes;
8011                                                                 if(player[numplayers].numclothes)
8012                                                                         for(i=0;i<player[numplayers].numclothes;i++){
8013                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
8014                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
8015                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
8016                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
8017                                                                                 tintr=player[numplayers].clothestintr[i];
8018                                                                                 tintg=player[numplayers].clothestintg[i];
8019                                                                                 tintb=player[numplayers].clothestintb[i];
8020                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8021                                                                         }
8022                                                                         if(player[numplayers].numclothes){
8023                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
8024                                                                         }
8025
8026                                                                         player[numplayers].power=player[0].power;
8027                                                                         player[numplayers].speedmult=player[0].speedmult;
8028
8029                                                                         player[numplayers].damage=0;
8030                                                                         player[numplayers].permanentdamage=0;
8031                                                                         player[numplayers].superpermanentdamage=0;
8032                                                                         player[numplayers].deathbleeding=0;
8033                                                                         player[numplayers].bleeding=0;
8034                                                                         player[numplayers].numwaypoints=0;
8035                                                                         player[numplayers].waypoint=0;
8036                                                                         player[numplayers].jumppath=0;
8037                                                                         player[numplayers].weaponstuck=-1;
8038                                                                         player[numplayers].weaponactive=-1;
8039                                                                         player[numplayers].num_weapons=0;
8040                                                                         player[numplayers].bloodloss=0;
8041                                                                         player[numplayers].dead=0;
8042
8043                                                                         player[numplayers].loaded=1;
8044
8045                                                                         numplayers++;
8046                                                         }
8047                                                         drawmodetogglekeydown=1;
8048                                                 }
8049
8050                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
8051                                                         if(player[numplayers-1].numwaypoints<90){
8052                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
8053                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
8054                                                                 player[numplayers-1].numwaypoints++;
8055                                                         }
8056                                                         drawmodetogglekeydown=1;
8057                                                 }
8058
8059                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
8060                                                         if(numpathpoints<30){
8061                                                                 bool connected,alreadyconnected;
8062                                                                 connected=0;
8063                                                                 if(numpathpoints>1)
8064                                                                         for(i=0;i<numpathpoints;i++){
8065                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
8066                                                                                         alreadyconnected=0;
8067                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
8068                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
8069                                                                                         }
8070                                                                                         if(!alreadyconnected){
8071                                                                                                 numpathpointconnect[pathpointselected]++;
8072                                                                                                 connected=1;
8073                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
8074                                                                                         }
8075                                                                                 }
8076                                                                         }
8077                                                                         if(!connected){
8078                                                                                 numpathpoints++;
8079                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
8080                                                                                 numpathpointconnect[numpathpoints-1]=0;
8081                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
8082                                                                                         numpathpointconnect[pathpointselected]++;
8083                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
8084                                                                                 }
8085                                                                                 pathpointselected=numpathpoints-1;
8086                                                                         }
8087                                                         }
8088                                                         drawmodetogglekeydown=1;
8089                                                 }
8090
8091                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
8092                                                         pathpointselected++;
8093                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
8094                                                         drawmodetogglekeydown=1;
8095                                                 }
8096                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8097                                                         pathpointselected--;
8098                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
8099                                                         drawmodetogglekeydown=1;
8100                                                 }
8101                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8102                                                         if(pathpointselected!=-1){
8103                                                                 numpathpoints--;
8104                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
8105                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
8106                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
8107                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
8108                                                                 }
8109                                                                 for(i=0;i<numpathpoints;i++){
8110                                                                         for(j=0;j<numpathpointconnect[i];j++){
8111                                                                                 if(pathpointconnect[i][j]==pathpointselected){
8112                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
8113                                                                                         numpathpointconnect[i]--;
8114                                                                                 }
8115                                                                                 if(pathpointconnect[i][j]==numpathpoints){
8116                                                                                         pathpointconnect[i][j]=pathpointselected;
8117                                                                                 }
8118                                                                         }
8119                                                                 }
8120                                                                 pathpointselected=numpathpoints-1;
8121                                                         }
8122                                                         drawmodetogglekeydown=1;
8123                                                 }
8124
8125                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
8126                                                         editorenabled=1-editorenabled;
8127                                                         if(editorenabled){
8128                                                                 player[0].damagetolerance=100000;
8129                                                                 player[0].damage=0;
8130                                                                 player[0].superpermanentdamage=0;
8131                                                                 player[0].bloodloss=0;
8132                                                                 player[0].deathbleeding=0;
8133                                                         }
8134                                                         if(!editorenabled){
8135                                                                 player[0].damagetolerance=200;
8136                                                                 player[0].damage=0;
8137                                                                 player[0].permanentdamage=0;
8138                                                                 player[0].superpermanentdamage=0;
8139                                                                 player[0].bloodloss=0;
8140                                                                 player[0].deathbleeding=0;
8141                                                         }
8142                                                         drawmodetogglekeydown=1;
8143                                                 }
8144
8145                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8146                                                         editortype--;
8147                                                         if(editortype==treeleavestype||editortype==10)editortype--;
8148                                                         if(editortype<0)editortype=firetype;
8149                                                         drawmodetogglekeydown=1;
8150                                                 }
8151
8152                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8153                                                         editortype++;
8154                                                         if(editortype==treeleavestype||editortype==10)editortype++;
8155                                                         if(editortype>firetype)editortype=0;
8156                                                         drawmodetogglekeydown=1;
8157                                                 }
8158
8159                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8160                                                         editorrotation-=multiplier*100;
8161                                                         if(editorrotation<-.01)editorrotation=-.01;
8162                                                         drawmodetogglekeydown=1;
8163                                                 }
8164
8165                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8166                                                         editorrotation+=multiplier*100;
8167                                                         drawmodetogglekeydown=1;
8168                                                 }
8169
8170                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8171                                                         editorsize+=multiplier;
8172                                                         drawmodetogglekeydown=1;
8173                                                 }
8174
8175                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8176                                                         editorsize-=multiplier;
8177                                                         if(editorsize<.1)editorsize=.1;
8178                                                         drawmodetogglekeydown=1;
8179                                                 }
8180
8181
8182                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8183                                                         mapradius-=multiplier*10;
8184                                                 }
8185
8186                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8187                                                         mapradius+=multiplier*10;
8188                                                 }
8189                                                 /*
8190                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8191                                                 mapcenter.x+=multiplier*20;
8192                                                 }
8193
8194                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8195                                                 mapcenter.x-=multiplier*20;
8196                                                 }
8197
8198                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8199                                                 mapcenter.z+=multiplier*20;
8200                                                 }
8201
8202                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8203                                                 mapcenter.z-=multiplier*20;
8204                                                 }
8205                                                 */
8206                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8207                                                         editorrotation2+=multiplier*100;
8208                                                 }
8209
8210                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8211                                                         editorrotation2-=multiplier*100;
8212                                                         if(editorrotation2<-.01)editorrotation2=-.01;
8213                                                 }
8214                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
8215                                                         int closest=-1;
8216                                                         float closestdist=-1;
8217                                                         float distance;
8218                                                         for(i=0;i<objects.numobjects;i++){
8219                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
8220                                                                 if(closestdist==-1||distance<closestdist){
8221                                                                         closestdist=distance;
8222                                                                         closest=i;
8223                                                                 }
8224                                                         }
8225                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);             
8226                                                         drawmodetogglekeydown=1;
8227                                                 }
8228
8229
8230                                                 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)){
8231                                                         drawmodetogglekeydown=0;
8232                                                 }
8233
8234                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8235                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8236                                                         player[0].RagDoll(0);
8237                                                         //player[0].spurt=1;
8238                                                         //player[0].DoDamage(1000);
8239
8240                                                         float gLoc[3];
8241                                                         float vel[3];
8242                                                         gLoc[0]=player[0].coords.x;
8243                                                         gLoc[1]=player[0].coords.y;
8244                                                         gLoc[2]=player[0].coords.z;
8245                                                         vel[0]=player[0].velocity.x;
8246                                                         vel[1]=player[0].velocity.y;
8247                                                         vel[2]=player[0].velocity.z;
8248                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
8249                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8250                                                         FSOUND_SetVolume(channels[whooshsound], 128);
8251                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
8252                                                         //FSOUND_SetPaused(channels[whooshsound], TRUE);
8253
8254                                                         texturesizetogglekeydown=1;
8255                                                 }
8256
8257                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8258
8259                                                         int closest=-1;
8260                                                         float closestdist=-1;
8261                                                         float distance;
8262                                                         for(i=0;i<objects.numobjects;i++){
8263                                                                 if(objects.type[i]==treeleavestype){
8264                                                                         objects.scale[i]*=.9;
8265                                                                 }
8266                                                         }
8267                                                         texturesizetogglekeydown=1;
8268                                                 }
8269
8270                                                 static XYZ relative;
8271                                                 static int randattack;
8272                                                 //Attack
8273                                                 static bool playerrealattackkeydown=0;
8274
8275                                                 if(!buttons[0])oldbutton=0;
8276                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8277                                                 if(oldattackkey)player[0].attackkeydown=0;
8278                                                 if(oldattackkey)playerrealattackkeydown=0;
8279                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8280                                                 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);
8281                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8282                                                         for(k=0;k<numplayers;k++){
8283                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8284                                                                         player[k].Reverse();
8285                                                         }
8286                                                 }
8287
8288                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8289
8290                                                 for(k=0;k<numplayers;k++){
8291                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8292                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8293                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
8294                                                                 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)){
8295                                                                         player[k].jumppower-=2;
8296                                                                 }
8297                                                                 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)){
8298                                                                         for(i=0;i<numplayers;i++){
8299                                                                                 if(i==k)i++;
8300                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8301                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8302                                                                                                 player[k].targetanimation=dodgebackanim;
8303                                                                                                 player[k].target=0;
8304                                                                                                 player[k].targetframe=0;
8305                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8306                                                                                                 Normalise(&rotatetarget);
8307                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8308                                                                                                 player[k].targetrotation*=360/6.28;
8309                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8310
8311                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8312                                                                                         }
8313                                                                         }
8314                                                                         if(player[k].targetanimation!=dodgebackanim){
8315                                                                                 if(k==0)numflipped++;
8316                                                                                 player[k].targetanimation=backhandspringanim;
8317                                                                                 player[k].target=0;
8318                                                                                 player[k].targetframe=0;
8319                                                                                 player[k].targetrotation=-rotation+180;
8320                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8321                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8322                                                                                 player[k].rotation=player[k].targetrotation;
8323                                                                                 player[k].jumppower-=2;
8324                                                                         }
8325                                                                 }
8326                                                                 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())){
8327                                                                         player[k].hasvictim=0;
8328                                                                         if(numplayers>1)
8329                                                                                 for(i=0;i<numplayers;i++){
8330                                                                                         if(i==k)i++;
8331                                                                                         if(!player[k].hasvictim)
8332                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){      
8333                                                                                                         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){
8334                                                                                                                 player[k].victim=&player[i];
8335                                                                                                                 player[k].hasvictim=1;
8336                                                                                                                 if(player[k].aitype==playercontrolled){
8337                                                                                                                         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;
8338                                                                                                                         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;
8339                                                                                                                         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;
8340                                                                                                                         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;
8341                                                                                                                         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;
8342                                                                                                                         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;
8343                                                                                                                         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;
8344                                                                                                                         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;
8345                                                                                                                         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;
8346                                                                                                                         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;
8347                                                                                                                 }
8348                                                                                                                 else {
8349                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8350                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8351                                                                                                                                 else randattack=abs(Random()%5);
8352                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8353                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8354                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8355                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8356                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8357                                                                                                                                 }
8358                                                                                                                                 if(player[k].weaponactive!=-1){
8359                                                                                                                                         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;
8360                                                                                                                                         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;
8361                                                                                                                                         //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;
8362                                                                                                                                         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;
8363                                                                                                                                         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;
8364                                                                                                                                         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;
8365                                                                                                                                         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;
8366                                                                                                                                         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;
8367                                                                                                                                 }
8368                                                                                                                         }
8369                                                                                                                 }
8370                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8371                                                                                                         }
8372                                                                                                         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)){
8373                                                                                                                 if(player[k].weaponactive==-1){
8374                                                                                                                         player[i].targetanimation=sneakattackedanim;
8375                                                                                                                         player[i].currentanimation=sneakattackedanim;
8376                                                                                                                         player[k].currentanimation=sneakattackanim;
8377                                                                                                                         player[k].targetanimation=sneakattackanim;
8378                                                                                                                         player[k].oldcoords=player[k].coords;
8379                                                                                                                         player[k].coords=player[i].coords;
8380                                                                                                                 }
8381                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8382                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8383                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8384                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8385                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8386                                                                                                                         player[i].oldcoords=player[i].coords;
8387                                                                                                                         player[i].coords=player[k].coords;
8388                                                                                                                 }
8389                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8390                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8391                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8392                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8393                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8394                                                                                                                         player[i].oldcoords=player[i].coords;
8395                                                                                                                         player[i].coords=player[k].coords;
8396                                                                                                                 }
8397                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8398                                                                                                                         player[k].victim=&player[i];
8399                                                                                                                         player[k].hasvictim=1;
8400                                                                                                                         player[i].targettilt2=0;
8401                                                                                                                         player[i].targetframe=1;
8402                                                                                                                         player[i].currentframe=0;
8403                                                                                                                         player[i].target=0;
8404                                                                                                                         player[i].velocity=0;
8405                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8406                                                                                                                         player[k].currentframe=player[i].currentframe;
8407                                                                                                                         player[k].targetframe=player[i].targetframe;
8408                                                                                                                         player[k].target=player[i].target;
8409                                                                                                                         player[k].velocity=0;
8410                                                                                                                         player[k].targetrotation=player[i].rotation;
8411                                                                                                                         player[k].rotation=player[i].rotation;
8412                                                                                                                         player[i].targetrotation=player[i].rotation;
8413                                                                                                                 }
8414                                                                                                         }
8415                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8416                                                                                                                 oldattackkey=1;
8417                                                                                                                 player[k].targetframe=0;
8418                                                                                                                 player[k].target=0;
8419                                                                                                                 //player[k].velocity=0;
8420
8421                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8422                                                                                                                 Normalise(&rotatetarget);
8423                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8424                                                                                                                 player[k].targetrotation*=360/6.28;
8425                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8426
8427                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8428
8429                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8430                                                                                                                 player[k].lastattack2=player[k].lastattack;
8431                                                                                                                 player[k].lastattack=player[k].targetanimation;
8432                                                                                                                 //player[k].targettilt2=0;
8433                                                                                                                 //slomo=1;
8434                                                                                                                 //slomodelay=.2;
8435                                                                                                         }
8436                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8437                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8438                                                                                                                 Normalise(&rotatetarget);
8439                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8440                                                                                                                 player[k].targetrotation*=360/6.28;
8441                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8442                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8443                                                                                                                 oldattackkey=1;
8444                                                                                                                 player[k].victim=&player[i];
8445                                                                                                                 player[k].hasvictim=1;
8446                                                                                                                 player[i].targetanimation=knifefollowedanim;
8447                                                                                                                 player[i].currentanimation=knifefollowedanim;
8448                                                                                                                 player[i].targettilt2=0;
8449                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8450                                                                                                                 player[i].targetframe=1;
8451                                                                                                                 player[i].currentframe=0;
8452                                                                                                                 player[i].target=0;
8453                                                                                                                 player[i].velocity=0;
8454                                                                                                                 player[k].currentanimation=knifefollowanim;
8455                                                                                                                 player[k].targetanimation=knifefollowanim;
8456                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8457                                                                                                                 player[k].currentframe=player[i].currentframe;
8458                                                                                                                 player[k].targetframe=player[i].targetframe;
8459                                                                                                                 player[k].target=player[i].target;
8460                                                                                                                 player[k].velocity=0;
8461                                                                                                                 player[k].oldcoords=player[k].coords;
8462                                                                                                                 player[i].coords=player[k].coords;
8463                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8464                                                                                                                 player[i].rotation=player[k].targetrotation;
8465                                                                                                                 player[k].rotation=player[k].targetrotation;
8466                                                                                                                 player[i].rotation=player[k].targetrotation;
8467                                                                                                         }
8468                                                                                                 }
8469                                                                                 }
8470                                                                                 bool hasstaff=0;
8471                                                                                 if(player[k].weaponactive!=-1){
8472                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8473                                                                                 }
8474                                                                                 if(numplayers>1)
8475                                                                                         for(i=0;i<numplayers;i++){
8476                                                                                                 if(i==k)i++;
8477                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){   
8478                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8479                                                                                                                 if(player[i].skeleton.free)
8480                                                                                                                         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)))){
8481                                                                                                                                 player[k].victim=&player[i];
8482                                                                                                                                 player[k].hasvictim=1;
8483                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8484                                                                                                                                         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;
8485                                                                                                                                         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;
8486                                                                                                                                         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;
8487                                                                                                                                 }
8488                                                                                                                                 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){
8489                                                                                                                                         player[k].targetanimation=killanim;
8490                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8491                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8492                                                                                                                                                         terrain.DeleteDecal(j);
8493                                                                                                                                                 }
8494                                                                                                                                         }
8495                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8496                                                                                                                                                 if(objects.model[l].type==decalstype)
8497                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8498                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8499                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8500                                                                                                                                                                 }
8501                                                                                                                                                         }
8502                                                                                                                                         }
8503                                                                                                                                 }
8504                                                                                                                                 if(!player[i].dead||musictype!=2)
8505                                                                                                                                         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)){
8506                                                                                                                                                 player[k].targetanimation=dropkickanim;
8507                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8508                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8509                                                                                                                                                                 terrain.DeleteDecal(j);
8510                                                                                                                                                         }
8511                                                                                                                                                 }
8512                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8513                                                                                                                                                         if(objects.model[l].type==decalstype)
8514                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8515                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8516                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8517                                                                                                                                                                         }
8518                                                                                                                                                                 }
8519                                                                                                                                                 }
8520                                                                                                                                         }
8521                                                                                                                         }
8522                                                                                                                         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)){
8523                                                                                                                                 oldattackkey=1;
8524                                                                                                                                 player[k].targetframe=0;
8525                                                                                                                                 player[k].target=0;
8526                                                                                                                                 //player[k].velocity=0;
8527
8528                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8529                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8530                                                                                                                                         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;
8531                                                                                                                                 }
8532                                                                                                                                 Normalise(&rotatetarget);
8533                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8534                                                                                                                                 player[k].targetrotation*=360/6.28;
8535                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8536
8537                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8538                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8539                                                                                                                                 }
8540
8541                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8542                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8543
8544                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8545                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8546                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8547
8548                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8549                                                                                                                                         player[k].targetrotation+=30;
8550                                                                                                                                 }
8551                                                                                                                                 //player[k].targettilt2=0;
8552                                                                                                                                 //slomo=1;
8553                                                                                                                                 //slomodelay=.2;
8554                                                                                                                         }
8555                                                                                                 }
8556                                                                                         }
8557                                                                                         if(!player[k].hasvictim){
8558                                                                                                 for(i=0;i<numplayers;i++){
8559                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8560                                                                                                                 player[k].victim=&player[i];
8561                                                                                                                 player[k].hasvictim=1;
8562                                                                                                         }
8563                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8564                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8565                                                                                                                         player[k].victim=&player[i];
8566                                                                                                                 }
8567                                                                                                 }
8568                                                                                         }
8569                                                                                         if(player[k].aitype==playercontrolled)
8570                                                                                                 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)){
8571                                                                                                         oldattackkey=1;
8572                                                                                                         player[k].targetanimation=rabbitkickanim;
8573                                                                                                         player[k].targetframe=0;
8574                                                                                                         player[k].target=0;
8575                                                                                                 }
8576                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8577                                                                                                         numattacks++;
8578                                                                                                         bool armedstaff=0;
8579                                                                                                         if(player[k].weaponactive!=-1){
8580                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8581                                                                                                         }
8582                                                                                                         bool armedsword=0;
8583                                                                                                         if(player[k].weaponactive!=-1){
8584                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8585                                                                                                         }
8586                                                                                                         bool armedknife=0;
8587                                                                                                         if(player[k].weaponactive!=-1){
8588                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8589                                                                                                         }
8590                                                                                                         if(armedstaff)numstaffattack++;
8591                                                                                                         else if(armedsword)numswordattack++;
8592                                                                                                         else if(armedknife)numknifeattack++;
8593                                                                                                         else numunarmedattack++;
8594                                                                                                 }
8595                                                                 }
8596                                                         }
8597                                                 }
8598
8599                                                 //Collisions
8600                                                 static float collisionradius;
8601                                                 if(numplayers>1)
8602                                                         for(k=0;k<numplayers;k++){
8603                                                                 for(i=k;i<numplayers;i++){
8604                                                                         if(i==k)i++;
8605                                                                         if(i<numplayers)
8606                                                                                 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))
8607                                                                                         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))
8608                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8609                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8610                                                                                                                 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)
8611                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8612                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8613                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8614                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8615                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8616                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8617                                                                                                                                                                         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)){
8618                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8619                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8620                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8621                                                                                                                                                                                 }       
8622                                                                                                                                                                         }
8623
8624                                                                                                                                                                         tempcoords1=player[i].coords;
8625                                                                                                                                                                         tempcoords2=player[k].coords;
8626                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8627                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8628                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8629                                                                                                                                                                         if(player[0].hasvictim)
8630                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8631                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){   
8632                                                                                                                                                                                 if(k==0)
8633                                                                                                                                                                                         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)){
8634                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8635                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8636                                                                                                                                                                                                 player[i].skeleton.free=0;
8637                                                                                                                                                                                                 player[i].rotation=0;
8638                                                                                                                                                                                                 player[i].RagDoll(0);
8639                                                                                                                                                                                                 player[i].DoDamage(20);
8640                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8641                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8642                                                                                                                                                                                                 player[k].lastcollide=1;        
8643                                                                                                                                                                                         }
8644                                                                                                                                                                                         if(i==0)
8645                                                                                                                                                                                                 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)){
8646                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8647                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8648                                                                                                                                                                                                         player[k].skeleton.free=0;
8649                                                                                                                                                                                                         player[k].rotation=0;
8650                                                                                                                                                                                                         player[k].RagDoll(0);
8651                                                                                                                                                                                                         player[k].DoDamage(20);
8652                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8653                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8654                                                                                                                                                                                                         player[i].lastcollide=1;        
8655                                                                                                                                                                                                 }
8656
8657                                                                                                                                                                                                 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)){     
8658                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8659                                                                                                                                                                                                         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))
8660                                                                                                                                                                                                                 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))){
8661                                                                                                                                                                                                                         //If hit by body
8662                                                                                                                                                                                                                         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)){
8663                                                                                                                                                                                                                                 static float gLoc[3];
8664                                                                                                                                                                                                                                 static float vel[3];
8665                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8666                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8667                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8668                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8669                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8670                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8671                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8672                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, TRUE);
8673                                                                                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8674                                                                                                                                                                                                                                         FSOUND_SetVolume(channels[heavyimpactsound], 256);
8675                                                                                                                                                                                                                                         FSOUND_SetPaused(channels[heavyimpactsound], FALSE);
8676                                                                                                                                                                                                                                 }
8677                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8678                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8679
8680                                                                                                                                                                                                                                 player[i].RagDoll(0);
8681                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8682                                                                                                                                                                                                                                         bonus=aimbonus;
8683                                                                                                                                                                                                                                         bonustime=0;
8684                                                                                                                                                                                                                                         bonusvalue=150;
8685                                                                                                                                                                                                                                 }
8686                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8687                                                                                                                                                                                                                                 player[k].RagDoll(0);
8688                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8689                                                                                                                                                                                                                                         bonus=aimbonus;
8690                                                                                                                                                                                                                                         bonustime=0;
8691                                                                                                                                                                                                                                         bonusvalue=150;
8692                                                                                                                                                                                                                                 }
8693                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8694
8695                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8696                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8697                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8698                                                                                                                                                                                                                                 }
8699                                                                                                                                                                                                                                 //}
8700                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8701                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8702                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8703                                                                                                                                                                                                                                 }
8704                                                                                                                                                                                                                                 //}
8705
8706                                                                                                                                                                                                                         }
8707                                                                                                                                                                                                                 }
8708                                                                                                                                                                                                                 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)){
8709                                                                                                                                                                                                                         //If bumped
8710                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8711                                                                                                                                                                                                                                 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)){
8712                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8713                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8714                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8715                                                                                                                                                                                                                                         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);
8716                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8717                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8718                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8719                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8720                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8721                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8722                                                                                                                                                                                                                                                                 player[k].target=0;
8723                                                                                                                                                                                                                                                         }
8724                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8725                                                                                                                                                                                                                                                         {
8726                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8727                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8728                                                                                                                                                                                                                                                                 player[k].target=0;
8729                                                                                                                                                                                                                                                         }
8730                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8731                                                                                                                                                                                                                                                 }
8732                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8733                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8734                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8735                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8736                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8737                                                                                                                                                                                                                                                                         player[i].target=0;
8738                                                                                                                                                                                                                                                                 }
8739                                                                                                                                                                                                                                                                 else
8740                                                                                                                                                                                                                                                                 {
8741                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8742                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8743                                                                                                                                                                                                                                                                         player[i].target=0;
8744                                                                                                                                                                                                                                                                 }
8745                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8746                                                                                                                                                                                                                                                         }
8747                                                                                                                                                                                                                                 }
8748                                                                                                                                                                                                                                 if(hostile){
8749                                                                                                                                                                                                                                         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){
8750                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8751                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8752                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8753                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8754                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8755                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8756                                                                                                                                                                                                                                                 player[k].lastcollide=1;        
8757                                                                                                                                                                                                                                                 if(k==0){
8758                                                                                                                                                                                                                                                         bonus=AboveBonus;
8759                                                                                                                                                                                                                                                         bonustime=0;
8760                                                                                                                                                                                                                                                         bonusvalue=50;
8761                                                                                                                                                                                                                                                 }
8762                                                                                                                                                                                                                                         }
8763                                                                                                                                                                                                                                         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){
8764                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8765                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8766                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8767                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8768                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8769                                                                                                                                                                                                                                                 player[k].RagDoll(0);   
8770                                                                                                                                                                                                                                                 player[i].lastcollide=1;        
8771                                                                                                                                                                                                                                                 if(i==0){
8772                                                                                                                                                                                                                                                         bonus=AboveBonus;
8773                                                                                                                                                                                                                                                         bonustime=0;
8774                                                                                                                                                                                                                                                         bonusvalue=50;
8775                                                                                                                                                                                                                                                 }
8776                                                                                                                                                                                                                                         }
8777                                                                                                                                                                                                                                 }
8778                                                                                                                                                                                                                         }
8779                                                                                                                                                                                                                 }
8780                                                                                                                                                                                                 }
8781                                                                                                                                                                                                 player[i].CheckKick();
8782                                                                                                                                                                                                 player[k].CheckKick();
8783                                                                                                                                                                         }
8784                                                                                                                                                                 }
8785                                                                 }
8786                                                         }
8787
8788                                                         for(k=0;k<numplayers;k++){
8789                                                                 for(i=k;i<numplayers;i++){
8790                                                                         if(i==k)i++;
8791                                                                         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))){
8792                                                                                 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)){
8793                                                                                         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)){
8794                                                                                                 player[i].victim=&player[k];
8795                                                                                                 player[i].targetanimation=jumpreversedanim;
8796                                                                                                 player[i].currentanimation=jumpreversedanim;
8797                                                                                                 player[k].currentanimation=jumpreversalanim;
8798                                                                                                 player[k].targetanimation=jumpreversalanim;
8799                                                                                                 player[i].targettilt2=0;
8800                                                                                                 player[i].currentframe=0;
8801                                                                                                 player[i].targetframe=1;
8802                                                                                                 player[k].currentframe=0;
8803                                                                                                 player[k].targetframe=1;
8804                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8805                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8806                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8807                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8808                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8809                                                                                                         player[k].currentframe=1;
8810                                                                                                         player[k].targetframe=2;
8811                                                                                                         player[i].currentframe=1;
8812                                                                                                         player[i].targetframe=2;
8813                                                                                                 }
8814                                                                                                 player[k].targettilt2=0;
8815                                                                                                 player[i].target=0;
8816                                                                                                 player[i].velocity=0;
8817                                                                                                 player[k].velocity=0;
8818                                                                                                 player[k].oldcoords=player[k].coords;
8819                                                                                                 player[i].coords=player[k].coords;
8820                                                                                                 player[k].targetrotation=player[i].targetrotation;
8821                                                                                                 player[k].rotation=player[i].targetrotation;
8822                                                                                                 player[k].victim=&player[i];
8823                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8824                                                                                         }
8825                                                                                         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)){
8826                                                                                                 player[k].victim=&player[i];
8827                                                                                                 player[k].targetanimation=jumpreversedanim;
8828                                                                                                 player[k].currentanimation=jumpreversedanim;
8829                                                                                                 player[i].currentanimation=jumpreversalanim;
8830                                                                                                 player[i].targetanimation=jumpreversalanim;
8831                                                                                                 player[k].targettilt2=0;
8832                                                                                                 player[i].targettilt2=0;
8833                                                                                                 player[k].currentframe=0;
8834                                                                                                 player[k].targetframe=1;
8835                                                                                                 player[i].currentframe=0;
8836                                                                                                 player[i].targetframe=1;
8837                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8838                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8839                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8840                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8841                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8842                                                                                                         player[k].currentframe=1;
8843                                                                                                         player[k].targetframe=2;
8844                                                                                                         player[i].currentframe=1;
8845                                                                                                         player[i].targetframe=2;
8846                                                                                                 }
8847                                                                                                 player[k].target=0;
8848                                                                                                 player[k].velocity=0;
8849                                                                                                 player[i].velocity=0;
8850                                                                                                 player[i].oldcoords=player[i].coords;
8851                                                                                                 player[k].coords=player[i].coords;
8852                                                                                                 player[i].targetrotation=player[k].targetrotation;
8853                                                                                                 player[i].rotation=player[k].targetrotation;
8854                                                                                                 player[i].victim=&player[k];
8855                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8856                                                                                         }
8857                                                                                 }
8858                                                                         }
8859                                                                 }
8860                                                         }
8861
8862                                                         for(k=0;k<numplayers;k++)
8863                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8864
8865
8866                                                         //pile
8867                                                         /*
8868                                                         XYZ tempdiff;
8869                                                         XYZ tempoldpos;
8870                                                         XYZ temp1,temp2;
8871                                                         bool isgood;
8872                                                         static float checkdelay;
8873                                                         checkdelay-=multiplier;
8874                                                         int m;
8875                                                         static bool checkedcoll[maxplayers][maxplayers];
8876                                                         static bool above[maxplayers];
8877
8878                                                         for(i=0;i<maxplayers;i++){
8879                                                         for(j=0;j<maxplayers;j++){
8880                                                         checkedcoll[i][j]=0;
8881                                                         }
8882                                                         }
8883
8884                                                         if(numplayers>1&&checkdelay<=0){
8885                                                         checkdelay=.015;
8886                                                         for(k=0;k<numplayers;k++){
8887                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8888
8889                                                         for(i=k;i<numplayers;i++){
8890                                                         if(i==k)i++;
8891                                                         if(i<numplayers)
8892                                                         if(!checkedcoll[i][k]){
8893                                                         checkedcoll[i][k]=1;
8894                                                         checkedcoll[k][i]=1;
8895                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8896                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8897                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8898                                                         if(player[i].coords.y>player[k].coords.y-3)
8899                                                         if(player[i].coords.y<player[k].coords.y+3)
8900                                                         if(player[i].coords.x>player[k].coords.x-3)
8901                                                         if(player[i].coords.x<player[k].coords.x+3)
8902                                                         if(player[i].coords.z>player[k].coords.z-3)
8903                                                         if(player[i].coords.z<player[k].coords.z+3)
8904                                                         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)){
8905                                                         int stuck,moving;
8906                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8907                                                         stuck=i;
8908                                                         moving=k;
8909                                                         }
8910                                                         else
8911                                                         {
8912                                                         moving=i;
8913                                                         stuck=k;
8914                                                         }
8915                                                         isgood=1;
8916
8917                                                         if(isgood){
8918                                                         above[moving]=stuck;
8919                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8920                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8921                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8922                                                         {
8923                                                         player[moving].skeleton.joints[l].position.y+=.003;
8924                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8925
8926                                                         }
8927                                                         }
8928                                                         }
8929                                                         }
8930                                                         }
8931                                                         }
8932                                                         }
8933                                                         }
8934                                                         }
8935
8936                                                         */
8937
8938                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
8939                                                                 texturesizetogglekeydown=0;
8940                                                         }
8941
8942                                                         for(k=0;k<numplayers;k++){
8943                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8944                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8945                                                                                 player[k].DoDamage(1000);
8946                                                                         }
8947                                                                 }
8948                                                         }
8949
8950                                                         static bool respawnkeydown;
8951                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
8952                                                                 targetlevel=whichlevel;
8953                                                                 loading=1;
8954                                                                 leveltime=5;
8955                                                         }
8956                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
8957                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
8958
8959
8960
8961
8962                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
8963                                                                 targetlevel++;
8964                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
8965                                                                 loading=1;
8966                                                                 leveltime=5;
8967                                                                 slomotogglekeydown=1;
8968                                                         }
8969
8970                                                         /*
8971                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
8972                                                         //Respawn
8973                                                         FSOUND_SetPaused(channels[whooshsound], TRUE);
8974                                                         changedelay=0;
8975                                                         for(k=0;k<numplayers;k++){
8976                                                         player[k].dead=0;
8977                                                         player[k].damage=0;
8978                                                         player[k].permanentdamage=0;
8979                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
8980                                                         player[k].aitype=passivetype;
8981                                                         }
8982                                                         player[0].aitype=playercontrolled;
8983                                                         }
8984                                                         */
8985
8986                                                         static bool movekey;
8987                                                         static bool connected;
8988                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
8989                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
8990                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
8991                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
8992                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
8993                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
8994
8995                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
8996
8997                 for(int i=0;i<numplayers;i++){  
8998                                                                 if(!player[i].skeleton.free){
8999                                                                         oldtargetrotation=player[i].targetrotation;
9000                                                                         if(i==0&&indialogue==-1){
9001                                                                                 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){
9002                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
9003                                                                                         if(cameramode)player[0].targetrotation=0;
9004                                                                                 }
9005
9006                                                                                 facing=0;
9007                                                                                 facing.z=-1;
9008
9009                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9010                                                                                 if(cameramode){facing=flatfacing;}
9011                                                                                 else{
9012                                                                                         facing=DoRotation(facing,-rotation2,0,0);
9013                                                                                         facing=DoRotation(facing,0,0-rotation,0);
9014                                                                                 }
9015
9016                                                                                 player[0].lookrotation=-rotation;
9017
9018                                                                                 player[i].targetheadrotation=rotation;
9019                                                                                 player[i].targetheadrotation2=rotation2;                        
9020                                                                         }
9021                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
9022                                                                                 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){
9023                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
9024                                                                                 }
9025
9026                                                                                 facing=0;
9027                                                                                 facing.z=-1;
9028
9029                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9030
9031                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
9032                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
9033
9034                                                                                 player[i].targetheadrotation=player[i].lookrotation;
9035                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;                  
9036                                                                         }
9037                                                                         if(indialogue!=-1){
9038                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
9039                                                                                 Normalise(&rotatetarget);
9040                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
9041                                                                                 player[i].targetheadrotation*=360/6.28;
9042                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9043
9044                                                                                 player[i].targetheadrotation*=-1;
9045                                                                                 player[i].targetheadrotation+=180;
9046                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9047                                                                         }
9048
9049                                                                         bool pause;
9050
9051                                                                         if(leveltime<.5)
9052                                                                                 numenvsounds=0;
9053
9054                                                                         player[i].avoidsomething=0;
9055
9056                                                                         for(j=0;j<objects.numobjects;j++){
9057                                                                                 if(objects.onfire[j]){
9058                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
9059                                                                                         {
9060                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
9061                                                                                                         player[i].collided=0;
9062                                                                                                         player[i].avoidcollided=1;
9063                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9064                                                                                                                 player[i].avoidwhere=objects.position[j];
9065                                                                                                 }
9066                                                                                         }
9067                                                                                 }
9068                                                                         }
9069
9070                                                                         //Add avoidwhere to players
9071
9072                                                                         for(j=0;j<numplayers;j++){
9073                                                                                 if(player[j].onfire){
9074                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
9075                                                                                         {
9076                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
9077                                                                                                         player[i].collided=0;
9078                                                                                                         player[i].avoidcollided=1;
9079                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9080                                                                                                                 player[i].avoidwhere=objects.position[j];
9081                                                                                                 }
9082                                                                                         }
9083                                                                                 }
9084                                                                         }
9085
9086                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
9087                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
9088                                                                                 player[i].jumpclimb=0;
9089                                                                                 //AI
9090                                                                                 if(editorenabled)player[i].stunned=1;
9091
9092                                                                                 player[i].pause=0;
9093                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
9094                                                                                 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;
9095
9096                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
9097                                                                                 player[i].forwardkeydown=0;
9098                                                                                 player[i].leftkeydown=0;
9099                                                                                 player[i].backkeydown=0;
9100                                                                                 player[i].rightkeydown=0;
9101                                                                                 player[i].crouchkeydown=0;
9102                                                                                 player[i].attackkeydown=0;
9103                                                                                 player[i].jumpkeydown=0;
9104                                                                                 player[i].throwkeydown=0;
9105                                                                                 }*/
9106
9107                                                                                 if(player[i].aitype==pathfindtype){
9108                                                                                         if(player[i].finalpathfindpoint==-1){
9109                                                                                                 float closestdistance;
9110                                                                                                 float tempdist;
9111                                                                                                 int closest;
9112                                                                                                 XYZ colpoint;
9113                                                                                                 closest=-1;
9114                                                                                                 closestdistance=-1;
9115                                                                                                 for(j=0;j<numpathpoints;j++){
9116                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
9117                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
9118                                                                                                                 closest=j;
9119                                                                                                                 player[i].finaltarget=pathpoint[j];
9120                                                                                                         }
9121                                                                                                 }
9122                                                                                                 player[i].finalpathfindpoint=closest;
9123                                                                                                 for(j=0;j<numpathpoints;j++){
9124                                                                                                         if(numpathpointconnect[j])
9125                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9126                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9127                                                                                                                         if(tempdist*tempdist<closestdistance){
9128                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9129                                                                                                                                         closestdistance=tempdist*tempdist;
9130                                                                                                                                         closest=j;
9131                                                                                                                                         player[i].finaltarget=colpoint;
9132                                                                                                                                 }
9133                                                                                                                         }
9134                                                                                                                 }
9135                                                                                                 }
9136                                                                                                 player[i].finalpathfindpoint=closest;
9137
9138                                                                                         }
9139                                                                                         if(player[i].targetpathfindpoint==-1){
9140                                                                                                 float closestdistance;
9141                                                                                                 float tempdist;
9142                                                                                                 int closest;
9143                                                                                                 XYZ colpoint;
9144                                                                                                 closest=-1;
9145                                                                                                 closestdistance=-1;
9146                                                                                                 if(player[i].lastpathfindpoint==-1){
9147                                                                                                         for(j=0;j<numpathpoints;j++){
9148                                                                                                                 if(j!=player[i].lastpathfindpoint)
9149                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
9150                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
9151                                                                                                                                 closest=j;
9152                                                                                                                         }
9153                                                                                                         }
9154                                                                                                         player[i].targetpathfindpoint=closest;
9155                                                                                                         for(j=0;j<numpathpoints;j++){
9156                                                                                                                 if(j!=player[i].lastpathfindpoint)
9157                                                                                                                         if(numpathpointconnect[j])
9158                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9159                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9160                                                                                                                                         if(tempdist*tempdist<closestdistance){
9161                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9162                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
9163                                                                                                                                                         closestdistance=tempdist*tempdist;
9164                                                                                                                                                         closest=j;
9165                                                                                                                                                         //}
9166                                                                                                                                                 }
9167                                                                                                                                         }
9168                                                                                                                                 }
9169                                                                                                         }
9170                                                                                                         player[i].targetpathfindpoint=closest;
9171                                                                                                 }
9172                                                                                                 else
9173                                                                                                 {
9174                                                                                                         for(j=0;j<numpathpoints;j++){
9175                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
9176                                                                                                                 {
9177                                                                                                                         connected=0;
9178                                                                                                                         if(numpathpointconnect[j])
9179                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9180                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
9181                                                                                                                                 }
9182                                                                                                                                 if(!connected)
9183                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
9184                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
9185                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
9186                                                                                                                                                 }
9187                                                                                                                                                 if(connected){
9188                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
9189                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
9190                                                                                                                                                                 closestdistance=tempdist;
9191                                                                                                                                                                 closest=j;
9192                                                                                                                                                         }
9193                                                                                                                                                 }
9194                                                                                                                 }
9195                                                                                                         }
9196                                                                                                         player[i].targetpathfindpoint=closest;
9197                                                                                                 }
9198                                                                                         }
9199                                                                                         player[i].losupdatedelay-=multiplier;
9200
9201                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
9202                                                                                         Normalise(&rotatetarget);
9203                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9204                                                                                         player[i].targetrotation*=360/6.28;
9205                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9206                                                                                         player[i].lookrotation=player[i].targetrotation;
9207                                                                                         //player[i].aiupdatedelay=.05;
9208
9209                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
9210                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9211                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9212                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9213                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
9214                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9215                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9216                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9217                                                                                                 player[i].targetpathfindpoint=-1;
9218                                                                                         }
9219                                                                                         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){
9220                                                                                                 player[i].aitype=passivetype;
9221                                                                                         }
9222
9223                                                                                         player[i].forwardkeydown=1;
9224                                                                                         player[i].leftkeydown=0;
9225                                                                                         player[i].backkeydown=0;
9226                                                                                         player[i].rightkeydown=0;
9227                                                                                         player[i].crouchkeydown=0;
9228                                                                                         player[i].attackkeydown=0;
9229                                                                                         player[i].throwkeydown=0;
9230
9231                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9232
9233                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9234                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9235
9236                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9237                                                                                                 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))
9238                                                                                                         player[i].aitype=attacktypecutoff;
9239                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9240                                                                                                         player[i].aitype=attacktypecutoff;
9241
9242                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9243                                                                                                         player[i].losupdatedelay=.2;
9244                                                                                                         for(j=0;j<numplayers;j++){
9245                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9246                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9247                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9248                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9249                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9250                                                                                                                                                         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)){
9251                                                                                                                                                                 player[i].aitype=searchtype;
9252                                                                                                                                                                 player[i].lastchecktime=12;
9253                                                                                                                                                                 player[i].lastseen=player[j].coords;
9254                                                                                                                                                                 player[i].lastseentime=12;
9255                                                                                                                                                         }
9256                                                                                                                 }
9257                                                                                                         }
9258                                                                                                 }
9259                                                                                         }       
9260                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9261                                                                                                 if(player[i].creature!=wolftype){
9262                                                                                                         player[i].stunned=.6;
9263                                                                                                         player[i].surprised=.6;
9264                                                                                                 }
9265                                                                                         }
9266                                                                                 }
9267
9268                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9269                                                                                         player[i].howactive=typeactive;
9270                                                                                 }
9271
9272                                                                                 if(player[i].aitype==passivetype){
9273                                                                                         player[i].aiupdatedelay-=multiplier;
9274                                                                                         player[i].losupdatedelay-=multiplier;
9275                                                                                         player[i].lastseentime+=multiplier;
9276                                                                                         player[i].pausetime-=multiplier;
9277                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9278
9279                                                                                         if(player[i].aiupdatedelay<0){
9280                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9281                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9282                                                                                                         Normalise(&rotatetarget);
9283                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9284                                                                                                         player[i].targetrotation*=360/6.28;
9285                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9286                                                                                                         player[i].lookrotation=player[i].targetrotation;
9287                                                                                                         player[i].aiupdatedelay=.05;
9288
9289                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9290                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9291                                                                                                                 player[i].waypoint++;
9292                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9293
9294                                                                                                         }
9295                                                                                                 }                       
9296
9297                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9298                                                                                                 else player[i].forwardkeydown=0;
9299                                                                                                 player[i].leftkeydown=0;
9300                                                                                                 player[i].backkeydown=0;
9301                                                                                                 player[i].rightkeydown=0;
9302                                                                                                 player[i].crouchkeydown=0;
9303                                                                                                 player[i].attackkeydown=0;
9304                                                                                                 player[i].throwkeydown=0;
9305
9306                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9307                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9308                                                                                                         else{
9309                                                                                                                 XYZ leftpos,rightpos;
9310                                                                                                                 float leftdist,rightdist;
9311                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9312                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9313                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9314                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9315                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9316                                                                                                                 else player[i].targetrotation-=90;
9317                                                                                                         }
9318                                                                                                 }
9319                                                                                         }                       
9320                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9321                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9322
9323
9324                                                                                         if(!editorenabled){
9325                                                                                                 if(player[i].howactive<typesleeping)
9326                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9327                                                                                                                 for(j=0;j<numenvsounds;j++){
9328                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9329                                                                                                                                 player[i].aitype=attacktypecutoff;
9330                                                                                                                         }
9331                                                                                                                 }
9332
9333                                                                                                                 if(player[i].howactive==typesleeping)
9334                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9335                                                                                                                                 for(j=0;j<numenvsounds;j++){
9336                                                                                                                                         if(envsoundvol[j]>14)
9337                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9338                                                                                                                                                         player[i].aitype=attacktypecutoff;
9339                                                                                                                                                 }
9340                                                                                                                                 }
9341
9342                                                                                                                                 if(player[i].aitype!=passivetype){
9343                                                                                                                                         if(player[i].howactive==typesleeping){
9344                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9345                                                                                                                                                 player[i].targetframe=0;
9346                                                                                                                                                 player[i].target=0;
9347                                                                                                                                         }
9348
9349                                                                                                                                         player[i].howactive=typeactive;
9350                                                                                                                                 }
9351                                                                                         }                       
9352
9353                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9354                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9355                                                                                                         player[i].aitype=attacktypecutoff;
9356                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9357                                                                                                         player[i].aitype=attacktypecutoff;
9358
9359                                                                                                 if(player[i].creature==wolftype){
9360                                                                                                         XYZ windsmell;
9361                                                                                                         float smelldistance;
9362                                                                                                         smelldistance=50;
9363                                                                                                         for(j=0;j<numplayers;j++){
9364                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9365                                                                                                                         if(j==0&&player[j].num_weapons>0){
9366                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9367                                                                                                                                 if(player[j].num_weapons==2)
9368                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9369                                                                                                                         }
9370                                                                                                                         if(j!=0){
9371                                                                                                                                 smelldistance=100;
9372                                                                                                                         }
9373                                                                                                                         windsmell=windvector;
9374                                                                                                                         Normalise(&windsmell);
9375                                                                                                                         windsmell=windsmell*2+player[j].coords;
9376                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9377                                                                                                                                 player[i].aitype=attacktypecutoff;
9378                                                                                                                 }
9379                                                                                                         }
9380                                                                                                 }
9381
9382                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9383                                                                                                         player[i].losupdatedelay=.2;
9384                                                                                                         for(j=0;j<numplayers;j++){
9385                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9386                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9387                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9388                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9389                                                                                                                                                 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)){
9390                                                                                                                                                         player[i].lastseentime-=.2;
9391                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9392                                                                                                                                                         else player[i].lastseentime-=.6;                                                                
9393                                                                                                                                                 }
9394                                                                                                                                                 if(player[i].lastseentime<=0){
9395                                                                                                                                                         player[i].aitype=searchtype;
9396                                                                                                                                                         player[i].lastchecktime=12;
9397                                                                                                                                                         player[i].lastseen=player[j].coords;
9398                                                                                                                                                         player[i].lastseentime=12;
9399                                                                                                                                                 }
9400                                                                                                                 }
9401                                                                                                         }
9402                                                                                                 }
9403                                                                                         }
9404                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9405                                                                                                 if(player[i].creature!=wolftype){
9406                                                                                                         player[i].stunned=.6;
9407                                                                                                         player[i].surprised=.6;
9408                                                                                                 }
9409                                                                                                 if(player[i].creature==wolftype){
9410                                                                                                         player[i].stunned=.47;
9411                                                                                                         player[i].surprised=.47;
9412                                                                                                 }
9413                                                                                                 numseen++;
9414                                                                                         }
9415                                                                                 }               
9416
9417                                                                                 if(player[i].aitype==searchtype){
9418                                                                                         player[i].aiupdatedelay-=multiplier;
9419                                                                                         player[i].losupdatedelay-=multiplier;
9420                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9421                                                                                         player[i].lastchecktime-=multiplier;
9422
9423                                                                                         if(player[i].isRun()&&!player[i].onground){
9424                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9425                                                                                                         test2=player[i].coords+player[i].facing;
9426                                                                                                         test2.y+=5;
9427                                                                                                         test=player[i].coords+player[i].facing;
9428                                                                                                         test.y-=10;
9429                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9430                                                                                                         if(j==-1)j=checkcollide(test2,test);
9431                                                                                                         if(j==-1){
9432                                                                                                                 player[i].velocity=0;
9433                                                                                                                 player[i].targetanimation=player[i].getStop();
9434                                                                                                                 player[i].targetframe=0;
9435                                                                                                                 player[i].target=0;
9436                                                                                                                 player[i].targetrotation+=180;
9437                                                                                                                 player[i].stunned=.5;
9438                                                                                                                 //player[i].aitype=passivetype;
9439                                                                                                                 player[i].aitype=pathfindtype;
9440                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9441                                                                                                                 player[i].finalpathfindpoint=-1;
9442                                                                                                                 player[i].targetpathfindpoint=-1;
9443                                                                                                                 player[i].lastpathfindpoint=-1;
9444                                                                                                                 player[i].lastpathfindpoint2=-1;
9445                                                                                                                 player[i].lastpathfindpoint3=-1;
9446                                                                                                                 player[i].lastpathfindpoint4=-1;
9447                                                                                                         }
9448                                                                                                         else player[i].laststanding=j;
9449                                                                                                 }
9450                                                                                         }       
9451                                                                                         if(player[i].aiupdatedelay<0){
9452                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9453                                                                                                 Normalise(&rotatetarget);
9454                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9455                                                                                                 player[i].targetrotation*=360/6.28;
9456                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9457                                                                                                 player[i].lookrotation=player[i].targetrotation;
9458                                                                                                 player[i].aiupdatedelay=.05;
9459                                                                                                 player[i].forwardkeydown=1;
9460
9461                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9462                                                                                                         player[i].forwardkeydown=0;
9463                                                                                                         player[i].aiupdatedelay=1;
9464                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9465                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9466                                                                                                         player[i].lastchecktime=3;
9467                                                                                                 }
9468
9469                                                                                                 player[i].leftkeydown=0;
9470                                                                                                 player[i].backkeydown=0;
9471                                                                                                 player[i].rightkeydown=0;
9472                                                                                                 player[i].crouchkeydown=0;
9473                                                                                                 player[i].attackkeydown=0;
9474                                                                                                 player[i].throwkeydown=0;
9475
9476                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9477                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9478                                                                                                         else{
9479                                                                                                                 XYZ leftpos,rightpos;
9480                                                                                                                 float leftdist,rightdist;
9481                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9482                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9483                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9484                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9485                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9486                                                                                                                 else player[i].targetrotation-=90;
9487                                                                                                         }
9488                                                                                                 }
9489                                                                                         }
9490                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9491                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9492
9493                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9494                                                                                                 for(j=0;j<numenvsounds;j++){
9495                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9496                                                                                                                 player[i].aitype=attacktypecutoff;
9497                                                                                                         }
9498                                                                                                 }
9499
9500                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9501                                                                                                         player[i].losupdatedelay=.2;
9502                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9503                                                                                                         {player[i].aitype=attacktypecutoff;
9504                                                                                                         player[i].lastseentime=1;}
9505                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9506                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9507                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9508                                                                                                                                 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)){
9509                                                                                                                                         player[i].aitype=attacktypecutoff;
9510                                                                                                                                         player[i].lastseentime=1;
9511                                                                                                                                 }
9512                                                                                                 }
9513                                                                                                 if(player[i].lastseentime<0){
9514                                                                                                         //player[i].aitype=passivetype;
9515                                                                                                         numescaped++;
9516                                                                                                         player[i].aitype=pathfindtype;
9517                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9518                                                                                                         player[i].finalpathfindpoint=-1;
9519                                                                                                         player[i].targetpathfindpoint=-1;
9520                                                                                                         player[i].lastpathfindpoint=-1;
9521                                                                                                         player[i].lastpathfindpoint2=-1;
9522                                                                                                         player[i].lastpathfindpoint3=-1;
9523                                                                                                         player[i].lastpathfindpoint4=-1;
9524                                                                                                 }
9525                                                                                 }
9526
9527                                                                                 if(player[i].aitype!=gethelptype){
9528                                                                                         player[i].runninghowlong=0;
9529                                                                                 }
9530
9531                                                                                 if(player[i].aitype==gethelptype){
9532                                                                                         player[i].runninghowlong+=multiplier;
9533                                                                                         player[i].aiupdatedelay-=multiplier;
9534
9535                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9536                                                                                                 player[i].aiupdatedelay=.2;
9537
9538                                                                                                 int closest;
9539                                                                                                 float closestdist;
9540                                                                                                 closest=-1;
9541                                                                                                 closestdist=-1;
9542                                                                                                 float distance;
9543
9544                                                                                                 if(!player[i].ally){
9545                                                                                                         for(j=0;j<numplayers;j++){
9546                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9547                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9548                                                                                                                         if(closestdist==-1||distance<closestdist){
9549                                                                                                                                 closestdist=distance;
9550                                                                                                                                 closest=j;
9551                                                                                                                         }
9552                                                                                                                         closest=j;
9553                                                                                                                 }
9554                                                                                                         }
9555                                                                                                         if(closest!=-1)player[i].ally=closest;
9556                                                                                                         else player[i].ally=0;
9557                                                                                                         player[i].lastseen=player[0].coords;
9558                                                                                                         player[i].lastseentime=12;
9559                                                                                                 }
9560
9561
9562                                                                                                 player[i].lastchecktime=12;
9563                                                                                                 //player[i].lastseentime-=.5;
9564
9565                                                                                                 facing=player[i].coords;
9566                                                                                                 flatfacing=player[player[i].ally].coords;
9567                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9568                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9569                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9570                                                                                                         player[i].lastseentime-=.1;
9571
9572                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9573                                                                                                         player[i].aitype=searchtype;
9574                                                                                                         player[i].lastseentime=12;
9575                                                                                                 }
9576
9577                                                                                                 if(player[i].ally>0){
9578                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9579                                                                                                         Normalise(&rotatetarget);
9580                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9581                                                                                                         player[i].targetrotation*=360/6.28;
9582                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9583                                                                                                         player[i].lookrotation=player[i].targetrotation;
9584                                                                                                         player[i].aiupdatedelay=.05;
9585                                                                                                         player[i].forwardkeydown=1;                                     
9586
9587                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9588                                                                                                                 player[i].aitype=searchtype;
9589                                                                                                                 player[i].lastseentime=12;
9590                                                                                                                 player[player[i].ally].aitype=searchtype;
9591                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9592                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9593                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9594                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9595                                                                                                                 }
9596                                                                                                         }
9597
9598                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9599                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9600                                                                                                                 else{
9601                                                                                                                         XYZ leftpos,rightpos;
9602                                                                                                                         float leftdist,rightdist;
9603                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9604                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9605                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9606                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9607                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9608                                                                                                                         else player[i].targetrotation-=90;
9609                                                                                                                 }
9610                                                                                                         }
9611                                                                                                 }
9612
9613                                                                                                 player[i].leftkeydown=0;
9614                                                                                                 player[i].backkeydown=0;
9615                                                                                                 player[i].rightkeydown=0;
9616                                                                                                 player[i].crouchkeydown=0;
9617                                                                                                 player[i].attackkeydown=0;
9618                                                                                         }
9619                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9620                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9621                                                                                 }
9622
9623                                                                                 if(player[i].aitype==getweapontype){
9624                                                                                         player[i].aiupdatedelay-=multiplier;
9625                                                                                         player[i].lastchecktime-=multiplier;
9626
9627                                                                                         if(player[i].aiupdatedelay<0){
9628                                                                                                 player[i].aiupdatedelay=.2;
9629
9630                                                                                                 int closest;
9631                                                                                                 float closestdist;
9632                                                                                                 closest=-1;
9633                                                                                                 closestdist=-1;
9634                                                                                                 float distance;
9635
9636                                                                                                 if(player[i].ally<0){
9637                                                                                                         for(j=0;j<weapons.numweapons;j++){
9638                                                                                                                 if(weapons.owner[j]==-1){
9639                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9640                                                                                                                         if(closestdist==-1||distance<closestdist){
9641                                                                                                                                 closestdist=distance;
9642                                                                                                                                 closest=j;
9643                                                                                                                         }
9644                                                                                                                         closest=j;
9645                                                                                                                 }
9646                                                                                                         }
9647                                                                                                         if(closest!=-1)player[i].ally=closest;
9648                                                                                                         else player[i].ally=-1;
9649                                                                                                 }
9650
9651                                                                                                 player[i].lastseentime=12;
9652
9653                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9654                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9655                                                                                                                 player[i].aitype=attacktypecutoff;
9656                                                                                                                 player[i].lastseentime=1;
9657                                                                                                         }                                       
9658                                                                                                         if(!player[0].dead)
9659                                                                                                                 if(player[i].ally>=0){
9660                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9661                                                                                                                                 player[i].aitype=attacktypecutoff;
9662                                                                                                                                 player[i].lastseentime=1;
9663                                                                                                                         }
9664                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9665                                                                                                                         Normalise(&rotatetarget);
9666                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9667                                                                                                                         player[i].targetrotation*=360/6.28;
9668                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9669                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9670                                                                                                                         player[i].aiupdatedelay=.05;
9671                                                                                                                         player[i].forwardkeydown=1;                                     
9672
9673
9674                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9675                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9676                                                                                                                                 else{
9677                                                                                                                                         XYZ leftpos,rightpos;
9678                                                                                                                                         float leftdist,rightdist;
9679                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9680                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9681                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9682                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9683                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9684                                                                                                                                         else player[i].targetrotation-=90;
9685                                                                                                                                 }
9686                                                                                                                         }
9687                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9688                                                                                                                         if(abs(Random()%6)){
9689                                                                                                                         player[i].crouchkeydown=1;
9690                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9691                                                                                                                         if(player[i].isRun()){
9692                                                                                                                         player[i].targetframe=0;
9693                                                                                                                         player[i].target=0;
9694                                                                                                                         player[i].targetanimation=sneakanim;
9695                                                                                                                         }
9696                                                                                                                         }
9697                                                                                                                         else player[i].forwardkeydown=0;
9698                                                                                                                         }
9699                                                                                                                         else player[i].crouchkeydown=0;
9700                                                                                                                         }
9701                                                                                                                         else player[i].crouchkeydown=0;*/
9702                                                                                                                 }
9703
9704                                                                                                                 player[i].leftkeydown=0;
9705                                                                                                                 player[i].backkeydown=0;
9706                                                                                                                 player[i].rightkeydown=0;
9707                                                                                                                 player[i].attackkeydown=0;
9708                                                                                                                 player[i].throwkeydown=1;
9709                                                                                                                 player[i].crouchkeydown=0;      
9710                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9711                                                                                                                 player[i].drawkeydown=0;
9712                                                                                         }
9713                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9714                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9715                                                                                 }
9716
9717                                                                                 if(player[i].aitype==attacktypecutoff){
9718                                                                                         player[i].aiupdatedelay-=multiplier;
9719                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9720                                                                                                 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)){
9721                                                                                                         player[i].attackkeydown=0;
9722                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9723                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9724                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9725                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9726                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9727                                                                                                                                 else player[i].targetanimation=rollanim;
9728                                                                                                                                 player[i].target=0;
9729                                                                                                                                 player[i].targetframe=0;
9730                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9731                                                                                                                                 player[i].wentforweapon=0;
9732                                                                                                                         }
9733                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9734                                                                                                                                 player[i].targetanimation=flipanim;
9735                                                                                                                                 player[i].target=0;
9736                                                                                                                                 player[i].targetframe=0;
9737                                                                                                                         }
9738                                                                                                                 }
9739                                                                                                         }
9740                                                                                                         player[i].forwardkeydown=0;
9741                                                                                                         player[i].aiupdatedelay=.02;
9742                                                                                                 }
9743                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9744                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9745                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9746                                                                                                 }
9747                                                                                                 if(player[i].wentforweapon<3)
9748                                                                                                         for(j=0;j<weapons.numweapons;j++){
9749                                                                                                                 if(player[i].creature!=wolftype)
9750                                                                                                                         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){
9751                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9752                                                                                                                                         player[i].wentforweapon++;
9753                                                                                                                                         player[i].lastchecktime=6;
9754                                                                                                                                         player[i].aitype=getweapontype;
9755                                                                                                                                         player[i].ally=-1;
9756                                                                                                                                 }
9757                                                                                                                         }
9758                                                                                                         }
9759                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9760                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9761                                                                                                                         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)))){
9762                                                                                                                                 player[i].crouchkeydown=1;
9763                                                                                                                         }
9764                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9765                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9766                                                                                                                                         test2=player[i].coords+player[i].facing;
9767                                                                                                                                         test2.y+=5;
9768                                                                                                                                         test=player[i].coords+player[i].facing;
9769                                                                                                                                         test.y-=10;
9770                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9771                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9772                                                                                                                                         if(j==-1){
9773                                                                                                                                                 player[i].velocity=0;
9774                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9775                                                                                                                                                 player[i].targetframe=0;
9776                                                                                                                                                 player[i].target=0;
9777                                                                                                                                                 player[i].targetrotation+=180;
9778                                                                                                                                                 player[i].stunned=.5;
9779                                                                                                                                                 //player[i].aitype=passivetype;
9780                                                                                                                                                 player[i].aitype=pathfindtype;
9781                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9782                                                                                                                                                 player[i].finalpathfindpoint=-1;
9783                                                                                                                                                 player[i].targetpathfindpoint=-1;
9784                                                                                                                                                 player[i].lastpathfindpoint=-1;
9785                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9786                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9787                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9788                                                                                                                                         }
9789                                                                                                                                         else player[i].laststanding=j;
9790                                                                                                                                 }
9791                                                                                                                         }
9792                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9793                                                                                                                                 player[i].aitype=pathfindtype;
9794                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9795                                                                                                                                 player[i].finalpathfindpoint=-1;
9796                                                                                                                                 player[i].targetpathfindpoint=-1;
9797                                                                                                                                 player[i].lastpathfindpoint=-1;
9798                                                                                                                                 player[i].lastpathfindpoint2=-1;
9799                                                                                                                                 player[i].lastpathfindpoint3=-1;
9800                                                                                                                                 player[i].lastpathfindpoint4=-1;
9801                                                                                                                         }       
9802                                                                                                                         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){
9803                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9804                                                                                                                                 else player[i].drawkeydown=0;
9805                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9806                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9807                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9808                                                                                                                                         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;
9809                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9810                                                                                                                                 Normalise(&rotatetarget);
9811                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9812                                                                                                                                 player[i].targetrotation*=360/6.28;
9813                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9814                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9815                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9816
9817                                                                                                                                 oldkey=player[i].forwardkeydown;
9818                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9819                                                                                                                                 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;
9820                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9821                                                                                                                                 else player[i].forwardkeydown=0;
9822                                                                                                                                 if(player[0].dead){
9823                                                                                                                                         player[i].forwardkeydown=0;
9824                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9825                                                                                                                                         if(Random()%100==0){
9826                                                                                                                                                 player[i].aitype=pathfindtype;
9827                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9828                                                                                                                                                 player[i].finalpathfindpoint=-1;
9829                                                                                                                                                 player[i].targetpathfindpoint=-1;
9830                                                                                                                                                 player[i].lastpathfindpoint=-1;
9831                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9832                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9833                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9834                                                                                                                                         }
9835                                                                                                                                 }
9836                                                                                                                                 player[i].leftkeydown=0;
9837                                                                                                                                 player[i].backkeydown=0;
9838                                                                                                                                 player[i].rightkeydown=0;
9839                                                                                                                                 player[i].crouchkeydown=0;
9840                                                                                                                                 player[i].throwkeydown=0;
9841
9842                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9843                                                                                                                                 /*for(j=0;j<numplayers;j++){
9844                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9845                                                                                                                                 player[i].crouchkeydown=1;
9846                                                                                                                                 }
9847                                                                                                                                 }*/
9848                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9849                                                                                                                                 else player[i].attackkeydown=0;
9850                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9851                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9852                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9853                                                                                                                                 player[i].attackkeydown=0;
9854                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9855                                                                                                                                 player[i].forwardkeydown=0;
9856                                                                                                                                 player[i].aiupdatedelay=.02;
9857                                                                                                                                 }*/
9858
9859                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9860                                                                                                                                         target=-2;
9861                                                                                                                                         for(j=0;j<numplayers;j++){
9862                                                                                                                                                 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)){
9863                                                                                                                                                         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))))){
9864                                                                                                                                                                 if(target>=0)target=-1;
9865                                                                                                                                                                 else target=j;
9866                                                                                                                                                         }
9867                                                                                                                                                 }
9868                                                                                                                                         }
9869                                                                                                                                         if(target>=0)player[target].Reverse();
9870                                                                                                                                 }
9871
9872                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9873                                                                                                                                 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;
9874                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9875                                                                                                                                         player[0].jumpkeydown=0;
9876                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9877                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9878                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9879
9880                                                                                                                                 if(tutoriallevel==1){
9881                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9882                                                                                                                                 }
9883
9884
9885                                                                                                                                 facing=player[i].coords;
9886                                                                                                                                 flatfacing=player[0].coords;
9887                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9888                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9889                                                                                                                                 if(player[i].occluded>=2)
9890                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9891                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9892                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9893                                                                                                                                                         player[i].aitype=searchtype;
9894                                                                                                                                                         player[i].lastchecktime=12;
9895                                                                                                                                                         player[i].lastseen=player[0].coords;
9896                                                                                                                                                         player[i].lastseentime=12;
9897                                                                                                                                                 }
9898                                                                                                                                         }
9899                                                                                                                                         else player[i].lastseentime=1;
9900                                                                                                                         }
9901                                                                                 }
9902                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9903                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9904                                                                                                 test=player[0].coords;
9905                                                                                                 test.y-=40;
9906                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9907                                                                                         }
9908                                                                                 }
9909                                                                                 // NOTE: Ask about logic of this call : NOTE
9910                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9911                                                                                         player[i].stunned>0 ||
9912                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9913                                                                                 {
9914                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9915                                                                                         player[i].targetrotation=player[i].rotation;
9916                                                                                         player[i].forwardkeydown=0;
9917                                                                                         player[i].leftkeydown=0;
9918                                                                                         player[i].backkeydown=0;
9919                                                                                         player[i].rightkeydown=0;
9920                                                                                         player[i].jumpkeydown=0;
9921                                                                                         player[i].attackkeydown=0;
9922                                                                                         player[i].crouchkeydown=0;
9923                                                                                         player[i].throwkeydown=0;
9924                                                                                 }
9925
9926
9927                                                                                 facing=0;
9928                                                                                 facing.z=-1;
9929
9930                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9931                                                                                 facing=flatfacing;
9932
9933                                                                                 if(player[i].aitype==attacktypecutoff){
9934                                                                                         rotatetarget=player[0].coords-player[i].coords;
9935                                                                                         Normalise(&rotatetarget);
9936                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9937                                                                                         player[i].targetheadrotation*=360/6.28;
9938                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9939
9940                                                                                         player[i].targetheadrotation*=-1;
9941                                                                                         player[i].targetheadrotation+=180;
9942                                                                                         //player[i].targetheadrotation2=0;
9943                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9944                                                                                 }
9945                                                                                 else if(player[i].howactive>=typesleeping){
9946                                                                                         player[i].targetheadrotation=player[i].targetrotation;
9947                                                                                         player[i].targetheadrotation2=0;
9948                                                                                 }
9949                                                                                 else {
9950                                                                                         if(player[i].interestdelay<=0){
9951                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
9952                                                                                                 player[i].headtarget=player[i].coords;
9953                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
9954                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
9955                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
9956                                                                                                 player[i].headtarget+=player[i].facing*1.5;
9957                                                                                         }
9958                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
9959                                                                                         Normalise(&rotatetarget);
9960                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9961                                                                                         player[i].targetheadrotation*=360/6.28;
9962                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9963
9964                                                                                         player[i].targetheadrotation*=-1;
9965                                                                                         player[i].targetheadrotation+=180;
9966                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9967                                                                                 }
9968                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
9969                                                                         }
9970                                                                         if(animation[player[i].targetanimation].attack==reversed){
9971                                                                                 //player[i].targetrotation=player[i].rotation;
9972                                                                                 player[i].forwardkeydown=0;
9973                                                                                 player[i].leftkeydown=0;
9974                                                                                 player[i].backkeydown=0;
9975                                                                                 player[i].rightkeydown=0;
9976                                                                                 player[i].jumpkeydown=0;
9977                                                                                 player[i].attackkeydown=0;
9978                                                                                 //player[i].crouchkeydown=0;
9979                                                                                 player[i].throwkeydown=0;
9980                                                                         }
9981
9982                                                                         if(indialogue!=-1){
9983                                                                                 player[i].forwardkeydown=0;
9984                                                                                 player[i].leftkeydown=0;
9985                                                                                 player[i].backkeydown=0;
9986                                                                                 player[i].rightkeydown=0;
9987                                                                                 player[i].jumpkeydown=0;
9988                                                                                 player[i].crouchkeydown=0;
9989                                                                                 player[i].drawkeydown=0;
9990                                                                                 player[i].throwkeydown=0;
9991                                                                         }
9992
9993                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
9994                                                                         if(player[i].collided>1)player[i].collided=1;
9995                                                                         player[i].collided-=multiplier*4;
9996                                                                         player[i].whichdirectiondelay-=multiplier;
9997                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
9998                                                                                 player[i].avoidcollided=-.3;
9999                                                                                 player[i].whichdirection=abs(Random()%2);
10000                                                                                 player[i].whichdirectiondelay=.4;
10001                                                                         }
10002                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
10003                                                                         player[i].avoidcollided-=multiplier/4;
10004                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
10005                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
10006                                                                         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;
10007
10008                                                                         if(!player[i].throwkeydown){
10009                                                                                 player[i].throwtogglekeydown=0;
10010                                                                         }
10011                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
10012                                                                                 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)){
10013                                                                                         for(j=0;j<weapons.numweapons;j++){
10014                                                                                                 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)
10015                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
10016                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
10017                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
10018                                                                                                                                 player[i].throwtogglekeydown=1;
10019                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10020                                                                                                                                 player[i].target=0;
10021                                                                                                                                 player[i].targetframe=0;
10022                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10023                                                                                                                                 Normalise(&rotatetarget);
10024                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10025                                                                                                                                 player[i].targetrotation*=360/6.28;
10026                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10027                                                                                                                                 player[i].hasvictim=0;
10028                                                                                                                         }
10029                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10030                                                                                                                                 player[i].throwtogglekeydown=1;
10031                                                                                                                                 player[i].hasvictim=0;
10032
10033                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
10034                                                                                                                                 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))
10035                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
10036                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
10037                                                                                                                                                         float gLoc[3];
10038                                                                                                                                                         float vel[3];
10039                                                                                                                                                         gLoc[0]=player[i].coords.x;
10040                                                                                                                                                         gLoc[1]=player[i].coords.y;
10041                                                                                                                                                         gLoc[2]=player[i].coords.z;
10042                                                                                                                                                         vel[0]=player[i].velocity.x;
10043                                                                                                                                                         vel[1]=player[i].velocity.y;
10044                                                                                                                                                         vel[2]=player[i].velocity.z;
10045                                                                                                                                                         if(weapons.type[j]!=staff){
10046                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10047                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10048                                                                                                                                                                 FSOUND_SetVolume(channels[knifedrawsound], 128);
10049                                                                                                                                                                 FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10050                                                                                                                                                         }
10051
10052                                                                                                                                                         player[i].weaponactive=0;
10053                                                                                                                                                         weapons.owner[j]=player[i].id;
10054                                                                                                                                                         if(player[i].num_weapons>0){
10055                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10056                                                                                                                                                         }
10057                                                                                                                                                         player[i].num_weapons++;
10058                                                                                                                                                         player[i].weaponids[0]=j;
10059                                                                                                                                                 }
10060                                                                                                                                         }
10061                                                                                                                                         //}
10062                                                                                                                         }
10063                                                                                                                 }
10064                                                                                                                 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){
10065                                                                                                                         if(!player[i].isFlip()){
10066                                                                                                                                 player[i].throwtogglekeydown=1;
10067                                                                                                                                 player[i].targetanimation=removeknifeanim;
10068                                                                                                                                 player[i].target=0;
10069                                                                                                                                 player[i].targetframe=0;
10070                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10071                                                                                                                                 Normalise(&rotatetarget);
10072                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10073                                                                                                                                 player[i].targetrotation*=360/6.28;
10074                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10075                                                                                                                         }
10076                                                                                                                         if(player[i].isFlip()){
10077                                                                                                                                 player[i].throwtogglekeydown=1;
10078                                                                                                                                 player[i].hasvictim=0;
10079
10080                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
10081                                                                                                                                         if(player[i].weaponactive==-1)
10082                                                                                                                                                 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))
10083                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
10084                                                                                                                                                                 float gLoc[3];
10085                                                                                                                                                                 float vel[3];
10086                                                                                                                                                                 gLoc[0]=player[i].coords.x;
10087                                                                                                                                                                 gLoc[1]=player[i].coords.y;
10088                                                                                                                                                                 gLoc[2]=player[i].coords.z;
10089                                                                                                                                                                 vel[0]=player[i].velocity.x;
10090                                                                                                                                                                 vel[1]=player[i].velocity.y;
10091                                                                                                                                                                 vel[2]=player[i].velocity.z;
10092                                                                                                                                                                 if(weapons.type[k]!=staff){
10093                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10094                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10095                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10096                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10097                                                                                                                                                                 }
10098
10099                                                                                                                                                                 player[i].weaponactive=0;
10100                                                                                                                                                                 weapons.owner[k]=player[i].id;
10101                                                                                                                                                                 if(player[i].num_weapons>0){
10102                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10103                                                                                                                                                                 }
10104                                                                                                                                                                 player[i].num_weapons++;
10105                                                                                                                                                                 player[i].weaponids[0]=k;
10106                                                                                                                                                         }
10107                                                                                                                                 }
10108                                                                                                                         }
10109                                                                                                                 }
10110                                                                                                         }
10111                                                                                         }
10112                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10113                                                                                                 if(numplayers>1)
10114                                                                                                         for(j=0;j<numplayers;j++){
10115                                                                                                                 if(player[i].weaponactive==-1)
10116                                                                                                                         if(j!=i)
10117                                                                                                                                 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)){
10118                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
10119                                                                                                                                                 player[i].throwtogglekeydown=1;
10120                                                                                                                                                 player[i].victim=&player[j];
10121                                                                                                                                                 player[i].hasvictim=1;
10122                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10123                                                                                                                                                 player[i].target=0;
10124                                                                                                                                                 player[i].targetframe=0;
10125                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10126                                                                                                                                                 Normalise(&rotatetarget);
10127                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10128                                                                                                                                                 player[i].targetrotation*=360/6.28;
10129                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10130                                                                                                                                         }
10131                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10132                                                                                                                                                 player[i].throwtogglekeydown=1;
10133                                                                                                                                                 player[i].victim=&player[j];
10134                                                                                                                                                 player[i].hasvictim=1;
10135                                                                                                                                                 int k = player[j].weaponids[0];
10136                                                                                                                                                 if(player[i].hasvictim){
10137                                                                                                                                                         float gLoc[3];
10138                                                                                                                                                         float vel[3];
10139                                                                                                                                                         gLoc[0]=player[i].coords.x;
10140                                                                                                                                                         gLoc[1]=player[i].coords.y;
10141                                                                                                                                                         gLoc[2]=player[i].coords.z;
10142                                                                                                                                                         vel[0]=player[i].velocity.x;
10143                                                                                                                                                         vel[1]=player[i].velocity.y;
10144                                                                                                                                                         vel[2]=player[i].velocity.z;
10145                                                                                                                                                         bool fleshstuck;
10146                                                                                                                                                         fleshstuck=0;
10147                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
10148                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10149                                                                                                                                                                         fleshstuck=1;
10150                                                                                                                                                                 }
10151                                                                                                                                                         }
10152                                                                                                                                                         if(!fleshstuck){
10153                                                                                                                                                                 if(weapons.type[k]!=staff){
10154                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
10155                                                                                                                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10156                                                                                                                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
10157                                                                                                                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
10158                                                                                                                                                                 }
10159                                                                                                                                                         }
10160                                                                                                                                                         if(fleshstuck){
10161                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, TRUE);
10162                                                                                                                                                                 FSOUND_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
10163                                                                                                                                                                 FSOUND_SetVolume(channels[fleshstabremovesound], 128);
10164                                                                                                                                                                 FSOUND_SetPaused(channels[fleshstabremovesound], FALSE);
10165                                                                                                                                                         }
10166
10167                                                                                                                                                         player[i].weaponactive=0;
10168                                                                                                                                                         if(weapons.owner[k]!=-1){
10169                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
10170                                                                                                                                                                 else player[i].victim->num_weapons=1;
10171
10172                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
10173                                                                                                                                                                 player[i].victim->skeleton.free=1;
10174                                                                                                                                                                 player[i].victim->skeleton.broken=0;
10175
10176                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
10177                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
10178                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
10179                                                                                                                                                                 }
10180
10181                                                                                                                                                                 XYZ relative;
10182                                                                                                                                                                 relative=0;
10183                                                                                                                                                                 relative.y=10;
10184                                                                                                                                                                 Normalise(&relative);
10185                                                                                                                                                                 XYZ footvel,footpoint;
10186                                                                                                                                                                 footvel=0;
10187                                                                                                                                                                 footpoint=weapons.position[k];
10188                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
10189                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10190                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
10191                                                                                                                                                                                 weapons.bloody[k]=2;
10192                                                                                                                                                                                 weapons.blooddrip[k]=5;
10193                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
10194                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
10195                                                                                                                                                                                 player[i].victim->DoDamage(2000);
10196                                                                                                                                                                         }
10197                                                                                                                                                                 }
10198                                                                                                                                                                 if(player[i].victim->num_weapons>0){
10199                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
10200                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
10201                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
10202                                                                                                                                                                 }
10203
10204                                                                                                                                                                 player[i].victim->weaponactive=-1;
10205
10206                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
10207                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
10208                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
10209                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
10210                                                                                                                                                         }
10211                                                                                                                                                         weapons.owner[k]=i;
10212                                                                                                                                                         if(player[i].num_weapons>0){
10213                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10214                                                                                                                                                         }
10215                                                                                                                                                         player[i].num_weapons++;
10216                                                                                                                                                         player[i].weaponids[0]=k;
10217                                                                                                                                                 }
10218                                                                                                                                         }
10219                                                                                                                                 }
10220                                                                                                         }
10221                                                                                         }
10222                                                                                 }
10223                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10224                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
10225                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
10226                                                                                                         if(numplayers>1)
10227                                                                                                                 for(j=0;j<numplayers;j++){
10228                                                                                                                         if(i!=j)
10229                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
10230                                                                                                                                         if(hostile)
10231                                                                                                                                                 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)){
10232                                                                                                                                                         if(!player[i].isFlip()){
10233                                                                                                                                                                 player[i].throwtogglekeydown=1;
10234                                                                                                                                                                 player[i].victim=&player[j];
10235                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10236                                                                                                                                                                 player[i].target=0;
10237                                                                                                                                                                 player[i].targetframe=0;
10238                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10239                                                                                                                                                                 Normalise(&rotatetarget);
10240                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10241                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10242                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10243
10244                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10245                                                                                                                                                         }
10246                                                                                                                                                         if(player[i].isFlip()){
10247                                                                                                                                                                 if(player[i].weaponactive!=-1){
10248                                                                                                                                                                         player[i].throwtogglekeydown=1;
10249                                                                                                                                                                         player[i].victim=&player[j];
10250                                                                                                                                                                         XYZ aim;
10251                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10252                                                                                                                                                                         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);                                                
10253                                                                                                                                                                         Normalise(&aim);
10254
10255                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10256
10257                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10258                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10259                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10260                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10261                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10262                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10263                                                                                                                                                                         player[i].num_weapons--;
10264                                                                                                                                                                         if(player[i].num_weapons){
10265                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10266                                                                                                                                                                         }
10267                                                                                                                                                                         player[i].weaponactive=-1;
10268                                                                                                                                                                 }               
10269                                                                                                                                                         }
10270                                                                                                                                                 }
10271                                                                                                                 }
10272                                                                                         }
10273                                                                                 }
10274                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10275                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10276                                                                                         {
10277                                                                                                 player[i].throwtogglekeydown=1;
10278                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10279                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10280                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10281                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10282                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10283                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10284                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10285                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10286                                                                                                 player[i].num_weapons--;
10287                                                                                                 if(player[i].num_weapons){
10288                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10289                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10290                                                                                                 }
10291
10292                                                                                                 player[i].weaponactive=-1;
10293                                                                                                 for(j=0;j<numplayers;j++){
10294                                                                                                         player[j].wentforweapon=0;
10295                                                                                                 }
10296                                                                                         }
10297                                                                                 }
10298
10299                                                                         }
10300
10301                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10302                                                                                 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)){
10303                                                                                         //Setenvironment(1-environment);
10304                                                                                         bool isgood;
10305                                                                                         isgood=1;
10306                                                                                         if(player[i].weaponactive!=-1){
10307                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10308                                                                                         }
10309                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10310                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10311                                                                                                         player[i].targetanimation=drawrightanim;
10312                                                                                                         player[i].targetframe=0;
10313                                                                                                         player[i].target=0;
10314                                                                                                         player[i].drawtogglekeydown=1;
10315                                                                                                 }
10316                                                                                                 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){
10317                                                                                                         player[i].targetanimation=drawleftanim;
10318                                                                                                         player[i].targetframe=0;
10319                                                                                                         player[i].target=0;
10320                                                                                                         player[i].drawtogglekeydown=1;
10321                                                                                                 }
10322                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10323                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10324                                                                                                         player[i].targetframe=0;
10325                                                                                                         player[i].target=0;
10326                                                                                                         player[i].drawtogglekeydown=1;
10327                                                                                                 }
10328                                                                                         }                        
10329                                                                                 }
10330                                                                                 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){
10331                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10332                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10333                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10334                                                                                                 player[i].targetframe=0;
10335                                                                                                 player[i].target=0;
10336                                                                                                 player[i].hasvictim=0;
10337                                                                                                 //player[i].attacktogglekeydown=1;
10338                                                                                         }
10339                                                                                 }
10340
10341                                                                                 if(!player[i].drawkeydown){
10342                                                                                         player[i].drawtogglekeydown=0;
10343                                                                                 }
10344
10345                                                                                 if(i==0){
10346                                                                                         absflatfacing=0;
10347                                                                                         absflatfacing.z=-1;
10348
10349                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10350                                                                                 }
10351                                                                                 else absflatfacing=flatfacing;
10352
10353                                                                                 if(indialogue!=-1){
10354                                                                                         player[i].forwardkeydown=0;
10355                                                                                         player[i].leftkeydown=0;
10356                                                                                         player[i].backkeydown=0;
10357                                                                                         player[i].rightkeydown=0;
10358                                                                                         player[i].jumpkeydown=0;
10359                                                                                         player[i].crouchkeydown=0;
10360                                                                                         player[i].drawkeydown=0;
10361                                                                                         player[i].throwkeydown=0;
10362                                                                                 }
10363                                                                                 movekey=0;
10364                                                                                 //Do controls
10365                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10366                                                                                         if(!player[i].forwardkeydown){
10367                                                                                                 player[i].forwardstogglekeydown=0;
10368                                                                                         }
10369                                                                                         if(player[i].crouchkeydown){
10370                                                                                                 //Crouch
10371                                                                                                 target=-2;
10372                                                                                                 if(i==0){
10373                                                                                                         player[i].superruntoggle=1;
10374                                                                                                         if(numplayers>1)
10375                                                                                                                 for(j=0;j<numplayers;j++){
10376                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10377                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10378                                                                                                                                         player[i].superruntoggle=0;
10379                                                                                                                                 }
10380                                                                                                                         }
10381                                                                                                                 }
10382                                                                                                 }
10383
10384                                                                                                 if(numplayers>1)
10385                                                                                                         for(j=0;j<numplayers;j++){
10386                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10387                                                                                                                         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))){
10388                                                                                                                                 if(target>=0)target=-1;
10389                                                                                                                                 else target=j;
10390                                                                                                                         }
10391                                                                                                                 }
10392                                                                                                         }
10393                                                                                                         if(target>=0)player[target].Reverse();
10394                                                                                                         player[i].lowreversaldelay=.5;
10395
10396                                                                                                         if(player[i].isIdle()){
10397                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10398                                                                                                                 player[i].target=0;
10399                                                                                                                 player[i].targetframe=0;
10400                                                                                                                 player[i].transspeed=10;
10401                                                                                                         }
10402                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10403                                                                                                                 player[i].targetanimation=rollanim;
10404                                                                                                                 player[i].target=0;
10405                                                                                                                 player[i].targetframe=0;
10406                                                                                                                 player[i].transspeed=20;
10407                                                                                                         }
10408                                                                                         }
10409                                                                                         if(!player[i].crouchkeydown){
10410                                                                                                 //Uncrouch
10411                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10412                                                                                                 target=-2;
10413                                                                                                 if(player[i].isCrouch()){
10414                                                                                                         if(numplayers>1)
10415                                                                                                                 for(j=0;j<numplayers;j++){
10416                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10417                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10418                                                                                                                                         if(target>=0)target=-1;
10419                                                                                                                                         else target=j;
10420                                                                                                                                 }
10421                                                                                                                         }
10422                                                                                                                 }
10423                                                                                                                 if(target>=0)player[target].Reverse();
10424                                                                                                                 player[i].highreversaldelay=.5;
10425
10426                                                                                                                 if(player[i].isCrouch()){                                               
10427                                                                                                                         if(!player[i].wasCrouch()){
10428                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10429                                                                                                                                 player[i].currentframe=0;
10430                                                                                                                         }
10431                                                                                                                         player[i].target=0;
10432                                                                                                                         player[i].targetanimation=player[i].getIdle();
10433                                                                                                                         player[i].targetframe=0;
10434                                                                                                                         player[i].transspeed=10;
10435                                                                                                                 }
10436                                                                                                 }
10437                                                                                                 if(player[i].targetanimation==sneakanim){
10438                                                                                                         player[i].targetanimation=player[i].getIdle();
10439                                                                                                         player[i].target=0;
10440                                                                                                         player[i].targetframe=0;
10441                                                                                                         player[i].transspeed=10;
10442                                                                                                 }
10443                                                                                         }
10444                                                                                         if(player[i].forwardkeydown){
10445                                                                                                 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)){
10446                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10447                                                                                                         else player[i].targetanimation=player[i].getRun();
10448                                                                                                         player[i].target=0;
10449                                                                                                         player[i].targetframe=0;
10450                                                                                                 }
10451                                                                                                 if(player[i].isCrouch()){
10452                                                                                                         player[i].targetanimation=sneakanim;
10453                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10454                                                                                                         player[i].targetframe=0;
10455                                                                                                 }
10456                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10457                                                                                                         player[i].targetanimation=climbanim;
10458                                                                                                         player[i].target=0;
10459                                                                                                         player[i].targetframe=1;
10460                                                                                                         player[i].jumpclimb=1;
10461                                                                                                 }
10462                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10463                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10464                                                                                                 }
10465                                                                                                 player[i].forwardstogglekeydown=1;
10466                                                                                                 movekey=1;
10467                                                                                         }
10468                                                                                         if (player[i].rightkeydown){
10469                                                                                                 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)){
10470                                                                                                         player[i].targetanimation=player[i].getRun();
10471                                                                                                         player[i].target=0;
10472                                                                                                         player[i].targetframe=0;
10473                                                                                                 }
10474                                                                                                 if(player[i].isCrouch()){
10475                                                                                                         player[i].targetanimation=sneakanim;
10476                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10477                                                                                                         player[i].targetframe=0;
10478                                                                                                 }
10479                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10480                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10481                                                                                                 }
10482                                                                                                 player[i].targetrotation-=90;
10483                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10484                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10485                                                                                                 movekey=1;
10486                                                                                         }
10487                                                                                         if ( player[i].leftkeydown){
10488                                                                                                 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)){
10489                                                                                                         player[i].targetanimation=player[i].getRun();
10490                                                                                                         player[i].target=0;
10491                                                                                                         player[i].targetframe=0;
10492                                                                                                 }
10493                                                                                                 if(player[i].isCrouch()){
10494                                                                                                         player[i].targetanimation=sneakanim;
10495                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10496                                                                                                         player[i].targetframe=0;
10497                                                                                                 }
10498                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10499                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10500                                                                                                 }
10501                                                                                                 player[i].targetrotation+=90;
10502                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10503                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10504                                                                                                 movekey=1;
10505                                                                                         }
10506                                                                                         if(player[i].backkeydown){
10507                                                                                                 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)){
10508                                                                                                         player[i].targetanimation=player[i].getRun();
10509                                                                                                         player[i].target=0;
10510                                                                                                         player[i].targetframe=0;
10511                                                                                                 }
10512                                                                                                 if(player[i].isCrouch()){
10513                                                                                                         player[i].targetanimation=sneakanim;
10514                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10515                                                                                                         player[i].targetframe=0;
10516                                                                                                 }
10517                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10518                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10519                                                                                                 }
10520                                                                                                 if(player[i].targetanimation==hanganim){
10521                                                                                                         player[i].currentanimation=jumpdownanim;
10522                                                                                                         player[i].targetanimation=jumpdownanim;
10523                                                                                                         player[i].target=0;
10524                                                                                                         player[i].currentframe=0;
10525                                                                                                         player[i].targetframe=1;
10526                                                                                                         player[i].velocity=0;
10527                                                                                                         player[i].velocity.y+=gravity;
10528                                                                                                         player[i].coords.y-=1.4;
10529                                                                                                         player[i].grabdelay=1;
10530                                                                                                 }
10531                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10532                                                                                                         player[i].targetrotation+=180;
10533                                                                                                 movekey=1;
10534                                                                                         }
10535                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10536                                                                                                 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)){
10537                                                                                                         player[i].jumpstart=0;
10538                                                                                                         player[i].targetanimation=jumpupanim;
10539                                                                                                         player[i].target=0;
10540                                                                                                         player[i].targetframe=0;
10541                                                                                                         player[i].rotation=player[i].targetrotation;
10542                                                                                                         player[i].transspeed=20;
10543                                                                                                         player[i].FootLand(0,1);
10544                                                                                                         player[i].FootLand(1,1);
10545
10546                                                                                                         facing=0;
10547                                                                                                         facing.z=-1;
10548                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10549
10550                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10551                                                                                                         if(!movekey)player[i].velocity=0;
10552
10553                                                                                                         //Dodge sweep?
10554                                                                                                         target=-2;
10555                                                                                                         if(numplayers>1)
10556                                                                                                                 for(j=0;j<numplayers;j++){
10557                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10558                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10559                                                                                                                                         if(target>=0)target=-1;
10560                                                                                                                                         else target=j;
10561                                                                                                                                 }
10562                                                                                                                         }
10563                                                                                                                 }
10564                                                                                                                 if(target>=0)player[i].velocity.y=1;
10565                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10566                                                                                                                         player[i].velocity.y=7;
10567                                                                                                                         player[i].crouchtogglekeydown=1;
10568                                                                                                                 }
10569                                                                                                                 else player[i].velocity.y=5;
10570
10571                                                                                                                 if(mousejump&&i==0&&debugmode){
10572                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10573                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10574                                                                                                                 }
10575
10576                                                                                                                 player[i].coords.y+=.2;
10577                                                                                                                 player[i].jumppower-=1;
10578
10579                                                                                                                 static float gLoc[3];
10580                                                                                                                 static float vel[3];
10581                                                                                                                 gLoc[0]=player[i].coords.x;
10582                                                                                                                 gLoc[1]=player[i].coords.y;
10583                                                                                                                 gLoc[2]=player[i].coords.z;
10584                                                                                                                 vel[0]=player[i].velocity.x;
10585                                                                                                                 vel[1]=player[i].velocity.y;
10586                                                                                                                 vel[2]=player[i].velocity.z;
10587
10588                                                                                                                 if(i==0){
10589                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, TRUE);
10590                                                                                                                         FSOUND_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10591                                                                                                                         FSOUND_SetVolume(channels[whooshsound], 128);
10592                                                                                                                         FSOUND_SetPaused(channels[whooshsound], FALSE);
10593                                                                                                                 }
10594
10595                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, TRUE);
10596                                                                                                                 FSOUND_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10597                                                                                                                 FSOUND_SetVolume(channels[jumpsound], 128);
10598                                                                                                                 FSOUND_SetPaused(channels[jumpsound], FALSE);
10599                                                                                                 }               
10600                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10601                                                                                                         player[i].targetanimation=player[i].getLanding();
10602                                                                                                         player[i].landhard=0;
10603                                                                                                         player[i].target=0;
10604                                                                                                         player[i].targetframe=2;
10605                                                                                                         player[i].jumpstart=1;
10606                                                                                                         player[i].tempdeltav=deltav;
10607                                                                                                 }               
10608                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10609                                                                                                         if(player[i].jumppower>multiplier*6){
10610                                                                                                                 player[i].velocity.y+=multiplier*6;
10611                                                                                                                 player[i].jumppower-=multiplier*6;
10612                                                                                                         }
10613                                                                                                         if(player[i].jumppower<=multiplier*6){
10614                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10615                                                                                                                 player[i].jumppower=0;
10616                                                                                                         }
10617                                                                                                 }
10618                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;           
10619                                                                                         }
10620
10621                                                                                         if(!movekey){
10622                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10623                                                                                                         player[i].targetanimation=player[i].getStop();
10624                                                                                                         player[i].target=0;
10625                                                                                                         player[i].targetframe=0;
10626                                                                                                 }
10627                                                                                                 if(player[i].targetanimation==sneakanim){
10628                                                                                                         player[i].targetanimation=player[i].getCrouch();
10629                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10630                                                                                                         player[i].targetframe=0;
10631                                                                                                 }
10632                                                                                         }
10633                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10634                                                                                                 player[i].targetanimation=player[i].getStop();
10635                                                                                                 player[i].target=0;
10636                                                                                                 player[i].targetframe=0;
10637                                                                                         }
10638                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10639                                                                                                 player[i].targetanimation=player[i].getStop();
10640                                                                                                 player[i].target=0;
10641                                                                                                 player[i].targetframe=0;
10642                                                                                         }
10643                                                                                 }
10644                                                                 }
10645                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10646                                                         }
10647
10648                                                         //Rotation
10649                                                         for(k=0;k<numplayers;k++){
10650                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10651                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10652                                                                         else player[k].rotation+=360;
10653                                                                 }
10654
10655                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10656                                                                         player[k].targetanimation=player[k].getStop();
10657                                                                         player[k].targetframe=0;
10658                                                                         player[k].target=0;
10659                                                                 }
10660
10661                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10662                                                                         player[k].targettilt=0;
10663                                                                 }
10664                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10665                                                                         player[k].targettilt=0;
10666                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10667                                                                         player[k].jumppower+=multiplier*7;
10668                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10669                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10670                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10671                                                                 }
10672
10673                                                                 if(player[k].isRun()){
10674                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10675                                                                 }
10676
10677                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10678                                                                 else if(player[k].tilt>player[k].targettilt){
10679                                                                         player[k].tilt-=multiplier*150;
10680                                                                 }
10681                                                                 else if(player[k].tilt<player[k].targettilt){
10682                                                                         player[k].tilt+=multiplier*150;
10683                                                                 }
10684
10685                                                                 player[k].grabdelay-=multiplier;
10686                                                         }
10687
10688                                                         for(k=0;k<numplayers;k++){
10689                                                                 player[k].DoAnimations();
10690                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10691                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10692                                                         }
10693
10694                                                         objects.DoStuff();
10695                                                         /*
10696                                                         player[0].righthandmorphstart=0;
10697                                                         player[0].righthandmorphend=1;
10698                                                         player[0].lefthandmorphstart=0;
10699                                                         player[0].lefthandmorphend=1;
10700                                                         player[0].headmorphstart=0;
10701                                                         player[0].headmorphend=2;*/
10702
10703                                                         /*
10704                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10705                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10706                                                         player[0].righthandmorphend=1;
10707                                                         player[0].targetrighthandmorphness=1;
10708
10709                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10710                                                         player[0].lefthandmorphend=0;
10711                                                         player[0].targetlefthandmorphness=1;
10712
10713                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10714                                                         player[0].headmorphend=2;
10715                                                         player[0].targetheadmorphness=1;
10716                                                         }
10717                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10718                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10719                                                         player[0].righthandmorphend=0;
10720                                                         player[0].targetrighthandmorphness=1;
10721
10722                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10723                                                         player[0].lefthandmorphend=1;
10724                                                         player[0].targetlefthandmorphness=1;
10725
10726                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10727                                                         player[0].headmorphend=0;
10728                                                         player[0].targetheadmorphness=1;
10729                                                         }
10730                                                         */
10731                                                         if(numenvsounds!=0)
10732                                                                 for(j=numenvsounds-1;j>=0;j--){
10733                                                                         envsoundlife[j]-=multiplier;
10734                                                                         if(envsoundlife[j]<0){
10735                                                                                 numenvsounds--;
10736                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10737                                                                                 envsound[j]=envsound[numenvsounds];
10738                                                                         }
10739                                                                 }
10740                                                                 if(!slomo)FSOUND_SetFrequency(FSOUND_ALL, 22050);
10741                                                                 if(slomo)FSOUND_SetFrequency(FSOUND_ALL, slomofreq);
10742
10743                                                                 if(tutoriallevel==1){
10744                                                                         XYZ temp;
10745                                                                         XYZ temp2;
10746                                                                         XYZ temp3;
10747                                                                         XYZ oldtemp;
10748                                                                         XYZ oldtemp2;
10749                                                                         temp.x=1011;
10750                                                                         temp.y=84;
10751                                                                         temp.z=491;
10752                                                                         temp2.x=1025;
10753                                                                         temp2.y=75;
10754                                                                         temp2.z=447;
10755                                                                         temp3.x=1038;
10756                                                                         temp3.y=76;
10757                                                                         temp3.z=453;
10758                                                                         oldtemp=temp;
10759                                                                         oldtemp2=temp2;
10760                                                                         if(tutorialstage>=51)
10761                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10762                                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);
10763
10764                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10765                                                                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10766                                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
10767
10768                                                                                         gameon=0;
10769                                                                                         mainmenu=5;
10770
10771                                                                                         float gLoc[3]={0,0,0};
10772                                                                                         float vel[3]={0,0,0};
10773                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10774                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10775                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10776                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10777                                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10778                                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10779
10780                                                                                         flashr=1;
10781                                                                                         flashg=0;
10782                                                                                         flashb=0;
10783                                                                                         flashamount=1;
10784                                                                                         flashdelay=1;
10785                                                                                 }
10786                                                                                 if(tutorialstage<51)
10787                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10788                                                                                                 float gLoc[3];
10789                                                                                                 float vel[3];
10790                                                                                                 gLoc[0]=player[0].coords.x;
10791                                                                                                 gLoc[1]=player[0].coords.y;
10792                                                                                                 gLoc[2]=player[0].coords.z;
10793                                                                                                 vel[0]=0;
10794                                                                                                 vel[1]=0;
10795                                                                                                 vel[2]=0;
10796                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10797                                                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10798                                                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
10799                                                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
10800
10801                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10802
10803                                                                                                 flashr=1;
10804                                                                                                 flashg=1;
10805                                                                                                 flashb=1;
10806                                                                                                 flashamount=1;
10807                                                                                                 flashdelay=1;
10808                                                                                         }
10809                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10810                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10811                                                                                                         float gLoc[3];
10812                                                                                                         float vel[3];
10813                                                                                                         gLoc[0]=player[1].coords.x;
10814                                                                                                         gLoc[1]=player[1].coords.y;
10815                                                                                                         gLoc[2]=player[1].coords.z;
10816                                                                                                         vel[0]=0;
10817                                                                                                         vel[1]=0;
10818                                                                                                         vel[2]=0;
10819                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10820                                                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10821                                                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
10822                                                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10823
10824                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10825                                                                                                                 if(Random()%2==0){
10826                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10827                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10828                                                                                                                         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;
10829                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10830                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10831                                                                                                                 }
10832                                                                                                         }
10833
10834                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10835                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10836                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10837                                                                                                                 if(Random()%2==0){
10838                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10839                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10840                                                                                                                         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;
10841                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10842                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10843                                                                                                                 }
10844                                                                                                         }
10845                                                                                                 }
10846                                                                 }
10847
10848
10849                                                                 //3d sound
10850                                                                 static float gLoc[3];
10851                                                                 gLoc[0]=viewer.x;
10852                                                                 gLoc[1]=viewer.y;
10853                                                                 gLoc[2]=viewer.z;
10854                                                                 static float vel[3];
10855                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10856                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10857                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10858
10859                                                                 //Set orientation with forward and up vectors
10860                                                                 static XYZ upvector;
10861                                                                 upvector=0;
10862                                                                 upvector.z=-1;
10863
10864                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10865                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10866
10867                                                                 facing=0;
10868                                                                 facing.z=-1;
10869                                                                 
10870                                                                 facing=DoRotation(facing,-rotation2,0,0);
10871                                                                 facing=DoRotation(facing,0,0-rotation,0);
10872                 
10873                 
10874                                                                 static float ori[6];
10875                                                                 ori[0] = -facing.x;
10876                                                                 ori[1] = facing.y;
10877                                                                 ori[2] = -facing.z;
10878                                                                 ori[3] = -upvector.x;
10879                                                                 ori[4] = upvector.y;
10880                                                                 ori[5] = -upvector.z;
10881
10882                                                                 FSOUND_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10883                                                                 FSOUND_Update();
10884
10885                                                                 oldviewer=viewer;
10886                 }
10887         }
10888
10889         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10890                 Screenshot();
10891                 freezetogglekeydown=1;
10892         }
10893 }
10894
10895 void    Game::TickOnce(){
10896         //if(!console){
10897         if(!mainmenu)
10898                 if(directing||indialogue==-1){
10899                         rotation+=deltah*.7;
10900                         if(!invertmouse)rotation2+=deltav*.7;
10901                         if(invertmouse)rotation2-=deltav*.7;
10902                         if(rotation2>90)rotation2=90;
10903                         if(rotation2<-70)rotation2=-70;
10904                 }
10905                 if(mainmenu)rotation+=multiplier*5;
10906                 if(!mainmenu&&!indemo&&!registered){
10907                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
10908                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10909                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10910                         FSOUND_SetVolume(channels[stream_music3], 256);
10911
10912                         gameon=0;
10913                         mainmenu=12;
10914
10915                         float gLoc[3]={0,0,0};
10916                         float vel[3]={0,0,0};
10917                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10918                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10919                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10920                         FSOUND_SetVolume(channels[fireendsound], 256);
10921                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10922                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10923
10924                         flashr=1;
10925                         flashg=0;
10926                         flashb=0;
10927                         flashamount=1;
10928                         flashdelay=1;
10929                 }
10930
10931                 if(tryquit==1&&!registered&&mainmenu!=12){
10932                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
10933                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
10934                         FSOUND_SetPaused(channels[stream_music3], FALSE);
10935                         FSOUND_SetVolume(channels[stream_music3], 256);
10936
10937                         gameon=0;
10938                         mainmenu=12;
10939
10940                         float gLoc[3]={0,0,0};
10941                         float vel[3]={0,0,0};
10942                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
10943                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
10944                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10945                         FSOUND_SetVolume(channels[fireendsound], 256);
10946                         FSOUND_SetPaused(channels[fireendsound], FALSE);
10947                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
10948
10949                         flashr=1;
10950                         flashg=0;
10951                         flashb=0;
10952                         flashamount=1;
10953                         flashdelay=1;
10954                 }
10955                 //}
10956 }
10957
10958 void    Game::TickOnceAfter(){
10959         static XYZ colviewer;
10960         static XYZ coltarget;
10961         static XYZ target;
10962         static XYZ col;
10963         static float brotate;
10964         static XYZ facing;
10965         static int i,j;
10966         static float changedelay;
10967         static bool alldead;
10968         static float unseendelay;
10969         static float cameraspeed;
10970
10971         if(!mainmenu){
10972
10973                 if(environment==snowyenvironment)music1=stream_music1snow;
10974                 if(environment==grassyenvironment)music1=stream_music1grass;
10975                 if(environment==desertenvironment)music1=stream_music1desert;
10976
10977                 realthreat=0;
10978
10979                 musictype=music1;
10980                 for(i=0;i<numplayers;i++){
10981                         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)){
10982                                 musictype=stream_music2;
10983                                 realthreat=1;
10984                         }
10985                 }
10986                 if(player[0].dead)musictype=stream_music3;
10987
10988
10989                 if(musictype==stream_music2){
10990                         unseendelay=1;
10991                 }
10992
10993                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
10994                         unseendelay-=multiplier;
10995                         if(unseendelay>0){
10996                                 musictype=stream_music2;
10997                         }
10998                 }
10999
11000
11001                 if(loading==2){
11002                         musictype=stream_music3;
11003                         musicvolume[2]=512;
11004                         musicvolume[0]=0;
11005                         musicvolume[1]=0;
11006                         musicvolume[3]=0;
11007                 }       
11008
11009                 if(musictoggle){                        
11010                         if(musictype!=oldmusictype&&musictype==stream_music2){
11011                                 static float gLoc[3];
11012                                 static float vel[3];
11013                                 gLoc[0]=cameraloc.x;
11014                                 gLoc[1]=cameraloc.y;
11015                                 gLoc[2]=cameraloc.z;
11016                                 vel[0]=0;
11017                                 vel[1]=0;
11018                                 vel[2]=0;
11019                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, TRUE);
11020                                 FSOUND_SetVolume(channels[alarmsound], 512);
11021                                 FSOUND_SetPaused(channels[alarmsound], FALSE);
11022
11023                         }
11024                 }
11025                 musicselected=musictype;
11026
11027                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
11028                 else musicvolume[0]-=multiplier*450;
11029                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
11030                 else musicvolume[1]-=multiplier*450;
11031                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
11032                 else musicvolume[2]-=multiplier*450;
11033                 /*
11034                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
11035                 else musicvolume[0]-=multiplier*450;
11036                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
11037                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
11038                 else musicvolume[1]-=multiplier*100;
11039                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
11040                 else musicvolume[2]-=multiplier*450;*/
11041
11042                 for(i=0;i<3;i++){
11043                         if(musicvolume[i]<0)musicvolume[i]=0;
11044                         if(musicvolume[i]>512)musicvolume[i]=512;
11045                 }
11046
11047                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
11048
11049                 if(musictoggle){                
11050                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
11051                                 PlayStreamEx( music1, strm[music1], NULL, TRUE);
11052                                 FSOUND_SetPaused(channels[music1], FALSE);
11053                         }
11054                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
11055                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, TRUE);
11056                                 FSOUND_SetPaused(channels[stream_music2], FALSE);
11057                         }
11058                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
11059                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11060                                 FSOUND_SetPaused(channels[stream_music3], FALSE);
11061                         }
11062                 }
11063
11064                 if(!musictoggle){               
11065                         FSOUND_SetPaused(channels[music1], TRUE);
11066                         FSOUND_SetPaused(channels[stream_music2], TRUE);
11067                         FSOUND_SetPaused(channels[stream_music3], TRUE);
11068
11069                         for(i=0;i<4;i++){
11070                                 oldmusicvolume[i]=0;
11071                                 musicvolume[i]=0;
11072                         }
11073                 }
11074
11075                 if(musictoggle){                
11076                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
11077                                 FSOUND_SetPaused(channels[music1], TRUE);
11078                         }
11079                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
11080                                 FSOUND_SetPaused(channels[stream_music2], TRUE);
11081                         }
11082                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
11083                                 FSOUND_SetPaused(channels[stream_music3], TRUE);
11084                         }
11085
11086                         if(musicvolume[0]!=oldmusicvolume[0]){
11087                                 FSOUND_SetVolume(channels[music1], musicvolume[0]);
11088                         }
11089                         if(musicvolume[1]!=oldmusicvolume[1]){
11090                                 FSOUND_SetVolume(channels[stream_music2], musicvolume[1]);
11091                         }
11092                         if(musicvolume[2]!=oldmusicvolume[2]){
11093                                 FSOUND_SetVolume(channels[stream_music3], musicvolume[2]);
11094                         }
11095
11096                         for(i=0;i<3;i++){
11097                                 oldmusicvolume[i]=musicvolume[i];
11098                         }
11099                 }
11100
11101                 killhotspot=2;
11102                 if(numhotspots)
11103                         for(i=0;i<numhotspots;i++){
11104                                 if(hotspottype[i]>10&&hotspottype[i]<20){
11105                                         if(player[hotspottype[i]-10].dead==0){
11106                                                 killhotspot=0;
11107                                         }
11108                                         else if(killhotspot==2)
11109                                                 killhotspot=1;
11110                                 }
11111                         }
11112                         if(killhotspot==2)killhotspot=0;
11113
11114
11115                         winhotspot=0;
11116                         if(numhotspots)
11117                                 for(i=0;i<numhotspots;i++){
11118                                         if(hotspottype[i]==-1){
11119                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
11120                                                         winhotspot=1;
11121                                         }
11122                                 }
11123
11124                                 int numalarmed=0;
11125                                 if(numplayers>1)
11126                                         for(i=1;i<numplayers;i++){              
11127                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
11128                                         }
11129                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
11130
11131                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){          
11132                                                 if(player[0].dead&&changedelay<=0){
11133                                                         changedelay=1;
11134                                                         targetlevel=whichlevel;
11135                                                 }
11136                                                 alldead=1;
11137                                                 if(numplayers>1)
11138                                                         for(i=1;i<numplayers;i++){              
11139                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
11140                                                         }
11141
11142
11143                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
11144                                                                 changedelay=1;
11145                                                                 targetlevel=whichlevel+1;
11146                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11147                                                         }
11148                                                         if(winhotspot||windialogue){
11149                                                                 changedelay=0.1;
11150                                                                 targetlevel=whichlevel+1;
11151                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11152                                                         }
11153
11154
11155                                                         if(killhotspot){
11156                                                                 changedelay=1;
11157                                                                 targetlevel=whichlevel+1;
11158                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11159                                                         }
11160
11161                                                         if(changedelay>0&&!player[0].dead&&!won){
11162                                                                 //high scores, awards, win
11163                                                                 if(campaign){
11164                                                                         won=1;
11165                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11166                                                                         accountcampaignchoicesmade[accountactive]++;
11167                                                                         accountcampaignscore[accountactive]+=bonustotal;
11168                                                                         scoreadded=1;
11169                                                                         accountcampaigntime[accountactive]+=leveltime;
11170                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
11171
11172                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11173                                                                 }
11174                                                                 else
11175                                                                 {
11176                                                                         won=1;
11177                                                                         if(!debugmode){
11178                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
11179                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;            
11180                                                                         }
11181                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11182
11183                                                                 }
11184                                                         }
11185                                         }
11186
11187                                         if(!winfreeze){
11188
11189                                                 if(leveltime<1){
11190                                                         loading=0;
11191                                                         changedelay=.1;
11192                                                         alldead=0;
11193                                                         winhotspot=0;
11194                                                         killhotspot=0;
11195                                                 }
11196
11197                                                 if(!editorenabled&&gameon&&!mainmenu){
11198                                                         if(changedelay!=-999)changedelay-=multiplier/7;
11199                                                         if(player[0].dead)targetlevel=whichlevel;
11200                                                         if(loading==2&&!campaign){
11201                                                                 flashr=1;
11202                                                                 flashg=0;
11203                                                                 flashb=0;
11204                                                                 flashamount=1;
11205                                                                 flashdelay=1;
11206                                                                 loadtime=0;
11207
11208                                                                 float gLoc[3]={0,0,0};
11209                                                                 float vel[3]={0,0,0};
11210                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11211                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11212                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11213                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11214                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
11215                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11216
11217                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
11218                                                                         startbonustotal=bonustotal;
11219                                                                 }
11220                                                                 if(!player[0].dead)Loadlevel(targetlevel);
11221                                                                 if(player[0].dead)Loadlevel(whichlevel);
11222
11223                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11224                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11225                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11226                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11227                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
11228                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11229
11230                                                                 loading=3;
11231                                                         }
11232                                                         if(loading==2&&targetlevel==whichlevel){
11233                                                                 flashr=1;
11234                                                                 flashg=0;
11235                                                                 flashb=0;
11236                                                                 flashamount=1;
11237                                                                 flashdelay=1;
11238                                                                 loadtime=0;
11239
11240                                                                 float gLoc[3]={0,0,0};
11241                                                                 float vel[3]={0,0,0};
11242                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11243                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11244                                                                 FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11245                                                                 FSOUND_SetVolume(channels[firestartsound], 256);
11246                                                                 FSOUND_SetPaused(channels[firestartsound], FALSE);
11247                                                                 FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11248
11249                                                                 for(i=0;i<255;i++){
11250                                                                         mapname[i]='\0';
11251                                                                 }
11252                                                                 mapname[0]=':';
11253                                                                 mapname[1]='D';
11254                                                                 mapname[2]='a';
11255                                                                 mapname[3]='t';
11256                                                                 mapname[4]='a';
11257                                                                 mapname[5]=':';
11258                                                                 mapname[6]='M';
11259                                                                 mapname[7]='a';
11260                                                                 mapname[8]='p';
11261                                                                 mapname[9]='s';
11262                                                                 mapname[10]=':';
11263                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
11264                                                                 Loadlevel(mapname);
11265
11266                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11267                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11268                                                                 FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11269                                                                 FSOUND_SetVolume(channels[fireendsound], 256);
11270                                                                 FSOUND_SetPaused(channels[fireendsound], FALSE);
11271                                                                 FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11272
11273                                                                 loading=3;
11274                                                         }
11275                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
11276                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
11277                                                                 if(accountprogress[accountactive]>3&&!registered){
11278                                                                         FSOUND_SetFrequency(FSOUND_ALL, 0.001);         
11279                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, TRUE);
11280                                                                         FSOUND_SetPaused(channels[stream_music3], FALSE);
11281                                                                         FSOUND_SetVolume(channels[stream_music3], 256);
11282
11283                                                                         gameon=0;
11284                                                                         mainmenu=12;
11285                                                                         accountprogress[accountactive]=3;
11286
11287                                                                         float gLoc[3]={0,0,0};
11288                                                                         float vel[3]={0,0,0};
11289                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); 
11290                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, TRUE);
11291                                                                         FSOUND_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11292                                                                         FSOUND_SetVolume(channels[fireendsound], 256);
11293                                                                         FSOUND_SetPaused(channels[fireendsound], FALSE);
11294                                                                         FSOUND_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);     
11295
11296                                                                         flashr=1;
11297                                                                         flashg=0;
11298                                                                         flashb=0;
11299                                                                         flashamount=1;
11300                                                                         flashdelay=1;
11301                                                                 }
11302                                                                 else{
11303                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
11304                                                                                 winfreeze=1;
11305                                                                                 changedelay=-999;
11306                                                                         }
11307                                                                         if(player[0].dead)loading=1;
11308                                                                 }
11309                                                         }
11310                                                 }
11311
11312                                                 if(campaign)
11313                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11314                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11315                                                                         endgame=1;
11316                                                                 }
11317                                                         }
11318                                                         else if(mainmenu==0&&winfreeze){
11319                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11320                                                                         stealthloading=1;
11321                                                                 else stealthloading=0;
11322
11323                                                                 if(!stealthloading){
11324                                                                         float gLoc[3]={0,0,0};
11325                                                                         float vel[3]={0,0,0};
11326                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);       
11327                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, TRUE);
11328                                                                         FSOUND_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11329                                                                         FSOUND_SetVolume(channels[firestartsound], 256);
11330                                                                         FSOUND_SetPaused(channels[firestartsound], FALSE);
11331                                                                         FSOUND_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);   
11332
11333                                                                         flashr=1;
11334                                                                         flashg=0;
11335                                                                         flashb=0;
11336                                                                         flashamount=1;
11337                                                                         flashdelay=1;
11338                                                                 }
11339
11340                                                                 startbonustotal=0;
11341
11342                                                                 //              ifstream ipstream(":Data:Campaigns:main.txt");  
11343                                                                 ifstream ipstream("./Data/Campaigns/main.txt"); 
11344                                                                 //campaignnumlevels=0;
11345                                                                 //accountcampaignchoicesmade[accountactive]=0;
11346                                                                 ipstream.ignore(256,':');
11347                                                                 ipstream >> campaignnumlevels;
11348                                                                 for(i=0;i<campaignnumlevels;i++){
11349                                                                         ipstream.ignore(256,':');
11350                                                                         ipstream.ignore(256,':');
11351                                                                         ipstream.ignore(256,' ');
11352                                                                         ipstream >> campaignmapname[i];
11353                                                                         ipstream.ignore(256,':');
11354                                                                         ipstream >> campaigndescription[i];
11355                                                                         for(j=0;j<256;j++){
11356                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11357                                                                         }
11358                                                                         ipstream.ignore(256,':');
11359                                                                         ipstream >> campaignchoosenext[i];
11360                                                                         ipstream.ignore(256,':');
11361                                                                         ipstream >> campaignnumnext[i];
11362                                                                         if(campaignnumnext[i])
11363                                                                                 for(j=0;j<campaignnumnext[i];j++){
11364                                                                                         ipstream.ignore(256,':');
11365                                                                                         ipstream >> campaignnextlevel[i][j];
11366                                                                                         campaignnextlevel[i][j]-=1;
11367                                                                                 }
11368                                                                                 ipstream.ignore(256,':');
11369                                                                                 ipstream >> campaignlocationx[i];
11370                                                                                 ipstream.ignore(256,':');
11371                                                                                 ipstream >> campaignlocationy[i];
11372                                                                 }
11373                                                                 ipstream.close();
11374
11375                                                                 for(i=0;i<campaignnumlevels;i++){
11376                                                                         levelvisible[i]=0;
11377                                                                         levelhighlight[i]=0;
11378                                                                 }
11379
11380
11381                                                                 for(i=0;i<campaignnumlevels;i++){
11382                                                                         levelvisible[i]=0;
11383                                                                         levelhighlight[i]=0;
11384                                                                 }
11385
11386                                                                 levelorder[0]=0;
11387                                                                 levelvisible[0]=1;
11388                                                                 if(accountcampaignchoicesmade[accountactive])
11389                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11390                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11391                                                                                 levelvisible[levelorder[i+1]]=1;
11392                                                                         }
11393                                                                         int whichlevelstart;
11394                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11395                                                                         if(whichlevelstart<0){
11396                                                                                 campaignchoicenum=1;
11397                                                                                 campaignchoicewhich[0]=0;
11398                                                                         }
11399                                                                         else
11400                                                                         {
11401                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11402                                                                                 if(campaignchoicenum)
11403                                                                                         for(i=0;i<campaignchoicenum;i++){
11404                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11405                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11406                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11407                                                                                         }
11408                                                                         }
11409
11410                                                                         loading=2;
11411                                                                         loadtime=0;
11412                                                                         targetlevel=7;
11413                                                                         //if(firstload)TickOnceAfter();
11414                                                                         if(!firstload)LoadStuff();
11415                                                                         //else {
11416                                                                         for(i=0;i<255;i++){
11417                                                                                 mapname[i]='\0';
11418                                                                         }
11419                                                                         mapname[0]=':';
11420                                                                         mapname[1]='D';
11421                                                                         mapname[2]='a';
11422                                                                         mapname[3]='t';
11423                                                                         mapname[4]='a';
11424                                                                         mapname[5]=':';
11425                                                                         mapname[6]='M';
11426                                                                         mapname[7]='a';
11427                                                                         mapname[8]='p';
11428                                                                         mapname[9]='s';
11429                                                                         mapname[10]=':';
11430
11431                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11432                                                                         //accountcampaignchoicesmade[accountactive]++;
11433
11434
11435                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11436                                                                         whichchoice=0;
11437                                                                         visibleloading=1;
11438                                                                         stillloading=1;
11439                                                                         Loadlevel(mapname);
11440                                                                         campaign=1;
11441                                                                         mainmenu=0;
11442                                                                         gameon=1;
11443                                                                         FSOUND_SetPaused(channels[stream_music3], TRUE);
11444
11445                                                                         stealthloading=0;
11446                                                         }
11447
11448                                                         if(loading==3)loading=0;
11449
11450                                         }
11451
11452                                         oldmusictype=musictype;
11453         }
11454
11455         facing=0;
11456         facing.z=-1;
11457
11458         facing=DoRotation(facing,-rotation2,0,0);
11459         facing=DoRotation(facing,0,0-rotation,0);
11460         viewerfacing=facing;
11461
11462         brotate=0;
11463         if(!cameramode){
11464                 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;
11465                 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;
11466                 target.y+=.1;
11467                 if(player[0].skeleton.free){
11468                         for(i=0;i<player[0].skeleton.num_joints;i++){
11469                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)                         
11470                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11471                         }
11472                         target.y+=.1;
11473                 }
11474                 if(player[0].skeleton.free!=2&&!autocam){
11475                         cameraspeed=20;
11476                         if(findLengthfast(&player[0].velocity)>400){
11477                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11478                         }
11479                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11480                         coltarget=target-cameraloc;
11481                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11482                         else {
11483                                 Normalise(&coltarget);
11484                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11485                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11486                         }
11487                         if(editorenabled)cameraloc=target;
11488                         cameradist+=multiplier*5;
11489                         if(cameradist>2.3)cameradist=2.3;
11490                         viewer=cameraloc-facing*cameradist;
11491                         colviewer=viewer;
11492                         coltarget=cameraloc;
11493                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11494                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11495                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11496                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11497                                         colviewer=viewer;
11498                                         coltarget=cameraloc;
11499                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;     
11500                                 }
11501                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11502                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11503                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11504                                                 colviewer=viewer;
11505                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11506                                                         viewer=colviewer;
11507                                                 }
11508                                         }
11509                                         cameradist=findDistance(&viewer,&target);
11510                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11511                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11512                                         }
11513                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11514                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11515                                         }
11516                 }
11517                 if(player[0].skeleton.free!=2&&autocam){
11518                         cameraspeed=20;
11519                         if(findLengthfast(&player[0].velocity)>400){
11520                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11521                         }
11522                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11523                         cameradist+=multiplier*5;
11524                         if(cameradist>3.3)cameradist=3.3;
11525                         coltarget=target-cameraloc;
11526                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11527                         else if(findLengthfast(&coltarget)>1)
11528                         {
11529                                 Normalise(&coltarget);
11530                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11531                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11532                         }
11533                         if(editorenabled)cameraloc=target;
11534                         viewer=cameraloc;
11535                         colviewer=viewer;
11536                         coltarget=cameraloc;
11537                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11538                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11539                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11540                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11541                                         colviewer=viewer;
11542                                         coltarget=cameraloc;
11543                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;     
11544                                 }
11545                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11546                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11547                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11548                                                 colviewer=viewer;
11549                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11550                                                         viewer=colviewer;
11551                                                 }
11552                                         }
11553                                         cameradist=findDistance(&viewer,&target);
11554                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11555                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11556                                         }
11557                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11558                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11559                                         }
11560                 }
11561                 if(camerashake>.8)camerashake=.8;
11562                 //if(woozy>10)woozy=10;
11563                 //woozy+=multiplier;
11564                 woozy+=multiplier;
11565                 if(player[0].dead)camerashake=0;
11566                 if(player[0].dead)woozy=0;
11567                 camerashake-=multiplier*2;
11568                 blackout-=multiplier*2;
11569                 //if(player[0].isCrouch())woozy-=multiplier*8;
11570                 if(camerashake<0)camerashake=0;
11571                 if(blackout<0)blackout=0;
11572                 //if(woozy<0)woozy=0;
11573                 if(camerashake){
11574                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11575                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11576                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11577                 }
11578         }
11579 }